Class: JRubyProf::GraphHtmlPrinter

Inherits:
GraphTextPrinter show all
Defined in:
lib/jruby-prof/graph_html_printer.rb

Constant Summary collapse

HEADER =
"    <html>\n      <body>\n<head>\n<style media=\"all\" type=\"text/css\">\n    table {\n      border-collapse: collapse;\n      border: 1px solid #CCC;\n      font-family: Verdana, Arial, Helvetica, sans-serif;\n      font-size: 9pt;\n      line-height: normal;\n    }\n\n    th {\n      text-align: center;\n      border-top: 1px solid #FB7A31;\n      border-bottom: 1px solid #FB7A31;\n      background: #FFC;\n      padding: 0.3em;\n      border-left: 1px solid silver;\n    }\n\n    tr.break td {\n      border: 0;\n      border-top: 1px solid #FB7A31;\n      padding: 0;\n      margin: 0;\n    }\n\n    tr.method td {\n      font-weight: bold;\n    }\n\n    td {\n      padding: 0.3em;\n    }\n\n    td:first-child {\n      width: 190px;\n      }\n\n    td {\n      border-left: 1px solid #CCC;\n      text-align: center;\n    } \n  </style>\n</head>\n"
TABLE_HEADER =
"<table>\n  <tr>\n    <th>%total</th>\n    <th>%self</th>\n    <th>total</th>\n    <th>self</th>\n    <th>children</th>\n    <th>calls</th>\n    <th>Name</th>\n  </tr>\n"
"</table>\n<br />\n<br />\n"
"</body>\n</html>\n"

Instance Attribute Summary

Attributes inherited from AbstractPrinter

#thread_set

Instance Method Summary collapse

Methods inherited from AbstractPrinter

#initialize, #print_to_file

Constructor Details

This class inherits a constructor from JRubyProf::AbstractPrinter

Instance Method Details



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/jruby-prof/graph_html_printer.rb', line 30

def print_method(output, method, total_duration, major_row)
  return if method.name =~ /JRubyProf\.stop/
  total    = method.duration
  total_pc = (total.to_f/total_duration)*100
  children = method.childrens_duration
  self_    = total - children
  self_pc  = (self_.to_f/total_duration)*100
  calls    = method.count
  name     = method.name
  inv_id   = nil
  template = File.read(File.join(File.dirname(__FILE__), "..", "..", "templates", "graph_row.html.erb"))
  erb = ERB.new(template)
  output.puts(erb.result(binding))
end


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jruby-prof/graph_html_printer.rb', line 4

def print_on(output)
  output.puts HEADER
  total_duration = thread_set.duration
  thread_set.invocations.each_with_index do |thread, i|
    methods = thread.get_methods.values.sort_by {|m| m.duration }.reverse
    output.puts "<h3>Thread #{i + 1}/#{thread_set.length}</h3>"
    output.puts TABLE_HEADER
    rows = methods.map do |method|
      method.parent_contexts.each do |context|  
        print_method(output, context, total_duration, false)
      end
      print_method(output, method, total_duration, true)
      method.child_contexts.each do |context|  
        print_method(output, context, total_duration, false)
      end
      output.puts "        <tr class=\"break\">\n          <td colspan=\"7\"></td>\n        </tr>\n      HTML\n    end\n    output.puts TABLE_FOOTER\n  end\n  output.puts FOOTER\nend\n"

#safe_name(name) ⇒ Object



45
46
47
# File 'lib/jruby-prof/graph_html_printer.rb', line 45

def safe_name(name)
  name.gsub("#", "_inst_").gsub(".", "_stat_")
end