From 228ee133bed59bbd53c7d84042b521d3c816b541 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Mon, 4 Dec 2006 19:45:00 +0000 Subject: [PATCH] [SIGAR-26] Change Pdh.getFormattedValue() to collect 2 counters if needed --- ChangeLog | 6 +++++- bindings/java/src/jni/win32/pdh.c | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index a342a142..64d3570f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,8 @@ -2006-12-03 Doug MacEachern +2006-12-04 Doug MacEachern + + * [SIGAR-26] Change Pdh.getFormattedValue() to collect 2 counters if needed + +2006-12-03 Doug MacEachern * [SIGAR-19] Change cpu time units to milliseconds diff --git a/bindings/java/src/jni/win32/pdh.c b/bindings/java/src/jni/win32/pdh.c index e707da1e..c9620930 100644 --- a/bindings/java/src/jni/win32/pdh.c +++ b/bindings/java/src/jni/win32/pdh.c @@ -173,10 +173,19 @@ JNIEXPORT jdouble SIGAR_JNI(win32_Pdh_pdhGetValue) } if (fmt) { - status = PdhGetFormattedCounterValue(h_counter, - PDH_FMT_DOUBLE, - (LPDWORD)NULL, - &fmt_value); + /* may require 2 counters, see msdn docs */ + int i=0; + for (i=0; i<2; i++) { + status = PdhGetFormattedCounterValue(h_counter, + PDH_FMT_DOUBLE, + (LPDWORD)NULL, + &fmt_value); + if (status == ERROR_SUCCESS) { + break; + } + + PdhCollectQueryData(h_query); + } } else { status = PdhGetRawCounterValue(h_counter, &type, &raw_value);