Created
March 8, 2023 13:27
-
-
Save jepio/ad07eced81501277570faf6eba841004 to your computer and use it in GitHub Desktop.
post-process ftrace stacktraces to allow using as input for flamegraph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import collections | |
def convert_stack(stack): | |
return ";".join(stack[::-1]) | |
def process_file(file): | |
current_stack = [] | |
for line in file: | |
if '=>' in line: | |
function = line.strip().lstrip('=> ') | |
current_stack += [function] | |
elif current_stack: | |
yield convert_stack(current_stack) | |
current_stack = [] | |
if current_stack: | |
yield convert_stack(current_stack) | |
if __name__ == '__main__': | |
stacks = collections.defaultdict(int) | |
for stack in process_file(sys.stdin): | |
stacks[stack] += 1 | |
for stack, count in stacks.items(): | |
print(stack, count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment