ruby-prof 0.13.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES +579 -371
  3. data/LICENSE +24 -23
  4. data/README.rdoc +5 -433
  5. data/Rakefile +98 -110
  6. data/bin/ruby-prof +328 -329
  7. data/bin/ruby-prof-check-trace +45 -0
  8. data/ext/ruby_prof/extconf.rb +16 -59
  9. data/ext/ruby_prof/rp_aggregate_call_tree.c +59 -0
  10. data/ext/ruby_prof/rp_aggregate_call_tree.h +13 -0
  11. data/ext/ruby_prof/rp_allocation.c +287 -0
  12. data/ext/ruby_prof/rp_allocation.h +31 -0
  13. data/ext/ruby_prof/rp_call_tree.c +369 -0
  14. data/ext/ruby_prof/rp_call_tree.h +43 -0
  15. data/ext/ruby_prof/rp_call_trees.c +288 -0
  16. data/ext/ruby_prof/rp_call_trees.h +28 -0
  17. data/ext/ruby_prof/rp_measure_allocations.c +50 -65
  18. data/ext/ruby_prof/rp_measure_memory.c +42 -73
  19. data/ext/ruby_prof/rp_measure_process_time.c +65 -71
  20. data/ext/ruby_prof/rp_measure_wall_time.c +64 -42
  21. data/ext/ruby_prof/rp_measurement.c +237 -0
  22. data/ext/ruby_prof/rp_measurement.h +50 -0
  23. data/ext/ruby_prof/rp_method.c +491 -420
  24. data/ext/ruby_prof/rp_method.h +62 -57
  25. data/ext/ruby_prof/rp_profile.c +908 -0
  26. data/ext/ruby_prof/rp_profile.h +35 -0
  27. data/ext/ruby_prof/rp_stack.c +212 -128
  28. data/ext/ruby_prof/rp_stack.h +53 -51
  29. data/ext/ruby_prof/rp_thread.c +362 -268
  30. data/ext/ruby_prof/rp_thread.h +39 -27
  31. data/ext/ruby_prof/ruby_prof.c +52 -695
  32. data/ext/ruby_prof/ruby_prof.h +26 -55
  33. data/ext/ruby_prof/vc/ruby_prof.sln +28 -21
  34. data/ext/ruby_prof/vc/{ruby_prof_20.vcxproj → ruby_prof.vcxproj} +56 -8
  35. data/lib/ruby-prof.rb +52 -67
  36. data/lib/ruby-prof/assets/call_stack_printer.html.erb +710 -0
  37. data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
  38. data/lib/ruby-prof/assets/graph_printer.html.erb +355 -0
  39. data/lib/ruby-prof/call_tree.rb +57 -0
  40. data/lib/ruby-prof/call_tree_visitor.rb +36 -0
  41. data/lib/ruby-prof/compatibility.rb +99 -169
  42. data/lib/ruby-prof/exclude_common_methods.rb +198 -0
  43. data/lib/ruby-prof/measurement.rb +17 -0
  44. data/lib/ruby-prof/method_info.rb +78 -131
  45. data/lib/ruby-prof/printers/abstract_printer.rb +137 -85
  46. data/lib/ruby-prof/printers/call_info_printer.rb +53 -41
  47. data/lib/ruby-prof/printers/call_stack_printer.rb +180 -773
  48. data/lib/ruby-prof/printers/call_tree_printer.rb +151 -92
  49. data/lib/ruby-prof/printers/dot_printer.rb +132 -132
  50. data/lib/ruby-prof/printers/flat_printer.rb +53 -69
  51. data/lib/ruby-prof/printers/graph_html_printer.rb +63 -255
  52. data/lib/ruby-prof/printers/graph_printer.rb +113 -116
  53. data/lib/ruby-prof/printers/multi_printer.rb +127 -56
  54. data/lib/ruby-prof/profile.rb +37 -77
  55. data/lib/ruby-prof/rack.rb +62 -15
  56. data/lib/ruby-prof/task.rb +147 -147
  57. data/lib/ruby-prof/thread.rb +10 -12
  58. data/lib/ruby-prof/version.rb +3 -0
  59. data/lib/unprof.rb +10 -10
  60. data/ruby-prof.gemspec +65 -61
  61. data/test/abstract_printer_test.rb +26 -0
  62. data/test/alias_test.rb +126 -0
  63. data/test/basic_test.rb +43 -128
  64. data/test/call_tree_visitor_test.rb +32 -0
  65. data/test/call_trees_test.rb +66 -0
  66. data/test/duplicate_names_test.rb +32 -32
  67. data/test/dynamic_method_test.rb +53 -74
  68. data/test/enumerable_test.rb +21 -16
  69. data/test/exceptions_test.rb +24 -16
  70. data/test/exclude_methods_test.rb +151 -0
  71. data/test/exclude_threads_test.rb +53 -54
  72. data/test/fiber_test.rb +129 -65
  73. data/test/gc_test.rb +90 -0
  74. data/test/inverse_call_tree_test.rb +175 -0
  75. data/test/line_number_test.rb +158 -71
  76. data/test/marshal_test.rb +113 -0
  77. data/test/measure_allocations.rb +30 -0
  78. data/test/measure_allocations_test.rb +375 -25
  79. data/test/measure_allocations_trace_test.rb +375 -0
  80. data/test/measure_memory_trace_test.rb +1101 -0
  81. data/test/measure_process_time_test.rb +785 -62
  82. data/test/measure_times.rb +56 -0
  83. data/test/measure_wall_time_test.rb +434 -254
  84. data/test/multi_printer_test.rb +71 -82
  85. data/test/no_method_class_test.rb +15 -15
  86. data/test/pause_resume_test.rb +175 -166
  87. data/test/prime.rb +54 -54
  88. data/test/prime_script.rb +6 -0
  89. data/test/printer_call_stack_test.rb +27 -0
  90. data/test/printer_call_tree_test.rb +30 -0
  91. data/test/printer_flat_test.rb +99 -0
  92. data/test/printer_graph_html_test.rb +59 -0
  93. data/test/printer_graph_test.rb +40 -0
  94. data/test/printers_test.rb +141 -257
  95. data/test/printing_recursive_graph_test.rb +81 -0
  96. data/test/profile_test.rb +16 -0
  97. data/test/rack_test.rb +93 -0
  98. data/test/recursive_test.rb +206 -215
  99. data/test/singleton_test.rb +38 -38
  100. data/test/stack_printer_test.rb +64 -78
  101. data/test/start_stop_test.rb +109 -112
  102. data/test/test_helper.rb +13 -115
  103. data/test/thread_test.rb +144 -178
  104. data/test/unique_call_path_test.rb +120 -224
  105. data/test/yarv_test.rb +56 -0
  106. metadata +77 -133
  107. data/doc/LICENSE.html +0 -155
  108. data/doc/README_rdoc.html +0 -648
  109. data/doc/Rack.html +0 -167
  110. data/doc/Rack/RubyProf.html +0 -319
  111. data/doc/RubyProf.html +0 -1000
  112. data/doc/RubyProf/AbstractPrinter.html +0 -580
  113. data/doc/RubyProf/AggregateCallInfo.html +0 -570
  114. data/doc/RubyProf/CallInfo.html +0 -512
  115. data/doc/RubyProf/CallInfoPrinter.html +0 -190
  116. data/doc/RubyProf/CallInfoVisitor.html +0 -332
  117. data/doc/RubyProf/CallStackPrinter.html +0 -1600
  118. data/doc/RubyProf/CallTreePrinter.html +0 -413
  119. data/doc/RubyProf/Cmd.html +0 -669
  120. data/doc/RubyProf/DotPrinter.html +0 -312
  121. data/doc/RubyProf/FlatPrinter.html +0 -229
  122. data/doc/RubyProf/FlatPrinterWithLineNumbers.html +0 -267
  123. data/doc/RubyProf/GraphHtmlPrinter.html +0 -630
  124. data/doc/RubyProf/GraphPrinter.html +0 -209
  125. data/doc/RubyProf/MethodInfo.html +0 -713
  126. data/doc/RubyProf/MultiPrinter.html +0 -407
  127. data/doc/RubyProf/Profile.html +0 -821
  128. data/doc/RubyProf/ProfileTask.html +0 -532
  129. data/doc/RubyProf/Test.html +0 -578
  130. data/doc/RubyProf/Thread.html +0 -262
  131. data/doc/created.rid +0 -32
  132. data/doc/examples/flat_txt.html +0 -191
  133. data/doc/examples/graph_txt.html +0 -305
  134. data/doc/images/add.png +0 -0
  135. data/doc/images/brick.png +0 -0
  136. data/doc/images/brick_link.png +0 -0
  137. data/doc/images/bug.png +0 -0
  138. data/doc/images/bullet_black.png +0 -0
  139. data/doc/images/bullet_toggle_minus.png +0 -0
  140. data/doc/images/bullet_toggle_plus.png +0 -0
  141. data/doc/images/date.png +0 -0
  142. data/doc/images/delete.png +0 -0
  143. data/doc/images/find.png +0 -0
  144. data/doc/images/loadingAnimation.gif +0 -0
  145. data/doc/images/macFFBgHack.png +0 -0
  146. data/doc/images/package.png +0 -0
  147. data/doc/images/page_green.png +0 -0
  148. data/doc/images/page_white_text.png +0 -0
  149. data/doc/images/page_white_width.png +0 -0
  150. data/doc/images/plugin.png +0 -0
  151. data/doc/images/ruby.png +0 -0
  152. data/doc/images/tag_blue.png +0 -0
  153. data/doc/images/tag_green.png +0 -0
  154. data/doc/images/transparent.png +0 -0
  155. data/doc/images/wrench.png +0 -0
  156. data/doc/images/wrench_orange.png +0 -0
  157. data/doc/images/zoom.png +0 -0
  158. data/doc/index.html +0 -647
  159. data/doc/js/darkfish.js +0 -155
  160. data/doc/js/jquery.js +0 -18
  161. data/doc/js/navigation.js +0 -142
  162. data/doc/js/search.js +0 -94
  163. data/doc/js/search_index.js +0 -1
  164. data/doc/js/searcher.js +0 -228
  165. data/doc/rdoc.css +0 -543
  166. data/doc/table_of_contents.html +0 -462
  167. data/examples/empty.png +0 -0
  168. data/examples/flat.txt +0 -55
  169. data/examples/graph.dot +0 -106
  170. data/examples/graph.html +0 -823
  171. data/examples/graph.png +0 -0
  172. data/examples/graph.txt +0 -170
  173. data/examples/minus.png +0 -0
  174. data/examples/multi.flat.txt +0 -23
  175. data/examples/multi.graph.html +0 -906
  176. data/examples/multi.grind.dat +0 -194
  177. data/examples/multi.stack.html +0 -573
  178. data/examples/plus.png +0 -0
  179. data/examples/stack.html +0 -573
  180. data/ext/ruby_prof/rp_call_info.c +0 -407
  181. data/ext/ruby_prof/rp_call_info.h +0 -48
  182. data/ext/ruby_prof/rp_measure.c +0 -48
  183. data/ext/ruby_prof/rp_measure.h +0 -45
  184. data/ext/ruby_prof/rp_measure_cpu_time.c +0 -112
  185. data/ext/ruby_prof/rp_measure_gc_runs.c +0 -65
  186. data/ext/ruby_prof/rp_measure_gc_time.c +0 -57
  187. data/ext/ruby_prof/vc/ruby_prof_18.vcxproj +0 -108
  188. data/ext/ruby_prof/vc/ruby_prof_19.vcxproj +0 -110
  189. data/ext/ruby_prof/version.h +0 -7
  190. data/lib/ruby-prof/aggregate_call_info.rb +0 -72
  191. data/lib/ruby-prof/call_info.rb +0 -89
  192. data/lib/ruby-prof/call_info_visitor.rb +0 -44
  193. data/lib/ruby-prof/images/empty.png +0 -0
  194. data/lib/ruby-prof/images/minus.png +0 -0
  195. data/lib/ruby-prof/images/plus.png +0 -0
  196. data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +0 -57
  197. data/lib/ruby-prof/test.rb +0 -150
  198. data/test/aggregate_test.rb +0 -136
  199. data/test/call_info_test.rb +0 -78
  200. data/test/call_info_visitor_test.rb +0 -31
  201. data/test/exec_test.rb +0 -14
  202. data/test/measure_cpu_time_test.rb +0 -220
  203. data/test/measure_gc_runs_test.rb +0 -32
  204. data/test/measure_gc_time_test.rb +0 -36
  205. data/test/measure_memory_test.rb +0 -31
  206. data/test/method_elimination_test.rb +0 -84
  207. data/test/module_test.rb +0 -45
  208. data/test/stack_test.rb +0 -138
  209. data/test/test_suite.rb +0 -37
@@ -0,0 +1,17 @@
1
+ module RubyProf
2
+ # The Measurement class is a helper class used by RubyProf::MethodInfo to store information about the method.
3
+ # You cannot create a CallTree object directly, they are generated while running a profile.
4
+ class Measurement
5
+ def children_time
6
+ self.total_time - self.self_time - self.wait_time
7
+ end
8
+
9
+ def to_s
10
+ "c: #{called}, tt: #{total_time}, st: #{self_time}"
11
+ end
12
+
13
+ def inspect
14
+ super + "(#{self.to_s})"
15
+ end
16
+ end
17
+ end
@@ -1,131 +1,78 @@
1
- # encoding: utf-8
2
-
3
- module RubyProf
4
- class MethodInfo
5
- include Comparable
6
-
7
- def <=>(other)
8
- if self.total_time < other.total_time
9
- -1
10
- elsif self.total_time > other.total_time
11
- 1
12
- elsif self.min_depth < other.min_depth
13
- 1
14
- elsif self.min_depth > other.min_depth
15
- -1
16
- else
17
- self.full_name <=> other.full_name
18
- end
19
- end
20
-
21
- def called
22
- @called ||= begin
23
- call_infos.inject(0) do |sum, call_info|
24
- sum += call_info.called
25
- end
26
- end
27
- end
28
-
29
- def total_time
30
- @total_time ||= begin
31
- call_infos.inject(0) do |sum, call_info|
32
- sum += call_info.total_time unless call_info.recursive
33
- sum
34
- end
35
- end
36
- end
37
-
38
- def self_time
39
- @self_time ||= begin
40
- call_infos.inject(0) do |sum, call_info|
41
- sum += call_info.self_time unless call_info.recursive
42
- sum
43
- end
44
- end
45
- end
46
-
47
- def wait_time
48
- @wait_time ||= begin
49
- call_infos.inject(0) do |sum, call_info|
50
- sum += call_info.wait_time unless call_info.recursive
51
- sum
52
- end
53
- end
54
- end
55
-
56
- def children_time
57
- @children_time ||= begin
58
- call_infos.inject(0) do |sum, call_info|
59
- sum += call_info.children_time unless call_info.recursive
60
- sum
61
- end
62
- end
63
- end
64
-
65
- def min_depth
66
- @min_depth ||= call_infos.map do |call_info|
67
- call_info.depth
68
- end.min
69
- end
70
-
71
- def root?
72
- @root ||= begin
73
- call_infos.find do |call_info|
74
- not call_info.root?
75
- end.nil?
76
- end
77
- end
78
-
79
- def recursive?
80
- call_infos.detect do |call_info|
81
- call_info.recursive
82
- end
83
- end
84
-
85
- def children
86
- @children ||= begin
87
- call_infos.map do |call_info|
88
- call_info.children
89
- end.flatten
90
- end
91
- end
92
-
93
- def aggregate_parents
94
- # Group call info's based on their parents
95
- groups = self.call_infos.inject(Hash.new) do |hash, call_info|
96
- key = call_info.parent ? call_info.parent.target : self
97
- (hash[key] ||= []) << call_info
98
- hash
99
- end
100
-
101
- groups.map do |key, value|
102
- AggregateCallInfo.new(value)
103
- end
104
- end
105
-
106
- def aggregate_children
107
- # Group call info's based on their targets
108
- groups = self.children.inject(Hash.new) do |hash, call_info|
109
- key = call_info.target
110
- (hash[key] ||= []) << call_info
111
- hash
112
- end
113
-
114
- groups.map do |key, value|
115
- AggregateCallInfo.new(value)
116
- end
117
- end
118
-
119
- def to_s
120
- "#{self.full_name} (c: #{self.called}, tt: #{self.total_time}, st: #{self.self_time}, ct: #{self.children_time})"
121
- end
122
-
123
- # remove method from the call graph. should not be called directly.
124
- def eliminate!
125
- # $stderr.puts "eliminating #{self}"
126
- call_infos.each{ |call_info| call_info.eliminate! }
127
- call_infos.clear
128
- end
129
-
130
- end
131
- end
1
+ # encoding: utf-8
2
+
3
+ module RubyProf
4
+ # The MethodInfo class is used to track information about each method that is profiled.
5
+ # You cannot create a MethodInfo object directly, they are generated while running a profile.
6
+ class MethodInfo
7
+ include Comparable
8
+
9
+ # Returns the full name of a class. The interpretation of method names is:
10
+ #
11
+ # * MyObject#test - An method defined in a class
12
+ # * <Class:MyObject>#test - A method defined in a singleton class.
13
+ # * <Module:MyObject>#test - A method defined in a singleton module.
14
+ # * <Object:MyObject>#test - A method defined in a singleton object.
15
+ def full_name
16
+ decorated_class_name = case self.klass_flags
17
+ when 0x2
18
+ "<Class::#{klass_name}>"
19
+ when 0x4
20
+ "<Module::#{klass_name}>"
21
+ when 0x8
22
+ "<Object::#{klass_name}>"
23
+ else
24
+ klass_name
25
+ end
26
+
27
+ "#{decorated_class_name}##{method_name}"
28
+ end
29
+
30
+ # The number of times this method was called
31
+ def called
32
+ self.measurement.called
33
+ end
34
+
35
+ # The total time this method took - includes self time + wait time + child time
36
+ def total_time
37
+ self.measurement.total_time
38
+ end
39
+
40
+ # The time this method took to execute
41
+ def self_time
42
+ self.measurement.self_time
43
+ end
44
+
45
+ # The time this method waited for other fibers/threads to execute
46
+ def wait_time
47
+ self.measurement.wait_time
48
+ end
49
+
50
+ # The time this method's children took to execute
51
+ def children_time
52
+ self.total_time - self.self_time - self.wait_time
53
+ end
54
+
55
+ # :enddoc:
56
+ def <=>(other)
57
+ if other.nil?
58
+ -1
59
+ elsif self.full_name == other.full_name
60
+ 0
61
+ elsif self.total_time < other.total_time
62
+ -1
63
+ elsif self.total_time > other.total_time
64
+ 1
65
+ elsif self.call_trees.min_depth < other.call_trees.min_depth
66
+ 1
67
+ elsif self.call_trees.min_depth > other.call_trees.min_depth
68
+ -1
69
+ else
70
+ self.full_name <=> other.full_name
71
+ end
72
+ end
73
+
74
+ def to_s
75
+ "#{self.full_name} (c: #{self.called}, tt: #{self.total_time}, st: #{self.self_time}, wt: #{wait_time}, ct: #{self.children_time})"
76
+ end
77
+ end
78
+ end
@@ -1,85 +1,137 @@
1
- # encoding: utf-8
2
-
3
- module RubyProf
4
- class AbstractPrinter
5
- # Create a new printer.
6
- #
7
- # result should be the output generated from a profiling run
8
- def initialize(result)
9
- @result = result
10
- @output = nil
11
- end
12
-
13
- # Specify print options.
14
- #
15
- # options - Hash table
16
- # :min_percent - Number 0 to 100 that specifes the minimum
17
- # %self (the methods self time divided by the
18
- # overall total time) that a method must take
19
- # for it to be printed out in the report.
20
- # Default value is 0.
21
- #
22
- # :print_file - True or false. Specifies if a method's source
23
- # file should be printed. Default value if false.
24
- #
25
- # :sort_method - Specifies method used for sorting method infos.
26
- # Available values are :total_time, :self_time,
27
- # :wait_time, :children_time
28
- # Default value is :total_time
29
- def setup_options(options = {})
30
- @options = options
31
- end
32
-
33
- def min_percent
34
- @options[:min_percent] || 0
35
- end
36
-
37
- def print_file
38
- @options[:print_file] || false
39
- end
40
-
41
- def sort_method
42
- @options[:sort_method] || :total_time
43
- end
44
-
45
- def method_name(method)
46
- name = method.full_name
47
- if print_file
48
- name += " (#{method.source_file}:#{method.line}}"
49
- end
50
- name
51
- end
52
-
53
- # Print a profiling report to the provided output.
54
- #
55
- # output - Any IO object, including STDOUT or a file.
56
- # The default value is STDOUT.
57
- #
58
- # options - Hash of print options. See #setup_options
59
- # for more information. Note that each printer can
60
- # define its own set of options.
61
- def print(output = STDOUT, options = {})
62
- @output = output
63
- setup_options(options)
64
- print_threads
65
- end
66
-
67
- def print_threads
68
- @result.threads.each do |thread|
69
- print_thread(thread)
70
- end
71
- end
72
-
73
- def print_thread(thread)
74
- print_header(thread)
75
- print_methods(thread)
76
- print_footer(thread)
77
- end
78
-
79
- def print_header(thread)
80
- end
81
-
82
- def print_footer(thread)
83
- end
84
- end
85
- end
1
+ # encoding: utf-8
2
+
3
+ module RubyProf
4
+ # This is the base class for all Printers. It is never used directly.
5
+ class AbstractPrinter
6
+ # :stopdoc:
7
+ def self.needs_dir?
8
+ false
9
+ end
10
+ # :startdoc:
11
+
12
+ # Create a new printer.
13
+ #
14
+ # result should be the output generated from a profiling run
15
+ def initialize(result)
16
+ @result = result
17
+ @output = nil
18
+ end
19
+
20
+ # Returns the min_percent of time a method must take to be included in a profiling report
21
+ def min_percent
22
+ @options[:min_percent] || 0
23
+ end
24
+
25
+ # Returns the max_percent of time a method can take to be included in a profiling report
26
+ def max_percent
27
+ @options[:max_percent] || 100
28
+ end
29
+
30
+ # Returns the method to filter methods by (when using min_percent and max_percent)
31
+ def filter_by
32
+ @options[:filter_by] || :self_time
33
+ end
34
+
35
+ # Returns the time format used to show when a profile was run
36
+ def time_format
37
+ '%A, %B %-d at %l:%M:%S %p (%Z)'
38
+ end
39
+
40
+ # Returns how profile data should be sorted
41
+ def sort_method
42
+ @options[:sort_method]
43
+ end
44
+
45
+ # Prints a report to the provided output.
46
+ #
47
+ # output - Any IO object, including STDOUT or a file.
48
+ # The default value is STDOUT.
49
+ #
50
+ # options - Hash of print options. Note that each printer can
51
+ # define its own set of options.
52
+ #
53
+ # :min_percent - Number 0 to 100 that specifes the minimum
54
+ # %self (the methods self time divided by the
55
+ # overall total time) that a method must take
56
+ # for it to be printed out in the report.
57
+ # Default value is 0.
58
+ #
59
+ # :sort_method - Specifies method used for sorting method infos.
60
+ # Available values are :total_time, :self_time,
61
+ # :wait_time, :children_time
62
+ # Default value is :total_time
63
+ def print(output = STDOUT, options = {})
64
+ @output = output
65
+ setup_options(options)
66
+ print_threads
67
+ end
68
+
69
+ # :nodoc:
70
+ def setup_options(options = {})
71
+ @options = options
72
+ end
73
+
74
+ def method_location(method)
75
+ if method.source_file
76
+ "#{method.source_file}:#{method.line}"
77
+ end
78
+ end
79
+
80
+ def method_href(thread, method)
81
+ h(method.full_name.gsub(/[><#\.\?=:]/,"_") + "_" + thread.fiber_id.to_s)
82
+ end
83
+
84
+ def open_asset(file)
85
+ path = File.join(File.expand_path('../../assets', __FILE__), file)
86
+ File.open(path, 'rb').read
87
+ end
88
+
89
+ def print_threads
90
+ @result.threads.each do |thread|
91
+ print_thread(thread)
92
+ end
93
+ end
94
+
95
+ def print_thread(thread)
96
+ print_header(thread)
97
+ print_methods(thread)
98
+ print_footer(thread)
99
+ end
100
+
101
+ def print_header(thread)
102
+ @output << "Measure Mode: %s\n" % @result.measure_mode_string
103
+ @output << "Thread ID: %d\n" % thread.id
104
+ @output << "Fiber ID: %d\n" % thread.fiber_id unless thread.id == thread.fiber_id
105
+ @output << "Total: %0.6f\n" % thread.total_time
106
+ @output << "Sort by: #{sort_method}\n"
107
+ @output << "\n"
108
+ print_column_headers
109
+ end
110
+
111
+ def print_column_headers
112
+ end
113
+
114
+ def print_footer(thread)
115
+ @output << <<~EOT
116
+
117
+ * recursively called methods
118
+
119
+ Columns are:
120
+
121
+ %self - The percentage of time spent in this method, derived from self_time/total_time.
122
+ total - The time spent in this method and its children.
123
+ self - The time spent in this method.
124
+ wait - The amount of time this method waited for other threads.
125
+ child - The time spent in this method's children.
126
+ calls - The number of times this method was called.
127
+ name - The name of the method.
128
+ location - The location of the method.
129
+
130
+ The interpretation of method names is:
131
+
132
+ * MyObject#test - An instance method "test" of the class "MyObject"
133
+ * <Object:MyObject>#test - The <> characters indicate a method on a singleton class.
134
+ EOT
135
+ end
136
+ end
137
+ end
@@ -1,41 +1,53 @@
1
- # encoding: utf-8
2
-
3
- module RubyProf
4
- # Prints out the call graph based on CallInfo instances. This
5
- # is mainly for debugging purposes as it provides access into
6
- # into RubyProf's internals.
7
-
8
- class CallInfoPrinter < AbstractPrinter
9
- TIME_WIDTH = 0
10
-
11
- private
12
-
13
- def print_header(thread)
14
- @output << "Thread ID: #{thread.id}\n"
15
- @output << "Fiber ID: #{thread.fiber_id}\n"
16
- @output << "Total Time: #{thread.total_time}\n"
17
- @output << "Sort by: #{sort_method}\n"
18
- @output << "\n"
19
- end
20
-
21
- def print_methods(thread)
22
- visitor = CallInfoVisitor.new(thread)
23
-
24
- visitor.visit do |call_info, event|
25
- if event == :enter
26
- @output << " " * call_info.depth
27
- @output << call_info.target.full_name
28
- @output << " ("
29
- @output << "tt:#{sprintf("%#{TIME_WIDTH}.2f", call_info.total_time)}, "
30
- @output << "st:#{sprintf("%#{TIME_WIDTH}.2f", call_info.self_time)}, "
31
- @output << "wt:#{sprintf("%#{TIME_WIDTH}.2f", call_info.wait_time)}, "
32
- @output << "ct:#{sprintf("%#{TIME_WIDTH}.2f", call_info.children_time)}, "
33
- @output << "call:#{call_info.called}, "
34
- @output << "rec:#{call_info.recursive}"
35
- @output << ")"
36
- @output << "\n"
37
- end
38
- end
39
- end
40
- end
41
- end
1
+ # encoding: utf-8
2
+
3
+ module RubyProf
4
+ # Prints out the call graph based on CallTree instances. This
5
+ # is mainly for debugging purposes as it provides access into
6
+ # into RubyProf's internals.
7
+ #
8
+ # To use the printer:
9
+ #
10
+ # result = RubyProf.profile do
11
+ # [code to profile]
12
+ # end
13
+ #
14
+ # printer = RubyProf::CallInfoPrinter.new(result)
15
+ # printer.print(STDOUT)
16
+ class CallInfoPrinter < AbstractPrinter
17
+ TIME_WIDTH = 0
18
+
19
+ private
20
+
21
+ def print_header(thread)
22
+ @output << "----------------------------------------------------\n"
23
+ @output << "Thread ID: #{thread.id}\n"
24
+ @output << "Fiber ID: #{thread.fiber_id}\n"
25
+ @output << "Total Time: #{thread.total_time}\n"
26
+ @output << "Sort by: #{sort_method}\n"
27
+ @output << "\n"
28
+ end
29
+
30
+ def print_methods(thread)
31
+ visitor = CallTreeVisitor.new(thread.call_tree)
32
+
33
+ visitor.visit do |call_tree, event|
34
+ if event == :enter
35
+ @output << " " * call_tree.depth
36
+ @output << call_tree.target.full_name
37
+ @output << " ("
38
+ @output << "tt:#{sprintf("%#{TIME_WIDTH}.2f", call_tree.total_time)}, "
39
+ @output << "st:#{sprintf("%#{TIME_WIDTH}.2f", call_tree.self_time)}, "
40
+ @output << "wt:#{sprintf("%#{TIME_WIDTH}.2f", call_tree.wait_time)}, "
41
+ @output << "ct:#{sprintf("%#{TIME_WIDTH}.2f", call_tree.children_time)}, "
42
+ @output << "call:#{call_tree.called}, "
43
+ @output << ")"
44
+ @output << "\n"
45
+ end
46
+ end
47
+ end
48
+
49
+ def print_footer(thread)
50
+ @output << "\n" << "\n"
51
+ end
52
+ end
53
+ end