there may be more than one index per name
This commit is contained in:
parent
9289f45dce
commit
98fd0fdbcc
|
@ -96,8 +96,19 @@ public class Pdh extends Win32 {
|
||||||
index = (String)o;
|
index = (String)o;
|
||||||
return true;
|
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
|
//name -> index
|
||||||
this.map.put(o, index);
|
this.map.put(o, ix);
|
||||||
index = null; //reset
|
index = null; //reset
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -158,12 +169,12 @@ public class Pdh extends Win32 {
|
||||||
private static String getCounterName(String englishName)
|
private static String getCounterName(String englishName)
|
||||||
throws Win32Exception {
|
throws Win32Exception {
|
||||||
|
|
||||||
String index = (String)counters.get(englishName);
|
int[] ix = (int[])counters.get(englishName);
|
||||||
if (index == null) {
|
if (ix == null) {
|
||||||
return englishName;
|
return englishName;
|
||||||
}
|
}
|
||||||
int ix = Integer.parseInt(index);
|
|
||||||
String name = getCounterName(ix);
|
String name = getCounterName(ix[0]);
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
package org.hyperic.sigar.win32.test;
|
package org.hyperic.sigar.win32.test;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hyperic.sigar.test.SigarTestCase;
|
import org.hyperic.sigar.test.SigarTestCase;
|
||||||
|
@ -76,19 +77,30 @@ public class TestPdh extends SigarTestCase {
|
||||||
Map counters = Pdh.getEnglishPerflibCounterMap();
|
Map counters = Pdh.getEnglishPerflibCounterMap();
|
||||||
|
|
||||||
assertGtZeroTrace("counters", counters.size());
|
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 = {
|
String[] keys = {
|
||||||
"System", "System Up Time"
|
"System", "System Up Time"
|
||||||
};
|
};
|
||||||
String last = null;
|
int last = -1;
|
||||||
for (int i=0; i<keys.length; i++) {
|
for (int i=0; i<keys.length; i++) {
|
||||||
String name = keys[i];
|
String name = keys[i];
|
||||||
String index = (String)counters.get(name);
|
int[] ix = (int[])counters.get(name);
|
||||||
assertFalse(index.equals(last));
|
assertFalse(ix[0] == last);
|
||||||
traceln(name + "=" + index);
|
traceln(name + "=" + ix[0]);
|
||||||
last = index;
|
last = ix[0];
|
||||||
String lookupName =
|
String lookupName =
|
||||||
Pdh.getCounterName(Integer.parseInt(index));
|
Pdh.getCounterName(ix[0]);
|
||||||
traceln(name + "=" + lookupName);
|
traceln(name + "=" + lookupName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue