Merge branch 'sigar-1.6'

This commit is contained in:
Doug MacEachern 2010-04-01 14:49:15 -07:00
commit bdfd156a63
3 changed files with 89 additions and 1 deletions

View File

@ -222,6 +222,55 @@ 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 jlong SIGAR_JNI(win32_Pdh_pdhGetCounterType)
(JNIEnv *env, jclass cur, jlong counter)
{
HCOUNTER h_counter = (HCOUNTER)counter;
PDH_COUNTER_INFO info;
DWORD size = sizeof(info);
PDH_STATUS status;
status = PdhGetCounterInfo(h_counter, FALSE, &size, &info);
if (status != ERROR_SUCCESS) {
win32_throw_exception(env, get_error_message(status));
return -1;
}
return info.dwType;
}
JNIEXPORT jobjectArray SIGAR_JNI(win32_Pdh_pdhGetInstances)
(JNIEnv *env, jclass cur, jstring cp)
{

View File

@ -63,6 +63,15 @@ public class Pdh extends Win32 {
public static final String PERFLIB_KEY =
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Perflib";
//see winperf.h
public static final long PERF_TYPE_NUMBER = 0x00000000; // a number (not a counter)
public static final long PERF_TYPE_COUNTER = 0x00000400; // an increasing numeric value
public static final long PERF_TYPE_TEXT = 0x00000800; // a text field
public static final long PERF_TYPE_ZERO = 0x00000C00; // displays a zero
private long query = -1l; // Handle to the query
private String hostname = null;
private static Map counters = null;
@ -292,6 +301,27 @@ 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 long getCounterType(String path) throws Win32Exception {
long counter =
pdhAddCounter(this.query, translate(path));
try {
return pdhGetCounterType(counter);
} finally {
pdhRemoveCounter(counter);
}
}
public static String[] getInstances(String path) throws Win32Exception {
return pdhGetInstances(getCounterName(path));
}
@ -319,6 +349,10 @@ 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 long pdhGetCounterType(long counter)
throws Win32Exception;
private static final native String[] pdhGetInstances(String path)
throws Win32Exception;
private static final native String[] pdhGetKeys(String path)

View File

@ -30,10 +30,15 @@ public class TestPdh extends SigarTestCase {
super(name);
}
private static boolean isCounter(long type) {
return (type & Pdh.PERF_TYPE_COUNTER) == Pdh.PERF_TYPE_COUNTER;
}
private void getValue(String key) throws Exception {
Pdh pdh = new Pdh();
traceln(key);
traceln(key + ": " + pdh.getDescription(key));
traceln("counter=" + isCounter(pdh.getCounterType(key)));
assertGtEqZeroTrace("raw",
(long)pdh.getRawValue(key));
assertGtEqZeroTrace("fmt",