From 98fd0fdbcc7b3edb6bad0573b14725ca382d25a9 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Mon, 5 Mar 2007 21:14:27 +0000 Subject: [PATCH] there may be more than one index per name --- .../java/src/org/hyperic/sigar/win32/Pdh.java | 21 ++++++++++++---- .../org/hyperic/sigar/win32/test/TestPdh.java | 24 ++++++++++++++----- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/bindings/java/src/org/hyperic/sigar/win32/Pdh.java b/bindings/java/src/org/hyperic/sigar/win32/Pdh.java index f8f6fa44..5ef6d356 100644 --- a/bindings/java/src/org/hyperic/sigar/win32/Pdh.java +++ b/bindings/java/src/org/hyperic/sigar/win32/Pdh.java @@ -96,8 +96,19 @@ public class Pdh extends Win32 { index = (String)o; return true; } + int[] ix = + (int[])this.map.get(o); + if (ix == null) { + ix = new int[1]; + } + else { + int[] cur = ix; + ix = new int[cur.length + 1]; + System.arraycopy(cur, 0, ix, 1, cur.length); + } + ix[0] = Integer.parseInt(index); //name -> index - this.map.put(o, index); + this.map.put(o, ix); index = null; //reset return true; } @@ -158,12 +169,12 @@ public class Pdh extends Win32 { private static String getCounterName(String englishName) throws Win32Exception { - String index = (String)counters.get(englishName); - if (index == null) { + int[] ix = (int[])counters.get(englishName); + if (ix == null) { return englishName; } - int ix = Integer.parseInt(index); - String name = getCounterName(ix); + + String name = getCounterName(ix[0]); return name; } 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 3c8b4d78..767ff3f3 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,7 @@ package org.hyperic.sigar.win32.test; +import java.util.Iterator; import java.util.Map; import org.hyperic.sigar.test.SigarTestCase; @@ -76,19 +77,30 @@ public class TestPdh extends SigarTestCase { Map counters = Pdh.getEnglishPerflibCounterMap(); assertGtZeroTrace("counters", counters.size()); + int dups = 0; + for (Iterator it=counters.entrySet().iterator(); it.hasNext();) { + Map.Entry entry = (Map.Entry)it.next(); + String name = (String)entry.getKey(); + int[] ix = (int[])entry.getValue(); + if (ix.length > 1) { + dups++; + //traceln(name + " has dups: " + ix.length); + } + } + traceln(dups + " names have dups"); String[] keys = { "System", "System Up Time" }; - String last = null; + int last = -1; for (int i=0; i