#!/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