lib/stackprof/report.rb in stackprof-0.2.5 vs lib/stackprof/report.rb in stackprof-0.2.6
- old
+ new
@@ -81,25 +81,28 @@
def print_flamegraph(f=STDOUT, skip_common=true)
raise "profile does not include raw samples" unless raw = data[:raw]
stacks = []
+ max_x = 0
max_y = 0
while len = raw.shift
max_y = len if len > max_y
- stacks << raw.slice!(0, len+1)
+ stack = raw.slice!(0, len+1)
+ stacks << stack
+ max_x += stack.last
end
- max_x = stacks.inject(0){ |sum, (*stack, weight)| sum + weight }
f.puts 'flamegraph(['
max_y.times do |y|
row_prev = nil
row_width = 0
x = 0
- stacks.each do |*stack, weight|
- cell = stack[y]
+ stacks.each do |stack|
+ weight = stack.last
+ cell = stack[y] unless y == stack.length-1
if cell.nil?
if row_prev
flamegraph_row(f, x - row_width, y, row_width, row_prev)
end
@@ -217,10 +220,10 @@
f.puts "fn=#{frame[:name]}"
frame[:lines].each do |line, weight|
f.puts "#{line} #{weight.is_a?(Array) ? weight[1] : weight}"
end if frame[:lines]
frame[:edges].each do |edge, weight|
- oframe = list[edge.to_s]
+ oframe = list[edge]
f.puts "cfl=#{oframe[:file]}" unless oframe[:file] == frame[:file]
f.puts "cfn=#{oframe[:name]}"
f.puts "calls=#{weight} #{frame[:line] || 0}\n#{oframe[:line] || 0} #{weight}"
end if frame[:edges]
f.puts