ruby-prof 0.16.2 → 1.1.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.
Files changed (203) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES +532 -467
  3. data/LICENSE +24 -24
  4. data/README.rdoc +5 -454
  5. data/Rakefile +110 -113
  6. data/bin/ruby-prof +380 -340
  7. data/bin/ruby-prof-check-trace +45 -45
  8. data/ext/ruby_prof/extconf.rb +36 -64
  9. data/ext/ruby_prof/rp_allocation.c +279 -0
  10. data/ext/ruby_prof/rp_allocation.h +31 -0
  11. data/ext/ruby_prof/rp_call_info.c +271 -407
  12. data/ext/ruby_prof/rp_call_info.h +35 -48
  13. data/ext/ruby_prof/rp_measure_allocations.c +52 -76
  14. data/ext/ruby_prof/rp_measure_memory.c +42 -77
  15. data/ext/ruby_prof/rp_measure_process_time.c +67 -71
  16. data/ext/ruby_prof/rp_measure_wall_time.c +62 -45
  17. data/ext/ruby_prof/rp_measurement.c +230 -0
  18. data/ext/ruby_prof/rp_measurement.h +50 -0
  19. data/ext/ruby_prof/rp_method.c +630 -411
  20. data/ext/ruby_prof/rp_method.h +70 -52
  21. data/ext/ruby_prof/rp_profile.c +895 -0
  22. data/ext/ruby_prof/rp_profile.h +37 -0
  23. data/ext/ruby_prof/rp_stack.c +196 -128
  24. data/ext/ruby_prof/rp_stack.h +56 -51
  25. data/ext/ruby_prof/rp_thread.c +337 -273
  26. data/ext/ruby_prof/rp_thread.h +36 -27
  27. data/ext/ruby_prof/ruby_prof.c +48 -671
  28. data/ext/ruby_prof/ruby_prof.h +17 -56
  29. data/ext/ruby_prof/vc/ruby_prof.sln +20 -21
  30. data/ext/ruby_prof/vc/{ruby_prof_20.vcxproj → ruby_prof.vcxproj} +38 -5
  31. data/lib/ruby-prof.rb +52 -58
  32. data/lib/ruby-prof/assets/call_stack_printer.html.erb +713 -0
  33. data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
  34. data/lib/ruby-prof/assets/graph_printer.html.erb +356 -0
  35. data/lib/ruby-prof/call_info.rb +57 -126
  36. data/lib/ruby-prof/call_info_visitor.rb +38 -40
  37. data/lib/ruby-prof/compatibility.rb +109 -178
  38. data/lib/ruby-prof/exclude_common_methods.rb +198 -0
  39. data/lib/ruby-prof/measurement.rb +14 -0
  40. data/lib/ruby-prof/method_info.rb +90 -129
  41. data/lib/ruby-prof/printers/abstract_printer.rb +127 -85
  42. data/lib/ruby-prof/printers/call_info_printer.rb +51 -41
  43. data/lib/ruby-prof/printers/call_stack_printer.rb +182 -260
  44. data/lib/ruby-prof/printers/call_tree_printer.rb +151 -130
  45. data/lib/ruby-prof/printers/dot_printer.rb +132 -132
  46. data/lib/ruby-prof/printers/flat_printer.rb +52 -70
  47. data/lib/ruby-prof/printers/graph_html_printer.rb +63 -244
  48. data/lib/ruby-prof/printers/graph_printer.rb +114 -116
  49. data/lib/ruby-prof/printers/multi_printer.rb +127 -58
  50. data/lib/ruby-prof/profile.rb +33 -55
  51. data/lib/ruby-prof/rack.rb +171 -95
  52. data/lib/ruby-prof/task.rb +147 -147
  53. data/lib/ruby-prof/thread.rb +35 -41
  54. data/lib/ruby-prof/version.rb +3 -3
  55. data/lib/unprof.rb +10 -10
  56. data/ruby-prof.gemspec +58 -57
  57. data/test/abstract_printer_test.rb +26 -0
  58. data/test/alias_test.rb +129 -0
  59. data/test/basic_test.rb +129 -128
  60. data/test/call_info_visitor_test.rb +31 -31
  61. data/test/duplicate_names_test.rb +32 -32
  62. data/test/dynamic_method_test.rb +53 -55
  63. data/test/enumerable_test.rb +21 -21
  64. data/test/exceptions_test.rb +24 -16
  65. data/test/exclude_methods_test.rb +146 -0
  66. data/test/exclude_threads_test.rb +53 -53
  67. data/test/fiber_test.rb +73 -79
  68. data/test/gc_test.rb +96 -0
  69. data/test/line_number_test.rb +161 -71
  70. data/test/marshal_test.rb +119 -0
  71. data/test/measure_allocations.rb +30 -0
  72. data/test/measure_allocations_test.rb +385 -26
  73. data/test/measure_allocations_trace_test.rb +385 -0
  74. data/test/measure_memory_trace_test.rb +756 -0
  75. data/test/measure_process_time_test.rb +849 -63
  76. data/test/measure_times.rb +54 -0
  77. data/test/measure_wall_time_test.rb +459 -255
  78. data/test/multi_printer_test.rb +71 -83
  79. data/test/no_method_class_test.rb +15 -15
  80. data/test/parser_timings.rb +24 -0
  81. data/test/pause_resume_test.rb +166 -166
  82. data/test/prime.rb +56 -54
  83. data/test/printer_call_stack_test.rb +28 -0
  84. data/test/printer_call_tree_test.rb +31 -0
  85. data/test/printer_flat_test.rb +68 -0
  86. data/test/printer_graph_html_test.rb +60 -0
  87. data/test/printer_graph_test.rb +41 -0
  88. data/test/printers_test.rb +141 -255
  89. data/test/printing_recursive_graph_test.rb +81 -127
  90. data/test/rack_test.rb +157 -93
  91. data/test/recursive_test.rb +210 -215
  92. data/test/singleton_test.rb +38 -38
  93. data/test/stack_printer_test.rb +64 -78
  94. data/test/start_stop_test.rb +109 -112
  95. data/test/test_helper.rb +24 -264
  96. data/test/thread_test.rb +144 -187
  97. data/test/unique_call_path_test.rb +190 -202
  98. data/test/yarv_test.rb +56 -55
  99. metadata +34 -114
  100. data/doc/LICENSE.html +0 -114
  101. data/doc/README_rdoc.html +0 -603
  102. data/doc/Rack.html +0 -95
  103. data/doc/Rack/RubyProf.html +0 -226
  104. data/doc/RubyProf.html +0 -962
  105. data/doc/RubyProf/AbstractPrinter.html +0 -546
  106. data/doc/RubyProf/AggregateCallInfo.html +0 -551
  107. data/doc/RubyProf/CallInfo.html +0 -639
  108. data/doc/RubyProf/CallInfoPrinter.html +0 -120
  109. data/doc/RubyProf/CallInfoVisitor.html +0 -198
  110. data/doc/RubyProf/CallStackPrinter.html +0 -1121
  111. data/doc/RubyProf/CallTreePrinter.html +0 -641
  112. data/doc/RubyProf/Cmd.html +0 -631
  113. data/doc/RubyProf/DotPrinter.html +0 -257
  114. data/doc/RubyProf/FlatPrinter.html +0 -163
  115. data/doc/RubyProf/FlatPrinterWithLineNumbers.html +0 -208
  116. data/doc/RubyProf/GraphHtmlPrinter.html +0 -552
  117. data/doc/RubyProf/GraphPrinter.html +0 -139
  118. data/doc/RubyProf/MethodInfo.html +0 -745
  119. data/doc/RubyProf/MultiPrinter.html +0 -360
  120. data/doc/RubyProf/Profile.html +0 -763
  121. data/doc/RubyProf/ProfileTask.html +0 -490
  122. data/doc/RubyProf/Thread.html +0 -310
  123. data/doc/created.rid +0 -31
  124. data/doc/css/fonts.css +0 -167
  125. data/doc/css/rdoc.css +0 -590
  126. data/doc/examples/flat_txt.html +0 -138
  127. data/doc/examples/graph_html.html +0 -909
  128. data/doc/examples/graph_txt.html +0 -247
  129. data/doc/fonts/Lato-Light.ttf +0 -0
  130. data/doc/fonts/Lato-LightItalic.ttf +0 -0
  131. data/doc/fonts/Lato-Regular.ttf +0 -0
  132. data/doc/fonts/Lato-RegularItalic.ttf +0 -0
  133. data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
  134. data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
  135. data/doc/images/add.png +0 -0
  136. data/doc/images/arrow_up.png +0 -0
  137. data/doc/images/brick.png +0 -0
  138. data/doc/images/brick_link.png +0 -0
  139. data/doc/images/bug.png +0 -0
  140. data/doc/images/bullet_black.png +0 -0
  141. data/doc/images/bullet_toggle_minus.png +0 -0
  142. data/doc/images/bullet_toggle_plus.png +0 -0
  143. data/doc/images/date.png +0 -0
  144. data/doc/images/delete.png +0 -0
  145. data/doc/images/find.png +0 -0
  146. data/doc/images/loadingAnimation.gif +0 -0
  147. data/doc/images/macFFBgHack.png +0 -0
  148. data/doc/images/package.png +0 -0
  149. data/doc/images/page_green.png +0 -0
  150. data/doc/images/page_white_text.png +0 -0
  151. data/doc/images/page_white_width.png +0 -0
  152. data/doc/images/plugin.png +0 -0
  153. data/doc/images/ruby.png +0 -0
  154. data/doc/images/tag_blue.png +0 -0
  155. data/doc/images/tag_green.png +0 -0
  156. data/doc/images/transparent.png +0 -0
  157. data/doc/images/wrench.png +0 -0
  158. data/doc/images/wrench_orange.png +0 -0
  159. data/doc/images/zoom.png +0 -0
  160. data/doc/index.html +0 -626
  161. data/doc/js/darkfish.js +0 -161
  162. data/doc/js/jquery.js +0 -4
  163. data/doc/js/navigation.js +0 -142
  164. data/doc/js/navigation.js.gz +0 -0
  165. data/doc/js/search.js +0 -109
  166. data/doc/js/search_index.js +0 -1
  167. data/doc/js/search_index.js.gz +0 -0
  168. data/doc/js/searcher.js +0 -228
  169. data/doc/js/searcher.js.gz +0 -0
  170. data/doc/table_of_contents.html +0 -942
  171. data/examples/cachegrind.out.1 +0 -114
  172. data/examples/cachegrind.out.1.32313213 +0 -114
  173. data/examples/flat.txt +0 -50
  174. data/examples/graph.dot +0 -84
  175. data/examples/graph.html +0 -823
  176. data/examples/graph.txt +0 -139
  177. data/examples/multi.flat.txt +0 -23
  178. data/examples/multi.graph.html +0 -760
  179. data/examples/multi.grind.dat +0 -114
  180. data/examples/multi.stack.html +0 -547
  181. data/examples/stack.html +0 -547
  182. data/ext/ruby_prof/rp_measure.c +0 -40
  183. data/ext/ruby_prof/rp_measure.h +0 -45
  184. data/ext/ruby_prof/rp_measure_cpu_time.c +0 -136
  185. data/ext/ruby_prof/rp_measure_gc_runs.c +0 -73
  186. data/ext/ruby_prof/rp_measure_gc_time.c +0 -60
  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/lib/ruby-prof/aggregate_call_info.rb +0 -76
  190. data/lib/ruby-prof/assets/call_stack_printer.css.html +0 -117
  191. data/lib/ruby-prof/assets/call_stack_printer.js.html +0 -385
  192. data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +0 -64
  193. data/test/aggregate_test.rb +0 -136
  194. data/test/block_test.rb +0 -74
  195. data/test/call_info_test.rb +0 -78
  196. data/test/issue137_test.rb +0 -63
  197. data/test/measure_cpu_time_test.rb +0 -213
  198. data/test/measure_gc_runs_test.rb +0 -32
  199. data/test/measure_gc_time_test.rb +0 -36
  200. data/test/measure_memory_test.rb +0 -33
  201. data/test/method_elimination_test.rb +0 -84
  202. data/test/module_test.rb +0 -45
  203. data/test/stack_test.rb +0 -138
@@ -0,0 +1,14 @@
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 CallInfo object directly, they are generated while running a profile.
4
+ class Measurement
5
+ # :nodoc:
6
+ def to_s
7
+ "c: #{called}, tt: #{total_time}, st: #{self_time}"
8
+ end
9
+
10
+ def inspect
11
+ super + "(#{self.to_s})"
12
+ end
13
+ end
14
+ end
@@ -1,129 +1,90 @@
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 detect_recursion
22
- call_infos.each(&:detect_recursion)
23
- end
24
-
25
- def called
26
- @called ||= begin
27
- call_infos.inject(0) do |sum, call_info|
28
- sum + call_info.called
29
- end
30
- end
31
- end
32
-
33
- def total_time
34
- @total_time ||= begin
35
- call_infos.inject(0) do |sum, call_info|
36
- sum += call_info.total_time unless call_info.recursive
37
- sum
38
- end
39
- end
40
- end
41
-
42
- def self_time
43
- @self_time ||= begin
44
- call_infos.inject(0) do |sum, call_info|
45
- sum += call_info.self_time unless call_info.recursive
46
- sum
47
- end
48
- end
49
- end
50
-
51
- def wait_time
52
- @wait_time ||= begin
53
- call_infos.inject(0) do |sum, call_info|
54
- sum += call_info.wait_time unless call_info.recursive
55
- sum
56
- end
57
- end
58
- end
59
-
60
- def children_time
61
- @children_time ||= begin
62
- call_infos.inject(0) do |sum, call_info|
63
- sum += call_info.children_time unless call_info.recursive
64
- sum
65
- end
66
- end
67
- end
68
-
69
- def min_depth
70
- @min_depth ||= call_infos.map(&:depth).min
71
- end
72
-
73
- def root?
74
- @root ||= begin
75
- call_infos.find do |call_info|
76
- not call_info.root?
77
- end.nil?
78
- end
79
- end
80
-
81
- def recursive?
82
- (@recursive ||= call_infos.detect(&:recursive) ? :true : :false) == :true
83
- end
84
-
85
- def children
86
- @children ||= call_infos.map(&:children).flatten
87
- end
88
-
89
- def parents
90
- @parents ||= call_infos.map(&:parent)
91
- end
92
-
93
- def aggregate_parents
94
- # group call infos based on their parents
95
- groups = self.call_infos.each_with_object({}) do |call_info, hash|
96
- key = call_info.parent ? call_info.parent.target : self
97
- (hash[key] ||= []) << call_info
98
- end
99
-
100
- groups.map do |key, value|
101
- AggregateCallInfo.new(value, self)
102
- end
103
- end
104
-
105
- def aggregate_children
106
- # group call infos based on their targets
107
- groups = self.children.each_with_object({}) do |call_info, hash|
108
- key = call_info.target
109
- (hash[key] ||= []) << call_info
110
- end
111
-
112
- groups.map do |key, value|
113
- AggregateCallInfo.new(value, self)
114
- end
115
- end
116
-
117
- def to_s
118
- "#{self.full_name} (c: #{self.called}, tt: #{self.total_time}, st: #{self.self_time}, wt: #{wait_time}, ct: #{self.children_time})"
119
- end
120
-
121
- # remove method from the call graph. should not be called directly.
122
- def eliminate!
123
- # $stderr.puts "eliminating #{self}"
124
- call_infos.each{ |call_info| call_info.eliminate! }
125
- call_infos.clear
126
- end
127
-
128
- end
129
- 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
+ # The min call depth of this method
56
+ def min_depth
57
+ @min_depth ||= callers.map(&:depth).min
58
+ end
59
+
60
+ # :enddoc:
61
+ def <=>(other)
62
+ if other == nil
63
+ -1
64
+ elsif self.full_name == other.full_name
65
+ 0
66
+ elsif self.total_time < other.total_time
67
+ -1
68
+ elsif self.total_time > other.total_time
69
+ 1
70
+ elsif self.min_depth < other.min_depth
71
+ 1
72
+ elsif self.min_depth > other.min_depth
73
+ -1
74
+ else
75
+ self.full_name <=> other.full_name
76
+ end
77
+ end
78
+
79
+ def to_s
80
+ "#{self.full_name} (c: #{self.called}, tt: #{self.total_time}, st: #{self.self_time}, wt: #{wait_time}, ct: #{self.children_time})"
81
+ end
82
+
83
+ # Remove method from the call graph. should not be called directly.
84
+ def eliminate!
85
+ # $stderr.puts "eliminating #{self}"
86
+ callers.each{ |call_info| call_info.eliminate! }
87
+ callers.clear
88
+ end
89
+ end
90
+ end
@@ -1,85 +1,127 @@
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 total 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 time format used to show when a profile was run
26
+ def time_format
27
+ '%A, %B %-d at %l:%M:%S %p (%Z)'
28
+ end
29
+
30
+ # Returns how profile data should be sorted
31
+ def sort_method
32
+ @options[:sort_method]
33
+ end
34
+
35
+ # Prints a report to the provided output.
36
+ #
37
+ # output - Any IO object, including STDOUT or a file.
38
+ # The default value is STDOUT.
39
+ #
40
+ # options - Hash of print options. Note that each printer can
41
+ # define its own set of options.
42
+ #
43
+ # :min_percent - Number 0 to 100 that specifes the minimum
44
+ # %self (the methods self time divided by the
45
+ # overall total time) that a method must take
46
+ # for it to be printed out in the report.
47
+ # Default value is 0.
48
+ #
49
+ # :sort_method - Specifies method used for sorting method infos.
50
+ # Available values are :total_time, :self_time,
51
+ # :wait_time, :children_time
52
+ # Default value is :total_time
53
+ def print(output = STDOUT, options = {})
54
+ @output = output
55
+ setup_options(options)
56
+ print_threads
57
+ end
58
+
59
+ # :nodoc:
60
+ def setup_options(options = {})
61
+ @options = options
62
+ end
63
+
64
+ def method_location(method)
65
+ if method.source_file
66
+ "#{method.source_file}:#{method.line}"
67
+ end
68
+ end
69
+
70
+ def method_href(thread, method)
71
+ h(method.full_name.gsub(/[><#\.\?=:]/,"_") + "_" + thread.fiber_id.to_s)
72
+ end
73
+
74
+ def open_asset(file)
75
+ path = File.join(File.expand_path('../../assets', __FILE__), file)
76
+ File.open(path, 'rb').read
77
+ end
78
+
79
+ def print_threads
80
+ @result.threads.each do |thread|
81
+ print_thread(thread)
82
+ end
83
+ end
84
+
85
+ def print_thread(thread)
86
+ print_header(thread)
87
+ print_methods(thread)
88
+ print_footer(thread)
89
+ end
90
+
91
+ def print_header(thread)
92
+ @output << "Measure Mode: %s\n" % RubyProf.measure_mode_string
93
+ @output << "Thread ID: %d\n" % thread.id
94
+ @output << "Fiber ID: %d\n" % thread.fiber_id unless thread.id == thread.fiber_id
95
+ @output << "Total: %0.6f\n" % thread.total_time
96
+ @output << "Sort by: #{sort_method}\n"
97
+ @output << "\n"
98
+ print_column_headers
99
+ end
100
+
101
+ def print_column_headers
102
+ end
103
+
104
+ def print_footer(thread)
105
+ @output << <<~EOT
106
+
107
+ * recursively called methods
108
+
109
+ Columns are:
110
+
111
+ %self - The percentage of time spent in this method, derived from self_time/total_time.
112
+ total - The time spent in this method and its children.
113
+ self - The time spent in this method.
114
+ wait - The amount of time this method waited for other threads.
115
+ child - The time spent in this method's children.
116
+ calls - The number of times this method was called.
117
+ name - The name of the method.
118
+ location - The location of the method.
119
+
120
+ The interpretation of method names is:
121
+
122
+ * MyObject#test - An instance method "test" of the class "MyObject"
123
+ * <Object:MyObject>#test - The <> characters indicate a method on a singleton class.
124
+ EOT
125
+ end
126
+ end
127
+ end
@@ -1,41 +1,51 @@
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.top_call_infos)
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 CallInfo 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 << "Thread ID: #{thread.id}\n"
23
+ @output << "Fiber ID: #{thread.fiber_id}\n"
24
+ @output << "Total Time: #{thread.total_time}\n"
25
+ @output << "Sort by: #{sort_method}\n"
26
+ @output << "\n"
27
+ end
28
+
29
+ def print_methods(thread)
30
+ visitor = CallInfoVisitor.new(thread.root_methods)
31
+
32
+ visitor.visit do |call_info, event|
33
+ if event == :enter
34
+ @output << " " * call_info.depth
35
+ @output << call_info.target.full_name
36
+ @output << " ("
37
+ @output << "tt:#{sprintf("%#{TIME_WIDTH}.2f", call_info.total_time)}, "
38
+ @output << "st:#{sprintf("%#{TIME_WIDTH}.2f", call_info.self_time)}, "
39
+ @output << "wt:#{sprintf("%#{TIME_WIDTH}.2f", call_info.wait_time)}, "
40
+ @output << "ct:#{sprintf("%#{TIME_WIDTH}.2f", call_info.children_time)}, "
41
+ @output << "call:#{call_info.called}, "
42
+ @output << ")"
43
+ @output << "\n"
44
+ end
45
+ end
46
+ end
47
+
48
+ def print_footer(thread)
49
+ end
50
+ end
51
+ end