ruby-prof 1.7.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/{CHANGES → CHANGELOG.md} +112 -178
  3. data/README.md +5 -5
  4. data/bin/ruby-prof +1 -4
  5. data/docs/advanced-usage.md +132 -0
  6. data/docs/alternatives.md +98 -0
  7. data/docs/architecture.md +122 -0
  8. data/docs/best-practices.md +27 -0
  9. data/docs/getting-started.md +130 -0
  10. data/docs/history.md +11 -0
  11. data/docs/index.md +45 -0
  12. data/docs/profiling-rails.md +64 -0
  13. data/docs/public/examples/example.rb +33 -0
  14. data/docs/public/examples/generate_reports.rb +92 -0
  15. data/docs/public/examples/reports/call_info.txt +27 -0
  16. data/docs/public/examples/reports/call_stack.html +835 -0
  17. data/docs/public/examples/reports/callgrind.out +150 -0
  18. data/docs/public/examples/reports/flame_graph.html +408 -0
  19. data/docs/public/examples/reports/flat.txt +45 -0
  20. data/docs/public/examples/reports/graph.dot +129 -0
  21. data/docs/public/examples/reports/graph.html +1319 -0
  22. data/docs/public/examples/reports/graph.txt +100 -0
  23. data/docs/public/examples/reports/graphviz_viewer.html +1 -0
  24. data/docs/public/images/call_stack.png +0 -0
  25. data/docs/public/images/class_diagram.png +0 -0
  26. data/docs/public/images/dot_printer.png +0 -0
  27. data/docs/public/images/flame_graph.png +0 -0
  28. data/docs/public/images/flat.png +0 -0
  29. data/docs/public/images/graph.png +0 -0
  30. data/docs/public/images/graph_html.png +0 -0
  31. data/docs/public/images/ruby-prof-logo.svg +1 -0
  32. data/docs/reports.md +150 -0
  33. data/docs/stylesheets/extra.css +80 -0
  34. data/ext/ruby_prof/rp_allocation.c +0 -15
  35. data/ext/ruby_prof/rp_allocation.h +29 -33
  36. data/ext/ruby_prof/rp_call_tree.c +3 -0
  37. data/ext/ruby_prof/rp_call_tree.h +1 -4
  38. data/ext/ruby_prof/rp_call_trees.h +1 -4
  39. data/ext/ruby_prof/rp_measurement.c +0 -5
  40. data/ext/ruby_prof/rp_measurement.h +49 -53
  41. data/ext/ruby_prof/rp_method.c +3 -0
  42. data/ext/ruby_prof/rp_method.h +1 -4
  43. data/ext/ruby_prof/rp_profile.c +1 -1
  44. data/ext/ruby_prof/rp_profile.h +1 -5
  45. data/ext/ruby_prof/rp_stack.h +50 -53
  46. data/ext/ruby_prof/rp_thread.h +1 -4
  47. data/ext/ruby_prof/ruby_prof.h +1 -4
  48. data/ext/ruby_prof/vc/ruby_prof.vcxproj +7 -8
  49. data/lib/ruby-prof/assets/call_stack_printer.html.erb +746 -711
  50. data/lib/ruby-prof/assets/flame_graph_printer.html.erb +412 -0
  51. data/lib/ruby-prof/assets/graph_printer.html.erb +355 -355
  52. data/lib/ruby-prof/call_tree.rb +57 -57
  53. data/lib/ruby-prof/call_tree_visitor.rb +36 -36
  54. data/lib/ruby-prof/measurement.rb +17 -17
  55. data/lib/ruby-prof/printers/abstract_printer.rb +19 -33
  56. data/lib/ruby-prof/printers/call_info_printer.rb +53 -53
  57. data/lib/ruby-prof/printers/call_stack_printer.rb +168 -180
  58. data/lib/ruby-prof/printers/call_tree_printer.rb +132 -145
  59. data/lib/ruby-prof/printers/dot_printer.rb +177 -132
  60. data/lib/ruby-prof/printers/flame_graph_printer.rb +79 -0
  61. data/lib/ruby-prof/printers/flat_printer.rb +52 -52
  62. data/lib/ruby-prof/printers/graph_html_printer.rb +62 -63
  63. data/lib/ruby-prof/printers/graph_printer.rb +112 -113
  64. data/lib/ruby-prof/printers/multi_printer.rb +134 -127
  65. data/lib/ruby-prof/profile.rb +13 -0
  66. data/lib/ruby-prof/rack.rb +114 -105
  67. data/lib/ruby-prof/task.rb +147 -147
  68. data/lib/ruby-prof/thread.rb +20 -20
  69. data/lib/ruby-prof/version.rb +1 -1
  70. data/lib/ruby-prof.rb +50 -52
  71. data/lib/unprof.rb +10 -10
  72. data/ruby-prof.gemspec +5 -5
  73. data/test/abstract_printer_test.rb +25 -27
  74. data/test/alias_test.rb +203 -117
  75. data/test/call_tree_builder.rb +126 -126
  76. data/test/call_tree_visitor_test.rb +27 -27
  77. data/test/call_trees_test.rb +66 -66
  78. data/test/duplicate_names_test.rb +32 -32
  79. data/test/dynamic_method_test.rb +50 -50
  80. data/test/exceptions_test.rb +24 -24
  81. data/test/exclude_threads_test.rb +48 -48
  82. data/test/fiber_test.rb +72 -72
  83. data/test/inverse_call_tree_test.rb +174 -174
  84. data/test/line_number_test.rb +138 -1
  85. data/test/marshal_test.rb +144 -145
  86. data/test/measure_allocations.rb +26 -26
  87. data/test/measure_allocations_test.rb +340 -1
  88. data/test/measure_process_time_test.rb +3098 -3142
  89. data/test/measure_times.rb +56 -56
  90. data/test/measure_wall_time_test.rb +511 -372
  91. data/test/measurement_test.rb +82 -82
  92. data/test/merge_test.rb +48 -48
  93. data/test/multi_printer_test.rb +52 -66
  94. data/test/no_method_class_test.rb +15 -15
  95. data/test/pause_resume_test.rb +171 -171
  96. data/test/prime.rb +54 -54
  97. data/test/prime_script.rb +5 -5
  98. data/test/printer_call_stack_test.rb +28 -27
  99. data/test/printer_call_tree_test.rb +30 -30
  100. data/test/printer_flame_graph_test.rb +82 -0
  101. data/test/printer_flat_test.rb +99 -99
  102. data/test/printer_graph_html_test.rb +62 -59
  103. data/test/printer_graph_test.rb +42 -40
  104. data/test/printers_test.rb +28 -44
  105. data/test/printing_recursive_graph_test.rb +81 -81
  106. data/test/profile_test.rb +101 -101
  107. data/test/rack_test.rb +103 -93
  108. data/test/recursive_test.rb +139 -139
  109. data/test/scheduler.rb +4 -0
  110. data/test/singleton_test.rb +39 -38
  111. data/test/stack_printer_test.rb +61 -61
  112. data/test/start_stop_test.rb +106 -106
  113. data/test/test_helper.rb +4 -0
  114. data/test/thread_test.rb +29 -29
  115. data/test/unique_call_path_test.rb +123 -123
  116. data/test/yarv_test.rb +56 -56
  117. metadata +53 -11
  118. data/ext/ruby_prof/rp_measure_memory.c +0 -46
  119. data/lib/ruby-prof/compatibility.rb +0 -113
  120. data/test/compatibility_test.rb +0 -49
  121. data/test/measure_memory_test.rb +0 -1193
@@ -1,113 +1,112 @@
1
- # encoding: utf-8
2
-
3
- module RubyProf
4
- # Generates graph[link:files/examples/graph_txt.html] profile reports as text.
5
- # To use the graph printer:
6
- #
7
- # result = RubyProf.profile do
8
- # [code to profile]
9
- # end
10
- #
11
- # printer = RubyProf::GraphPrinter.new(result)
12
- # printer.print(STDOUT, {})
13
- #
14
- # The constructor takes two arguments. See the README
15
-
16
- class GraphPrinter < AbstractPrinter
17
- PERCENTAGE_WIDTH = 8
18
- TIME_WIDTH = 11
19
- CALL_WIDTH = 17
20
-
21
- private
22
-
23
- def sort_method
24
- @options[:sort_method] || :total_time
25
- end
26
-
27
- def print_header(thread)
28
- @output << "Measure Mode: %s\n" % @result.measure_mode_string
29
- @output << "Thread ID: #{thread.id}\n"
30
- @output << "Fiber ID: #{thread.fiber_id}\n"
31
- @output << "Total Time: #{thread.total_time}\n"
32
- @output << "Sort by: #{sort_method}\n"
33
- @output << "\n"
34
-
35
- # 1 is for % sign
36
- @output << sprintf("%#{PERCENTAGE_WIDTH}s", "%total")
37
- @output << sprintf("%#{PERCENTAGE_WIDTH}s", "%self")
38
- @output << sprintf("%#{TIME_WIDTH}s", "total")
39
- @output << sprintf("%#{TIME_WIDTH}s", "self")
40
- @output << sprintf("%#{TIME_WIDTH}s", "wait")
41
- @output << sprintf("%#{TIME_WIDTH}s", "child")
42
- @output << sprintf("%#{CALL_WIDTH}s", "calls")
43
- @output << " name"
44
- @output << " location"
45
- @output << "\n"
46
- end
47
-
48
- def print_methods(thread)
49
- total_time = thread.total_time
50
- # Sort methods from longest to shortest total time
51
- methods = thread.methods.sort_by(&sort_method)
52
-
53
- # Print each method in total time order
54
- methods.reverse_each do |method|
55
- total_percentage = (method.total_time/total_time) * 100
56
- next if total_percentage < min_percent
57
-
58
- self_percentage = (method.self_time/total_time) * 100
59
-
60
- @output << "-" * 150 << "\n"
61
- print_parents(thread, method)
62
-
63
- # 1 is for % sign
64
- @output << sprintf("%#{PERCENTAGE_WIDTH-1}.2f%%", total_percentage)
65
- @output << sprintf("%#{PERCENTAGE_WIDTH-1}.2f%%", self_percentage)
66
- @output << sprintf("%#{TIME_WIDTH}.3f", method.total_time)
67
- @output << sprintf("%#{TIME_WIDTH}.3f", method.self_time)
68
- @output << sprintf("%#{TIME_WIDTH}.3f", method.wait_time)
69
- @output << sprintf("%#{TIME_WIDTH}.3f", method.children_time)
70
- @output << sprintf("%#{CALL_WIDTH}i", method.called)
71
- @output << sprintf(" %s", method.recursive? ? "*" : " ")
72
- @output << sprintf("%-30s", method.full_name)
73
- @output << sprintf(" %s", method_location(method))
74
- @output << "\n"
75
-
76
- print_children(method)
77
- end
78
- end
79
-
80
- def print_parents(thread, method)
81
- method.call_trees.callers.sort_by(&:total_time).each do |caller|
82
- @output << " " * 2 * PERCENTAGE_WIDTH
83
- @output << sprintf("%#{TIME_WIDTH}.3f", caller.total_time)
84
- @output << sprintf("%#{TIME_WIDTH}.3f", caller.self_time)
85
- @output << sprintf("%#{TIME_WIDTH}.3f", caller.wait_time)
86
- @output << sprintf("%#{TIME_WIDTH}.3f", caller.children_time)
87
-
88
- call_called = "#{caller.called}/#{method.called}"
89
- @output << sprintf("%#{CALL_WIDTH}s", call_called)
90
- @output << sprintf(" %s", caller.parent.target.full_name)
91
- @output << "\n"
92
- end
93
- end
94
-
95
- def print_children(method)
96
- method.call_trees.callees.sort_by(&:total_time).reverse.each do |child|
97
- # Get children method
98
-
99
- @output << " " * 2 * PERCENTAGE_WIDTH
100
-
101
- @output << sprintf("%#{TIME_WIDTH}.3f", child.total_time)
102
- @output << sprintf("%#{TIME_WIDTH}.3f", child.self_time)
103
- @output << sprintf("%#{TIME_WIDTH}.3f", child.wait_time)
104
- @output << sprintf("%#{TIME_WIDTH}.3f", child.children_time)
105
-
106
- call_called = "#{child.called}/#{child.target.called}"
107
- @output << sprintf("%#{CALL_WIDTH}s", call_called)
108
- @output << sprintf(" %s", child.target.full_name)
109
- @output << "\n"
110
- end
111
- end
112
- end
113
- end
1
+ # encoding: utf-8
2
+
3
+ module RubyProf
4
+ # Generates graph[link:files/examples/graph_txt.html] profile reports as text.
5
+ # To use the graph printer:
6
+ #
7
+ # result = RubyProf.profile do
8
+ # [code to profile]
9
+ # end
10
+ #
11
+ # printer = RubyProf::GraphPrinter.new(result)
12
+ # printer.print(STDOUT)
13
+
14
+ class GraphPrinter < AbstractPrinter
15
+ PERCENTAGE_WIDTH = 8
16
+ TIME_WIDTH = 11
17
+ CALL_WIDTH = 17
18
+
19
+ # Override to default sort by total time
20
+ def print(output = STDOUT, sort_method: :total_time, **options)
21
+ super(output, sort_method: sort_method, **options)
22
+ end
23
+
24
+ private
25
+
26
+ def print_header(thread)
27
+ @output << "Measure Mode: %s\n" % @result.measure_mode_string
28
+ @output << "Thread ID: #{thread.id}\n"
29
+ @output << "Fiber ID: #{thread.fiber_id}\n"
30
+ @output << "Total Time: #{thread.total_time}\n"
31
+ @output << "Sort by: #{sort_method}\n"
32
+ @output << "\n"
33
+
34
+ # 1 is for % sign
35
+ @output << sprintf("%#{PERCENTAGE_WIDTH}s", "%total")
36
+ @output << sprintf("%#{PERCENTAGE_WIDTH}s", "%self")
37
+ @output << sprintf("%#{TIME_WIDTH}s", "total")
38
+ @output << sprintf("%#{TIME_WIDTH}s", "self")
39
+ @output << sprintf("%#{TIME_WIDTH}s", "wait")
40
+ @output << sprintf("%#{TIME_WIDTH}s", "child")
41
+ @output << sprintf("%#{CALL_WIDTH}s", "calls")
42
+ @output << " name"
43
+ @output << " location"
44
+ @output << "\n"
45
+ end
46
+
47
+ def print_methods(thread)
48
+ total_time = thread.total_time
49
+ # Sort methods from longest to shortest total time
50
+ methods = thread.methods.sort_by(&sort_method)
51
+
52
+ # Print each method in total time order
53
+ methods.reverse_each do |method|
54
+ total_percentage = (method.total_time/total_time) * 100
55
+ next if total_percentage < min_percent
56
+
57
+ self_percentage = (method.self_time/total_time) * 100
58
+
59
+ @output << "-" * 150 << "\n"
60
+ print_parents(thread, method)
61
+
62
+ # 1 is for % sign
63
+ @output << sprintf("%#{PERCENTAGE_WIDTH-1}.2f%%", total_percentage)
64
+ @output << sprintf("%#{PERCENTAGE_WIDTH-1}.2f%%", self_percentage)
65
+ @output << sprintf("%#{TIME_WIDTH}.3f", method.total_time)
66
+ @output << sprintf("%#{TIME_WIDTH}.3f", method.self_time)
67
+ @output << sprintf("%#{TIME_WIDTH}.3f", method.wait_time)
68
+ @output << sprintf("%#{TIME_WIDTH}.3f", method.children_time)
69
+ @output << sprintf("%#{CALL_WIDTH}i", method.called)
70
+ @output << sprintf(" %s", method.recursive? ? "*" : " ")
71
+ @output << sprintf("%-30s", method.full_name)
72
+ @output << sprintf(" %s", method_location(method))
73
+ @output << "\n"
74
+
75
+ print_children(method)
76
+ end
77
+ end
78
+
79
+ def print_parents(thread, method)
80
+ method.call_trees.callers.sort_by(&:total_time).each do |caller|
81
+ @output << " " * 2 * PERCENTAGE_WIDTH
82
+ @output << sprintf("%#{TIME_WIDTH}.3f", caller.total_time)
83
+ @output << sprintf("%#{TIME_WIDTH}.3f", caller.self_time)
84
+ @output << sprintf("%#{TIME_WIDTH}.3f", caller.wait_time)
85
+ @output << sprintf("%#{TIME_WIDTH}.3f", caller.children_time)
86
+
87
+ call_called = "#{caller.called}/#{method.called}"
88
+ @output << sprintf("%#{CALL_WIDTH}s", call_called)
89
+ @output << sprintf(" %s", caller.parent.target.full_name)
90
+ @output << "\n"
91
+ end
92
+ end
93
+
94
+ def print_children(method)
95
+ method.call_trees.callees.sort_by(&:total_time).reverse.each do |child|
96
+ # Get children method
97
+
98
+ @output << " " * 2 * PERCENTAGE_WIDTH
99
+
100
+ @output << sprintf("%#{TIME_WIDTH}.3f", child.total_time)
101
+ @output << sprintf("%#{TIME_WIDTH}.3f", child.self_time)
102
+ @output << sprintf("%#{TIME_WIDTH}.3f", child.wait_time)
103
+ @output << sprintf("%#{TIME_WIDTH}.3f", child.children_time)
104
+
105
+ call_called = "#{child.called}/#{child.target.called}"
106
+ @output << sprintf("%#{CALL_WIDTH}s", call_called)
107
+ @output << sprintf(" %s", child.target.full_name)
108
+ @output << "\n"
109
+ end
110
+ end
111
+ end
112
+ end
@@ -1,127 +1,134 @@
1
- # encoding: utf-8
2
-
3
- module RubyProf
4
- # Helper class to simplify printing profiles of several types from
5
- # one profiling run. Currently prints a flat profile, a callgrind
6
- # profile, a call stack profile and a graph profile.
7
- class MultiPrinter
8
- def initialize(result, printers = [:flat, :graph_html])
9
- @flat_printer = printers.include?(:flat) ? FlatPrinter.new(result) : nil
10
-
11
- @graph_printer = printers.include?(:graph) ? GraphPrinter.new(result) : nil
12
- @graph_html_printer = printers.include?(:graph_html) ? GraphHtmlPrinter.new(result) : nil
13
-
14
- @tree_printer = printers.include?(:tree) ? CallTreePrinter.new(result) : nil
15
- @call_info_printer = printers.include?(:call_tree) ? CallInfoPrinter.new(result) : nil
16
-
17
- @stack_printer = printers.include?(:stack) ? CallStackPrinter.new(result) : nil
18
- @dot_printer = printers.include?(:dot) ? DotPrinter.new(result) : nil
19
- end
20
-
21
- def self.needs_dir?
22
- true
23
- end
24
-
25
- # create profile files under options[:path] or the current
26
- # directory. options[:profile] is used as the base name for the
27
- # profile file, defaults to "profile".
28
- def print(options)
29
- validate_print_params(options)
30
-
31
- @file_name = options.delete(:profile) || "profile"
32
- @directory = options.delete(:path) || File.expand_path(".")
33
-
34
- print_to_flat(options) if @flat_printer
35
-
36
- print_to_graph(options) if @graph_printer
37
- print_to_graph_html(options) if @graph_html_printer
38
-
39
- print_to_stack(options) if @stack_printer
40
- print_to_call_info(options) if @call_info_printer
41
- print_to_tree(options) if @tree_printer
42
- print_to_dot(options) if @dot_printer
43
- end
44
-
45
- # the name of the flat profile file
46
- def flat_report
47
- "#{@directory}/#{@file_name}.flat.txt"
48
- end
49
-
50
- # the name of the graph profile file
51
- def graph_report
52
- "#{@directory}/#{@file_name}.graph.txt"
53
- end
54
-
55
- def graph_html_report
56
- "#{@directory}/#{@file_name}.graph.html"
57
- end
58
-
59
- # the name of the callinfo profile file
60
- def call_info_report
61
- "#{@directory}/#{@file_name}.call_tree.txt"
62
- end
63
-
64
- # the name of the callgrind profile file
65
- def tree_report
66
- "#{@directory}/#{@file_name}.callgrind.out.#{$$}"
67
- end
68
-
69
- # the name of the call stack profile file
70
- def stack_report
71
- "#{@directory}/#{@file_name}.stack.html"
72
- end
73
-
74
- # the name of the call stack profile file
75
- def dot_report
76
- "#{@directory}/#{@file_name}.dot"
77
- end
78
-
79
- def print_to_flat(options)
80
- File.open(flat_report, "wb") do |file|
81
- @flat_printer.print(file, options)
82
- end
83
- end
84
-
85
- def print_to_graph(options)
86
- File.open(graph_report, "wb") do |file|
87
- @graph_printer.print(file, options)
88
- end
89
- end
90
-
91
- def print_to_graph_html(options)
92
- File.open(graph_html_report, "wb") do |file|
93
- @graph_html_printer.print(file, options)
94
- end
95
- end
96
-
97
- def print_to_call_info(options)
98
- File.open(call_info_report, "wb") do |file|
99
- @call_info_printer.print(file, options)
100
- end
101
- end
102
-
103
- def print_to_tree(options)
104
- @tree_printer.print(options.merge(:path => @directory, :profile => @file_name))
105
- end
106
-
107
- def print_to_stack(options)
108
- File.open(stack_report, "wb") do |file|
109
- @stack_printer.print(file, options.merge(:graph => "#{@file_name}.graph.html"))
110
- end
111
- end
112
-
113
- def print_to_dot(options)
114
- File.open(dot_report, "wb") do |file|
115
- @dot_printer.print(file, options)
116
- end
117
- end
118
-
119
- def validate_print_params(options)
120
- if options.is_a?(IO)
121
- raise ArgumentError, "#{self.class.name}#print cannot print to IO objects"
122
- elsif !options.is_a?(Hash)
123
- raise ArgumentError, "#{self.class.name}#print requires an options hash"
124
- end
125
- end
126
- end
127
- end
1
+ # encoding: utf-8
2
+
3
+ module RubyProf
4
+ # Helper class to simplify printing profiles of several types from
5
+ # one profiling run. Currently prints a flat profile, a callgrind
6
+ # profile, a call stack profile and a graph profile.
7
+ class MultiPrinter
8
+ def initialize(result, printers = [:flat, :graph, :graph_html, :flame_graph, :stack])
9
+ @flat_printer = printers.include?(:flat) ? FlatPrinter.new(result) : nil
10
+
11
+ @graph_printer = printers.include?(:graph) ? GraphPrinter.new(result) : nil
12
+ @graph_html_printer = printers.include?(:graph_html) ? GraphHtmlPrinter.new(result) : nil
13
+
14
+ @tree_printer = printers.include?(:tree) ? CallTreePrinter.new(result) : nil
15
+ @call_info_printer = printers.include?(:call_tree) ? CallInfoPrinter.new(result) : nil
16
+
17
+ @stack_printer = printers.include?(:stack) ? CallStackPrinter.new(result) : nil
18
+ @flame_graph_printer = printers.include?(:flame_graph) ? FlameGraphPrinter.new(result) : nil
19
+ @dot_printer = printers.include?(:dot) ? DotPrinter.new(result) : nil
20
+ end
21
+
22
+ def self.needs_dir?
23
+ true
24
+ end
25
+
26
+ # Create profile files under the specified directory.
27
+ #
28
+ # Keyword arguments:
29
+ # profile: - Base name for profile files. Default is "profile".
30
+ # path: - Directory to write files to. Default is current directory.
31
+ #
32
+ # Also accepts min_percent:, sort_method:, and other printer-specific kwargs.
33
+ def print(profile: "profile", path: File.expand_path("."), **options)
34
+ @file_name = profile
35
+ @directory = path
36
+
37
+ print_to_flat(**options) if @flat_printer
38
+
39
+ print_to_graph(**options) if @graph_printer
40
+ print_to_graph_html(**options) if @graph_html_printer
41
+
42
+ print_to_stack(**options) if @stack_printer
43
+ print_to_flame_graph(**options) if @flame_graph_printer
44
+ print_to_call_info(**options) if @call_info_printer
45
+ print_to_tree(**options) if @tree_printer
46
+ print_to_dot(**options) if @dot_printer
47
+ end
48
+
49
+ # the name of the flat profile file
50
+ def flat_report
51
+ "#{@directory}/#{@file_name}.flat.txt"
52
+ end
53
+
54
+ # the name of the graph profile file
55
+ def graph_report
56
+ "#{@directory}/#{@file_name}.graph.txt"
57
+ end
58
+
59
+ def graph_html_report
60
+ "#{@directory}/#{@file_name}.graph.html"
61
+ end
62
+
63
+ # the name of the callinfo profile file
64
+ def call_info_report
65
+ "#{@directory}/#{@file_name}.call_tree.txt"
66
+ end
67
+
68
+ # the name of the callgrind profile file
69
+ def tree_report
70
+ "#{@directory}/#{@file_name}.callgrind.out.#{$$}"
71
+ end
72
+
73
+ # the name of the call stack profile file
74
+ def stack_report
75
+ "#{@directory}/#{@file_name}.stack.html"
76
+ end
77
+
78
+ # the name of the flame graph profile file
79
+ def flame_graph_report
80
+ "#{@directory}/#{@file_name}.flame_graph.html"
81
+ end
82
+
83
+ # the name of the call stack profile file
84
+ def dot_report
85
+ "#{@directory}/#{@file_name}.dot"
86
+ end
87
+
88
+ def print_to_flat(**options)
89
+ File.open(flat_report, "wb") do |file|
90
+ @flat_printer.print(file, **options)
91
+ end
92
+ end
93
+
94
+ def print_to_graph(**options)
95
+ File.open(graph_report, "wb") do |file|
96
+ @graph_printer.print(file, **options)
97
+ end
98
+ end
99
+
100
+ def print_to_graph_html(**options)
101
+ File.open(graph_html_report, "wb") do |file|
102
+ @graph_html_printer.print(file, **options)
103
+ end
104
+ end
105
+
106
+ def print_to_call_info(**options)
107
+ File.open(call_info_report, "wb") do |file|
108
+ @call_info_printer.print(file, **options)
109
+ end
110
+ end
111
+
112
+ def print_to_tree(**options)
113
+ @tree_printer.print(path: @directory, **options)
114
+ end
115
+
116
+ def print_to_stack(**options)
117
+ File.open(stack_report, "wb") do |file|
118
+ @stack_printer.print(file, **options)
119
+ end
120
+ end
121
+
122
+ def print_to_flame_graph(**options)
123
+ File.open(flame_graph_report, "wb") do |file|
124
+ @flame_graph_printer.print(file, **options)
125
+ end
126
+ end
127
+
128
+ def print_to_dot(**options)
129
+ File.open(dot_report, "wb") do |file|
130
+ @dot_printer.print(file, **options)
131
+ end
132
+ end
133
+ end
134
+ end
@@ -17,6 +17,19 @@ module RubyProf
17
17
  end
18
18
  end
19
19
 
20
+ def measure_mode_name
21
+ case self.measure_mode
22
+ when WALL_TIME
23
+ "Wall Time"
24
+ when PROCESS_TIME
25
+ "Process Time"
26
+ when ALLOCATIONS
27
+ "Allocations"
28
+ when MEMORY
29
+ "Memory"
30
+ end
31
+ end
32
+
20
33
  # Hides methods that, when represented as a call graph, have
21
34
  # extremely large in and out degrees and make navigation impossible.
22
35
  def exclude_common_methods!