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
111 112 113 |
# File 'lib/tuttle/ruby_prof/fast_call_stack_printer.rb', line 111 def application @application ||= @options.delete(:application) || $PROGRAM_NAME end |
#expansion ⇒ Object
107 108 109 |
# File 'lib/tuttle/ruby_prof/fast_call_stack_printer.rb', line 107 def expansion @expansion ||= super end |
#method_full_name(method) ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/tuttle/ruby_prof/fast_call_stack_printer.rb', line 94 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
16 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 |
# File 'lib/tuttle/ruby_prof/fast_call_stack_printer.rb', line 16 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}" 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
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/tuttle/ruby_prof/fast_call_stack_printer.rb', line 124 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
52 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 |
# File 'lib/tuttle/ruby_prof/fast_call_stack_printer.rb', line 52 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
115 116 117 118 119 120 121 122 |
# File 'lib/tuttle/ruby_prof/fast_call_stack_printer.rb', line 115 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
103 104 105 |
# File 'lib/tuttle/ruby_prof/fast_call_stack_printer.rb', line 103 def threshold @threshold ||= super end |