ruby-prof 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGES +523 -0
- data/LICENSE +25 -0
- data/README.rdoc +5 -0
- data/Rakefile +110 -0
- data/bin/ruby-prof +380 -0
- data/bin/ruby-prof-check-trace +45 -0
- data/ext/ruby_prof/extconf.rb +36 -0
- data/ext/ruby_prof/rp_allocation.c +292 -0
- data/ext/ruby_prof/rp_allocation.h +31 -0
- data/ext/ruby_prof/rp_call_info.c +283 -0
- data/ext/ruby_prof/rp_call_info.h +35 -0
- data/ext/ruby_prof/rp_measure_allocations.c +52 -0
- data/ext/ruby_prof/rp_measure_memory.c +42 -0
- data/ext/ruby_prof/rp_measure_process_time.c +63 -0
- data/ext/ruby_prof/rp_measure_wall_time.c +62 -0
- data/ext/ruby_prof/rp_measurement.c +236 -0
- data/ext/ruby_prof/rp_measurement.h +49 -0
- data/ext/ruby_prof/rp_method.c +642 -0
- data/ext/ruby_prof/rp_method.h +70 -0
- data/ext/ruby_prof/rp_profile.c +881 -0
- data/ext/ruby_prof/rp_profile.h +36 -0
- data/ext/ruby_prof/rp_stack.c +196 -0
- data/ext/ruby_prof/rp_stack.h +56 -0
- data/ext/ruby_prof/rp_thread.c +338 -0
- data/ext/ruby_prof/rp_thread.h +36 -0
- data/ext/ruby_prof/ruby_prof.c +48 -0
- data/ext/ruby_prof/ruby_prof.h +17 -0
- data/ext/ruby_prof/vc/ruby_prof.sln +31 -0
- data/ext/ruby_prof/vc/ruby_prof.vcxproj +143 -0
- data/lib/ruby-prof.rb +53 -0
- data/lib/ruby-prof/assets/call_stack_printer.css.html +117 -0
- data/lib/ruby-prof/assets/call_stack_printer.js.html +385 -0
- data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
- data/lib/ruby-prof/assets/graph_printer.html.erb +356 -0
- data/lib/ruby-prof/call_info.rb +57 -0
- data/lib/ruby-prof/call_info_visitor.rb +38 -0
- data/lib/ruby-prof/compatibility.rb +109 -0
- data/lib/ruby-prof/exclude_common_methods.rb +198 -0
- data/lib/ruby-prof/measurement.rb +14 -0
- data/lib/ruby-prof/method_info.rb +90 -0
- data/lib/ruby-prof/printers/abstract_printer.rb +118 -0
- data/lib/ruby-prof/printers/call_info_printer.rb +51 -0
- data/lib/ruby-prof/printers/call_stack_printer.rb +269 -0
- data/lib/ruby-prof/printers/call_tree_printer.rb +151 -0
- data/lib/ruby-prof/printers/dot_printer.rb +132 -0
- data/lib/ruby-prof/printers/flat_printer.rb +52 -0
- data/lib/ruby-prof/printers/graph_html_printer.rb +64 -0
- data/lib/ruby-prof/printers/graph_printer.rb +114 -0
- data/lib/ruby-prof/printers/multi_printer.rb +127 -0
- data/lib/ruby-prof/profile.rb +33 -0
- data/lib/ruby-prof/rack.rb +171 -0
- data/lib/ruby-prof/task.rb +147 -0
- data/lib/ruby-prof/thread.rb +35 -0
- data/lib/ruby-prof/version.rb +3 -0
- data/lib/unprof.rb +10 -0
- data/ruby-prof.gemspec +58 -0
- data/test/abstract_printer_test.rb +26 -0
- data/test/alias_test.rb +129 -0
- data/test/basic_test.rb +129 -0
- data/test/call_info_visitor_test.rb +31 -0
- data/test/duplicate_names_test.rb +32 -0
- data/test/dynamic_method_test.rb +53 -0
- data/test/enumerable_test.rb +21 -0
- data/test/exceptions_test.rb +24 -0
- data/test/exclude_methods_test.rb +146 -0
- data/test/exclude_threads_test.rb +53 -0
- data/test/line_number_test.rb +161 -0
- data/test/marshal_test.rb +119 -0
- data/test/measure_allocations.rb +30 -0
- data/test/measure_allocations_test.rb +385 -0
- data/test/measure_allocations_trace_test.rb +385 -0
- data/test/measure_memory_trace_test.rb +756 -0
- data/test/measure_process_time_test.rb +849 -0
- data/test/measure_times.rb +54 -0
- data/test/measure_wall_time_test.rb +459 -0
- data/test/multi_printer_test.rb +71 -0
- data/test/no_method_class_test.rb +15 -0
- data/test/parser_timings.rb +24 -0
- data/test/pause_resume_test.rb +166 -0
- data/test/prime.rb +56 -0
- data/test/printer_call_tree_test.rb +31 -0
- data/test/printer_flat_test.rb +68 -0
- data/test/printer_graph_html_test.rb +60 -0
- data/test/printer_graph_test.rb +41 -0
- data/test/printers_test.rb +141 -0
- data/test/printing_recursive_graph_test.rb +81 -0
- data/test/rack_test.rb +157 -0
- data/test/recursive_test.rb +210 -0
- data/test/singleton_test.rb +38 -0
- data/test/stack_printer_test.rb +64 -0
- data/test/start_stop_test.rb +109 -0
- data/test/test_helper.rb +24 -0
- data/test/thread_test.rb +144 -0
- data/test/unique_call_path_test.rb +190 -0
- data/test/yarv_test.rb +56 -0
- metadata +189 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'set'
|
|
4
|
+
|
|
5
|
+
module RubyProf
|
|
6
|
+
# Generates a graphviz graph in dot format.
|
|
7
|
+
#
|
|
8
|
+
# To use the dot printer:
|
|
9
|
+
#
|
|
10
|
+
# result = RubyProf.profile do
|
|
11
|
+
# [code to profile]
|
|
12
|
+
# end
|
|
13
|
+
#
|
|
14
|
+
# printer = RubyProf::DotPrinter.new(result)
|
|
15
|
+
# printer.print(STDOUT)
|
|
16
|
+
#
|
|
17
|
+
# You can use either dot viewer such as GraphViz, or the dot command line tool
|
|
18
|
+
# to reformat the output into a wide variety of outputs:
|
|
19
|
+
#
|
|
20
|
+
# dot -Tpng graph.dot > graph.png
|
|
21
|
+
#
|
|
22
|
+
class DotPrinter < RubyProf::AbstractPrinter
|
|
23
|
+
CLASS_COLOR = '"#666666"'
|
|
24
|
+
EDGE_COLOR = '"#666666"'
|
|
25
|
+
|
|
26
|
+
# Creates the DotPrinter using a RubyProf::Proile.
|
|
27
|
+
def initialize(result)
|
|
28
|
+
super(result)
|
|
29
|
+
@seen_methods = Set.new
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Print a graph report to the provided output.
|
|
33
|
+
#
|
|
34
|
+
# output - Any IO object, including STDOUT or a file. The default value is
|
|
35
|
+
# STDOUT.
|
|
36
|
+
#
|
|
37
|
+
# options - Hash of print options. See #setup_options
|
|
38
|
+
# for more information.
|
|
39
|
+
#
|
|
40
|
+
# When profiling results that cover a large number of method calls it
|
|
41
|
+
# helps to use the :min_percent option, for example:
|
|
42
|
+
#
|
|
43
|
+
# DotPrinter.new(result).print(STDOUT, :min_percent=>5)
|
|
44
|
+
#
|
|
45
|
+
def print(output = STDOUT, options = {})
|
|
46
|
+
@output = output
|
|
47
|
+
setup_options(options)
|
|
48
|
+
|
|
49
|
+
puts 'digraph "Profile" {'
|
|
50
|
+
#puts "label=\"#{mode_name} >=#{min_percent}%\\nTotal: #{total_time}\";"
|
|
51
|
+
puts "labelloc=t;"
|
|
52
|
+
puts "labeljust=l;"
|
|
53
|
+
print_threads
|
|
54
|
+
puts '}'
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
# Something of a hack, figure out which constant went with the
|
|
60
|
+
# RubyProf.measure_mode so that we can display it. Otherwise it's easy to
|
|
61
|
+
# forget what measurement was made.
|
|
62
|
+
def mode_name
|
|
63
|
+
RubyProf.constants.find{|c| RubyProf.const_get(c) == RubyProf.measure_mode}
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def print_threads
|
|
67
|
+
@result.threads.each do |thread|
|
|
68
|
+
puts "subgraph \"Thread #{thread.id}\" {"
|
|
69
|
+
|
|
70
|
+
print_thread(thread)
|
|
71
|
+
puts "}"
|
|
72
|
+
|
|
73
|
+
print_classes(thread)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Determines an ID to use to represent the subject in the Dot file.
|
|
78
|
+
def dot_id(subject)
|
|
79
|
+
subject.object_id
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def print_thread(thread)
|
|
83
|
+
total_time = thread.total_time
|
|
84
|
+
thread.methods.sort_by(&sort_method).reverse_each do |method|
|
|
85
|
+
total_percentage = (method.total_time/total_time) * 100
|
|
86
|
+
|
|
87
|
+
next if total_percentage < min_percent
|
|
88
|
+
name = method.full_name.split("#").last
|
|
89
|
+
puts "#{dot_id(method)} [label=\"#{name}\\n(#{total_percentage.round}%)\"];"
|
|
90
|
+
@seen_methods << method
|
|
91
|
+
print_edges(total_time, method)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def print_classes(thread)
|
|
96
|
+
grouped = {}
|
|
97
|
+
thread.methods.each{|m| grouped[m.klass_name] ||= []; grouped[m.klass_name] << m}
|
|
98
|
+
grouped.each do |cls, methods2|
|
|
99
|
+
# Filter down to just seen methods
|
|
100
|
+
big_methods = methods2.select{|m| @seen_methods.include? m}
|
|
101
|
+
|
|
102
|
+
if !big_methods.empty?
|
|
103
|
+
puts "subgraph cluster_#{cls.object_id} {"
|
|
104
|
+
puts "label = \"#{cls}\";"
|
|
105
|
+
puts "fontcolor = #{CLASS_COLOR};"
|
|
106
|
+
puts "fontsize = 16;"
|
|
107
|
+
puts "color = #{CLASS_COLOR};"
|
|
108
|
+
big_methods.each do |m|
|
|
109
|
+
puts "#{m.object_id};"
|
|
110
|
+
end
|
|
111
|
+
puts "}"
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def print_edges(total_time, method)
|
|
117
|
+
method.callers.sort_by(&:total_time).reverse.each do |call_info|
|
|
118
|
+
target_percentage = (call_info.target.total_time / total_time) * 100.0
|
|
119
|
+
next if target_percentage < min_percent
|
|
120
|
+
|
|
121
|
+
# Get children method
|
|
122
|
+
puts "#{dot_id(method)} -> #{dot_id(call_info.target)} [label=\"#{call_info.called}/#{call_info.target.called}\" fontsize=10 fontcolor=#{EDGE_COLOR}];"
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Silly little helper for printing to the @output
|
|
127
|
+
def puts(str)
|
|
128
|
+
@output.puts(str)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
end
|
|
132
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module RubyProf
|
|
4
|
+
# Generates flat[link:files/examples/flat_txt.html] profile reports as text.
|
|
5
|
+
# To use the flat printer:
|
|
6
|
+
#
|
|
7
|
+
# result = RubyProf.profile do
|
|
8
|
+
# [code to profile]
|
|
9
|
+
# end
|
|
10
|
+
#
|
|
11
|
+
# printer = RubyProf::FlatPrinter.new(result)
|
|
12
|
+
# printer.print(STDOUT, {})
|
|
13
|
+
#
|
|
14
|
+
class FlatPrinter < AbstractPrinter
|
|
15
|
+
# Override for this printer to sort by self time by default
|
|
16
|
+
def sort_method
|
|
17
|
+
@options[:sort_method] || :self_time
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def print_column_headers
|
|
23
|
+
@output << " %self total self wait child calls name location\n"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def print_methods(thread)
|
|
27
|
+
total_time = thread.total_time
|
|
28
|
+
methods = thread.methods.sort_by(&sort_method).reverse
|
|
29
|
+
|
|
30
|
+
sum = 0
|
|
31
|
+
methods.each do |method|
|
|
32
|
+
self_percent = (method.self_time / total_time) * 100
|
|
33
|
+
next if self_percent < min_percent
|
|
34
|
+
|
|
35
|
+
sum += method.self_time
|
|
36
|
+
#self_time_called = method.called > 0 ? method.self_time/method.called : 0
|
|
37
|
+
#total_time_called = method.called > 0? method.total_time/method.called : 0
|
|
38
|
+
|
|
39
|
+
@output << "%6.2f %9.3f %9.3f %9.3f %9.3f %8d %s%-30s %s\n" % [
|
|
40
|
+
method.self_time / total_time * 100, # %self
|
|
41
|
+
method.total_time, # total
|
|
42
|
+
method.self_time, # self
|
|
43
|
+
method.wait_time, # wait
|
|
44
|
+
method.children_time, # children
|
|
45
|
+
method.called, # calls
|
|
46
|
+
method.recursive? ? "*" : " ", # cycle
|
|
47
|
+
method.full_name, # method_name]
|
|
48
|
+
method_location(method)] # location]
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'erb'
|
|
4
|
+
|
|
5
|
+
module RubyProf
|
|
6
|
+
# Generates graph[link:files/examples/graph_html.html] profile reports as html.
|
|
7
|
+
# To use the graph html printer:
|
|
8
|
+
#
|
|
9
|
+
# result = RubyProf.profile do
|
|
10
|
+
# [code to profile]
|
|
11
|
+
# end
|
|
12
|
+
#
|
|
13
|
+
# printer = RubyProf::GraphHtmlPrinter.new(result)
|
|
14
|
+
# printer.print(STDOUT, :min_percent=>0)
|
|
15
|
+
#
|
|
16
|
+
# The Graph printer takes the following options in its print methods:
|
|
17
|
+
|
|
18
|
+
class GraphHtmlPrinter < AbstractPrinter
|
|
19
|
+
include ERB::Util
|
|
20
|
+
|
|
21
|
+
def setup_options(options)
|
|
22
|
+
super(options)
|
|
23
|
+
@erb = ERB.new(self.template)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def print(output = STDOUT, options = {})
|
|
27
|
+
setup_options(options)
|
|
28
|
+
output << @erb.result(binding)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Creates a link to a method. Note that we do not create
|
|
32
|
+
# links to methods which are under the min_perecent
|
|
33
|
+
# specified by the user, since they will not be
|
|
34
|
+
# printed out.
|
|
35
|
+
def create_link(thread, overall_time, method)
|
|
36
|
+
total_percent = (method.total_time/overall_time) * 100
|
|
37
|
+
if total_percent < min_percent
|
|
38
|
+
# Just return name
|
|
39
|
+
h method.full_name
|
|
40
|
+
else
|
|
41
|
+
href = '#' + method_href(thread, method)
|
|
42
|
+
"<a href=\"#{href}\">#{h method.full_name}</a>"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def method_href(thread, method)
|
|
47
|
+
h(method.full_name.gsub(/[><#\.\?=:]/,"_") + "_" + thread.fiber_id.to_s)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def file_link(path, linenum)
|
|
51
|
+
if path.nil?
|
|
52
|
+
""
|
|
53
|
+
else
|
|
54
|
+
srcfile = File.expand_path(path)
|
|
55
|
+
"<a href=\"file://#{h srcfile}##{linenum}\" title=\"#{h srcfile}:#{linenum}\">#{linenum}</a>"
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def template
|
|
60
|
+
path = File.expand_path(File.join(__FILE__, '..', '..', 'assets', 'graph_printer.html.erb'))
|
|
61
|
+
File.read(path, :mode => 'rb')
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module RubyProf
|
|
4
|
+
# Generates graph[link:files/examples/graph_txt.html] profile reports as text.
|
|
5
|
+
# To use the graph printer:
|
|
6
|
+
#
|
|
7
|
+
# result = RubyProf.profile do
|
|
8
|
+
# [code to profile]
|
|
9
|
+
# end
|
|
10
|
+
#
|
|
11
|
+
# printer = RubyProf::GraphPrinter.new(result)
|
|
12
|
+
# printer.print(STDOUT, {})
|
|
13
|
+
#
|
|
14
|
+
# The constructor takes two arguments. See the README
|
|
15
|
+
|
|
16
|
+
class GraphPrinter < AbstractPrinter
|
|
17
|
+
PERCENTAGE_WIDTH = 8
|
|
18
|
+
TIME_WIDTH = 11
|
|
19
|
+
CALL_WIDTH = 17
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def sort_method
|
|
24
|
+
@options[:sort_method] || :total_time
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def print_header(thread)
|
|
28
|
+
@output << "Measure Mode: %s\n" % RubyProf.measure_mode_string
|
|
29
|
+
@output << "Thread ID: #{thread.id}\n"
|
|
30
|
+
@output << "Fiber ID: #{thread.fiber_id}\n"
|
|
31
|
+
@output << "Total Time: #{thread.total_time}\n"
|
|
32
|
+
@output << "Sort by: #{sort_method}\n"
|
|
33
|
+
@output << "\n"
|
|
34
|
+
|
|
35
|
+
# 1 is for % sign
|
|
36
|
+
@output << sprintf("%#{PERCENTAGE_WIDTH}s", "%total")
|
|
37
|
+
@output << sprintf("%#{PERCENTAGE_WIDTH}s", "%self")
|
|
38
|
+
@output << sprintf("%#{TIME_WIDTH}s", "total")
|
|
39
|
+
@output << sprintf("%#{TIME_WIDTH}s", "self")
|
|
40
|
+
@output << sprintf("%#{TIME_WIDTH}s", "wait")
|
|
41
|
+
@output << sprintf("%#{TIME_WIDTH}s", "child")
|
|
42
|
+
@output << sprintf("%#{CALL_WIDTH}s", "calls")
|
|
43
|
+
@output << " name"
|
|
44
|
+
@output << " location"
|
|
45
|
+
@output << "\n"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def print_methods(thread)
|
|
49
|
+
total_time = thread.total_time
|
|
50
|
+
# Sort methods from longest to shortest total time
|
|
51
|
+
methods = thread.methods.sort_by(&sort_method)
|
|
52
|
+
|
|
53
|
+
# Print each method in total time order
|
|
54
|
+
methods.reverse_each do |method|
|
|
55
|
+
total_percentage = (method.total_time/total_time) * 100
|
|
56
|
+
next if total_percentage < min_percent
|
|
57
|
+
|
|
58
|
+
self_percentage = (method.self_time/total_time) * 100
|
|
59
|
+
|
|
60
|
+
@output << "-" * 150 << "\n"
|
|
61
|
+
print_parents(thread, method)
|
|
62
|
+
|
|
63
|
+
# 1 is for % sign
|
|
64
|
+
@output << sprintf("%#{PERCENTAGE_WIDTH-1}.2f%%", total_percentage)
|
|
65
|
+
@output << sprintf("%#{PERCENTAGE_WIDTH-1}.2f%%", self_percentage)
|
|
66
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", method.total_time)
|
|
67
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", method.self_time)
|
|
68
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", method.wait_time)
|
|
69
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", method.children_time)
|
|
70
|
+
@output << sprintf("%#{CALL_WIDTH}i", method.called)
|
|
71
|
+
@output << sprintf(" %s", method.recursive? ? "*" : " ")
|
|
72
|
+
@output << sprintf("%-30s", method.full_name)
|
|
73
|
+
@output << sprintf(" %s", method_location(method))
|
|
74
|
+
@output << "\n"
|
|
75
|
+
|
|
76
|
+
print_children(method)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def print_parents(thread, method)
|
|
81
|
+
return if method.root?
|
|
82
|
+
method.callers.sort_by(&:total_time).each do |caller|
|
|
83
|
+
@output << " " * 2 * PERCENTAGE_WIDTH
|
|
84
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", caller.total_time)
|
|
85
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", caller.self_time)
|
|
86
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", caller.wait_time)
|
|
87
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", caller.children_time)
|
|
88
|
+
|
|
89
|
+
call_called = "#{caller.called}/#{method.called}"
|
|
90
|
+
@output << sprintf("%#{CALL_WIDTH}s", call_called)
|
|
91
|
+
@output << sprintf(" %s", caller.parent.full_name)
|
|
92
|
+
@output << "\n"
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def print_children(method)
|
|
97
|
+
method.callees.sort_by(&:total_time).reverse.each do |child|
|
|
98
|
+
# Get children method
|
|
99
|
+
|
|
100
|
+
@output << " " * 2 * PERCENTAGE_WIDTH
|
|
101
|
+
|
|
102
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", child.total_time)
|
|
103
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", child.self_time)
|
|
104
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", child.wait_time)
|
|
105
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", child.children_time)
|
|
106
|
+
|
|
107
|
+
call_called = "#{child.called}/#{child.target.called}"
|
|
108
|
+
@output << sprintf("%#{CALL_WIDTH}s", call_called)
|
|
109
|
+
@output << sprintf(" %s", child.target.full_name)
|
|
110
|
+
@output << "\n"
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module RubyProf
|
|
4
|
+
# Helper class to simplify printing profiles of several types from
|
|
5
|
+
# one profiling run. Currently prints a flat profile, a callgrind
|
|
6
|
+
# profile, a call stack profile and a graph profile.
|
|
7
|
+
class MultiPrinter
|
|
8
|
+
def initialize(result, printers = [:flat, :graph_html])
|
|
9
|
+
@flat_printer = FlatPrinter.new(result) if printers.include?(:flat)
|
|
10
|
+
|
|
11
|
+
@graph_printer = GraphPrinter.new(result) if printers.include?(:graph)
|
|
12
|
+
@graph_html_printer = GraphHtmlPrinter.new(result) if printers.include?(:graph_html)
|
|
13
|
+
|
|
14
|
+
@tree_printer = CallTreePrinter.new(result) if printers.include?(:tree)
|
|
15
|
+
@call_info_printer = CallInfoPrinter.new(result) if printers.include?(:call_info)
|
|
16
|
+
|
|
17
|
+
@stack_printer = CallStackPrinter.new(result) if printers.include?(:stack)
|
|
18
|
+
@dot_printer = DotPrinter.new(result) if printers.include?(:dot)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.needs_dir?
|
|
22
|
+
true
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# create profile files under options[:path] or the current
|
|
26
|
+
# directory. options[:profile] is used as the base name for the
|
|
27
|
+
# profile file, defaults to "profile".
|
|
28
|
+
def print(options)
|
|
29
|
+
validate_print_params(options)
|
|
30
|
+
|
|
31
|
+
@profile = options.delete(:profile) || "profile"
|
|
32
|
+
@directory = options.delete(:path) || File.expand_path(".")
|
|
33
|
+
|
|
34
|
+
print_to_flat(options) if @flat_printer
|
|
35
|
+
|
|
36
|
+
print_to_graph(options) if @graph_printer
|
|
37
|
+
print_to_graph_html(options) if @graph_html_printer
|
|
38
|
+
|
|
39
|
+
print_to_stack(options) if @stack_printer
|
|
40
|
+
print_to_call_info(options) if @call_info_printer
|
|
41
|
+
print_to_tree(options) if @tree_printer
|
|
42
|
+
print_to_dot(options) if @dot_printer
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# the name of the flat profile file
|
|
46
|
+
def flat_report
|
|
47
|
+
"#{@directory}/#{@profile}.flat.txt"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# the name of the graph profile file
|
|
51
|
+
def graph_report
|
|
52
|
+
"#{@directory}/#{@profile}.graph.txt"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def graph_html_report
|
|
56
|
+
"#{@directory}/#{@profile}.graph.html"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# the name of the callinfo profile file
|
|
60
|
+
def call_info_report
|
|
61
|
+
"#{@directory}/#{@profile}.call_info.txt"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# the name of the callgrind profile file
|
|
65
|
+
def tree_report
|
|
66
|
+
"#{@directory}/#{@profile}.callgrind.out.#{$$}"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# the name of the call stack profile file
|
|
70
|
+
def stack_report
|
|
71
|
+
"#{@directory}/#{@profile}.stack.html"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# the name of the call stack profile file
|
|
75
|
+
def dot_report
|
|
76
|
+
"#{@directory}/#{@profile}.dot"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def print_to_flat(options)
|
|
80
|
+
File.open(flat_report, "wb") do |file|
|
|
81
|
+
@flat_printer.print(file, options)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def print_to_graph(options)
|
|
86
|
+
File.open(graph_report, "wb") do |file|
|
|
87
|
+
@graph_printer.print(file, options)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def print_to_graph_html(options)
|
|
92
|
+
File.open(graph_html_report, "wb") do |file|
|
|
93
|
+
@graph_html_printer.print(file, options)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def print_to_call_info(options)
|
|
98
|
+
File.open(call_info_report, "wb") do |file|
|
|
99
|
+
@call_info_printer.print(file, options)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def print_to_tree(options)
|
|
104
|
+
@tree_printer.print(options.merge(:path => @directory, :profile => @profile))
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def print_to_stack(options)
|
|
108
|
+
File.open(stack_report, "wb") do |file|
|
|
109
|
+
@stack_printer.print(file, options.merge(:graph => "#{@profile}.graph.html"))
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def print_to_dot(options)
|
|
114
|
+
File.open(dot_report, "wb") do |file|
|
|
115
|
+
@dot_printer.print(file, options)
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def validate_print_params(options)
|
|
120
|
+
if options.is_a?(IO)
|
|
121
|
+
raise ArgumentError, "#{self.class.name}#print cannot print to IO objects"
|
|
122
|
+
elsif !options.is_a?(Hash)
|
|
123
|
+
raise ArgumentError, "#{self.class.name}#print requires an options hash"
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|