pdh: Implement and test PdhSetCounterScaleFactor and PdhGetFormattedCounterValue.
This commit is contained in:
parent
5dfc2ead80
commit
0d516c5377
|
@ -57,7 +57,7 @@
|
|||
@ stub PdhGetDllVersion
|
||||
@ stub PdhGetFormattedCounterArrayA
|
||||
@ stub PdhGetFormattedCounterArrayW
|
||||
@ stub PdhGetFormattedCounterValue
|
||||
@ stdcall PdhGetFormattedCounterValue(ptr long ptr ptr)
|
||||
@ stub PdhGetLogFileSize
|
||||
@ stub PdhGetLogFileTypeA
|
||||
@ stub PdhGetLogFileTypeW
|
||||
|
@ -123,7 +123,7 @@
|
|||
@ stdcall PdhRemoveCounter(ptr)
|
||||
@ stub PdhSelectDataSourceA
|
||||
@ stub PdhSelectDataSourceW
|
||||
@ stub PdhSetCounterScaleFactor
|
||||
@ stdcall PdhSetCounterScaleFactor(ptr long)
|
||||
@ stub PdhSetDefaultRealTimeDataSource
|
||||
@ stub PdhSetLogSetRunID
|
||||
@ stub PdhSetQueryTimeRange
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <math.h>
|
||||
|
||||
#define NONAMELESSUNION
|
||||
#define NONAMELESSSTRUCT
|
||||
|
@ -282,6 +283,49 @@ PDH_STATUS WINAPI PdhCollectQueryData( PDH_HQUERY handle )
|
|||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* PdhGetFormattedCounterValue (PDH.@)
|
||||
*/
|
||||
PDH_STATUS WINAPI PdhGetFormattedCounterValue( PDH_HCOUNTER handle, DWORD format,
|
||||
LPDWORD type, PPDH_FMT_COUNTERVALUE value )
|
||||
{
|
||||
LONG factor;
|
||||
struct counter *counter = handle;
|
||||
|
||||
TRACE("%p %x %p %p\n", handle, format, type, value);
|
||||
|
||||
if (!value) return PDH_INVALID_ARGUMENT;
|
||||
if (!counter) return PDH_INVALID_HANDLE;
|
||||
|
||||
if (counter->status) return PDH_INVALID_DATA;
|
||||
|
||||
factor = counter->scale ? counter->scale : counter->defaultscale;
|
||||
if (format & PDH_FMT_LONG)
|
||||
{
|
||||
if (format & PDH_FMT_1000) value->u.longValue = counter->two.longvalue * 1000;
|
||||
else value->u.longValue = counter->two.longvalue * pow( 10, factor );
|
||||
}
|
||||
else if (format & PDH_FMT_LARGE)
|
||||
{
|
||||
if (format & PDH_FMT_1000) value->u.longValue = counter->two.largevalue * 1000;
|
||||
else value->u.largeValue = counter->two.largevalue * pow( 10, factor );
|
||||
}
|
||||
else if (format & PDH_FMT_DOUBLE)
|
||||
{
|
||||
if (format & PDH_FMT_1000) value->u.longValue = counter->two.doublevalue * 1000;
|
||||
else value->u.doubleValue = counter->two.doublevalue * pow( 10, factor );
|
||||
}
|
||||
else
|
||||
{
|
||||
WARN("unknown format %x\n", format);
|
||||
return PDH_INVALID_ARGUMENT;
|
||||
}
|
||||
value->CStatus = ERROR_SUCCESS;
|
||||
|
||||
if (type) *type = counter->type;
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* PdhOpenQueryA (PDH.@)
|
||||
*/
|
||||
|
@ -344,3 +388,19 @@ PDH_STATUS WINAPI PdhRemoveCounter( PDH_HCOUNTER handle )
|
|||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* PdhSetCounterScaleFactor (PDH.@)
|
||||
*/
|
||||
PDH_STATUS WINAPI PdhSetCounterScaleFactor( PDH_HCOUNTER handle, LONG factor )
|
||||
{
|
||||
struct counter *counter = handle;
|
||||
|
||||
TRACE("%p\n", handle);
|
||||
|
||||
if (!counter) return PDH_INVALID_HANDLE;
|
||||
if (factor < PDH_MIN_SCALE || factor > PDH_MAX_SCALE) return PDH_INVALID_ARGUMENT;
|
||||
|
||||
counter->scale = factor;
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -95,8 +95,94 @@ static void test_add_remove_counter( void )
|
|||
ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
|
||||
}
|
||||
|
||||
static void test_PdhGetFormattedCounterValue( void )
|
||||
{
|
||||
PDH_STATUS ret;
|
||||
PDH_HQUERY query;
|
||||
PDH_HCOUNTER counter;
|
||||
PDH_FMT_COUNTERVALUE value;
|
||||
|
||||
ret = PdhOpenQueryA( NULL, 0, &query );
|
||||
ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
|
||||
ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhGetFormattedCounterValue( NULL, PDH_FMT_LARGE, NULL, NULL );
|
||||
ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhGetFormattedCounterValue( NULL, PDH_FMT_LARGE, NULL, &value );
|
||||
ok(ret == PDH_INVALID_HANDLE, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, NULL );
|
||||
ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
|
||||
ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhCollectQueryData( query );
|
||||
ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
|
||||
ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_NOSCALE, NULL, &value );
|
||||
ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_NOCAP100, NULL, &value );
|
||||
ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE | PDH_FMT_1000, NULL, &value );
|
||||
ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhSetCounterScaleFactor( counter, 2 );
|
||||
ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhGetFormattedCounterValue( counter, PDH_FMT_LARGE, NULL, &value );
|
||||
ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhCloseQuery( query );
|
||||
ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
|
||||
}
|
||||
|
||||
static void test_PdhSetCounterScaleFactor( void )
|
||||
{
|
||||
PDH_STATUS ret;
|
||||
PDH_HQUERY query;
|
||||
PDH_HCOUNTER counter;
|
||||
|
||||
ret = PdhOpenQueryA( NULL, 0, &query );
|
||||
ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhAddCounterA( query, "\\System\\System Up Time", 0, &counter );
|
||||
ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhSetCounterScaleFactor( NULL, 8 );
|
||||
ok(ret == PDH_INVALID_HANDLE, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhSetCounterScaleFactor( NULL, 1 );
|
||||
ok(ret == PDH_INVALID_HANDLE, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhSetCounterScaleFactor( counter, 8 );
|
||||
ok(ret == PDH_INVALID_ARGUMENT, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhSetCounterScaleFactor( counter, -8 );
|
||||
ok(ret == PDH_INVALID_ARGUMENT, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhSetCounterScaleFactor( counter, 7 );
|
||||
ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhSetCounterScaleFactor( counter, 0 );
|
||||
ok(ret == ERROR_SUCCESS, "PdhSetCounterScaleFactor failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhCloseQuery( query );
|
||||
ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
|
||||
}
|
||||
|
||||
START_TEST(pdh)
|
||||
{
|
||||
test_open_close_query();
|
||||
test_add_remove_counter();
|
||||
test_PdhGetFormattedCounterValue();
|
||||
test_PdhSetCounterScaleFactor();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue