Sha256: 9c16422faa4eb99513164c98ceff3e92cb967eeb4d8c87c0b898aaa19ba16d42

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

#!/usr/bin/env ruby
require 'optparse'
require 'stackprof'

options = {
  :format => :text,
  :sort => false,
  :limit => 30
}

OptionParser.new(ARGV) do |o|
  o.banner = 'stackprof-report [file.dump]+'

  o.on('--text', 'Text output (default)'){ options[:format] = :text }
  o.on('--callgrind'){ options[:format] = :callgrind }
  o.on('--graphviz'){ options[:format] = :graphviz }
  o.on('--file [grep]'){ |f| options[:format] = :file; options[:filter] = f }
  o.on('--files'){ |f| options[:format] = :files }
  o.on('--method [grep]'){ |f| options[:format] = :method; options[:filter] = f }
  o.on('--debug'){ options[:format] = :debug }
  o.on('--sort-total'){ options[:sort] = true }
  o.on('--limit [num]', Integer){ |n| options[:limit] = n }
end.parse!

reports = []
while ARGV.size > 0
  reports << StackProf::Report.new(Marshal.load(IO.binread(ARGV.pop)))
end
report = reports.inject(:+)

case options[:format]
when :text
  report.print_text(options[:sort], options[:limit])
when :callgrind
  report.print_callgrind
when :graphviz
  report.print_graphviz
when :method
  report.print_method(options[:filter])
when :file
  report.print_file(options[:filter])
when :files
  report.print_files(options[:sort], options[:limit])
else
  raise ArgumentError, "unknown format: #{options[:format]}"
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stackprof-0.2.0 bin/stackprof