Skip to content

Instantly share code, notes, and snippets.

@jepio
Created March 8, 2023 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jepio/ad07eced81501277570faf6eba841004 to your computer and use it in GitHub Desktop.
Save jepio/ad07eced81501277570faf6eba841004 to your computer and use it in GitHub Desktop.
post-process ftrace stacktraces to allow using as input for flamegraph
#!/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