Skip to content

Commit

Permalink
Fix counts for root frame
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmitterdorfer committed Sep 11, 2023
1 parent d063722 commit 7d1b25a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ public double getTotalSeconds() {
return totalSeconds;
}

public List<Integer> getCountInclusive() {
return countInclusive;
}

public List<Integer> getCountExclusive() {
return countExclusive;
}

@Override
public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params) {
return Iterators.concat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public void onFailure(Exception e) {

static GetFlamegraphResponse buildFlamegraph(GetStackTracesResponse response) {
// TODO: Are full seconds good enough? (they probably are)
long totalSeconds = Duration.between(response.getStartTime(), response.getEndTime()).getSeconds();
Duration observedDuration = Duration.between(response.getStartTime(), response.getEndTime());
long totalSeconds = (observedDuration.getNano() > 0) ? observedDuration.getSeconds() + 1 : observedDuration.getSeconds();

FlamegraphBuilder builder = new FlamegraphBuilder(response.getTotalFrames(), response.getSamplingRate(), totalSeconds);
if (response.getTotalFrames() == 0) {
return builder.build();
Expand All @@ -92,6 +94,8 @@ static GetFlamegraphResponse buildFlamegraph(GetStackTracesResponse response) {
StackTrace stackTrace = st.getValue();
int samples = response.getStackTraceEvents().getOrDefault(stackTraceId, 0);
builder.setCurrentNode(0);
builder.addSamplesInclusive(0, samples);
builder.addSamplesExclusive(0, 0);

int frameCount = stackTrace.frameIds.size();
for (int i = 0; i < frameCount; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,8 @@ public void testCreateFlamegraph() {
assertEquals(10, response.getSize());
assertEquals(1.0d, response.getTotalSeconds(), 0.001d);
assertEquals(1.0d, response.getSamplingRate(), 0.001d);
assertEquals(List.of(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), response.getCountInclusive());
assertEquals(List.of(0, 0, 0, 0, 0, 0, 0, 0, 0, 1), response.getCountExclusive());

}
}

0 comments on commit 7d1b25a

Please sign in to comment.