ruby-prof 0.13.1 → 1.4.2
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 +5 -5
- data/CHANGES +579 -371
- data/LICENSE +24 -23
- data/README.rdoc +5 -433
- data/Rakefile +98 -110
- data/bin/ruby-prof +328 -329
- data/bin/ruby-prof-check-trace +45 -0
- data/ext/ruby_prof/extconf.rb +16 -59
- data/ext/ruby_prof/rp_aggregate_call_tree.c +59 -0
- data/ext/ruby_prof/rp_aggregate_call_tree.h +13 -0
- data/ext/ruby_prof/rp_allocation.c +287 -0
- data/ext/ruby_prof/rp_allocation.h +31 -0
- data/ext/ruby_prof/rp_call_tree.c +369 -0
- data/ext/ruby_prof/rp_call_tree.h +43 -0
- data/ext/ruby_prof/rp_call_trees.c +288 -0
- data/ext/ruby_prof/rp_call_trees.h +28 -0
- data/ext/ruby_prof/rp_measure_allocations.c +50 -65
- data/ext/ruby_prof/rp_measure_memory.c +42 -73
- data/ext/ruby_prof/rp_measure_process_time.c +65 -71
- data/ext/ruby_prof/rp_measure_wall_time.c +64 -42
- data/ext/ruby_prof/rp_measurement.c +237 -0
- data/ext/ruby_prof/rp_measurement.h +50 -0
- data/ext/ruby_prof/rp_method.c +491 -420
- data/ext/ruby_prof/rp_method.h +62 -57
- data/ext/ruby_prof/rp_profile.c +908 -0
- data/ext/ruby_prof/rp_profile.h +35 -0
- data/ext/ruby_prof/rp_stack.c +212 -128
- data/ext/ruby_prof/rp_stack.h +53 -51
- data/ext/ruby_prof/rp_thread.c +362 -268
- data/ext/ruby_prof/rp_thread.h +39 -27
- data/ext/ruby_prof/ruby_prof.c +52 -695
- data/ext/ruby_prof/ruby_prof.h +26 -55
- data/ext/ruby_prof/vc/ruby_prof.sln +28 -21
- data/ext/ruby_prof/vc/{ruby_prof_20.vcxproj → ruby_prof.vcxproj} +56 -8
- data/lib/ruby-prof.rb +52 -67
- data/lib/ruby-prof/assets/call_stack_printer.html.erb +710 -0
- data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
- data/lib/ruby-prof/assets/graph_printer.html.erb +355 -0
- data/lib/ruby-prof/call_tree.rb +57 -0
- data/lib/ruby-prof/call_tree_visitor.rb +36 -0
- data/lib/ruby-prof/compatibility.rb +99 -169
- data/lib/ruby-prof/exclude_common_methods.rb +198 -0
- data/lib/ruby-prof/measurement.rb +17 -0
- data/lib/ruby-prof/method_info.rb +78 -131
- data/lib/ruby-prof/printers/abstract_printer.rb +137 -85
- data/lib/ruby-prof/printers/call_info_printer.rb +53 -41
- data/lib/ruby-prof/printers/call_stack_printer.rb +180 -773
- data/lib/ruby-prof/printers/call_tree_printer.rb +151 -92
- data/lib/ruby-prof/printers/dot_printer.rb +132 -132
- data/lib/ruby-prof/printers/flat_printer.rb +53 -69
- data/lib/ruby-prof/printers/graph_html_printer.rb +63 -255
- data/lib/ruby-prof/printers/graph_printer.rb +113 -116
- data/lib/ruby-prof/printers/multi_printer.rb +127 -56
- data/lib/ruby-prof/profile.rb +37 -77
- data/lib/ruby-prof/rack.rb +62 -15
- data/lib/ruby-prof/task.rb +147 -147
- data/lib/ruby-prof/thread.rb +10 -12
- data/lib/ruby-prof/version.rb +3 -0
- data/lib/unprof.rb +10 -10
- data/ruby-prof.gemspec +65 -61
- data/test/abstract_printer_test.rb +26 -0
- data/test/alias_test.rb +126 -0
- data/test/basic_test.rb +43 -128
- data/test/call_tree_visitor_test.rb +32 -0
- data/test/call_trees_test.rb +66 -0
- data/test/duplicate_names_test.rb +32 -32
- data/test/dynamic_method_test.rb +53 -74
- data/test/enumerable_test.rb +21 -16
- data/test/exceptions_test.rb +24 -16
- data/test/exclude_methods_test.rb +151 -0
- data/test/exclude_threads_test.rb +53 -54
- data/test/fiber_test.rb +129 -65
- data/test/gc_test.rb +90 -0
- data/test/inverse_call_tree_test.rb +175 -0
- data/test/line_number_test.rb +158 -71
- data/test/marshal_test.rb +113 -0
- data/test/measure_allocations.rb +30 -0
- data/test/measure_allocations_test.rb +375 -25
- data/test/measure_allocations_trace_test.rb +375 -0
- data/test/measure_memory_trace_test.rb +1101 -0
- data/test/measure_process_time_test.rb +785 -62
- data/test/measure_times.rb +56 -0
- data/test/measure_wall_time_test.rb +434 -254
- data/test/multi_printer_test.rb +71 -82
- data/test/no_method_class_test.rb +15 -15
- data/test/pause_resume_test.rb +175 -166
- data/test/prime.rb +54 -54
- data/test/prime_script.rb +6 -0
- data/test/printer_call_stack_test.rb +27 -0
- data/test/printer_call_tree_test.rb +30 -0
- data/test/printer_flat_test.rb +99 -0
- data/test/printer_graph_html_test.rb +59 -0
- data/test/printer_graph_test.rb +40 -0
- data/test/printers_test.rb +141 -257
- data/test/printing_recursive_graph_test.rb +81 -0
- data/test/profile_test.rb +16 -0
- data/test/rack_test.rb +93 -0
- data/test/recursive_test.rb +206 -215
- data/test/singleton_test.rb +38 -38
- data/test/stack_printer_test.rb +64 -78
- data/test/start_stop_test.rb +109 -112
- data/test/test_helper.rb +13 -115
- data/test/thread_test.rb +144 -178
- data/test/unique_call_path_test.rb +120 -224
- data/test/yarv_test.rb +56 -0
- metadata +77 -133
- data/doc/LICENSE.html +0 -155
- data/doc/README_rdoc.html +0 -648
- data/doc/Rack.html +0 -167
- data/doc/Rack/RubyProf.html +0 -319
- data/doc/RubyProf.html +0 -1000
- data/doc/RubyProf/AbstractPrinter.html +0 -580
- data/doc/RubyProf/AggregateCallInfo.html +0 -570
- data/doc/RubyProf/CallInfo.html +0 -512
- data/doc/RubyProf/CallInfoPrinter.html +0 -190
- data/doc/RubyProf/CallInfoVisitor.html +0 -332
- data/doc/RubyProf/CallStackPrinter.html +0 -1600
- data/doc/RubyProf/CallTreePrinter.html +0 -413
- data/doc/RubyProf/Cmd.html +0 -669
- data/doc/RubyProf/DotPrinter.html +0 -312
- data/doc/RubyProf/FlatPrinter.html +0 -229
- data/doc/RubyProf/FlatPrinterWithLineNumbers.html +0 -267
- data/doc/RubyProf/GraphHtmlPrinter.html +0 -630
- data/doc/RubyProf/GraphPrinter.html +0 -209
- data/doc/RubyProf/MethodInfo.html +0 -713
- data/doc/RubyProf/MultiPrinter.html +0 -407
- data/doc/RubyProf/Profile.html +0 -821
- data/doc/RubyProf/ProfileTask.html +0 -532
- data/doc/RubyProf/Test.html +0 -578
- data/doc/RubyProf/Thread.html +0 -262
- data/doc/created.rid +0 -32
- data/doc/examples/flat_txt.html +0 -191
- data/doc/examples/graph_txt.html +0 -305
- data/doc/images/add.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +0 -647
- data/doc/js/darkfish.js +0 -155
- data/doc/js/jquery.js +0 -18
- data/doc/js/navigation.js +0 -142
- data/doc/js/search.js +0 -94
- data/doc/js/search_index.js +0 -1
- data/doc/js/searcher.js +0 -228
- data/doc/rdoc.css +0 -543
- data/doc/table_of_contents.html +0 -462
- data/examples/empty.png +0 -0
- data/examples/flat.txt +0 -55
- data/examples/graph.dot +0 -106
- data/examples/graph.html +0 -823
- data/examples/graph.png +0 -0
- data/examples/graph.txt +0 -170
- data/examples/minus.png +0 -0
- data/examples/multi.flat.txt +0 -23
- data/examples/multi.graph.html +0 -906
- data/examples/multi.grind.dat +0 -194
- data/examples/multi.stack.html +0 -573
- data/examples/plus.png +0 -0
- data/examples/stack.html +0 -573
- data/ext/ruby_prof/rp_call_info.c +0 -407
- data/ext/ruby_prof/rp_call_info.h +0 -48
- data/ext/ruby_prof/rp_measure.c +0 -48
- data/ext/ruby_prof/rp_measure.h +0 -45
- data/ext/ruby_prof/rp_measure_cpu_time.c +0 -112
- data/ext/ruby_prof/rp_measure_gc_runs.c +0 -65
- data/ext/ruby_prof/rp_measure_gc_time.c +0 -57
- data/ext/ruby_prof/vc/ruby_prof_18.vcxproj +0 -108
- data/ext/ruby_prof/vc/ruby_prof_19.vcxproj +0 -110
- data/ext/ruby_prof/version.h +0 -7
- data/lib/ruby-prof/aggregate_call_info.rb +0 -72
- data/lib/ruby-prof/call_info.rb +0 -89
- data/lib/ruby-prof/call_info_visitor.rb +0 -44
- data/lib/ruby-prof/images/empty.png +0 -0
- data/lib/ruby-prof/images/minus.png +0 -0
- data/lib/ruby-prof/images/plus.png +0 -0
- data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +0 -57
- data/lib/ruby-prof/test.rb +0 -150
- data/test/aggregate_test.rb +0 -136
- data/test/call_info_test.rb +0 -78
- data/test/call_info_visitor_test.rb +0 -31
- data/test/exec_test.rb +0 -14
- data/test/measure_cpu_time_test.rb +0 -220
- data/test/measure_gc_runs_test.rb +0 -32
- data/test/measure_gc_time_test.rb +0 -36
- data/test/measure_memory_test.rb +0 -31
- data/test/method_elimination_test.rb +0 -84
- data/test/module_test.rb +0 -45
- data/test/stack_test.rb +0 -138
- data/test/test_suite.rb +0 -37
|
@@ -1,773 +1,180 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
require 'erb'
|
|
4
|
-
require 'fileutils'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
51
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
def copy_image_files
|
|
184
|
-
if @output.is_a?(File)
|
|
185
|
-
target_dir = File.dirname(@output.path)
|
|
186
|
-
image_dir = File.join(File.dirname(__FILE__), '..', 'images')
|
|
187
|
-
%w(empty plus minus).each do |img|
|
|
188
|
-
source_file = "#{image_dir}/#{img}.png"
|
|
189
|
-
target_file = "#{target_dir}/#{img}.png"
|
|
190
|
-
FileUtils.cp(source_file, target_file) unless File.exist?(target_file)
|
|
191
|
-
end
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
def print_header
|
|
196
|
-
@output.puts "<html><head>"
|
|
197
|
-
@output.puts '<meta http-equiv="content-type" content="text/html; charset=utf-8">'
|
|
198
|
-
@output.puts "<title>#{h title}</title>"
|
|
199
|
-
print_css
|
|
200
|
-
print_java_script
|
|
201
|
-
@output.puts '</head><body><div style="display: inline-block;">'
|
|
202
|
-
print_title_bar
|
|
203
|
-
print_commands
|
|
204
|
-
print_help
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
def print_footer
|
|
208
|
-
@output.puts '<div id="sentinel"></div></div></body></html>'
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
def print_css
|
|
212
|
-
@output.puts <<-'end_css'
|
|
213
|
-
<style type="text/css">
|
|
214
|
-
<!--
|
|
215
|
-
body {
|
|
216
|
-
font-size:70%;
|
|
217
|
-
padding:0px;
|
|
218
|
-
margin:5px;
|
|
219
|
-
margin-right:0px;
|
|
220
|
-
margin-left:0px;
|
|
221
|
-
background: #ffffff;
|
|
222
|
-
}
|
|
223
|
-
ul {
|
|
224
|
-
margin-left:0px;
|
|
225
|
-
margin-top:0px;
|
|
226
|
-
margin-bottom:0px;
|
|
227
|
-
padding-left:0px;
|
|
228
|
-
list-style-type:none;
|
|
229
|
-
}
|
|
230
|
-
li {
|
|
231
|
-
margin-left:11px;
|
|
232
|
-
padding:0px;
|
|
233
|
-
white-space:nowrap;
|
|
234
|
-
border-top:1px solid #cccccc;
|
|
235
|
-
border-left:1px solid #cccccc;
|
|
236
|
-
border-bottom:none;
|
|
237
|
-
}
|
|
238
|
-
.thread {
|
|
239
|
-
margin-left:11px;
|
|
240
|
-
background:#708090;
|
|
241
|
-
padding-top:3px;
|
|
242
|
-
padding-left:12px;
|
|
243
|
-
padding-bottom:2px;
|
|
244
|
-
border-left:1px solid #CCCCCC;
|
|
245
|
-
border-top:1px solid #CCCCCC;
|
|
246
|
-
font-weight:bold;
|
|
247
|
-
}
|
|
248
|
-
.hidden {
|
|
249
|
-
display:none;
|
|
250
|
-
width:0px;
|
|
251
|
-
height:0px;
|
|
252
|
-
margin:0px;
|
|
253
|
-
padding:0px;
|
|
254
|
-
border-style:none;
|
|
255
|
-
}
|
|
256
|
-
.color01 { background:#adbdeb }
|
|
257
|
-
.color05 { background:#9daddb }
|
|
258
|
-
.color0 { background:#8d9dcb }
|
|
259
|
-
.color1 { background:#89bccb }
|
|
260
|
-
.color2 { background:#56e3e7 }
|
|
261
|
-
.color3 { background:#32cd70 }
|
|
262
|
-
.color4 { background:#a3d53c }
|
|
263
|
-
.color5 { background:#c4cb34 }
|
|
264
|
-
.color6 { background:#dcb66d }
|
|
265
|
-
.color7 { background:#cda59e }
|
|
266
|
-
.color8 { background:#be9d9c }
|
|
267
|
-
.color9 { background:#cf947a }
|
|
268
|
-
#commands {
|
|
269
|
-
font-size:10pt;
|
|
270
|
-
padding:10px;
|
|
271
|
-
margin-left:11px;
|
|
272
|
-
margin-bottom:0px;
|
|
273
|
-
margin-top:0px;
|
|
274
|
-
background:#708090;
|
|
275
|
-
border-top:1px solid #cccccc;
|
|
276
|
-
border-left:1px solid #cccccc;
|
|
277
|
-
border-bottom:none;
|
|
278
|
-
}
|
|
279
|
-
#titlebar {
|
|
280
|
-
font-size:10pt;
|
|
281
|
-
padding:10px;
|
|
282
|
-
margin-left:11px;
|
|
283
|
-
margin-bottom:0px;
|
|
284
|
-
margin-top:10px;
|
|
285
|
-
background:#8090a0;
|
|
286
|
-
border-top:1px solid #cccccc;
|
|
287
|
-
border-left:1px solid #cccccc;
|
|
288
|
-
border-bottom:none;
|
|
289
|
-
}
|
|
290
|
-
#help {
|
|
291
|
-
font-size:10pt;
|
|
292
|
-
padding:10px;
|
|
293
|
-
margin-left:11px;
|
|
294
|
-
margin-bottom:0px;
|
|
295
|
-
margin-top:0px;
|
|
296
|
-
background:#8090a0;
|
|
297
|
-
display:none;
|
|
298
|
-
border-top:1px solid #cccccc;
|
|
299
|
-
border-left:1px solid #cccccc;
|
|
300
|
-
border-bottom:none;
|
|
301
|
-
}
|
|
302
|
-
#sentinel {
|
|
303
|
-
height: 400px;
|
|
304
|
-
margin-left:11px;
|
|
305
|
-
background:#8090a0;
|
|
306
|
-
border-top:1px solid #cccccc;
|
|
307
|
-
border-left:1px solid #cccccc;
|
|
308
|
-
border-bottom:none;
|
|
309
|
-
}
|
|
310
|
-
input { margin-left:10px; }
|
|
311
|
-
-->
|
|
312
|
-
</style>
|
|
313
|
-
end_css
|
|
314
|
-
end
|
|
315
|
-
|
|
316
|
-
def print_java_script
|
|
317
|
-
@output.puts <<-'end_java_script'
|
|
318
|
-
<script type="text/javascript">
|
|
319
|
-
/*
|
|
320
|
-
Copyright (C) 2005,2009 Stefan Kaes
|
|
321
|
-
skaes@railsexpress.de
|
|
322
|
-
*/
|
|
323
|
-
|
|
324
|
-
function rootNode() {
|
|
325
|
-
return currentThread;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
function hideUL(node) {
|
|
329
|
-
var lis = node.childNodes
|
|
330
|
-
var l = lis.length;
|
|
331
|
-
for (var i=0; i < l ; i++ ) {
|
|
332
|
-
hideLI(lis[i]);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
function showUL(node) {
|
|
337
|
-
var lis = node.childNodes;
|
|
338
|
-
var l = lis.length;
|
|
339
|
-
for (var i=0; i < l ; i++ ) {
|
|
340
|
-
showLI(lis[i]);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
function findUlChild(li){
|
|
345
|
-
var ul = li.childNodes[2];
|
|
346
|
-
while (ul && ul.nodeName != "UL") {
|
|
347
|
-
ul = ul.nextSibling;
|
|
348
|
-
}
|
|
349
|
-
return ul;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
function isLeafNode(li) {
|
|
353
|
-
var img = li.firstChild;
|
|
354
|
-
return (img.src.indexOf('empty.png') > -1);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
function hideLI(li) {
|
|
358
|
-
if (isLeafNode(li))
|
|
359
|
-
return;
|
|
360
|
-
|
|
361
|
-
var img = li.firstChild;
|
|
362
|
-
img.src = 'plus.png';
|
|
363
|
-
|
|
364
|
-
var ul = findUlChild(li);
|
|
365
|
-
if (ul) {
|
|
366
|
-
ul.style.display = 'none';
|
|
367
|
-
hideUL(ul);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
function showLI(li) {
|
|
372
|
-
if (isLeafNode(li))
|
|
373
|
-
return;
|
|
374
|
-
|
|
375
|
-
var img = li.firstChild;
|
|
376
|
-
img.src = 'minus.png';
|
|
377
|
-
|
|
378
|
-
var ul = findUlChild(li);
|
|
379
|
-
if (ul) {
|
|
380
|
-
ul.style.display = 'block';
|
|
381
|
-
showUL(ul);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
function toggleLI(li) {
|
|
386
|
-
var img = li.firstChild;
|
|
387
|
-
if (img.src.indexOf("minus.png")>-1)
|
|
388
|
-
hideLI(li);
|
|
389
|
-
else {
|
|
390
|
-
if (img.src.indexOf("plus.png")>-1)
|
|
391
|
-
showLI(li);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
function aboveThreshold(text, threshold) {
|
|
396
|
-
var match = text.match(/\d+[.,]\d+/);
|
|
397
|
-
return (match && parseFloat(match[0].replace(/,/, '.'))>=threshold);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
function setThresholdLI(li, threshold) {
|
|
401
|
-
var img = li.firstChild;
|
|
402
|
-
var text = img.nextSibling;
|
|
403
|
-
var ul = findUlChild(li);
|
|
404
|
-
|
|
405
|
-
var visible = aboveThreshold(text.nodeValue, threshold) ? 1 : 0;
|
|
406
|
-
|
|
407
|
-
var count = 0;
|
|
408
|
-
if (ul) {
|
|
409
|
-
count = setThresholdUL(ul, threshold);
|
|
410
|
-
}
|
|
411
|
-
if (count>0) {
|
|
412
|
-
img.src = 'minus.png';
|
|
413
|
-
}
|
|
414
|
-
else {
|
|
415
|
-
img.src = 'empty.png';
|
|
416
|
-
}
|
|
417
|
-
if (visible) {
|
|
418
|
-
li.style.display = 'block'
|
|
419
|
-
}
|
|
420
|
-
else {
|
|
421
|
-
li.style.display = 'none'
|
|
422
|
-
}
|
|
423
|
-
return visible;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
function setThresholdUL(node, threshold) {
|
|
427
|
-
var lis = node.childNodes;
|
|
428
|
-
var l = lis.length;
|
|
429
|
-
|
|
430
|
-
var count = 0;
|
|
431
|
-
for ( var i = 0; i < l ; i++ ) {
|
|
432
|
-
count = count + setThresholdLI(lis[i], threshold);
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
var visible = (count > 0) ? 1 : 0;
|
|
436
|
-
if (visible) {
|
|
437
|
-
node.style.display = 'block';
|
|
438
|
-
}
|
|
439
|
-
else {
|
|
440
|
-
node.style.display = 'none';
|
|
441
|
-
}
|
|
442
|
-
return visible;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
function toggleChildren(img, event) {
|
|
446
|
-
event.cancelBubble=true;
|
|
447
|
-
|
|
448
|
-
if (img.src.indexOf('empty.png') > -1)
|
|
449
|
-
return;
|
|
450
|
-
|
|
451
|
-
var minus = (img.src.indexOf('minus.png') > -1);
|
|
452
|
-
|
|
453
|
-
if (minus) {
|
|
454
|
-
img.src = 'plus.png';
|
|
455
|
-
}
|
|
456
|
-
else
|
|
457
|
-
img.src = 'minus.png';
|
|
458
|
-
|
|
459
|
-
var li = img.parentNode;
|
|
460
|
-
var ul = findUlChild(li);
|
|
461
|
-
if (ul) {
|
|
462
|
-
if (minus)
|
|
463
|
-
ul.style.display = 'none';
|
|
464
|
-
else
|
|
465
|
-
ul.style.display = 'block';
|
|
466
|
-
}
|
|
467
|
-
if (minus)
|
|
468
|
-
moveSelectionIfNecessary(li);
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
function showChildren(li) {
|
|
472
|
-
var img = li.firstChild;
|
|
473
|
-
if (img.src.indexOf('empty.png') > -1)
|
|
474
|
-
return;
|
|
475
|
-
img.src = 'minus.png';
|
|
476
|
-
|
|
477
|
-
var ul = findUlChild(li);
|
|
478
|
-
if (ul) {
|
|
479
|
-
ul.style.display = 'block';
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
function setThreshold() {
|
|
484
|
-
var tv = document.getElementById("threshold").value;
|
|
485
|
-
if (tv.match(/[0-9]+([.,][0-9]+)?/)) {
|
|
486
|
-
var f = parseFloat(tv.replace(/,/, '.'));
|
|
487
|
-
var threads = document.getElementsByName("thread");
|
|
488
|
-
var l = threads.length;
|
|
489
|
-
for ( var i = 0; i < l ; i++ ) {
|
|
490
|
-
setThresholdUL(threads[i], f);
|
|
491
|
-
}
|
|
492
|
-
var p = selectedNode;
|
|
493
|
-
while (p && p.style.display=='none')
|
|
494
|
-
p=p.parentNode.parentNode;
|
|
495
|
-
if (p && p.nodeName=="LI")
|
|
496
|
-
selectNode(p);
|
|
497
|
-
}
|
|
498
|
-
else {
|
|
499
|
-
alert("Please specify a decimal number as threshold value!");
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
function collapseAll(event) {
|
|
504
|
-
event.cancelBubble=true;
|
|
505
|
-
var threads = document.getElementsByName("thread");
|
|
506
|
-
var l = threads.length;
|
|
507
|
-
for ( var i = 0; i < l ; i++ ) {
|
|
508
|
-
hideUL(threads[i]);
|
|
509
|
-
}
|
|
510
|
-
selectNode(rootNode(), null);
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
function expandAll(event) {
|
|
514
|
-
event.cancelBubble=true;
|
|
515
|
-
var threads = document.getElementsByName("thread");
|
|
516
|
-
var l = threads.length;
|
|
517
|
-
for ( var i = 0; i < l ; i++ ) {
|
|
518
|
-
showUL(threads[i]);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
function toggleHelp(node) {
|
|
523
|
-
var help = document.getElementById("help");
|
|
524
|
-
if (node.value == "Show Help") {
|
|
525
|
-
node.value = "Hide Help";
|
|
526
|
-
help.style.display = 'block';
|
|
527
|
-
}
|
|
528
|
-
else {
|
|
529
|
-
node.value = "Show Help";
|
|
530
|
-
help.style.display = 'none';
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
var selectedNode = null;
|
|
535
|
-
var selectedColor = null;
|
|
536
|
-
var selectedThread = null;
|
|
537
|
-
|
|
538
|
-
function descendentOf(a,b){
|
|
539
|
-
while (a!=b && b!=null)
|
|
540
|
-
b=b.parentNode;
|
|
541
|
-
return (a==b);
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
function moveSelectionIfNecessary(node){
|
|
545
|
-
if (descendentOf(node, selectedNode))
|
|
546
|
-
selectNode(node, null);
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
function selectNode(node, event) {
|
|
550
|
-
if (event) {
|
|
551
|
-
event.cancelBubble = true;
|
|
552
|
-
thread = findThread(node);
|
|
553
|
-
selectThread(thread);
|
|
554
|
-
}
|
|
555
|
-
if (selectedNode) {
|
|
556
|
-
selectedNode.style.background = selectedColor;
|
|
557
|
-
}
|
|
558
|
-
selectedNode = node;
|
|
559
|
-
selectedColor = node.style.background;
|
|
560
|
-
selectedNode.style.background = "red";
|
|
561
|
-
selectedNode.scrollIntoView();
|
|
562
|
-
window.scrollBy(0,-400);
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
function moveUp(){
|
|
566
|
-
var p = selectedNode.previousSibling;
|
|
567
|
-
while (p && p.style.display == 'none')
|
|
568
|
-
p = p.previousSibling;
|
|
569
|
-
if (p && p.nodeName == "LI") {
|
|
570
|
-
selectNode(p, null);
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
function moveDown(){
|
|
575
|
-
var p = selectedNode.nextSibling;
|
|
576
|
-
while (p && p.style.display == 'none')
|
|
577
|
-
p = p.nextSibling;
|
|
578
|
-
if (p && p.nodeName == "LI") {
|
|
579
|
-
selectNode(p, null);
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
function moveLeft(){
|
|
584
|
-
var p = selectedNode.parentNode.parentNode;
|
|
585
|
-
if (p && p.nodeName=="LI") {
|
|
586
|
-
selectNode(p, null);
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
function moveRight(){
|
|
591
|
-
if (!isLeafNode(selectedNode)) {
|
|
592
|
-
showChildren(selectedNode);
|
|
593
|
-
var ul = findUlChild(selectedNode);
|
|
594
|
-
if (ul) {
|
|
595
|
-
selectNode(ul.firstChild, null);
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
function moveForward(){
|
|
601
|
-
if (isLeafNode(selectedNode)) {
|
|
602
|
-
var p = selectedNode;
|
|
603
|
-
while ((p.nextSibling == null || p.nextSibling.style.display=='none') && p.nodeName=="LI") {
|
|
604
|
-
p = p.parentNode.parentNode;
|
|
605
|
-
}
|
|
606
|
-
if (p.nodeName=="LI")
|
|
607
|
-
selectNode(p.nextSibling, null);
|
|
608
|
-
}
|
|
609
|
-
else {
|
|
610
|
-
moveRight();
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
function isExpandedNode(li){
|
|
615
|
-
var img = li.firstChild;
|
|
616
|
-
return(img.src.indexOf('minus.png')>-1);
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
function moveBackward(){
|
|
620
|
-
var p = selectedNode;
|
|
621
|
-
var q = p.previousSibling;
|
|
622
|
-
while (q != null && q.style.display=='none')
|
|
623
|
-
q = q.previousSibling;
|
|
624
|
-
if (q == null) {
|
|
625
|
-
p = p.parentNode.parentNode;
|
|
626
|
-
} else {
|
|
627
|
-
while (!isLeafNode(q) && isExpandedNode(q)) {
|
|
628
|
-
q = findUlChild(q).lastChild;
|
|
629
|
-
while (q.style.display=='none')
|
|
630
|
-
q = q.previousSibling;
|
|
631
|
-
}
|
|
632
|
-
p = q;
|
|
633
|
-
}
|
|
634
|
-
if (p.nodeName=="LI")
|
|
635
|
-
selectNode(p, null);
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
function moveHome() {
|
|
639
|
-
selectNode(currentThread);
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
var currentThreadIndex = null;
|
|
643
|
-
|
|
644
|
-
function findThread(node){
|
|
645
|
-
while (node && node.parentNode.nodeName!="BODY") {
|
|
646
|
-
node = node.parentNode;
|
|
647
|
-
}
|
|
648
|
-
return node.firstChild;
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
function selectThread(node){
|
|
652
|
-
var threads = document.getElementsByName("thread");
|
|
653
|
-
currentThread = node;
|
|
654
|
-
for (var i=0; i<threads.length; i++) {
|
|
655
|
-
if (threads[i]==currentThread.parentNode)
|
|
656
|
-
currentThreadIndex = i;
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
function nextThread(){
|
|
661
|
-
var threads = document.getElementsByName("thread");
|
|
662
|
-
if (currentThreadIndex==threads.length-1)
|
|
663
|
-
currentThreadIndex = 0;
|
|
664
|
-
else
|
|
665
|
-
currentThreadIndex += 1
|
|
666
|
-
currentThread = threads[currentThreadIndex].firstChild;
|
|
667
|
-
selectNode(currentThread, null);
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
function previousThread(){
|
|
671
|
-
var threads = document.getElementsByName("thread");
|
|
672
|
-
if (currentThreadIndex==0)
|
|
673
|
-
currentThreadIndex = threads.length-1;
|
|
674
|
-
else
|
|
675
|
-
currentThreadIndex -= 1
|
|
676
|
-
currentThread = threads[currentThreadIndex].firstChild;
|
|
677
|
-
selectNode(currentThread, null);
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
function switchThread(node, event){
|
|
681
|
-
event.cancelBubble = true;
|
|
682
|
-
selectThread(node.nextSibling.firstChild);
|
|
683
|
-
selectNode(currentThread, null);
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
function handleKeyEvent(event){
|
|
687
|
-
var code = event.charCode ? event.charCode : event.keyCode;
|
|
688
|
-
var str = String.fromCharCode(code);
|
|
689
|
-
switch (str) {
|
|
690
|
-
case "a": moveLeft(); break;
|
|
691
|
-
case "s": moveDown(); break;
|
|
692
|
-
case "d": moveRight(); break;
|
|
693
|
-
case "w": moveUp(); break;
|
|
694
|
-
case "f": moveForward(); break;
|
|
695
|
-
case "b": moveBackward(); break;
|
|
696
|
-
case "x": toggleChildren(selectedNode.firstChild, event); break;
|
|
697
|
-
case "*": toggleLI(selectedNode); break;
|
|
698
|
-
case "n": nextThread(); break;
|
|
699
|
-
case "h": moveHome(); break;
|
|
700
|
-
case "p": previousThread(); break;
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
document.onkeypress=function(event){ handleKeyEvent(event) };
|
|
704
|
-
|
|
705
|
-
window.onload=function(){
|
|
706
|
-
var images = document.getElementsByTagName("img");
|
|
707
|
-
for (var i=0; i<images.length; i++) {
|
|
708
|
-
var img = images[i];
|
|
709
|
-
if (img.className == "toggle") {
|
|
710
|
-
img.onclick = function(event){ toggleChildren(this, event); };
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
var divs = document.getElementsByTagName("div");
|
|
714
|
-
for (i=0; i<divs.length; i++) {
|
|
715
|
-
var div = divs[i];
|
|
716
|
-
if (div.className == "thread")
|
|
717
|
-
div.onclick = function(event){ switchThread(this, event) };
|
|
718
|
-
}
|
|
719
|
-
var lis = document.getElementsByTagName("li");
|
|
720
|
-
for (var i=0; i<lis.length; i++) {
|
|
721
|
-
lis[i].onclick = function(event){ selectNode(this, event); };
|
|
722
|
-
}
|
|
723
|
-
var threads = document.getElementsByName("thread");
|
|
724
|
-
currentThreadIndex = 0;
|
|
725
|
-
currentThread = threads[0].firstChild;
|
|
726
|
-
selectNode(currentThread, null);
|
|
727
|
-
}
|
|
728
|
-
</script>
|
|
729
|
-
end_java_script
|
|
730
|
-
end
|
|
731
|
-
|
|
732
|
-
def print_title_bar
|
|
733
|
-
@output.puts <<-"end_title_bar"
|
|
734
|
-
<div id="titlebar">
|
|
735
|
-
Call tree for application <b>#{h application} #{h arguments}</b><br/>
|
|
736
|
-
Generated on #{Time.now} with options #{h @options.inspect}<br/>
|
|
737
|
-
</div>
|
|
738
|
-
end_title_bar
|
|
739
|
-
end
|
|
740
|
-
|
|
741
|
-
def print_commands
|
|
742
|
-
@output.puts <<-"end_commands"
|
|
743
|
-
<div id=\"commands\">
|
|
744
|
-
<span style=\"font-size: 11pt; font-weight: bold;\">Threshold:</span>
|
|
745
|
-
<input value=\"#{h threshold}\" size=\"3\" id=\"threshold\" type=\"text\">
|
|
746
|
-
<input value=\"Apply\" onclick=\"setThreshold();\" type=\"submit\">
|
|
747
|
-
<input value=\"Expand All\" onclick=\"expandAll(event);\" type=\"submit\">
|
|
748
|
-
<input value=\"Collapse All\" onclick=\"collapseAll(event);\" type=\"submit\">
|
|
749
|
-
<input value=\"Show Help\" onclick=\"toggleHelp(this);\" type=\"submit\">
|
|
750
|
-
</div>
|
|
751
|
-
end_commands
|
|
752
|
-
end
|
|
753
|
-
|
|
754
|
-
def print_help
|
|
755
|
-
@output.puts <<-'end_help'
|
|
756
|
-
<div style="display: none;" id="help">
|
|
757
|
-
<img src="empty.png"> Enter a decimal value <i>d</i> into the threshold field and click "Apply"
|
|
758
|
-
to hide all nodes marked with time values lower than <i>d</i>.<br>
|
|
759
|
-
<img src="empty.png"> Click on "Expand All" for full tree expansion.<br>
|
|
760
|
-
<img src="empty.png"> Click on "Collapse All" to show only top level nodes.<br>
|
|
761
|
-
<img src="empty.png"> Use a, s, d, w as in Quake or Urban Terror to navigate the tree.<br>
|
|
762
|
-
<img src="empty.png"> Use f and b to navigate the tree in preorder forward and backwards.<br>
|
|
763
|
-
<img src="empty.png"> Use x to toggle visibility of a subtree.<br>
|
|
764
|
-
<img src="empty.png"> Use * to expand/collapse a whole subtree.<br>
|
|
765
|
-
<img src="empty.png"> Use h to navigate to thread root.<br>
|
|
766
|
-
<img src="empty.png"> Use n and p to navigate between threads.<br>
|
|
767
|
-
<img src="empty.png"> Click on background to move focus to a subtree.<br>
|
|
768
|
-
</div>
|
|
769
|
-
end_help
|
|
770
|
-
end
|
|
771
|
-
end
|
|
772
|
-
end
|
|
773
|
-
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'erb'
|
|
4
|
+
require 'fileutils'
|
|
5
|
+
require 'base64'
|
|
6
|
+
require 'set'
|
|
7
|
+
require 'stringio'
|
|
8
|
+
|
|
9
|
+
module RubyProf
|
|
10
|
+
# Prints a HTML visualization of the call tree.
|
|
11
|
+
#
|
|
12
|
+
# To use the printer:
|
|
13
|
+
#
|
|
14
|
+
# result = RubyProf.profile do
|
|
15
|
+
# [code to profile]
|
|
16
|
+
# end
|
|
17
|
+
#
|
|
18
|
+
# printer = RubyProf::CallStackPrinter.new(result)
|
|
19
|
+
# printer.print(STDOUT)
|
|
20
|
+
|
|
21
|
+
class CallStackPrinter < AbstractPrinter
|
|
22
|
+
include ERB::Util
|
|
23
|
+
|
|
24
|
+
# Specify print options.
|
|
25
|
+
#
|
|
26
|
+
# options - Hash table
|
|
27
|
+
# :min_percent - Number 0 to 100 that specifes the minimum
|
|
28
|
+
# %self (the methods self time divided by the
|
|
29
|
+
# overall total time) that a method must take
|
|
30
|
+
# for it to be printed out in the report.
|
|
31
|
+
# Default value is 0.
|
|
32
|
+
#
|
|
33
|
+
# :threshold - a float from 0 to 100 that sets the threshold of
|
|
34
|
+
# results displayed.
|
|
35
|
+
# Default value is 1.0
|
|
36
|
+
#
|
|
37
|
+
# :title - a String to overide the default "ruby-prof call tree"
|
|
38
|
+
# title of the report.
|
|
39
|
+
#
|
|
40
|
+
# :expansion - a float from 0 to 100 that sets the threshold of
|
|
41
|
+
# results that are expanded, if the percent_total
|
|
42
|
+
# exceeds it.
|
|
43
|
+
# Default value is 10.0
|
|
44
|
+
#
|
|
45
|
+
# :application - a String to overide the name of the application,
|
|
46
|
+
# as it appears on the report.
|
|
47
|
+
def print(output = STDOUT, options = {})
|
|
48
|
+
setup_options(options)
|
|
49
|
+
output << @erb.result(binding)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# :enddoc:
|
|
53
|
+
def setup_options(options)
|
|
54
|
+
super(options)
|
|
55
|
+
@erb = ERB.new(self.template)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def print_stack(output, visited, call_tree, parent_time)
|
|
59
|
+
total_time = call_tree.total_time
|
|
60
|
+
percent_parent = (total_time/parent_time)*100
|
|
61
|
+
percent_total = (total_time/@overall_time)*100
|
|
62
|
+
return unless percent_total > min_percent
|
|
63
|
+
color = self.color(percent_total)
|
|
64
|
+
visible = percent_total >= threshold
|
|
65
|
+
expanded = percent_total >= expansion
|
|
66
|
+
display = visible ? "block" : "none"
|
|
67
|
+
|
|
68
|
+
output << "<li class=\"color#{color}\" style=\"display:#{display}\">" << "\n"
|
|
69
|
+
|
|
70
|
+
if visited.include?(call_tree)
|
|
71
|
+
output << "<a href=\"#\" class=\"toggle empty\" ></a>" << "\n"
|
|
72
|
+
output << "<span>%s %s</span>" % [link(call_tree.target, true), graph_link(call_tree)] << "\n"
|
|
73
|
+
else
|
|
74
|
+
visited << call_tree
|
|
75
|
+
|
|
76
|
+
if call_tree.children.empty?
|
|
77
|
+
output << "<a href=\"#\" class=\"toggle empty\" ></a>" << "\n"
|
|
78
|
+
else
|
|
79
|
+
visible_children = call_tree.children.any?{|ci| (ci.total_time/@overall_time)*100 >= threshold}
|
|
80
|
+
image = visible_children ? (expanded ? "minus" : "plus") : "empty"
|
|
81
|
+
output << "<a href=\"#\" class=\"toggle #{image}\" ></a>" << "\n"
|
|
82
|
+
end
|
|
83
|
+
output << "<span>%4.2f%% (%4.2f%%) %s %s</span>" % [percent_total, percent_parent,
|
|
84
|
+
link(call_tree.target, false), graph_link(call_tree)] << "\n"
|
|
85
|
+
|
|
86
|
+
unless call_tree.children.empty?
|
|
87
|
+
output << (expanded ? '<ul>' : '<ul style="display:none">') << "\n"
|
|
88
|
+
call_tree.children.sort_by{|c| -c.total_time}.each do |child_call_tree|
|
|
89
|
+
print_stack(output, visited, child_call_tree, total_time)
|
|
90
|
+
end
|
|
91
|
+
output << '</ul>' << "\n"
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
visited.delete(call_tree)
|
|
95
|
+
end
|
|
96
|
+
output << '</li>' << "\n"
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def name(call_tree)
|
|
100
|
+
method = call_tree.target
|
|
101
|
+
method.full_name
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def link(method, recursive)
|
|
105
|
+
method_name = "#{recursive ? '*' : ''}#{method.full_name}"
|
|
106
|
+
if method.source_file.nil?
|
|
107
|
+
h method_name
|
|
108
|
+
else
|
|
109
|
+
file = File.expand_path(method.source_file)
|
|
110
|
+
"<a href=\"file://#{file}##{method.line}\">#{h method_name}</a>"
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def graph_link(call_tree)
|
|
115
|
+
total_calls = call_tree.target.called
|
|
116
|
+
totals = total_calls.to_s
|
|
117
|
+
"[#{call_tree.called} calls, #{totals} total]"
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def method_href(method)
|
|
121
|
+
h(method.full_name.gsub(/[><#\.\?=:]/,"_"))
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def total_time(call_trees)
|
|
125
|
+
sum(call_trees.map{|ci| ci.total_time})
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def sum(a)
|
|
129
|
+
a.inject(0.0){|s,t| s+=t}
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def dump(ci)
|
|
133
|
+
$stderr.printf "%s/%d t:%f s:%f w:%f \n", ci, ci.object_id, ci.total_time, ci.self_time, ci.wait_time
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def color(p)
|
|
137
|
+
case i = p.to_i
|
|
138
|
+
when 0..5
|
|
139
|
+
"01"
|
|
140
|
+
when 5..10
|
|
141
|
+
"05"
|
|
142
|
+
when 100
|
|
143
|
+
"9"
|
|
144
|
+
else
|
|
145
|
+
"#{i/10}"
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def application
|
|
150
|
+
@options[:application] || $PROGRAM_NAME
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def arguments
|
|
154
|
+
ARGV.join(' ')
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def title
|
|
158
|
+
@title ||= @options.delete(:title) || "ruby-prof call tree"
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def threshold
|
|
162
|
+
@options[:threshold] || 1.0
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def expansion
|
|
166
|
+
@options[:expansion] || 10.0
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def base64_image
|
|
170
|
+
@data ||= begin
|
|
171
|
+
file = open_asset('call_stack_printer.png')
|
|
172
|
+
Base64.encode64(file).gsub(/\n/, '')
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def template
|
|
177
|
+
open_asset('call_stack_printer.html.erb')
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|