/**
* @param args
*/
public static void main(String[] args) {
PerformanceCounters perfCtr = VmProcessor.current()
.getPerformanceCounters();
if (perfCtr.getMaximumCounters() == 0) {
System.out.println("No counters available");
return;
}
if (args.length == 0) {
System.out.println("Available events:");
for (PerformanceCounterEvent evt : perfCtr.getAvailableEvents()) {
System.out.println(evt);
}
System.out.println();
} else {
PerformanceCounterEvent[] events = new PerformanceCounterEvent[perfCtr
.getMaximumCounters()];
int i = 0;
for (String arg : args) {
if (i >= events.length) {
break;
}
PerformanceCounterEvent evt = perfCtr.getAvailableEvent(arg);
if (evt != null) {
events[i++] = evt;
}
}
// for (PerformanceCounterEvent evt : perfCtr.getAvailableEvents())
// {
// if (i >= events.length) {
// break;
// }
// events[i++] = evt;
// }
if (i < events.length) {
PerformanceCounterEvent[] evt2 = new PerformanceCounterEvent[i];
System.arraycopy(events, 0, evt2, 0, i);
events = evt2;
}
long[] counters = new long[events.length];
perfCtr.startCounters(events);
ArithOpt.main(new String[0]);
perfCtr.getCounterValues(counters);
perfCtr.stopCounters();
for (i = 0; i < events.length; i++) {
System.out.println(events[i].getId() + " 0x"
+ NumberUtils.hex(counters[i]));
}
}