Skip to content

Instantly share code, notes, and snippets.

@itarato
Created April 11, 2023 14:30
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 itarato/fbb1efccde0774c29616f340af406d16 to your computer and use it in GitHub Desktop.
Save itarato/fbb1efccde0774c29616f340af406d16 to your computer and use it in GitHub Desktop.
Extracts a block of subtree from a callgraph of a given function (matched by a substring).
=begin
Extracts a block of subtree from a callgraph of a given function (matched by a substring).
Use:
jt ruby --cpusampler=calltree -e 'a=[];a.push(1);p(a.size)' | ruby truffle_calltree_find.rb "IO#puts"
=end
pattern = ARGV[0]
in_match = false
tab_size = nil
STDIN.each_line.with_index do |line, idx|
if !in_match
if line.index(pattern) != nil
in_match = true
tab_size = line.match(/^ */)[0].size
puts(line)
end
else
current_tab_size = line.match(/^ */)[0].size
if current_tab_size == tab_size
in_match = false
puts("\n\n---\n\n")
else
puts(line)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment