diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/java/JavaDataAggregator.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/java/JavaDataAggregator.java index c51ec052..b7b841ea 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/sampler/java/JavaDataAggregator.java +++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/java/JavaDataAggregator.java @@ -99,7 +99,7 @@ public List exportData() { return super.exportData(); } - private static boolean isSleeping(ThreadInfo thread) { + static boolean isSleeping(ThreadInfo thread) { if (thread.getThreadState() == Thread.State.WAITING || thread.getThreadState() == Thread.State.TIMED_WAITING) { return true; } diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/java/TickedDataAggregator.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/java/TickedDataAggregator.java index 08cb7193..f24af3f3 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/sampler/java/TickedDataAggregator.java +++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/java/TickedDataAggregator.java @@ -110,7 +110,7 @@ private void pushCurrentTick(Executor executor) { } // approximate how long the tick lasted - int tickLengthMicros = currentData.getList().size() * this.interval; + int tickLengthMicros = currentData.sizeWithoutTrailingSleeping() * this.interval; // don't push data below the threshold if (tickLengthMicros < this.tickLengthThreshold) { @@ -151,6 +151,16 @@ public List getList() { return this.list; } + public int sizeWithoutTrailingSleeping() { + // find the last index at which the thread wasn't sleeping + for (int i = this.list.size() - 1; i >= 0; i--) { + if (!isSleeping(this.list.get(i))) { + return i + 1; // add one to go from index to size + } + } + return 0; + } + public void addData(ThreadInfo data) { this.list.add(data); }