diff --git a/bindings/java/src/org/hyperic/sigar/win32/Pdh.java b/bindings/java/src/org/hyperic/sigar/win32/Pdh.java index 38d9482c..6649ba8a 100644 --- a/bindings/java/src/org/hyperic/sigar/win32/Pdh.java +++ b/bindings/java/src/org/hyperic/sigar/win32/Pdh.java @@ -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) 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 c9b13f8c..d1749abc 100644 --- a/bindings/java/src/org/hyperic/sigar/win32/test/TestPdh.java +++ b/bindings/java/src/org/hyperic/sigar/win32/test/TestPdh.java @@ -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