pdh: Implement and test PdhLookupPerfIndexByName{A, W} and PdhLookupPerfNameByIndex{A, W}.
This commit is contained in:
parent
75a9146268
commit
0fbb4619e1
|
@ -72,10 +72,10 @@
|
|||
@ stub PdhLogServiceCommandW
|
||||
@ stub PdhLogServiceControlA
|
||||
@ stub PdhLogServiceControlW
|
||||
@ stub PdhLookupPerfIndexByNameA
|
||||
@ stub PdhLookupPerfIndexByNameW
|
||||
@ stub PdhLookupPerfNameByIndexA
|
||||
@ stub PdhLookupPerfNameByIndexW
|
||||
@ stdcall PdhLookupPerfIndexByNameA(str str ptr)
|
||||
@ stdcall PdhLookupPerfIndexByNameW(wstr wstr ptr)
|
||||
@ stdcall PdhLookupPerfNameByIndexA(str long ptr ptr)
|
||||
@ stdcall PdhLookupPerfNameByIndexW(wstr long ptr ptr)
|
||||
@ stub PdhMakeCounterPathA
|
||||
@ stub PdhMakeCounterPathW
|
||||
@ stub PdhOpenLogA
|
||||
|
|
|
@ -145,6 +145,7 @@ static struct query *create_query( void )
|
|||
|
||||
struct source
|
||||
{
|
||||
DWORD index; /* name index */
|
||||
const WCHAR *path; /* identifier */
|
||||
void (CALLBACK *collect)( struct counter * ); /* collect callback */
|
||||
DWORD type; /* counter type */
|
||||
|
@ -180,10 +181,20 @@ static void CALLBACK collect_uptime( struct counter *counter )
|
|||
/* counter source registry */
|
||||
static const struct source counter_sources[] =
|
||||
{
|
||||
{ path_processor_time, collect_processor_time, TYPE_PROCESSOR_TIME, -5, 10000000 },
|
||||
{ path_uptime, collect_uptime, TYPE_UPTIME, -3, 1000 }
|
||||
{ 6, path_processor_time, collect_processor_time, TYPE_PROCESSOR_TIME, -5, 10000000 },
|
||||
{ 674, path_uptime, collect_uptime, TYPE_UPTIME, -3, 1000 }
|
||||
};
|
||||
|
||||
static BOOL pdh_match_path( LPCWSTR fullpath, LPCWSTR path )
|
||||
{
|
||||
const WCHAR *p;
|
||||
|
||||
if (strchrW( path, '\\')) p = fullpath;
|
||||
else p = strrchrW( fullpath, '\\' ) + 1;
|
||||
if (strcmpW( p, path )) return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* PdhAddCounterA (PDH.@)
|
||||
*/
|
||||
|
@ -224,7 +235,7 @@ PDH_STATUS WINAPI PdhAddCounterW( PDH_HQUERY hquery, LPCWSTR path,
|
|||
*hcounter = NULL;
|
||||
for (i = 0; i < sizeof(counter_sources) / sizeof(counter_sources[0]); i++)
|
||||
{
|
||||
if (strstrW( path, counter_sources[i].path ))
|
||||
if (pdh_match_path( counter_sources[i].path, path ))
|
||||
{
|
||||
if ((counter = create_counter()))
|
||||
{
|
||||
|
@ -445,6 +456,129 @@ PDH_STATUS WINAPI PdhGetRawCounterValue( PDH_HCOUNTER handle, LPDWORD type,
|
|||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* PdhLookupPerfIndexByNameA (PDH.@)
|
||||
*/
|
||||
PDH_STATUS WINAPI PdhLookupPerfIndexByNameA( LPCSTR machine, LPCSTR name, LPDWORD index )
|
||||
{
|
||||
PDH_STATUS ret;
|
||||
WCHAR *nameW;
|
||||
|
||||
TRACE("%s %s %p\n", debugstr_a(machine), debugstr_a(name), index);
|
||||
|
||||
if (!name || !index) return PDH_INVALID_ARGUMENT;
|
||||
|
||||
if (machine)
|
||||
{
|
||||
FIXME("remote machine not supported\n");
|
||||
return PDH_CSTATUS_NO_MACHINE;
|
||||
}
|
||||
if (!(nameW = pdh_strdup_aw( name )))
|
||||
return PDH_MEMORY_ALLOCATION_FAILURE;
|
||||
|
||||
ret = PdhLookupPerfIndexByNameW( NULL, nameW, index );
|
||||
|
||||
pdh_free( nameW );
|
||||
return ret;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* PdhLookupPerfIndexByNameW (PDH.@)
|
||||
*/
|
||||
PDH_STATUS WINAPI PdhLookupPerfIndexByNameW( LPCWSTR machine, LPCWSTR name, LPDWORD index )
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
TRACE("%s %s %p\n", debugstr_w(machine), debugstr_w(name), index);
|
||||
|
||||
if (!name || !index) return PDH_INVALID_ARGUMENT;
|
||||
|
||||
if (machine)
|
||||
{
|
||||
FIXME("remote machine not supported\n");
|
||||
return PDH_CSTATUS_NO_MACHINE;
|
||||
}
|
||||
for (i = 0; i < sizeof(counter_sources) / sizeof(counter_sources[0]); i++)
|
||||
{
|
||||
if (pdh_match_path( counter_sources[i].path, name ))
|
||||
{
|
||||
*index = counter_sources[i].index;
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
}
|
||||
return PDH_STRING_NOT_FOUND;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* PdhLookupPerfNameByIndexA (PDH.@)
|
||||
*/
|
||||
PDH_STATUS WINAPI PdhLookupPerfNameByIndexA( LPCSTR machine, DWORD index, LPSTR buffer, LPDWORD size )
|
||||
{
|
||||
PDH_STATUS ret;
|
||||
WCHAR bufferW[PDH_MAX_COUNTER_NAME];
|
||||
DWORD sizeW = sizeof(bufferW) / sizeof(WCHAR);
|
||||
|
||||
TRACE("%s %d %p %p\n", debugstr_a(machine), index, buffer, size);
|
||||
|
||||
if (machine)
|
||||
{
|
||||
FIXME("remote machine not supported\n");
|
||||
return PDH_CSTATUS_NO_MACHINE;
|
||||
}
|
||||
|
||||
if (!buffer && !size) return PDH_INVALID_ARGUMENT;
|
||||
if (!index) return ERROR_SUCCESS;
|
||||
|
||||
if (!(ret = PdhLookupPerfNameByIndexW( NULL, index, bufferW, &sizeW )))
|
||||
{
|
||||
int required = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL );
|
||||
|
||||
if (size && *size < required) ret = PDH_MORE_DATA;
|
||||
else WideCharToMultiByte( CP_ACP, 0, bufferW, -1, buffer, required, NULL, NULL );
|
||||
if (size) *size = required;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* PdhLookupPerfNameByIndexW (PDH.@)
|
||||
*/
|
||||
PDH_STATUS WINAPI PdhLookupPerfNameByIndexW( LPCWSTR machine, DWORD index, LPWSTR buffer, LPDWORD size )
|
||||
{
|
||||
PDH_STATUS ret;
|
||||
unsigned int i;
|
||||
|
||||
TRACE("%s %d %p %p\n", debugstr_w(machine), index, buffer, size);
|
||||
|
||||
if (machine)
|
||||
{
|
||||
FIXME("remote machine not supported\n");
|
||||
return PDH_CSTATUS_NO_MACHINE;
|
||||
}
|
||||
|
||||
if (!buffer && !size) return PDH_INVALID_ARGUMENT;
|
||||
if (!index) return ERROR_SUCCESS;
|
||||
|
||||
for (i = 0; i < sizeof(counter_sources) / sizeof(counter_sources[0]); i++)
|
||||
{
|
||||
if (counter_sources[i].index == index)
|
||||
{
|
||||
WCHAR *p = strrchrW( counter_sources[i].path, '\\' ) + 1;
|
||||
unsigned int required = strlenW( p ) + 1;
|
||||
|
||||
if (*size < required) ret = PDH_MORE_DATA;
|
||||
else
|
||||
{
|
||||
strcpyW( buffer, p );
|
||||
ret = ERROR_SUCCESS;
|
||||
}
|
||||
*size = required;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return PDH_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* PdhOpenQueryA (PDH.@)
|
||||
*/
|
||||
|
|
|
@ -27,6 +27,11 @@
|
|||
|
||||
#include "wine/test.h"
|
||||
|
||||
static const WCHAR processor_time[] =
|
||||
{'%',' ','P','r','o','c','e','s','s','o','r',' ','T','i','m','e',0};
|
||||
static const WCHAR uptime[] =
|
||||
{'S','y','s','t','e','m',' ','U','p',' ','T','i','m','e',0};
|
||||
|
||||
static const WCHAR system_uptime[] =
|
||||
{'\\','S','y','s','t','e','m','\\','S','y','s','t','e','m',' ','U','p',' ','T','i','m','e',0};
|
||||
static const WCHAR system_downtime[] = /* does not exist */
|
||||
|
@ -432,6 +437,143 @@ static void test_PdhGetCounterInfoW( void )
|
|||
ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08x\n", ret);
|
||||
}
|
||||
|
||||
static void test_PdhLookupPerfIndexByNameA( void )
|
||||
{
|
||||
PDH_STATUS ret;
|
||||
DWORD index;
|
||||
|
||||
ret = PdhLookupPerfIndexByNameA( NULL, NULL, NULL );
|
||||
ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhLookupPerfIndexByNameA( NULL, NULL, &index );
|
||||
ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhLookupPerfIndexByNameA( NULL, "No Counter", &index );
|
||||
ok(ret == PDH_STRING_NOT_FOUND, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhLookupPerfIndexByNameA( NULL, "% Processor Time", NULL );
|
||||
ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhLookupPerfIndexByNameA( NULL, "% Processor Time", &index );
|
||||
ok(ret == ERROR_SUCCESS, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
|
||||
ok(index == 6, "PdhLookupPerfIndexByNameA failed %d\n", index);
|
||||
|
||||
ret = PdhLookupPerfIndexByNameA( NULL, "System Up Time", &index );
|
||||
ok(ret == ERROR_SUCCESS, "PdhLookupPerfIndexByNameA failed 0x%08x\n", ret);
|
||||
ok(index == 674, "PdhLookupPerfIndexByNameA failed %d\n", index);
|
||||
}
|
||||
|
||||
static void test_PdhLookupPerfIndexByNameW( void )
|
||||
{
|
||||
PDH_STATUS ret;
|
||||
DWORD index;
|
||||
|
||||
static const WCHAR no_counter[] = {'N','o',' ','C','o','u','n','t','e','r',0};
|
||||
|
||||
ret = PdhLookupPerfIndexByNameW( NULL, NULL, NULL );
|
||||
ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhLookupPerfIndexByNameW( NULL, NULL, &index );
|
||||
ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhLookupPerfIndexByNameW( NULL, no_counter, &index );
|
||||
ok(ret == PDH_STRING_NOT_FOUND, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhLookupPerfIndexByNameW( NULL, processor_time, NULL );
|
||||
ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
|
||||
|
||||
ret = PdhLookupPerfIndexByNameW( NULL, processor_time, &index );
|
||||
ok(ret == ERROR_SUCCESS, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
|
||||
ok(index == 6, "PdhLookupPerfIndexByNameW failed %d\n", index);
|
||||
|
||||
ret = PdhLookupPerfIndexByNameW( NULL, uptime, &index );
|
||||
ok(ret == ERROR_SUCCESS, "PdhLookupPerfIndexByNameW failed 0x%08x\n", ret);
|
||||
ok(index == 674, "PdhLookupPerfIndexByNameW failed %d\n", index);
|
||||
}
|
||||
|
||||
static void test_PdhLookupPerfNameByIndexA( void )
|
||||
{
|
||||
PDH_STATUS ret;
|
||||
char buffer[PDH_MAX_COUNTER_NAME] = "!!";
|
||||
DWORD size;
|
||||
|
||||
ret = PdhLookupPerfNameByIndexA( NULL, 0, NULL, NULL );
|
||||
ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
|
||||
|
||||
size = 1;
|
||||
ret = PdhLookupPerfNameByIndexA( NULL, 0, NULL, &size );
|
||||
ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
|
||||
ok(size == 1, "PdhLookupPerfNameByIndexA failed %d\n", size);
|
||||
|
||||
size = sizeof(buffer);
|
||||
ret = PdhLookupPerfNameByIndexA( NULL, 0, buffer, &size );
|
||||
ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
|
||||
ok(!strcmp(buffer, "!!"), "PdhLookupPerfNameByIndexA failed %s\n", buffer);
|
||||
|
||||
size = 0;
|
||||
ret = PdhLookupPerfNameByIndexA( NULL, 6, buffer, &size );
|
||||
ok(ret == PDH_MORE_DATA, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
|
||||
ok(size == sizeof("% Processor Time"), "PdhLookupPerfNameByIndexA failed %d\n", size);
|
||||
|
||||
size = sizeof(buffer);
|
||||
ret = PdhLookupPerfNameByIndexA( NULL, 6, buffer, &size );
|
||||
ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
|
||||
ok(!lstrcmpA( buffer, "% Processor Time" ),
|
||||
"PdhLookupPerfNameByIndexA failed, got %s expected \'%% Processor Time\'\n", buffer);
|
||||
ok(size == sizeof("% Processor Time"), "PdhLookupPerfNameByIndexA failed %d\n", size);
|
||||
|
||||
size = 0;
|
||||
ret = PdhLookupPerfNameByIndexA( NULL, 674, NULL, &size );
|
||||
ok(ret == PDH_MORE_DATA, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
|
||||
ok(size == sizeof("System Up Time"), "PdhLookupPerfNameByIndexA failed %d\n", size);
|
||||
|
||||
size = sizeof(buffer);
|
||||
ret = PdhLookupPerfNameByIndexA( NULL, 674, buffer, &size );
|
||||
ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexA failed 0x%08x\n", ret);
|
||||
ok(!lstrcmpA( buffer, "System Up Time" ),
|
||||
"PdhLookupPerfNameByIndexA failed, got %s expected \'System Up Time\'\n", buffer);
|
||||
ok(size == sizeof("System Up Time"), "PdhLookupPerfNameByIndexA failed %d\n", size);
|
||||
}
|
||||
|
||||
static void test_PdhLookupPerfNameByIndexW( void )
|
||||
{
|
||||
PDH_STATUS ret;
|
||||
WCHAR buffer[PDH_MAX_COUNTER_NAME];
|
||||
DWORD size;
|
||||
|
||||
ret = PdhLookupPerfNameByIndexW( NULL, 0, NULL, NULL );
|
||||
ok(ret == PDH_INVALID_ARGUMENT, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
|
||||
|
||||
size = 1;
|
||||
ret = PdhLookupPerfNameByIndexW( NULL, 0, NULL, &size );
|
||||
ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
|
||||
ok(size == 1, "PdhLookupPerfNameByIndexW failed %d\n", size);
|
||||
|
||||
size = sizeof(buffer) / sizeof(WCHAR);
|
||||
ret = PdhLookupPerfNameByIndexW( NULL, 0, buffer, &size );
|
||||
ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
|
||||
|
||||
size = 0;
|
||||
ret = PdhLookupPerfNameByIndexW( NULL, 6, buffer, &size );
|
||||
ok(ret == PDH_MORE_DATA, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
|
||||
ok(size == sizeof(processor_time) / sizeof(WCHAR), "PdhLookupPerfNameByIndexW failed %d\n", size);
|
||||
|
||||
size = sizeof(buffer) / sizeof(WCHAR);
|
||||
ret = PdhLookupPerfNameByIndexW( NULL, 6, buffer, &size );
|
||||
ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
|
||||
ok(size == sizeof(processor_time) / sizeof(WCHAR), "PdhLookupPerfNameByIndexW failed %d\n", size);
|
||||
|
||||
size = 0;
|
||||
ret = PdhLookupPerfNameByIndexW( NULL, 674, NULL, &size );
|
||||
ok(ret == PDH_MORE_DATA, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
|
||||
ok(size == sizeof(uptime) / sizeof(WCHAR), "PdhLookupPerfNameByIndexW failed %d\n", size);
|
||||
|
||||
size = sizeof(buffer) / sizeof(WCHAR);
|
||||
ret = PdhLookupPerfNameByIndexW( NULL, 674, buffer, &size );
|
||||
ok(ret == ERROR_SUCCESS, "PdhLookupPerfNameByIndexW failed 0x%08x\n", ret);
|
||||
ok(size == sizeof(uptime) / sizeof(WCHAR), "PdhLookupPerfNameByIndexW failed %d\n", size);
|
||||
}
|
||||
|
||||
START_TEST(pdh)
|
||||
{
|
||||
test_PdhOpenQueryA();
|
||||
|
@ -447,4 +589,10 @@ START_TEST(pdh)
|
|||
|
||||
test_PdhGetCounterInfoA();
|
||||
test_PdhGetCounterInfoW();
|
||||
|
||||
test_PdhLookupPerfIndexByNameA();
|
||||
test_PdhLookupPerfIndexByNameW();
|
||||
|
||||
test_PdhLookupPerfNameByIndexA();
|
||||
test_PdhLookupPerfNameByIndexW();
|
||||
}
|
||||
|
|
|
@ -39,6 +39,8 @@ typedef HANDLE PDH_HCOUNTER;
|
|||
#define PDH_MAX_SCALE 7
|
||||
#define PDH_MIN_SCALE (-7)
|
||||
|
||||
#define PDH_MAX_COUNTER_NAME 1024
|
||||
|
||||
#define PDH_FMT_LONG 0x00000100
|
||||
#define PDH_FMT_DOUBLE 0x00000200
|
||||
#define PDH_FMT_LARGE 0x00000400
|
||||
|
@ -173,6 +175,12 @@ PDH_STATUS WINAPI PdhGetCounterInfoW(PDH_HCOUNTER, BOOLEAN, LPDWORD, PPDH_COUNTE
|
|||
PDH_STATUS WINAPI PdhGetCounterTimeBase(PDH_HCOUNTER, LONGLONG *);
|
||||
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);
|
||||
PDH_STATUS WINAPI PdhLookupPerfIndexByNameW(LPCWSTR, LPCWSTR, LPDWORD);
|
||||
#define PdhLookupPerfIndexByName WINELIB_NAME_AW(PdhLookupPerfIndexByName)
|
||||
PDH_STATUS WINAPI PdhLookupPerfNameByIndexA(LPCSTR, DWORD, LPSTR, LPDWORD);
|
||||
PDH_STATUS WINAPI PdhLookupPerfNameByIndexW(LPCWSTR, DWORD, LPWSTR, LPDWORD);
|
||||
#define PdhLookupPerfNameByIndex WINELIB_NAME_AW(PdhLookupPerfNameByIndex)
|
||||
PDH_STATUS WINAPI PdhOpenQueryA(LPCSTR, DWORD_PTR, PDH_HQUERY *);
|
||||
PDH_STATUS WINAPI PdhOpenQueryW(LPCWSTR, DWORD_PTR, PDH_HQUERY *);
|
||||
#define PdhOpenQuery WINELIB_NAME_AW(PdhOpenQuery)
|
||||
|
|
|
@ -22,11 +22,14 @@
|
|||
#define _PDH_MSG_H_
|
||||
|
||||
#define PDH_CSTATUS_VALID_DATA 0x00000000
|
||||
#define PDH_CSTATUS_NO_MACHINE 0x800007d0
|
||||
#define PDH_MORE_DATA 0x800007d2
|
||||
#define PDH_NO_DATA 0x800007d5
|
||||
#define PDH_CSTATUS_NO_COUNTER 0xc0000bb9
|
||||
#define PDH_MEMORY_ALLOCATION_FAILURE 0xc0000bbb
|
||||
#define PDH_INVALID_HANDLE 0xc0000bbc
|
||||
#define PDH_INVALID_ARGUMENT 0xc0000bbd
|
||||
#define PDH_INVALID_DATA 0xc0000bc6
|
||||
#define PDH_STRING_NOT_FOUND 0xc0000bd4
|
||||
|
||||
#endif /* _PDH_MSG_H_ */
|
||||
|
|
Loading…
Reference in New Issue