diff options
author | Luck <git@lucko.me> | 2019-02-21 13:06:10 +0000 |
---|---|---|
committer | Luck <git@lucko.me> | 2019-02-21 13:06:10 +0000 |
commit | 161d3bdfbfe331a1ea3c6da1d096e86fd7a5c525 (patch) | |
tree | 96be6a24e9bd45198e4d5620eff57bba1e0a94cb /spark-common/src/main/java/me/lucko/spark/sampler/node | |
parent | 77c93aeeea763c68a4fd7f5b59afcfc2f6336379 (diff) | |
download | spark-161d3bdfbfe331a1ea3c6da1d096e86fd7a5c525.tar.gz spark-161d3bdfbfe331a1ea3c6da1d096e86fd7a5c525.tar.bz2 spark-161d3bdfbfe331a1ea3c6da1d096e86fd7a5c525.zip |
Allow sampling at fractions of a millisecond intervals
Diffstat (limited to 'spark-common/src/main/java/me/lucko/spark/sampler/node')
-rw-r--r-- | spark-common/src/main/java/me/lucko/spark/sampler/node/AbstractNode.java | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/sampler/node/AbstractNode.java b/spark-common/src/main/java/me/lucko/spark/sampler/node/AbstractNode.java index 75632c4..859014f 100644 --- a/spark-common/src/main/java/me/lucko/spark/sampler/node/AbstractNode.java +++ b/spark-common/src/main/java/me/lucko/spark/sampler/node/AbstractNode.java @@ -30,6 +30,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.LongAdder; /** @@ -45,12 +46,21 @@ public abstract class AbstractNode { private final Map<String, StackTraceNode> children = new ConcurrentHashMap<>(); /** - * The accumulated sample time for this node + * The accumulated sample time for this node, measured in microseconds */ private final LongAdder totalTime = new LongAdder(); - + + /** + * Returns the total sample time for this node in milliseconds. + * + * @return the total time + */ public long getTotalTime() { - return this.totalTime.longValue(); + long millis = TimeUnit.MICROSECONDS.toMillis(this.totalTime.longValue()); + if (millis == 0) { + return 1; + } + return millis; } private AbstractNode resolveChild(String className, String methodName, int lineNumber) { |