Skip to content

Commit

Permalink
Include empty frames
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmitterdorfer committed Sep 11, 2023
1 parent 5011885 commit d063722
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeCollection(this.countExclusive, StreamOutput::writeInt);
}

public int getSize() {
return size;
}

public double getSamplingRate() {
return samplingRate;
}

public double getTotalSeconds() {
return totalSeconds;
}

@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 @@ -31,7 +31,7 @@

public class TransportGetFlamegraphAction extends HandledTransportAction<GetStackTracesRequest, GetFlamegraphResponse> {
private static final Logger log = LogManager.getLogger(TransportGetFlamegraphAction.class);
private static final StackFrame EMPTY_STACKFRAME = new StackFrame(null, null, null, null);
private static final StackFrame EMPTY_STACKFRAME = new StackFrame("", "", 0, 0);

private final NodeClient nodeClient;
private final TransportService transportService;
Expand Down Expand Up @@ -73,7 +73,7 @@ public void onFailure(Exception e) {
});
}

private GetFlamegraphResponse buildFlamegraph(GetStackTracesResponse response) {
static GetFlamegraphResponse buildFlamegraph(GetStackTracesResponse response) {
// TODO: Are full seconds good enough? (they probably are)
long totalSeconds = Duration.between(response.getStartTime(), response.getEndTime()).getSeconds();
FlamegraphBuilder builder = new FlamegraphBuilder(response.getTotalFrames(), response.getSamplingRate(), totalSeconds);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.profiling;

import org.elasticsearch.test.ESTestCase;

import java.time.Instant;
import java.util.List;
import java.util.Map;

public class TransportGetFlamegraphActionTests extends ESTestCase {
public void testCreateFlamegraph() {
GetStackTracesResponse stacktraces = new GetStackTracesResponse(
Map.of(
"2buqP1GpF-TXYmL4USW8gA",
new StackTrace(
List.of(12784352, 19334053, 19336161, 18795859, 18622708, 18619213, 12989721, 13658842, 16339645),
List.of(
"fr28zxcZ2UDasxYuu6dV-w",
"fr28zxcZ2UDasxYuu6dV-w",
"fr28zxcZ2UDasxYuu6dV-w",
"fr28zxcZ2UDasxYuu6dV-w",
"fr28zxcZ2UDasxYuu6dV-w",
"fr28zxcZ2UDasxYuu6dV-w",
"fr28zxcZ2UDasxYuu6dV-w",
"fr28zxcZ2UDasxYuu6dV-w",
"fr28zxcZ2UDasxYuu6dV-w"
),
List.of(
"fr28zxcZ2UDasxYuu6dV-wAAAAAAwxLg",
"fr28zxcZ2UDasxYuu6dV-wAAAAABJwOl",
"fr28zxcZ2UDasxYuu6dV-wAAAAABJwvh",
"fr28zxcZ2UDasxYuu6dV-wAAAAABHs1T",
"fr28zxcZ2UDasxYuu6dV-wAAAAABHCj0",
"fr28zxcZ2UDasxYuu6dV-wAAAAABHBtN",
"fr28zxcZ2UDasxYuu6dV-wAAAAAAxjUZ",
"fr28zxcZ2UDasxYuu6dV-wAAAAAA0Gra",
"fr28zxcZ2UDasxYuu6dV-wAAAAAA-VK9"
),
List.of(3, 3, 3, 3, 3, 3, 3, 3, 3)
)
),
Map.of(),
Map.of("fr28zxcZ2UDasxYuu6dV-w", "containerd"),
Map.of("2buqP1GpF-TXYmL4USW8gA", 1),
9,
1.0d,
Instant.ofEpochSecond(1694419200),
Instant.ofEpochSecond(1694419201)
);
GetFlamegraphResponse response = TransportGetFlamegraphAction.buildFlamegraph(stacktraces);
assertNotNull(response);
assertEquals(10, response.getSize());
assertEquals(1.0d, response.getTotalSeconds(), 0.001d);
assertEquals(1.0d, response.getSamplingRate(), 0.001d);
}
}

0 comments on commit d063722

Please sign in to comment.