add PdhLookupPerfNameByIndex wrapper

This commit is contained in:
Doug MacEachern 2007-03-03 22:20:24 +00:00
parent 36bd793822
commit 9dae5e1ab1
3 changed files with 31 additions and 2 deletions

View File

@ -401,6 +401,23 @@ JNIEXPORT jobjectArray SIGAR_JNI(win32_Pdh_pdhGetObjects)
return array;
}
JNIEXPORT jstring SIGAR_JNI(win32_Pdh_pdhLookupPerfName)
(JNIEnv *env, jclass cur, jint index)
{
TCHAR path[8192];
DWORD len = sizeof(path);
PDH_STATUS status =
PdhLookupPerfNameByIndex(NULL, index, path, &len);
if (status == ERROR_SUCCESS) {
return JENV->NewStringUTF(env, path);
}
else {
win32_throw_exception(env, get_error_message(status));
return NULL;
}
}
#ifdef __cplusplus
}
#endif

View File

@ -101,6 +101,12 @@ public class Pdh extends Win32 {
return counters.map;
}
public static String getCounterName(int index)
throws Win32Exception {
return pdhLookupPerfName(index);
}
/**
* @deprecated
* @see #getRawValue(String path)
@ -163,6 +169,8 @@ public class Pdh extends Win32 {
throws Win32Exception;
private static final native String[] pdhGetObjects()
throws Win32Exception;
private static final native String pdhLookupPerfName(int index)
throws Win32Exception;
/**
* Main method for dumping the entire PDH

View File

@ -68,10 +68,14 @@ public class TestPdh extends SigarTestCase {
};
String last = null;
for (int i=0; i<keys.length; i++) {
String index = (String)counters.get(keys[i]);
String name = keys[i];
String index = (String)counters.get(name);
assertFalse(index.equals(last));
traceln(keys[i] + "=" + index);
traceln(name + "=" + index);
last = index;
String lookupName =
Pdh.getCounterName(Integer.parseInt(index));
traceln(name + "=" + lookupName);
}
}