add simple timer registry

This commit is contained in:
Doug MacEachern 2007-02-01 01:01:19 +00:00
parent 421f3b4dc5
commit 6742c80134
1 changed files with 15 additions and 0 deletions

View File

@ -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();