[강운덕] [LUCYSUS-1744] call을 추적하는 Trace객체 리팩토링, 자체 call stack을 가지고 있도록 변경함.

git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@851 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
Woonduk Kang
2012-11-08 07:55:13 +00:00
parent edbaeed4df
commit 9e562b54eb
27 changed files with 738 additions and 590 deletions
+38 -37
View File
@@ -5,49 +5,50 @@ import java.util.Map;
import com.profiler.util.NamedThreadLocal;
@Deprecated
public class StopWatch {
private static ThreadLocal<Map<String, Long>> local = new NamedThreadLocal<Map<String, Long>>("StopWatch");
private static ThreadLocal<Map<String, Long>> local = new NamedThreadLocal<Map<String, Long>>("StopWatch");
public static void start(int id) {
start(String.valueOf(id));
}
public static void start(int id) {
start(String.valueOf(id));
}
public static long stopAndGetElapsed(int id) {
return stopAndGetElapsed(String.valueOf(id));
}
public static long stopAndGetElapsed(int id) {
return stopAndGetElapsed(String.valueOf(id));
}
public static void start(String id) {
Map<String, Long> map = local.get();
if (map == null) {
map = new HashMap<String, Long>(1);
map.put(id, System.nanoTime());
local.set(map);
} else {
map.put(id, System.nanoTime());
}
}
public static void start(String id) {
Map<String, Long> map = local.get();
if (map == null) {
map = new HashMap<String, Long>(1);
map.put(id, System.nanoTime());
local.set(map);
} else {
map.put(id, System.nanoTime());
}
}
public static long stopAndGetElapsed(String id) {
Map<String, Long> map = local.get();
if (map == null) {
// throw new IllegalStateException("Stopwatch is not started.");
// TODO application 에러로 전달되는경우가 있어서 일단 0으로
return -1;
} else {
Long startTime = map.get(id);
public static long stopAndGetElapsed(String id) {
Map<String, Long> map = local.get();
if (map == null) {
// throw new IllegalStateException("Stopwatch is not started.");
// TODO application 에러로 전달되는경우가 있어서 일단 0으로
return -1;
} else {
Long startTime = map.get(id);
map.remove(id);
// TODO: if using thread pool, this is unnecessary.
// if (map.size() == 0) {
// local.remove();
// }
map.remove(id);
// TODO: if using thread pool, this is unnecessary.
// if (map.size() == 0) {
// local.remove();
// }
if (startTime != null) {
return System.nanoTime() - startTime;
} else {
return -1;
}
}
}
if (startTime != null) {
return System.nanoTime() - startTime;
} else {
return -1;
}
}
}
}