From 9dae5e1ab1db7012dc225fcac865e92e17a8f3b4 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sat, 3 Mar 2007 22:20:24 +0000 Subject: [PATCH] add PdhLookupPerfNameByIndex wrapper --- bindings/java/src/jni/win32/pdh.c | 17 +++++++++++++++++ .../java/src/org/hyperic/sigar/win32/Pdh.java | 8 ++++++++ .../org/hyperic/sigar/win32/test/TestPdh.java | 8 ++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/bindings/java/src/jni/win32/pdh.c b/bindings/java/src/jni/win32/pdh.c index c9620930..940d15d9 100644 --- a/bindings/java/src/jni/win32/pdh.c +++ b/bindings/java/src/jni/win32/pdh.c @@ -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 diff --git a/bindings/java/src/org/hyperic/sigar/win32/Pdh.java b/bindings/java/src/org/hyperic/sigar/win32/Pdh.java index 379e4a32..2e1ece45 100644 --- a/bindings/java/src/org/hyperic/sigar/win32/Pdh.java +++ b/bindings/java/src/org/hyperic/sigar/win32/Pdh.java @@ -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 diff --git a/bindings/java/src/org/hyperic/sigar/win32/test/TestPdh.java b/bindings/java/src/org/hyperic/sigar/win32/test/TestPdh.java index 374136fc..67a9e0c0 100644 --- a/bindings/java/src/org/hyperic/sigar/win32/test/TestPdh.java +++ b/bindings/java/src/org/hyperic/sigar/win32/test/TestPdh.java @@ -68,10 +68,14 @@ public class TestPdh extends SigarTestCase { }; String last = null; for (int i=0; i