Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bin/stackprof
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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('--json', 'JSON output (use with web viewers)'){ options[:format] = :json }
o.on('--files', 'List of files'){ |f| options[:format] = :files }
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 }
Expand Down Expand Up @@ -62,6 +63,8 @@ options.delete(:limit) if options[:limit] == 0
case options[:format]
when :text
report.print_text(options[:sort], options[:limit], options[:select_files], options[:reject_files], options[:select_names], options[:reject_names])
when :json
report.print_json
when :debug
report.print_debug
when :dump
Expand Down
5 changes: 5 additions & 0 deletions lib/stackprof/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ def print_dump(f=STDOUT)
f.puts Marshal.dump(@data.reject{|k,v| k == :files })
end

def print_json(f=STDOUT)
require "json"
f.puts JSON.generate(@data)
end

def print_stackcollapse
raise "profile does not include raw samples (add `raw: true` to collecting StackProf.run)" unless raw = data[:raw]

Expand Down