lib/stackprof/report.rb in stackprof-0.2.2 vs lib/stackprof/report.rb in stackprof-0.2.3
- old
+ new
@@ -61,10 +61,26 @@
def print_debug
pp @data
end
+ def print_dump
+ puts Marshal.dump(@data.reject{|k,v| k == :files })
+ end
+
+ def print_stackcollapse
+ raise "profile does not include raw samples" unless raw = data[:raw]
+
+ while len = raw.shift
+ frames = raw.slice!(0, len)
+ weight = raw.shift
+
+ print frames.map{ |a| data[:frames][a][:name] }.join(';')
+ puts " #{weight}"
+ end
+ end
+
def print_graphviz(filter = nil, f = STDOUT)
if filter
mark_stack = []
list = frames
list.each{ |addr, frame| mark_stack << addr if frame[:name] =~ filter }
@@ -159,11 +175,11 @@
lines = info[:lines]
maxline = lines ? lines.keys.max : line + 5
f.printf "%s (%s:%d)\n", info[:name], file, line
f.printf " samples: % 5d self (%2.1f%%) / % 5d total (%2.1f%%)\n", info[:samples], 100.0*info[:samples]/overall_samples, info[:total_samples], 100.0*info[:total_samples]/overall_samples
- if (callers = data[:frames].map{ |id, other| [other[:name], other[:edges][frame]] if other[:edges] && other[:edges].include?(frame) }.compact).any?
+ if (callers = callers_for(frame)).any?
f.puts " callers:"
callers = callers.sort_by(&:last).reverse
callers.each do |name, weight|
f.printf " % 5d (% 8s) %s\n", weight, "%3.1f%%" % (100.0*weight/info[:total_samples]), name
end
@@ -200,9 +216,18 @@
source_display(f, file, lines)
end
end
private
+
+ def root_frames
+ frames.select{ |addr, frame| callers_for(addr).size == 0 }
+ end
+
+ def callers_for(addr)
+ @callers_for ||= {}
+ @callers_for[addr] ||= data[:frames].map{ |id, other| [other[:name], other[:edges][addr]] if other[:edges] && other[:edges].include?(addr) }.compact
+ end
def source_display(f, file, lines, range=nil)
File.readlines(file).each_with_index do |code, i|
next unless range.nil? || range.include?(i)
if lines and lineinfo = lines[i+1]