Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ $ ./jfr-flame-graph -h
-rv, --show-return-value
Show return value for methods in the stack
Default: false
-rev, --reverse-call-stack
Reverse call stacks so that it can show JFR style graph(bottom-up)
Default: false
-st, --start-timestamp
Start timestamp in seconds for filtering
Default: -9223372036854775808
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public final class JFRToFlameGraphWriter {
"--event"}, description = "Type of event used to generate the flamegraph", converter = EventType.EventTypeConverter.class)
EventType eventType = EventType.METHOD_PROFILING_SAMPLE;

@Parameter(names = {"-rev",
"--reverse-call-stack"}, description = "Reverse call stacks so that it can show JFR style graph(bottom-up)")
boolean reverseCallStack;

private static final String EVENT_VALUE_STACK = "(stackTrace)";

private static final String PRINT_FORMAT = "%-16s: %s%n";
Expand Down Expand Up @@ -236,6 +240,13 @@ private Stack<String> getStack(IEvent event) {
stack.push(frameName);
}
}
if(reverseCallStack){
Stack<String> stack_rev = new Stack<>();
while(!stack.isEmpty()){
stack_rev.push(stack.pop());
}
stack = stack_rev;
}
return stack;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public StackFrame(String name) {
this.name = name;
}

public StackFrame addFrame(String frameName) {
public StackFrame addFrame(String frameName, long size) {
if (children == null) {
children = new ArrayList<>();
}
Expand All @@ -87,7 +87,7 @@ public StackFrame addFrame(String frameName) {
childrenMap.put(frameName, frame);
children.add(frame);
}
frame.value++;
frame.value += size;
return frame;
}
}
Expand All @@ -108,7 +108,7 @@ public void processEvent(long startTimestamp, long endTimestamp, long duration,
}

while (!stack.empty()) {
frame = frame.addFrame(stack.pop());
frame = frame.addFrame(stack.pop(), size);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,9 @@ public void testEventTypeOptionDefaultValue() throws Exception {
assertEquals(EventType.METHOD_PROFILING_SAMPLE, jfrToFlameGraphWriter.eventType);
}

public void testReverseCallStackValue() throws Exception {
String[] args = {"-f", "temp", "-rev"};
parseCommands(args);
assertTrue(jfrToFlameGraphWriter.reverseCallStack);
}
}