From: Vijay Kiran Kamuju infyquest@gmail.com
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=56580 --- dlls/pdh/pdh.spec | 4 +- dlls/pdh/pdh_main.c | 59 +++++++++++++++++++++++ dlls/pdh/tests/pdh.c | 111 +++++++++++++++++++++++++++++++++++++++++++ include/pdh.h | 16 +++++++ 4 files changed, 188 insertions(+), 2 deletions(-)
diff --git a/dlls/pdh/pdh.spec b/dlls/pdh/pdh.spec index 3d51f6257ef..854b8004399 100644 --- a/dlls/pdh/pdh.spec +++ b/dlls/pdh/pdh.spec @@ -58,8 +58,8 @@ @ stub PdhGetDefaultPerfObjectHW @ stub PdhGetDefaultPerfObjectW @ stdcall PdhGetDllVersion(ptr) -@ stub PdhGetFormattedCounterArrayA -@ stub PdhGetFormattedCounterArrayW +@ stdcall PdhGetFormattedCounterArrayA(ptr long ptr ptr ptr) +@ stdcall PdhGetFormattedCounterArrayW(ptr long ptr ptr ptr) @ stdcall PdhGetFormattedCounterValue(ptr long ptr ptr) @ stub PdhGetLogFileSize @ stdcall PdhGetLogFileTypeA(str ptr) diff --git a/dlls/pdh/pdh_main.c b/dlls/pdh/pdh_main.c index dec86a9962b..426000443e8 100644 --- a/dlls/pdh/pdh_main.c +++ b/dlls/pdh/pdh_main.c @@ -761,6 +761,65 @@ PDH_STATUS WINAPI PdhGetFormattedCounterValue( PDH_HCOUNTER handle, DWORD format return ret; }
+/*********************************************************************** + * PdhGetFormattedCounterArrayA (PDH.@) + */ +PDH_STATUS WINAPI PdhGetFormattedCounterArrayA( PDH_HCOUNTER handle, DWORD format, + DWORD *size, DWORD *count, + PDH_FMT_COUNTERVALUE_ITEM_A *items ) +{ + PDH_STATUS ret = PDH_MORE_DATA; + struct counter *counter = handle; + + TRACE("%p %lx %p %p %p\n", handle, format, size, count, items); + + if (!size || !count ) return PDH_INVALID_ARGUMENT; + + EnterCriticalSection( &pdh_handle_cs ); + if (!counter || counter->magic != PDH_MAGIC_COUNTER) + { + LeaveCriticalSection( &pdh_handle_cs ); + return PDH_INVALID_HANDLE; + } + if (counter->status) + { + LeaveCriticalSection( &pdh_handle_cs ); + return PDH_INVALID_DATA; + } + + LeaveCriticalSection( &pdh_handle_cs ); + return ret; +} + +/*********************************************************************** + * PdhGetFormattedCounterArrayW (PDH.@) + */ +PDH_STATUS WINAPI PdhGetFormattedCounterArrayW( PDH_HCOUNTER handle, DWORD format, + DWORD *size, DWORD *count, + PDH_FMT_COUNTERVALUE_ITEM_W *items ) +{ + PDH_STATUS ret = PDH_MORE_DATA; + struct counter *counter = handle; + + TRACE("%p %lx %p %p %p\n", handle, format, size, count, items); + + if (!size || !count) return PDH_INVALID_ARGUMENT; + + EnterCriticalSection( &pdh_handle_cs ); + if (!counter || counter->magic != PDH_MAGIC_COUNTER) + { + LeaveCriticalSection( &pdh_handle_cs ); + return PDH_INVALID_HANDLE; + } + if (counter->status) + { + LeaveCriticalSection( &pdh_handle_cs ); + return PDH_INVALID_DATA; + } + + LeaveCriticalSection( &pdh_handle_cs ); + return ret; +} /*********************************************************************** * PdhGetRawCounterValue (PDH.@) */ diff --git a/dlls/pdh/tests/pdh.c b/dlls/pdh/tests/pdh.c index 5408e4cc3f3..d4f4651809b 100644 --- a/dlls/pdh/tests/pdh.c +++ b/dlls/pdh/tests/pdh.c @@ -32,6 +32,8 @@ static HMODULE pdh; static PDH_STATUS (WINAPI *pPdhAddEnglishCounterA)(PDH_HQUERY, LPCSTR, DWORD_PTR, PDH_HCOUNTER *); static PDH_STATUS (WINAPI *pPdhAddEnglishCounterW)(PDH_HQUERY, LPCWSTR, DWORD_PTR, PDH_HCOUNTER *); static PDH_STATUS (WINAPI *pPdhCollectQueryDataWithTime)(PDH_HQUERY, LONGLONG *); +static PDH_STATUS (WINAPI *pPdhGetFormattedCounterArrayA)(PDH_HCOUNTER, DWORD, LPDWORD, LPDWORD, PPDH_FMT_COUNTERVALUE_ITEM_A); +static PDH_STATUS (WINAPI *pPdhGetFormattedCounterArrayW)(PDH_HCOUNTER, DWORD, LPDWORD, LPDWORD, PPDH_FMT_COUNTERVALUE_ITEM_W); static PDH_STATUS (WINAPI *pPdhValidatePathExA)(PDH_HLOG, LPCSTR); static PDH_STATUS (WINAPI *pPdhValidatePathExW)(PDH_HLOG, LPCWSTR); static double (WINAPI *pPdhVbGetDoubleCounterValue)(PDH_HCOUNTER, PDH_STATUS *); @@ -68,6 +70,8 @@ static void init_function_ptrs( void ) GETFUNCPTR( PdhAddEnglishCounterA ) GETFUNCPTR( PdhAddEnglishCounterW ) GETFUNCPTR( PdhCollectQueryDataWithTime ) + GETFUNCPTR( PdhGetFormattedCounterArrayA ) + GETFUNCPTR( PdhGetFormattedCounterArrayW ) GETFUNCPTR( PdhValidatePathExA ) GETFUNCPTR( PdhValidatePathExW ) GETFUNCPTR( PdhVbGetDoubleCounterValue ) @@ -342,6 +346,111 @@ static void test_PdhCollectQueryDataWithTime( void ) ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08lx\n", ret); }
+static void test_PdhGetFormattedCounterArrayA( void ) +{ + PDH_STATUS ret; + PDH_HQUERY query; + PDH_HCOUNTER counter; + PDH_FMT_COUNTERVALUE_ITEM_A *items = NULL; + DWORD size, count; + + ret = PdhOpenQueryA( NULL, 0, &query ); + ok(ret == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08lx\n", ret); + + ret = PdhAddCounterA( query, "\System\System Up Time", 0, &counter ); + ok(ret == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08lx\n", ret); + + ret = pPdhGetFormattedCounterArrayA( NULL, PDH_FMT_LARGE, NULL, NULL, NULL ); + ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterArrayA failed 0x%08lx\n", ret); + + ret = pPdhGetFormattedCounterArrayA( NULL, PDH_FMT_LARGE, &size, NULL, NULL ); + ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterArrayA failed 0x%08lx\n", ret); + + ret = pPdhGetFormattedCounterArrayA( NULL, PDH_FMT_LARGE, &size, &count, NULL ); + todo_wine ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterArrayA failed 0x%08lx\n", ret); + + size = 0; + ret = pPdhGetFormattedCounterArrayA( NULL, PDH_FMT_LARGE, &size, &count, NULL ); + ok(ret == PDH_INVALID_HANDLE, "PdhGetFormattedCounterArrayA failed 0x%08lx\n", ret); + + ret = pPdhGetFormattedCounterArrayA( NULL, PDH_FMT_LARGE, &size, &count, items ); + ok(ret == PDH_INVALID_HANDLE, "PdhGetFormattedCounterArrayA failed 0x%08lx\n", ret); + + ret = pPdhGetFormattedCounterArrayA( counter, PDH_FMT_LARGE, NULL, NULL, NULL ); + ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterArrayA failed 0x%08lx\n", ret); + + ret = pPdhGetFormattedCounterArrayA( counter, PDH_FMT_LARGE, &size, &count, NULL ); + todo_wine ok(ret == PDH_NO_DATA, "PdhGetFormattedCounterArrayA failed 0x%08lx\n", ret); + + ret = PdhCollectQueryData( query ); + ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08lx\n", ret); + + count = 0; + ret = pPdhGetFormattedCounterArrayA( counter, PDH_FMT_LARGE, &size, &count, NULL ); + ok(ret == PDH_MORE_DATA, "PdhGetFormattedCounterArrayA failed 0x%08lx\n", ret); + todo_wine ok(size > 0, "Got size %ld\n", size); + todo_wine ok(count > 0, "Got count %ld\n", count); + + items = (PDH_FMT_COUNTERVALUE_ITEM_A *) malloc(size); + ret = pPdhGetFormattedCounterArrayA( counter, PDH_FMT_LARGE, &size, &count, items ); + todo_wine ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterArrayA failed 0x%08lx\n", ret); + + ret = PdhCloseQuery( query ); + ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08lx\n", ret); +} + +static void test_PdhGetFormattedCounterArrayW( void ) +{ + PDH_STATUS ret; + PDH_HQUERY query; + PDH_HCOUNTER counter; + PDH_FMT_COUNTERVALUE_ITEM_W *items = NULL; + DWORD size, count; + + ret = PdhOpenQueryW( NULL, 0, &query ); + ok(ret == ERROR_SUCCESS, "PdhOpenQueryW failed 0x%08lx\n", ret); + + ret = PdhAddCounterW( query, L"\System\System Up Time", 0, &counter ); + ok(ret == ERROR_SUCCESS, "PdhAddCounterW failed 0x%08lx\n", ret); + + ret = pPdhGetFormattedCounterArrayW( NULL, PDH_FMT_LARGE, NULL, NULL, NULL ); + ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterArrayW failed 0x%08lx\n", ret); + + ret = pPdhGetFormattedCounterArrayW( NULL, PDH_FMT_LARGE, &size, NULL, NULL ); + ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterArrayW failed 0x%08lx\n", ret); + + ret = pPdhGetFormattedCounterArrayW( NULL, PDH_FMT_LARGE, &size, &count, NULL ); + todo_wine ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterArrayW failed 0x%08lx\n", ret); + + size = 0; + ret = pPdhGetFormattedCounterArrayW( NULL, PDH_FMT_LARGE, &size, &count, NULL ); + ok(ret == PDH_INVALID_HANDLE, "PdhGetFormattedCounterArrayW failed 0x%08lx\n", ret); + + ret = pPdhGetFormattedCounterArrayW( NULL, PDH_FMT_LARGE, &size, &count, items ); + ok(ret == PDH_INVALID_HANDLE, "PdhGetFormattedCounterArrayW failed 0x%08lx\n", ret); + + ret = pPdhGetFormattedCounterArrayW( counter, PDH_FMT_LARGE, NULL, NULL, NULL ); + ok(ret == PDH_INVALID_ARGUMENT, "PdhGetFormattedCounterArrayW failed 0x%08lx\n", ret); + + ret = pPdhGetFormattedCounterArrayW( counter, PDH_FMT_LARGE, &size, &count, NULL ); + todo_wine ok(ret == PDH_NO_DATA, "PdhGetFormattedCounterArrayW failed 0x%08lx\n", ret); + + ret = PdhCollectQueryData( query ); + ok(ret == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08lx\n", ret); + + ret = pPdhGetFormattedCounterArrayW( counter, PDH_FMT_LARGE, &size, &count, NULL ); + ok(ret == PDH_MORE_DATA, "PdhGetFormattedCounterArrayW failed 0x%08lx\n", ret); + todo_wine ok(size != 0, "Got size %ld\n", size); + todo_wine ok(count != 0, "Got count %ld\n", count); + + items = (PDH_FMT_COUNTERVALUE_ITEM_W *) malloc(size); + ret = pPdhGetFormattedCounterArrayW( counter, PDH_FMT_LARGE, &size, &count, items ); + todo_wine ok(ret == ERROR_SUCCESS, "PdhGetFormattedCounterArrayW failed 0x%08lx\n", ret); + + ret = PdhCloseQuery( query ); + ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08lx\n", ret); +} + static void test_PdhGetFormattedCounterValue( void ) { PDH_STATUS ret; @@ -1035,6 +1144,8 @@ START_TEST(pdh) if (pPdhAddEnglishCounterW) test_PdhAddEnglishCounterW(); if (pPdhCollectQueryDataWithTime) test_PdhCollectQueryDataWithTime();
+ if (pPdhGetFormattedCounterArrayA) test_PdhGetFormattedCounterArrayA(); + if (pPdhGetFormattedCounterArrayW) test_PdhGetFormattedCounterArrayW(); test_PdhGetFormattedCounterValue(); test_PdhGetRawCounterValue(); test_PdhSetCounterScaleFactor(); diff --git a/include/pdh.h b/include/pdh.h index 3d688bd8ded..0fdba099b16 100644 --- a/include/pdh.h +++ b/include/pdh.h @@ -89,6 +89,19 @@ typedef struct _PDH_RAW_COUNTER DWORD MultiCount; } PDH_RAW_COUNTER, *PPDH_RAW_COUNTER;
+typedef struct _PDH_FMT_COUNTERVALUE_ITEM_A { + LPSTR szName; + PDH_FMT_COUNTERVALUE FmtValue; +} PDH_FMT_COUNTERVALUE_ITEM_A, *PPDH_FMT_COUNTERVALUE_ITEM_A; + +typedef struct _PDH_FMT_COUNTERVALUE_ITEM_W { + LPWSTR szName; + PDH_FMT_COUNTERVALUE FmtValue; +} PDH_FMT_COUNTERVALUE_ITEM_W, *PPDH_FMT_COUNTERVALUE_ITEM_W; + +DECL_PDH_TYPE_AW(PDH_FMT_COUNTERVALUE_ITEM) +DECL_PDH_TYPE_AW(PPDH_FMT_COUNTERVALUE_ITEM) + typedef struct _PDH_COUNTER_PATH_ELEMENTS_A { LPSTR szMachineName; @@ -218,6 +231,9 @@ PDH_STATUS WINAPI PdhGetCounterInfoW(PDH_HCOUNTER, BOOLEAN, LPDWORD, PPDH_COUNTE #define PdhGetCounterInfo WINELIB_NAME_AW(PdhGetCounterInfo) PDH_STATUS WINAPI PdhGetCounterTimeBase(PDH_HCOUNTER, LONGLONG *); PDH_STATUS WINAPI PdhGetDllVersion(LPDWORD); +PDH_STATUS WINAPI PdhGetFormattedCounterArrayA(PDH_HCOUNTER, DWORD, LPDWORD, LPDWORD, PPDH_FMT_COUNTERVALUE_ITEM_A); +PDH_STATUS WINAPI PdhGetFormattedCounterArrayW(PDH_HCOUNTER, DWORD, LPDWORD, LPDWORD, PPDH_FMT_COUNTERVALUE_ITEM_W); +#define PdhGetFormattedCounterArray WINELIB_NAME_AW(PdhGetFormattedCounterArray) PDH_STATUS WINAPI PdhGetFormattedCounterValue(PDH_HCOUNTER, DWORD, LPDWORD, PPDH_FMT_COUNTERVALUE); PDH_STATUS WINAPI PdhGetRawCounterValue(PDH_HCOUNTER, LPDWORD, PPDH_RAW_COUNTER); PDH_STATUS WINAPI PdhLookupPerfIndexByNameA(LPCSTR, LPCSTR, LPDWORD);