From 9289f45dce802ff5f542cee498dff6c2bad37614 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sun, 4 Mar 2007 19:06:53 +0000 Subject: [PATCH] add PdhLookupPerfIndexByName wrapper --- bindings/java/src/jni/win32/pdh.c | 20 +++++++++++++++++++ .../java/src/org/hyperic/sigar/win32/Pdh.java | 2 ++ 2 files changed, 22 insertions(+) diff --git a/bindings/java/src/jni/win32/pdh.c b/bindings/java/src/jni/win32/pdh.c index e37485a5..405220ab 100644 --- a/bindings/java/src/jni/win32/pdh.c +++ b/bindings/java/src/jni/win32/pdh.c @@ -430,6 +430,26 @@ JNIEXPORT jstring SIGAR_JNI(win32_Pdh_pdhLookupPerfName) } } +JNIEXPORT jint SIGAR_JNI(win32_Pdh_pdhLookupPerfIndex) +(JNIEnv *env, jclass cur, jstring jname) +{ + DWORD index; + LPCTSTR name = + JENV->GetStringChars(env, jname, NULL); + PDH_STATUS status = + PdhLookupPerfIndexByNameW(NULL, name, &index); + + JENV->ReleaseStringChars(env, jname, name); + + if (status == ERROR_SUCCESS) { + return index; + } + else { + win32_throw_exception(env, get_error_message(status)); + return -1; + } +} + #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 bd1174b7..f8f6fa44 100644 --- a/bindings/java/src/org/hyperic/sigar/win32/Pdh.java +++ b/bindings/java/src/org/hyperic/sigar/win32/Pdh.java @@ -253,6 +253,8 @@ public class Pdh extends Win32 { throws Win32Exception; private static final native String pdhLookupPerfName(int index) throws Win32Exception; + private static final native int pdhLookupPerfIndex(String name) + throws Win32Exception; /** * Main method for dumping the entire PDH