fix monitor command time stat problem(#942)

pull/952/head
huangjIT 5 years ago committed by hengyunabc
parent 653b21760a
commit 107da67c2d

@ -1,31 +1,33 @@
package com.taobao.arthas.core.util;
import java.util.Stack;
/**
* TODO stack
*
* Created by vlinux on 16/6/1.
* @author hengyunabc 2016-10-31
*/
public class ThreadLocalWatch {
private final ThreadLocal<Long> timestampRef = new ThreadLocal<Long>() {
private final ThreadLocal<Stack<Long>> timestampRef = new ThreadLocal<Stack<Long>>() {
@Override
protected Long initialValue() {
return System.nanoTime();
protected Stack<Long> initialValue() {
return new Stack<Long>();
}
};
public long start() {
final long timestamp = System.nanoTime();
timestampRef.set(timestamp);
timestampRef.get().push(timestamp);
return timestamp;
}
public long cost() {
return (System.nanoTime() - timestampRef.get());
return (System.nanoTime() - timestampRef.get().pop());
}
public double costInMillis() {
return (System.nanoTime() - timestampRef.get()) / 1000000.0;
return (System.nanoTime() - timestampRef.get().pop()) / 1000000.0;
}
public void clear() {

Loading…
Cancel
Save