(SIGAR-207) Add Pdh.getDescription method
This commit is contained in:
parent
b2d33467b8
commit
7905904cb6
|
@ -222,6 +222,38 @@ JNIEXPORT jdouble SIGAR_JNI(win32_Pdh_pdhGetValue)
|
|||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jstring SIGAR_JNI(win32_Pdh_pdhGetDescription)
|
||||
(JNIEnv *env, jclass cur, jlong counter)
|
||||
{
|
||||
HCOUNTER h_counter = (HCOUNTER)counter;
|
||||
PDH_COUNTER_INFO *info = NULL;
|
||||
jstring retval = NULL;
|
||||
DWORD size = 0;
|
||||
PDH_STATUS status;
|
||||
|
||||
status = PdhGetCounterInfo(h_counter, TRUE, &size, NULL);
|
||||
if (status != PDH_MORE_DATA) {
|
||||
win32_throw_exception(env, get_error_message(status));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
info = malloc(size);
|
||||
|
||||
status = PdhGetCounterInfo(h_counter, 1, &size, info);
|
||||
if (status == ERROR_SUCCESS) {
|
||||
if (info->szExplainText) {
|
||||
retval = JENV->NewString(env, info->szExplainText,
|
||||
lstrlen(info->szExplainText));
|
||||
}
|
||||
}
|
||||
else {
|
||||
win32_throw_exception(env, get_error_message(status));
|
||||
}
|
||||
|
||||
free(info);
|
||||
return retval;
|
||||
}
|
||||
|
||||
JNIEXPORT jobjectArray SIGAR_JNI(win32_Pdh_pdhGetInstances)
|
||||
(JNIEnv *env, jclass cur, jstring cp)
|
||||
{
|
||||
|
|
|
@ -292,6 +292,17 @@ public class Pdh extends Win32 {
|
|||
}
|
||||
}
|
||||
|
||||
/* PdhCounterInfo.ExplainText */
|
||||
public String getDescription(String path) throws Win32Exception {
|
||||
long counter =
|
||||
pdhAddCounter(this.query, translate(path));
|
||||
try {
|
||||
return pdhGetDescription(counter);
|
||||
} finally {
|
||||
pdhRemoveCounter(counter);
|
||||
}
|
||||
}
|
||||
|
||||
public static String[] getInstances(String path) throws Win32Exception {
|
||||
return pdhGetInstances(getCounterName(path));
|
||||
}
|
||||
|
@ -319,6 +330,8 @@ public class Pdh extends Win32 {
|
|||
long counter,
|
||||
boolean fmt)
|
||||
throws Win32Exception;
|
||||
private static final native String pdhGetDescription(long counter)
|
||||
throws Win32Exception;
|
||||
private static final native String[] pdhGetInstances(String path)
|
||||
throws Win32Exception;
|
||||
private static final native String[] pdhGetKeys(String path)
|
||||
|
|
|
@ -33,7 +33,7 @@ public class TestPdh extends SigarTestCase {
|
|||
private void getValue(String key) throws Exception {
|
||||
Pdh pdh = new Pdh();
|
||||
|
||||
traceln(key);
|
||||
traceln(key + ": " + pdh.getDescription(key));
|
||||
assertGtEqZeroTrace("raw",
|
||||
(long)pdh.getRawValue(key));
|
||||
assertGtEqZeroTrace("fmt",
|
||||
|
|
Loading…
Reference in New Issue