add simple timer registry
This commit is contained in:
parent
421f3b4dc5
commit
6742c80134
|
@ -21,8 +21,14 @@ package org.hyperic.sigar;
|
||||||
import org.hyperic.sigar.jmx.CpuTimerMBean;
|
import org.hyperic.sigar.jmx.CpuTimerMBean;
|
||||||
|
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class CpuTimer implements CpuTimerMBean {
|
public class CpuTimer implements CpuTimerMBean {
|
||||||
|
private static final Map timers =
|
||||||
|
Collections.synchronizedMap(new HashMap());
|
||||||
|
|
||||||
private Sigar sigar;
|
private Sigar sigar;
|
||||||
private long totalTime;
|
private long totalTime;
|
||||||
private long cpuTotal;
|
private long cpuTotal;
|
||||||
|
@ -146,6 +152,15 @@ public class CpuTimer implements CpuTimerMBean {
|
||||||
return this.stopTime;
|
return this.stopTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static CpuTimer getInstance(String name) {
|
||||||
|
CpuTimer timer = (CpuTimer)timers.get(name);
|
||||||
|
if (timer == null) {
|
||||||
|
timer = new CpuTimer();
|
||||||
|
timers.put(name, timer);
|
||||||
|
}
|
||||||
|
return timer;
|
||||||
|
}
|
||||||
|
|
||||||
public String format(long elap) {
|
public String format(long elap) {
|
||||||
String fraction = (elap % 1000) + "";
|
String fraction = (elap % 1000) + "";
|
||||||
int pad = 3 - fraction.length();
|
int pad = 3 - fraction.length();
|
||||||
|
|
Loading…
Reference in New Issue