there may be more than one index per name

This commit is contained in:
Doug MacEachern 2007-03-05 21:14:27 +00:00
parent 9289f45dce
commit 98fd0fdbcc
2 changed files with 34 additions and 11 deletions

View File

@ -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;
}

View File

@ -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<keys.length; i++) {
String name = keys[i];
String index = (String)counters.get(name);
assertFalse(index.equals(last));
traceln(name + "=" + index);
last = index;
int[] ix = (int[])counters.get(name);
assertFalse(ix[0] == last);
traceln(name + "=" + ix[0]);
last = ix[0];
String lookupName =
Pdh.getCounterName(Integer.parseInt(index));
Pdh.getCounterName(ix[0]);
traceln(name + "=" + lookupName);
}
}