Class: Tuttle::RubyProf::FastCallStackPrinter
- Inherits:
-
RubyProf::CallStackPrinter
- Object
- RubyProf::CallStackPrinter
- Tuttle::RubyProf::FastCallStackPrinter
- Defined in:
- lib/tuttle/ruby_prof/fast_call_stack_printer.rb
Overview
prints a HTML visualization of the call tree
Instance Method Summary collapse
- #application ⇒ Object
- #expansion ⇒ Object
- #method_full_name(method) ⇒ Object
-
#print(output = STDOUT, options = {}) ⇒ Object
Specify print options.
- #print_css ⇒ Object
- #print_stack(call_info, parent_time) ⇒ Object
- #print_title_bar ⇒ Object
- #threshold ⇒ Object
Instance Method Details
#application ⇒ Object
112 113 114 |
# File 'lib/tuttle/ruby_prof/fast_call_stack_printer.rb', line 112 def application @application ||= @options.delete(:application) || $PROGRAM_NAME end |
#expansion ⇒ Object
108 109 110 |
# File 'lib/tuttle/ruby_prof/fast_call_stack_printer.rb', line 108 def expansion @expansion ||= super end |
#method_full_name(method) ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/tuttle/ruby_prof/fast_call_stack_printer.rb', line 95 def method_full_name(method) @method_full_name_cache[method] ||= begin # Use ruby-prof klass_name only for non-Classes or klasses that do not report a name # This prevents klass.inspect from being used which prints complex names for ActiveRecord classes klass_name = method.klass && method.klass.class == Class && method.klass.name || method.klass_name h("#{klass_name}##{method.method_name}") end end |
#print(output = STDOUT, options = {}) ⇒ Object
Specify print options.
options - See CallStackPrinter for based options
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/tuttle/ruby_prof/fast_call_stack_printer.rb', line 17 def print(output = STDOUT, = {}) @output = output () print_header @overall_threads_time = @result.threads.inject(0) do |val, thread| val + thread.total_time end @method_full_name_cache = {}.compare_by_identity @result.threads.each do |thread| @overall_time = thread.total_time thread_info = "Thread: #{thread.id}".dup thread_info << ", Fiber: #{thread.fiber_id}" unless thread.id == thread.fiber_id thread_info << format(' (%4.2f%% ~ %f)', (@overall_time / @overall_threads_time) * 100, @overall_time) @output.print "<div class=\"thread\">#{thread_info}</div>" @output.print '<ul name="thread">' thread.methods.each do |m| # $stderr.print m.dump next unless m.root? m.call_infos.each do |ci| next unless ci.root? print_stack ci, @overall_time end end @output.print '</ul>' end @method_full_name_cache = nil end |
#print_css ⇒ Object
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/tuttle/ruby_prof/fast_call_stack_printer.rb', line 125 def print_css super @output.puts <<-CSS_OVERRIDE <style type="text/css"> <!-- ul li { background-color: white; } --> </style> CSS_OVERRIDE end |
#print_stack(call_info, parent_time) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/tuttle/ruby_prof/fast_call_stack_printer.rb', line 53 def print_stack(call_info, parent_time) total_time = call_info.total_time percent_total = (total_time / @overall_time) * 100 return unless percent_total > min_percent percent_parent = (total_time / parent_time) * 100 if percent_total < threshold @output.write '<li style="display:none;">'.freeze else @output.write '<li>'.freeze end = percent_total >= expansion kids = call_info.children toggle_href = if kids.empty? || kids.none? {|ci| (ci.total_time / @overall_time) * 100 >= threshold} '<a href="#" class="toggle empty"></a>'.freeze elsif '<a href="#" class="toggle minus"></a>'.freeze else '<a href="#" class="toggle plus"></a>'.freeze end @output.write toggle_href method = call_info.target @output.printf "<span>%4.2f%% (%4.2f%%) %s [%d calls, %d total]</span>\n".freeze, percent_total, percent_parent, method_full_name(method), call_info.called, method.called unless kids.empty? if @output.write '<ul>'.freeze else @output.write '<ul style="display:none">'.freeze end kids.sort_by!(&:total_time).reverse_each do |callinfo| print_stack callinfo, total_time end @output.write '</ul>'.freeze end @output.write '</li>'.freeze end |
#print_title_bar ⇒ Object
116 117 118 119 120 121 122 123 |
# File 'lib/tuttle/ruby_prof/fast_call_stack_printer.rb', line 116 def @output.puts <<-"end_title_bar" <div id="titlebar"> Call tree for application <b>#{h application} #{h arguments}</b><br/> Generated on #{Time.current} with options #{h @options.inspect}<br/> </div> end_title_bar end |
#threshold ⇒ Object
104 105 106 |
# File 'lib/tuttle/ruby_prof/fast_call_stack_printer.rb', line 104 def threshold @threshold ||= super end |