add Pdh.getPerflibCounterMap()
This commit is contained in:
parent
8f70da2dd3
commit
fc5d1b1823
|
@ -19,11 +19,16 @@
|
|||
package org.hyperic.sigar.win32;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
public class Pdh extends Win32 {
|
||||
|
||||
public static final String PERFLIB_KEY =
|
||||
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Perflib";
|
||||
|
||||
private long query = -1l; // Handle to the query
|
||||
private String hostname = null;
|
||||
private Properties names;
|
||||
|
@ -57,6 +62,52 @@ public class Pdh extends Win32 {
|
|||
}
|
||||
}
|
||||
|
||||
private static class PerflibCounterMap extends ArrayList {
|
||||
private Map map = new HashMap();
|
||||
private String index = null;
|
||||
|
||||
//called by RegistryKey.getMultiStringValue
|
||||
//format description see: http://support.microsoft.com/kb/q287159/
|
||||
public boolean add(Object o) {
|
||||
if (index == null) {
|
||||
index = (String)o;
|
||||
return true;
|
||||
}
|
||||
//name -> index
|
||||
this.map.put(o, index);
|
||||
index = null; //reset
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static Map getEnglishPerflibCounterMap()
|
||||
throws Win32Exception {
|
||||
|
||||
LocaleInfo locale =
|
||||
new LocaleInfo(LocaleInfo.LANG_ENGLISH);
|
||||
|
||||
return getPerflibCounterMap(locale);
|
||||
}
|
||||
|
||||
public static Map getPerflibCounterMap(LocaleInfo locale)
|
||||
throws Win32Exception {
|
||||
|
||||
String path =
|
||||
PERFLIB_KEY + "\\" + locale.getPerflibLangId();
|
||||
|
||||
RegistryKey key =
|
||||
RegistryKey.LocalMachine.openSubKey(path);
|
||||
|
||||
PerflibCounterMap counters = new PerflibCounterMap();
|
||||
try {
|
||||
key.getMultiStringValue("Counter", counters);
|
||||
} finally {
|
||||
key.close();
|
||||
}
|
||||
|
||||
return counters.map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @see #getRawValue(String path)
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
package org.hyperic.sigar.win32.test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hyperic.sigar.test.SigarTestCase;
|
||||
import org.hyperic.sigar.win32.Pdh;
|
||||
|
||||
|
@ -56,6 +58,23 @@ public class TestPdh extends SigarTestCase {
|
|||
*/
|
||||
}
|
||||
|
||||
public void testCounterMap() throws Exception {
|
||||
Map counters = Pdh.getEnglishPerflibCounterMap();
|
||||
|
||||
assertGtZeroTrace("counters", counters.size());
|
||||
|
||||
String[] keys = {
|
||||
"System", "System Up Time"
|
||||
};
|
||||
String last = null;
|
||||
for (int i=0; i<keys.length; i++) {
|
||||
String index = (String)counters.get(keys[i]);
|
||||
assertFalse(index.equals(last));
|
||||
traceln(keys[i] + "=" + index);
|
||||
last = index;
|
||||
}
|
||||
}
|
||||
|
||||
public void testPdh() throws Exception {
|
||||
|
||||
String[] iface = Pdh.getKeys("Thread");
|
||||
|
|
Loading…
Reference in New Issue