ruby-prof 0.8.1-x86-mingw32 → 0.11.0.rc1-x86-mingw32
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.
- data/CHANGES +89 -13
- data/LICENSE +4 -3
- data/{README → README.rdoc} +155 -162
- data/Rakefile +50 -123
- data/bin/ruby-prof +86 -47
- data/examples/empty.png +0 -0
- data/examples/graph.dot +106 -0
- data/examples/graph.png +0 -0
- data/examples/minus.png +0 -0
- data/examples/multi.flat.txt +23 -0
- data/examples/multi.graph.html +906 -0
- data/examples/multi.grind.dat +194 -0
- data/examples/multi.stack.html +573 -0
- data/examples/plus.png +0 -0
- data/examples/stack.html +573 -0
- data/ext/ruby_prof/extconf.rb +53 -0
- data/ext/ruby_prof/rp_call_info.c +369 -0
- data/ext/ruby_prof/rp_call_info.h +46 -0
- data/ext/ruby_prof/rp_measure.c +48 -0
- data/ext/ruby_prof/rp_measure.h +45 -0
- data/ext/ruby_prof/rp_measure_allocations.c +86 -0
- data/ext/ruby_prof/rp_measure_cpu_time.c +112 -0
- data/ext/ruby_prof/rp_measure_gc_runs.c +87 -0
- data/ext/ruby_prof/rp_measure_gc_time.c +73 -0
- data/ext/ruby_prof/rp_measure_memory.c +81 -0
- data/ext/ruby_prof/rp_measure_process_time.c +71 -0
- data/ext/ruby_prof/rp_measure_wall_time.c +42 -0
- data/ext/ruby_prof/rp_method.c +363 -0
- data/ext/ruby_prof/rp_method.h +55 -0
- data/ext/ruby_prof/rp_stack.c +61 -0
- data/ext/ruby_prof/rp_stack.h +40 -0
- data/ext/ruby_prof/rp_thread.c +113 -0
- data/ext/ruby_prof/rp_thread.h +20 -0
- data/ext/ruby_prof/ruby_prof.c +332 -1377
- data/ext/ruby_prof/ruby_prof.h +54 -188
- data/ext/ruby_prof/version.h +6 -3
- data/lib/1.8/ruby_prof.so +0 -0
- data/lib/1.9/ruby_prof.exp +0 -0
- data/lib/1.9/ruby_prof.ilk +0 -0
- data/lib/1.9/ruby_prof.lib +0 -0
- data/lib/1.9/ruby_prof.pdb +0 -0
- data/lib/1.9/ruby_prof.so +0 -0
- data/lib/ruby-prof.rb +32 -18
- data/lib/ruby-prof/abstract_printer.rb +15 -5
- data/lib/ruby-prof/aggregate_call_info.rb +11 -3
- data/lib/ruby-prof/call_info.rb +68 -1
- data/lib/ruby-prof/call_stack_printer.rb +775 -0
- data/lib/ruby-prof/call_tree_printer.rb +17 -9
- data/lib/ruby-prof/compatibility.rb +134 -0
- data/lib/ruby-prof/dot_printer.rb +152 -0
- data/lib/ruby-prof/empty.png +0 -0
- data/lib/ruby-prof/flat_printer.rb +23 -24
- data/lib/ruby-prof/flat_printer_with_line_numbers.rb +17 -21
- data/lib/ruby-prof/graph_html_printer.rb +69 -39
- data/lib/ruby-prof/graph_printer.rb +35 -35
- data/lib/ruby-prof/method_info.rb +26 -4
- data/lib/ruby-prof/minus.png +0 -0
- data/lib/ruby-prof/multi_printer.rb +56 -0
- data/lib/ruby-prof/plus.png +0 -0
- data/lib/ruby-prof/profile.rb +72 -0
- data/lib/ruby-prof/rack.rb +31 -0
- data/lib/ruby-prof/symbol_to_proc.rb +3 -1
- data/lib/ruby-prof/task.rb +20 -19
- data/lib/ruby-prof/test.rb +5 -3
- data/lib/ruby_prof.exp +0 -0
- data/lib/ruby_prof.ilk +0 -0
- data/lib/ruby_prof.lib +0 -0
- data/lib/ruby_prof.pdb +0 -0
- data/lib/ruby_prof.so +0 -0
- data/lib/unprof.rb +2 -0
- data/test/aggregate_test.rb +29 -14
- data/test/basic_test.rb +3 -251
- data/test/bug_test.rb +6 -0
- data/test/duplicate_names_test.rb +4 -4
- data/test/dynamic_method_test.rb +61 -0
- data/test/enumerable_test.rb +4 -4
- data/test/exceptions_test.rb +6 -5
- data/test/exclude_threads_test.rb +47 -47
- data/test/exec_test.rb +5 -5
- data/test/line_number_test.rb +16 -16
- data/test/measure_allocations_test.rb +25 -0
- data/test/measure_cpu_time_test.rb +212 -0
- data/test/measure_gc_runs_test.rb +29 -0
- data/test/measure_gc_time_test.rb +29 -0
- data/test/measure_memory_test.rb +36 -0
- data/test/measure_process_time_test.rb +205 -0
- data/test/measure_wall_time_test.rb +209 -0
- data/test/method_elimination_test.rb +74 -0
- data/test/module_test.rb +12 -21
- data/test/multi_printer_test.rb +81 -0
- data/test/no_method_class_test.rb +5 -3
- data/test/prime.rb +7 -10
- data/test/prime_test.rb +3 -3
- data/test/printers_test.rb +180 -54
- data/test/recursive_test.rb +34 -72
- data/test/singleton_test.rb +5 -4
- data/test/stack_printer_test.rb +73 -0
- data/test/stack_test.rb +7 -7
- data/test/start_stop_test.rb +23 -6
- data/test/test_helper.rb +81 -0
- data/test/test_suite.rb +35 -21
- data/test/thread_test.rb +40 -39
- data/test/unique_call_path_test.rb +6 -6
- metadata +106 -51
- data/ext/ruby_prof/measure_allocations.h +0 -58
- data/ext/ruby_prof/measure_cpu_time.h +0 -152
- data/ext/ruby_prof/measure_gc_runs.h +0 -76
- data/ext/ruby_prof/measure_gc_time.h +0 -57
- data/ext/ruby_prof/measure_memory.h +0 -101
- data/ext/ruby_prof/measure_process_time.h +0 -52
- data/ext/ruby_prof/measure_wall_time.h +0 -53
- data/ext/ruby_prof/mingw/Rakefile +0 -23
- data/ext/ruby_prof/mingw/build.rake +0 -38
- data/rails/environment/profile.rb +0 -24
- data/rails/example/example_test.rb +0 -9
- data/rails/profile_test_helper.rb +0 -21
- data/test/current_failures_windows +0 -8
- data/test/measurement_test.rb +0 -121
- data/test/ruby-prof-bin +0 -20
@@ -1,9 +1,10 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
2
3
|
require 'erb'
|
3
4
|
|
4
5
|
module RubyProf
|
5
|
-
# Generates graph[link:files/examples/graph_html.html] profile reports as html.
|
6
|
-
# To use the
|
6
|
+
# Generates graph[link:files/examples/graph_html.html] profile reports as html.
|
7
|
+
# To use the graph html printer:
|
7
8
|
#
|
8
9
|
# result = RubyProf.profile do
|
9
10
|
# [code to profile]
|
@@ -14,20 +15,20 @@ module RubyProf
|
|
14
15
|
#
|
15
16
|
# The constructor takes two arguments. The first is
|
16
17
|
# a RubyProf::Result object generated from a profiling
|
17
|
-
# run. The second is the minimum %total (the methods
|
18
|
+
# run. The second is the minimum %total (the methods
|
18
19
|
# total time divided by the overall total time) that
|
19
|
-
# a method must take for it to be printed out in
|
20
|
+
# a method must take for it to be printed out in
|
20
21
|
# the report. Use this parameter to eliminate methods
|
21
22
|
# that are not important to the overall profiling results.
|
22
|
-
|
23
|
+
|
23
24
|
class GraphHtmlPrinter < AbstractPrinter
|
24
25
|
include ERB::Util
|
25
|
-
|
26
|
+
|
26
27
|
PERCENTAGE_WIDTH = 8
|
27
28
|
TIME_WIDTH = 10
|
28
29
|
CALL_WIDTH = 20
|
29
|
-
|
30
|
-
# Create a GraphPrinter. Result is a RubyProf::Result
|
30
|
+
|
31
|
+
# Create a GraphPrinter. Result is a RubyProf::Result
|
31
32
|
# object generated from a profiling run.
|
32
33
|
def initialize(result)
|
33
34
|
super(result)
|
@@ -36,17 +37,24 @@ module RubyProf
|
|
36
37
|
end
|
37
38
|
|
38
39
|
# Print a graph html report to the provided output.
|
39
|
-
#
|
40
|
-
# output - Any IO oject, including STDOUT or a file.
|
40
|
+
#
|
41
|
+
# output - Any IO oject, including STDOUT or a file.
|
41
42
|
# The default value is STDOUT.
|
42
|
-
#
|
43
|
-
# options - Hash of print options. See #setup_options
|
44
|
-
#
|
43
|
+
#
|
44
|
+
# options - Hash of print options. See #setup_options
|
45
|
+
# for more information.
|
46
|
+
#
|
47
|
+
# unique options are:
|
48
|
+
# :filename - specify a file to use that contains the ERB
|
49
|
+
# template to use, instead of the built-in self.template
|
50
|
+
#
|
51
|
+
# :template - specify an ERB template to use, instead of the
|
52
|
+
# built-in self.template
|
45
53
|
#
|
46
54
|
def print(output = STDOUT, options = {})
|
47
55
|
@output = output
|
48
56
|
setup_options(options)
|
49
|
-
|
57
|
+
|
50
58
|
filename = options[:filename]
|
51
59
|
template = filename ? File.read(filename).untaint : (options[:template] || self.template)
|
52
60
|
_erbout = @output
|
@@ -55,38 +63,46 @@ module RubyProf
|
|
55
63
|
@output << erb.result(binding)
|
56
64
|
end
|
57
65
|
|
66
|
+
def total_time(call_infos)
|
67
|
+
sum(call_infos.map{|ci| ci.total_time})
|
68
|
+
end
|
69
|
+
|
70
|
+
def sum(a)
|
71
|
+
a.inject(0.0){|s,t| s+=t}
|
72
|
+
end
|
73
|
+
|
58
74
|
# These methods should be private but then ERB doesn't
|
59
|
-
# work. Turn off RDOC though
|
75
|
+
# work. Turn off RDOC though
|
60
76
|
#--
|
61
77
|
def calculate_thread_times
|
62
78
|
# Cache thread times since this is an expensive
|
63
|
-
# operation with the required sorting
|
79
|
+
# operation with the required sorting
|
80
|
+
@overall_threads_time = 0.0
|
81
|
+
@thread_times = Hash.new
|
64
82
|
@result.threads.each do |thread_id, methods|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
@thread_times[thread_id] = thread_time
|
83
|
+
roots = methods.select{|m| m.root?}
|
84
|
+
thread_total_time = sum(roots.map{|r| self.total_time(r.call_infos)})
|
85
|
+
@overall_threads_time += thread_total_time
|
86
|
+
@thread_times[thread_id] = thread_total_time
|
71
87
|
end
|
72
88
|
end
|
73
|
-
|
89
|
+
|
74
90
|
def thread_time(thread_id)
|
75
91
|
@thread_times[thread_id]
|
76
92
|
end
|
77
|
-
|
93
|
+
|
78
94
|
def total_percent(thread_id, method)
|
79
95
|
overall_time = self.thread_time(thread_id)
|
80
96
|
(method.total_time/overall_time) * 100
|
81
97
|
end
|
82
|
-
|
98
|
+
|
83
99
|
def self_percent(method)
|
84
100
|
overall_time = self.thread_time(method.thread_id)
|
85
101
|
(method.self_time/overall_time) * 100
|
86
102
|
end
|
87
103
|
|
88
104
|
# Creates a link to a method. Note that we do not create
|
89
|
-
# links to methods which are under the min_perecent
|
105
|
+
# links to methods which are under the min_perecent
|
90
106
|
# specified by the user, since they will not be
|
91
107
|
# printed out.
|
92
108
|
def create_link(thread_id, method)
|
@@ -95,14 +111,27 @@ module RubyProf
|
|
95
111
|
h method.full_name
|
96
112
|
else
|
97
113
|
href = '#' + method_href(thread_id, method)
|
98
|
-
"<a href=\"#{href}\">#{h method.full_name}</a>"
|
114
|
+
"<a href=\"#{href}\">#{h method.full_name}</a>"
|
99
115
|
end
|
100
116
|
end
|
101
|
-
|
117
|
+
|
102
118
|
def method_href(thread_id, method)
|
103
119
|
h(method.full_name.gsub(/[><#\.\?=:]/,"_") + "_" + thread_id.to_s)
|
104
120
|
end
|
105
|
-
|
121
|
+
|
122
|
+
def file_link(path, linenum)
|
123
|
+
srcfile = File.expand_path(path)
|
124
|
+
if srcfile =~ /\/ruby_runtime$/
|
125
|
+
""
|
126
|
+
else
|
127
|
+
if RUBY_PLATFORM =~ /darwin/
|
128
|
+
"<a href=\"txmt://open?url=file://#{h srcfile}&line=#{linenum}\" title=\"#{h srcfile}:#{linenum}\">#{linenum}</a>"
|
129
|
+
else
|
130
|
+
"<a href=\"file://#{h srcfile}##{linenum}\" title=\"#{h srcfile}:#{linenum}\">#{linenum}</a>"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
106
135
|
def template
|
107
136
|
'
|
108
137
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
@@ -149,7 +178,7 @@ module RubyProf
|
|
149
178
|
td {
|
150
179
|
border-left: 1px solid #CCC;
|
151
180
|
text-align: center;
|
152
|
-
}
|
181
|
+
}
|
153
182
|
|
154
183
|
.method_name {
|
155
184
|
text-align: left;
|
@@ -164,7 +193,7 @@ module RubyProf
|
|
164
193
|
<th>Thread ID</th>
|
165
194
|
<th>Total Time</th>
|
166
195
|
</tr>
|
167
|
-
<% for thread_id
|
196
|
+
<% for thread_id in @result.threads.keys.sort %>
|
168
197
|
<tr>
|
169
198
|
<td><a href="#<%= thread_id %>"><%= thread_id %></a></td>
|
170
199
|
<td><%= thread_time(thread_id) %></td>
|
@@ -173,7 +202,8 @@ module RubyProf
|
|
173
202
|
</table>
|
174
203
|
|
175
204
|
<!-- Methods Tables -->
|
176
|
-
<% for thread_id
|
205
|
+
<% for thread_id in @result.threads.keys.sort
|
206
|
+
methods = @result.threads[thread_id]
|
177
207
|
total_time = thread_time(thread_id) %>
|
178
208
|
<h2><a name="<%= thread_id %>">Thread <%= thread_id %></a></h2>
|
179
209
|
|
@@ -191,12 +221,12 @@ module RubyProf
|
|
191
221
|
</tr>
|
192
222
|
|
193
223
|
<% min_time = @options[:min_time] || (@options[:nonzero] ? 0.005 : nil)
|
194
|
-
methods.
|
224
|
+
methods.sort_by(&sort_method).reverse_each do |method|
|
195
225
|
total_percentage = (method.total_time/total_time) * 100
|
196
226
|
next if total_percentage < min_percent
|
197
227
|
next if min_time && method.total_time < min_time
|
198
228
|
self_percentage = (method.self_time/total_time) * 100 %>
|
199
|
-
|
229
|
+
|
200
230
|
<!-- Parents -->
|
201
231
|
<% for caller in method.aggregate_parents.sort_by(&:total_time)
|
202
232
|
next unless caller.parent
|
@@ -211,7 +241,7 @@ module RubyProf
|
|
211
241
|
<% called = "#{caller.called}/#{method.called}" %>
|
212
242
|
<td><%= sprintf("%#{CALL_WIDTH}s", called) %></td>
|
213
243
|
<td class="method_name"><%= create_link(thread_id, caller.parent.target) %></td>
|
214
|
-
<td
|
244
|
+
<td><%= file_link(caller.parent.target.source_file, caller.line) %></td>
|
215
245
|
</tr>
|
216
246
|
<% end %>
|
217
247
|
|
@@ -224,7 +254,7 @@ module RubyProf
|
|
224
254
|
<td><%= sprintf("%#{TIME_WIDTH}.2f", method.children_time) %></td>
|
225
255
|
<td><%= sprintf("%#{CALL_WIDTH}i", method.called) %></td>
|
226
256
|
<td class="method_name"><a name="<%= method_href(thread_id, method) %>"><%= h method.full_name %></a></td>
|
227
|
-
<td
|
257
|
+
<td><%= file_link(method.source_file, method.line) %></td>
|
228
258
|
</tr>
|
229
259
|
|
230
260
|
<!-- Children -->
|
@@ -240,7 +270,7 @@ module RubyProf
|
|
240
270
|
<% called = "#{callee.called}/#{callee.target.called}" %>
|
241
271
|
<td><%= sprintf("%#{CALL_WIDTH}s", called) %></td>
|
242
272
|
<td class="method_name"><%= create_link(thread_id, callee.target) %></td>
|
243
|
-
<td
|
273
|
+
<td><%= file_link(method.source_file, callee.line) %></td>
|
244
274
|
</tr>
|
245
275
|
<% end %>
|
246
276
|
<!-- Create divider row -->
|
@@ -252,5 +282,5 @@ module RubyProf
|
|
252
282
|
</html>'
|
253
283
|
end
|
254
284
|
end
|
255
|
-
end
|
285
|
+
end
|
256
286
|
|
@@ -1,15 +1,15 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
module RubyProf
|
4
|
-
# Generates graph[link:files/examples/graph_txt.html] profile reports as text.
|
4
|
+
# Generates graph[link:files/examples/graph_txt.html] profile reports as text.
|
5
5
|
# To use the graph printer:
|
6
6
|
#
|
7
7
|
# result = RubyProf.profile do
|
8
8
|
# [code to profile]
|
9
9
|
# end
|
10
10
|
#
|
11
|
-
# printer = RubyProf::GraphPrinter.new(result
|
12
|
-
# printer.print(STDOUT,
|
11
|
+
# printer = RubyProf::GraphPrinter.new(result)
|
12
|
+
# printer.print(STDOUT, {})
|
13
13
|
#
|
14
14
|
# The constructor takes two arguments. See the README
|
15
15
|
|
@@ -17,8 +17,8 @@ module RubyProf
|
|
17
17
|
PERCENTAGE_WIDTH = 8
|
18
18
|
TIME_WIDTH = 10
|
19
19
|
CALL_WIDTH = 17
|
20
|
-
|
21
|
-
# Create a GraphPrinter. Result is a RubyProf::Result
|
20
|
+
|
21
|
+
# Create a GraphPrinter. Result is a RubyProf::Result
|
22
22
|
# object generated from a profiling run.
|
23
23
|
def initialize(result)
|
24
24
|
super(result)
|
@@ -28,23 +28,23 @@ module RubyProf
|
|
28
28
|
|
29
29
|
def calculate_thread_times
|
30
30
|
# Cache thread times since this is an expensive
|
31
|
-
# operation with the required sorting
|
31
|
+
# operation with the required sorting
|
32
32
|
@result.threads.each do |thread_id, methods|
|
33
33
|
top = methods.max
|
34
|
-
|
34
|
+
|
35
35
|
thread_time = [top.total_time, 0.01].max
|
36
|
-
|
37
|
-
@thread_times[thread_id] = thread_time
|
36
|
+
|
37
|
+
@thread_times[thread_id] = thread_time
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
# Print a graph report to the provided output.
|
42
|
-
#
|
43
|
-
# output - Any IO oject, including STDOUT or a file.
|
42
|
+
#
|
43
|
+
# output - Any IO oject, including STDOUT or a file.
|
44
44
|
# The default value is STDOUT.
|
45
|
-
#
|
46
|
-
# options - Hash of print options. See #setup_options
|
47
|
-
#
|
45
|
+
#
|
46
|
+
# options - Hash of print options. See #setup_options
|
47
|
+
# for more information.
|
48
48
|
#
|
49
49
|
def print(output = STDOUT, options = {})
|
50
50
|
@output = output
|
@@ -52,7 +52,7 @@ module RubyProf
|
|
52
52
|
print_threads
|
53
53
|
end
|
54
54
|
|
55
|
-
private
|
55
|
+
private
|
56
56
|
def print_threads
|
57
57
|
# sort assumes that spawned threads have higher object_ids
|
58
58
|
@result.threads.sort.each do |thread_id, methods|
|
@@ -60,30 +60,30 @@ module RubyProf
|
|
60
60
|
@output << "\n" * 2
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
def print_methods(thread_id, methods)
|
65
65
|
# Sort methods from longest to shortest total time
|
66
|
-
methods = methods.
|
67
|
-
|
66
|
+
methods = methods.sort_by(&sort_method)
|
67
|
+
|
68
68
|
toplevel = methods.last
|
69
69
|
total_time = toplevel.total_time
|
70
70
|
if total_time == 0
|
71
71
|
total_time = 0.01
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
print_heading(thread_id)
|
75
|
-
|
75
|
+
|
76
76
|
# Print each method in total time order
|
77
77
|
methods.reverse_each do |method|
|
78
78
|
total_percentage = (method.total_time/total_time) * 100
|
79
79
|
self_percentage = (method.self_time/total_time) * 100
|
80
|
-
|
80
|
+
|
81
81
|
next if total_percentage < min_percent
|
82
|
-
|
82
|
+
|
83
83
|
@output << "-" * 80 << "\n"
|
84
84
|
|
85
85
|
print_parents(thread_id, method)
|
86
|
-
|
86
|
+
|
87
87
|
# 1 is for % sign
|
88
88
|
@output << sprintf("%#{PERCENTAGE_WIDTH-1}.2f\%", total_percentage)
|
89
89
|
@output << sprintf("%#{PERCENTAGE_WIDTH-1}.2f\%", self_percentage)
|
@@ -95,18 +95,18 @@ module RubyProf
|
|
95
95
|
@output << sprintf(" %s", method_name(method))
|
96
96
|
if print_file
|
97
97
|
@output << sprintf(" %s:%s", method.source_file, method.line)
|
98
|
-
end
|
98
|
+
end
|
99
99
|
@output << "\n"
|
100
|
-
|
100
|
+
|
101
101
|
print_children(method)
|
102
102
|
end
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
def print_heading(thread_id)
|
106
106
|
@output << "Thread ID: #{thread_id}\n"
|
107
107
|
@output << "Total Time: #{@thread_times[thread_id]}\n"
|
108
108
|
@output << "\n"
|
109
|
-
|
109
|
+
|
110
110
|
# 1 is for % sign
|
111
111
|
@output << sprintf("%#{PERCENTAGE_WIDTH}s", "%total")
|
112
112
|
@output << sprintf("%#{PERCENTAGE_WIDTH}s", "%self")
|
@@ -118,7 +118,7 @@ module RubyProf
|
|
118
118
|
@output << " Name"
|
119
119
|
@output << "\n"
|
120
120
|
end
|
121
|
-
|
121
|
+
|
122
122
|
def print_parents(thread_id, method)
|
123
123
|
method.aggregate_parents.sort_by(&:total_time).each do |caller|
|
124
124
|
next unless caller.parent
|
@@ -127,20 +127,20 @@ module RubyProf
|
|
127
127
|
@output << sprintf("%#{TIME_WIDTH}.2f", caller.self_time)
|
128
128
|
@output << sprintf("%#{TIME_WIDTH}.2f", caller.wait_time)
|
129
129
|
@output << sprintf("%#{TIME_WIDTH}.2f", caller.children_time)
|
130
|
-
|
130
|
+
|
131
131
|
call_called = "#{caller.called}/#{method.called}"
|
132
132
|
@output << sprintf("%#{CALL_WIDTH}s", call_called)
|
133
133
|
@output << sprintf(" %s", caller.parent.target.full_name)
|
134
134
|
@output << "\n"
|
135
135
|
end
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
def print_children(method)
|
139
139
|
method.aggregate_children.sort_by(&:total_time).reverse.each do |child|
|
140
140
|
# Get children method
|
141
|
-
|
141
|
+
|
142
142
|
@output << " " * 2 * PERCENTAGE_WIDTH
|
143
|
-
|
143
|
+
|
144
144
|
@output << sprintf("%#{TIME_WIDTH}.2f", child.total_time)
|
145
145
|
@output << sprintf("%#{TIME_WIDTH}.2f", child.self_time)
|
146
146
|
@output << sprintf("%#{TIME_WIDTH}.2f", child.wait_time)
|
@@ -153,5 +153,5 @@ module RubyProf
|
|
153
153
|
end
|
154
154
|
end
|
155
155
|
end
|
156
|
-
end
|
156
|
+
end
|
157
157
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module RubyProf
|
2
4
|
class MethodInfo
|
3
5
|
include Comparable
|
@@ -27,11 +29,12 @@ module RubyProf
|
|
27
29
|
def total_time
|
28
30
|
@total_time ||= begin
|
29
31
|
call_infos.inject(0) do |sum, call_info|
|
30
|
-
sum += call_info.total_time
|
32
|
+
sum += call_info.total_time if call_info.minimal?
|
33
|
+
sum
|
31
34
|
end
|
32
35
|
end
|
33
36
|
end
|
34
|
-
|
37
|
+
|
35
38
|
def self_time
|
36
39
|
@self_time ||= begin
|
37
40
|
call_infos.inject(0) do |sum, call_info|
|
@@ -51,7 +54,8 @@ module RubyProf
|
|
51
54
|
def children_time
|
52
55
|
@children_time ||= begin
|
53
56
|
call_infos.inject(0) do |sum, call_info|
|
54
|
-
sum += call_info.children_time
|
57
|
+
sum += call_info.children_time if call_info.minimal?
|
58
|
+
sum
|
55
59
|
end
|
56
60
|
end
|
57
61
|
end
|
@@ -107,5 +111,23 @@ module RubyProf
|
|
107
111
|
def to_s
|
108
112
|
full_name
|
109
113
|
end
|
114
|
+
|
115
|
+
def dump
|
116
|
+
res = ""
|
117
|
+
res << "MINFO: #{klass_name}##{method_name} total_time: #{total_time} (#{full_name})\n"
|
118
|
+
call_infos.each do |ci|
|
119
|
+
pinfo = ci.root? ? "TOPLEVEL" : (p=ci.parent.target; "#{p.klass_name}##{p.method_name} (#{ci.parent.object_id}) (#{p.full_name})")
|
120
|
+
res << "CINFO[#{ci.object_id}] called #{ci.called} times from #{pinfo}\n"
|
121
|
+
end
|
122
|
+
res
|
123
|
+
end
|
124
|
+
|
125
|
+
# remove method from the call graph. should not be called directly.
|
126
|
+
def eliminate!
|
127
|
+
# $stderr.puts "eliminating #{self}"
|
128
|
+
call_infos.each{ |call_info| call_info.eliminate! }
|
129
|
+
call_infos.clear
|
130
|
+
end
|
131
|
+
|
110
132
|
end
|
111
|
-
end
|
133
|
+
end
|