class StackProf::Webnav::Presenter

Attributes

report[R]

Public Class Methods

new(report) click to toggle source
# File lib/stackprof-webnav/presenter.rb, line 9
def initialize report
  @report = report
end

Public Instance Methods

file_overview(path) click to toggle source
# File lib/stackprof-webnav/presenter.rb, line 13
def file_overview path
  buffer = StringIO.new
  report.print_file(path, buffer)
  data = buffer.string.split("\n").map {|l| l.split('|').first}

  {
    :lineinfo => data,
    :code => BetterErrors::CodeFormatter::HTML.new(path, 0, 9999).output
  }
end
method_info(name) click to toggle source
# File lib/stackprof-webnav/presenter.rb, line 37
def method_info name
  name = /#{Regexp.escape name}/ unless Regexp === name
  frames = report.frames.select do |frame, info|
    info[:name] =~ name
  end.map do |frame, info|
    file, line = info.values_at(:file, :line)

    {
      :callers => callers(frame, info),
      :callees => callees(frame, info),
      :location => file,
      :source => BetterErrors::CodeFormatter::HTML.new(file, line).output
    }
  end
end
overview_frames() click to toggle source
# File lib/stackprof-webnav/presenter.rb, line 24
def overview_frames
  report.frames.map do |frame, info|
    call, total = info.values_at(:samples, :total_samples)
    {
      :total => total,
      :total_pct => percent(total.to_f/report.overall_samples),
      :samples => call,
      :samples_pct => percent(call.to_f/report.overall_samples),
      :method => info[:name]
    }
  end
end

Private Instance Methods

callees(frame, info) click to toggle source
# File lib/stackprof-webnav/presenter.rb, line 73
def callees frame, info
  (info[:edges] || []).map do |k, weight|
    [report.data[:frames][k][:name], weight]
  end.sort_by { |k,v| -v }.map do |name, weight|
    {
      :weight =>  weight,
      :pct =>     percent(weight.to_f/(info[:total_samples]-info[:samples])),
      :method =>  name
    }
  end
end
callers(frame, info) click to toggle source
# File lib/stackprof-webnav/presenter.rb, line 59
def callers frame, info
  report.data[:frames].select do |id, other|
    other[:edges] && other[:edges].include?(frame)
  end.map do |id, other|
    [other[:name], other[:edges][frame]]
  end.sort_by(&:last).reverse.map do |name, weight|
    {
      :weight =>  weight,
      :pct =>     percent(weight.to_f/info[:total_samples]),
      :method =>  name
    }
  end
end
percent(value) click to toggle source
# File lib/stackprof-webnav/presenter.rb, line 55
def percent value
  "%2.2f%%" % (value*100)
end