Skip to content

Commit

Permalink
Ignore trailing sleeping samples for duration estimation (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
SirYwell authored Jul 14, 2024
1 parent 45ce159 commit d909d19
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public List<ThreadNode> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -151,6 +151,16 @@ public List<ThreadInfo> 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);
}
Expand Down

0 comments on commit d909d19

Please sign in to comment.