Class: StackProf::Webnav::Presenter

Inherits:
Object
  • Object
show all
Defined in:
lib/stackprof-webnav/presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(report) ⇒ Presenter

Returns a new instance of Presenter.



11
12
13
# File 'lib/stackprof-webnav/presenter.rb', line 11

def initialize report
  @report = report
end

Instance Attribute Details

#reportObject (readonly)

Returns the value of attribute report.



10
11
12
# File 'lib/stackprof-webnav/presenter.rb', line 10

def report
  @report
end

Instance Method Details

#file_overview(path) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/stackprof-webnav/presenter.rb', line 15

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

#listing_dumpsObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/stackprof-webnav/presenter.rb', line 39

def listing_dumps
  Server.report_dump_listing += "/" unless Server.report_dump_listing.end_with?("/") 
  xml_data = Net::HTTP.get(URI.parse(Server.report_dump_listing))
  if xml_data
    doc = REXML::Document.new(xml_data)
    dumps = []
    doc.elements.each('ListBucketResult/Contents') do |ele|
      dumps << {
        :key => ele.elements["Key"].text, 
        :date => ele.elements["LastModified"].text,
        :size => number_with_delimiter(ele.elements["Size"].text.to_i),
        :uri => Server.report_dump_listing + ele.elements["Key"].text
      }
    end
  end
  dumps.sort_by! { |hash| hash[:date] }
  dumps.reverse!
end

#method_info(name) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/stackprof-webnav/presenter.rb', line 58

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_framesObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/stackprof-webnav/presenter.rb', line 26

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