lib/stackprof/report.rb in stackprof-0.2.9 vs lib/stackprof/report.rb in stackprof-0.2.10
- old
+ new
@@ -7,11 +7,12 @@
@data = data
end
attr_reader :data
def frames(sort_by_total=false)
- @data[:frames].sort_by{ |iseq, stats| -stats[sort_by_total ? :total_samples : :samples] }.inject({}){|h, (k, v)| h[k] = v; h}
+ @data[:"sorted_frames_#{sort_by_total}"] ||=
+ @data[:frames].sort_by{ |iseq, stats| -stats[sort_by_total ? :total_samples : :samples] }.inject({}){|h, (k, v)| h[k] = v; h}
end
def normalized_frames
id2hash = {}
@data[:frames].each do |frame, info|
@@ -207,17 +208,21 @@
end
end
f.puts "}"
end
- def print_text(sort_by_total=false, limit=nil, f = STDOUT)
+ def print_text(sort_by_total=false, limit=nil, select_files= nil, reject_files=nil, select_names=nil, reject_names=nil, f = STDOUT)
f.puts "=================================="
f.printf " Mode: #{modeline}\n"
f.printf " Samples: #{@data[:samples]} (%.2f%% miss rate)\n", 100.0*@data[:missed_samples]/(@data[:missed_samples]+@data[:samples])
f.printf " GC: #{@data[:gc_samples]} (%.2f%%)\n", 100.0*@data[:gc_samples]/@data[:samples]
f.puts "=================================="
f.printf "% 10s (pct) % 10s (pct) FRAME\n" % ["TOTAL", "SAMPLES"]
list = frames(sort_by_total)
+ list.select!{|_, info| select_files.any?{|path| info[:file].start_with?(path)}} if select_files
+ list.select!{|_, info| select_names.any?{|reg| info[:name] =~ reg}} if select_names
+ list.reject!{|_, info| reject_files.any?{|path| info[:file].start_with?(path)}} if reject_files
+ list.reject!{|_, info| reject_names.any?{|reg| info[:name] =~ reg}} if reject_names
list = list.first(limit) if limit
list.each do |frame, info|
call, total = info.values_at(:samples, :total_samples)
f.printf "% 10d % 8s % 10d % 8s %s\n", total, "(%2.1f%%)" % (total*100.0/overall_samples), call, "(%2.1f%%)" % (call*100.0/overall_samples), info[:name]
end