bin/stackprof in stackprof-0.2.7 vs bin/stackprof in stackprof-0.2.8

- old
+ new

@@ -1,26 +1,23 @@ #!/usr/bin/env ruby require 'optparse' require 'stackprof' -options = { - :format => :text, - :sort => false, - :limit => 30 -} +options = {} parser = OptionParser.new(ARGV) do |o| o.banner = "Usage: stackprof [file.dump]+ [--text|--method=NAME|--callgrind|--graphviz]" o.on('--text', 'Text summary per method (default)'){ options[:format] = :text } o.on('--files', 'List of files'){ |f| options[:format] = :files } - o.on('--limit [num]', Integer, 'Limit --text or --files output to N lines'){ |n| options[:limit] = n } + o.on('--limit [num]', Integer, 'Limit --text, --files, or --graphviz output to N entries'){ |n| options[:limit] = n } 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\n\n"){ |f| options[:format] = :file; options[:filter] = f } o.on('--callgrind', 'Callgrind output (use with kcachegrind, stackprof-gprof2dot.py)'){ options[:format] = :callgrind } o.on('--graphviz', "Graphviz output (use with dot)"){ options[:format] = :graphviz } + o.on('--node-fraction [frac]', OptionParser::DecimalNumeric, 'Drop nodes representing less than [frac] fraction of samples'){ |n| options[:node_fraction] = n } o.on('--stackcollapse', 'stackcollapse.pl compatible output (use with stackprof-flamegraph.pl)'){ options[:format] = :stackcollapse } o.on('--flamegraph', "timeline-flamegraph output (js)"){ options[:format] = :flamegraph } o.on('--flamegraph-viewer [f.js]', String, "open html viewer for flamegraph output\n\n"){ |file| puts("open file://#{File.expand_path('../../lib/stackprof/flamegraph/viewer.html', __FILE__)}?data=#{File.expand_path(file)}") exit @@ -41,20 +38,34 @@ STDERR.puts "** error parsing #{file}: #{e.inspect}" end end report = reports.inject(:+) +default_options = { + :format => :text, + :sort => false, + :limit => 30 +} + +if options[:format] == :graphviz + default_options[:limit] = 120 + default_options[:node_fraction] = 0.005 +end + +options = default_options.merge(options) +options.delete(:limit) if options[:limit] == 0 + case options[:format] when :text report.print_text(options[:sort], options[:limit]) when :debug report.print_debug when :dump report.print_dump when :callgrind report.print_callgrind when :graphviz - report.print_graphviz + report.print_graphviz(options) when :stackcollapse report.print_stackcollapse when :flamegraph report.print_flamegraph when :method