mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-19 17:56:41 +10:00
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@556 84d0f5b1-2673-498c-a247-62c4ff18d310
32 lines
774 B
Java
32 lines
774 B
Java
package com.profiler;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
import com.profiler.util.NamedThreadLocal;
|
|
|
|
public class StopWatch {
|
|
|
|
private static ThreadLocal<Map<String, Long>> local = new NamedThreadLocal<Map<String, Long>>("StopWatch");
|
|
|
|
public static void start(String name) {
|
|
Map<String, Long> map = local.get();
|
|
if (map == null) {
|
|
map = new HashMap<String, Long>(1);
|
|
map.put(name, System.currentTimeMillis());
|
|
local.set(map);
|
|
} else {
|
|
map.put(name, System.currentTimeMillis());
|
|
}
|
|
}
|
|
|
|
public static long stopAndGetElapsed(String name) {
|
|
Map<String, Long> map = local.get();
|
|
if (map == null) {
|
|
throw new IllegalStateException("Stopwatch is not started.");
|
|
} else {
|
|
return System.currentTimeMillis() - map.get(name);
|
|
}
|
|
}
|
|
}
|