Skip to content

Commit

Permalink
stackcollapse reporting for flamegraphs
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Jan 24, 2014
1 parent 08167c8 commit 453bb7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bin/stackprof
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ parser = OptionParser.new(ARGV) do |o|
o.on('--sort-total', "Sort --text or --files output on total samples\n\n"){ options[:sort] = true }
o.on('--method [grep]', 'Zoom into specified method'){ |f| options[:format] = :method; options[:filter] = f }
o.on('--file [grep]', 'Show annotated code for specified file'){ |f| options[:format] = :file; options[:filter] = f }
o.on('--stackcollapse', 'stackcollapse.pl compatible output (use with flamegraph.pl)'){ options[:format] = :stackcollapse }
o.on('--callgrind', 'Callgrind output (use with kcachegrind, gprof2dot)'){ options[:format] = :callgrind }
o.on('--graphviz', "Graphviz output (use with dot)\n\n"){ options[:format] = :graphviz }
o.on('--dump', 'Print marshaled profile dump (combine multiple profiles)'){ options[:format] = :dump }
Expand Down Expand Up @@ -48,6 +49,8 @@ when :callgrind
report.print_callgrind
when :graphviz
report.print_graphviz
when :stackcollapse
report.print_stackcollapse
when :method
report.print_method(options[:filter])
when :file
Expand Down
12 changes: 12 additions & 0 deletions lib/stackprof/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ def print_dump
puts Marshal.dump(@data.reject{|k,v| k == :files })
end

def print_stackcollapse
raise "profile does not include raw samples" unless raw = data[:raw]

while len = raw.shift
frames = raw.slice!(0, len)
weight = raw.shift

print frames.map{ |a| data[:frames][a][:name] }.join(';')
puts " #{weight}"
end
end

def print_graphviz(filter = nil, f = STDOUT)
if filter
mark_stack = []
Expand Down

0 comments on commit 453bb7f

Please sign in to comment.