ruby-prof 0.18.0 → 1.2.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 (129) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +44 -1
  3. data/LICENSE +2 -2
  4. data/README.rdoc +1 -483
  5. data/Rakefile +3 -6
  6. data/bin/ruby-prof +111 -128
  7. data/ext/ruby_prof/extconf.rb +6 -38
  8. data/ext/ruby_prof/rp_aggregate_call_tree.c +41 -0
  9. data/ext/ruby_prof/rp_aggregate_call_tree.h +13 -0
  10. data/ext/ruby_prof/rp_allocation.c +259 -0
  11. data/ext/ruby_prof/rp_allocation.h +31 -0
  12. data/ext/ruby_prof/rp_call_tree.c +353 -0
  13. data/ext/ruby_prof/rp_call_tree.h +43 -0
  14. data/ext/ruby_prof/rp_call_trees.c +266 -0
  15. data/ext/ruby_prof/rp_call_trees.h +29 -0
  16. data/ext/ruby_prof/rp_measure_allocations.c +25 -51
  17. data/ext/ruby_prof/rp_measure_memory.c +21 -56
  18. data/ext/ruby_prof/rp_measure_process_time.c +37 -43
  19. data/ext/ruby_prof/rp_measure_wall_time.c +40 -21
  20. data/ext/ruby_prof/rp_measurement.c +221 -0
  21. data/ext/ruby_prof/rp_measurement.h +50 -0
  22. data/ext/ruby_prof/rp_method.c +279 -439
  23. data/ext/ruby_prof/rp_method.h +33 -45
  24. data/ext/ruby_prof/rp_profile.c +902 -0
  25. data/ext/ruby_prof/rp_profile.h +36 -0
  26. data/ext/ruby_prof/rp_stack.c +163 -132
  27. data/ext/ruby_prof/rp_stack.h +18 -28
  28. data/ext/ruby_prof/rp_thread.c +192 -124
  29. data/ext/ruby_prof/rp_thread.h +18 -8
  30. data/ext/ruby_prof/ruby_prof.c +36 -778
  31. data/ext/ruby_prof/ruby_prof.h +11 -45
  32. data/ext/ruby_prof/vc/ruby_prof.vcxproj +18 -12
  33. data/lib/ruby-prof.rb +4 -21
  34. data/lib/ruby-prof/assets/call_stack_printer.html.erb +710 -0
  35. data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
  36. data/lib/ruby-prof/assets/graph_printer.html.erb +355 -0
  37. data/lib/ruby-prof/call_tree.rb +57 -0
  38. data/lib/ruby-prof/call_tree_visitor.rb +36 -0
  39. data/lib/ruby-prof/compatibility.rb +37 -107
  40. data/lib/ruby-prof/exclude_common_methods.rb +198 -0
  41. data/lib/ruby-prof/measurement.rb +17 -0
  42. data/lib/ruby-prof/method_info.rb +47 -90
  43. data/lib/ruby-prof/printers/abstract_printer.rb +73 -50
  44. data/lib/ruby-prof/printers/call_info_printer.rb +24 -12
  45. data/lib/ruby-prof/printers/call_stack_printer.rb +66 -152
  46. data/lib/ruby-prof/printers/call_tree_printer.rb +20 -12
  47. data/lib/ruby-prof/printers/dot_printer.rb +5 -5
  48. data/lib/ruby-prof/printers/flat_printer.rb +6 -24
  49. data/lib/ruby-prof/printers/graph_html_printer.rb +6 -192
  50. data/lib/ruby-prof/printers/graph_printer.rb +11 -14
  51. data/lib/ruby-prof/printers/multi_printer.rb +66 -23
  52. data/lib/ruby-prof/profile.rb +10 -3
  53. data/lib/ruby-prof/thread.rb +5 -20
  54. data/lib/ruby-prof/version.rb +1 -1
  55. data/ruby-prof.gemspec +9 -2
  56. data/test/abstract_printer_test.rb +0 -27
  57. data/test/alias_test.rb +126 -0
  58. data/test/basic_test.rb +1 -86
  59. data/test/call_tree_visitor_test.rb +32 -0
  60. data/test/call_trees_test.rb +66 -0
  61. data/test/dynamic_method_test.rb +0 -2
  62. data/test/exclude_methods_test.rb +17 -12
  63. data/test/fiber_test.rb +214 -23
  64. data/test/gc_test.rb +105 -0
  65. data/test/inverse_call_tree_test.rb +175 -0
  66. data/test/line_number_test.rb +118 -40
  67. data/test/marshal_test.rb +115 -0
  68. data/test/measure_allocations.rb +30 -0
  69. data/test/measure_allocations_test.rb +361 -12
  70. data/test/measure_allocations_trace_test.rb +375 -0
  71. data/test/measure_memory_trace_test.rb +1101 -0
  72. data/test/measure_process_time_test.rb +757 -33
  73. data/test/measure_times.rb +56 -0
  74. data/test/measure_wall_time_test.rb +329 -149
  75. data/test/multi_printer_test.rb +1 -34
  76. data/test/pause_resume_test.rb +24 -15
  77. data/test/prime.rb +1 -1
  78. data/test/prime_script.rb +6 -0
  79. data/test/printer_call_stack_test.rb +28 -0
  80. data/test/printer_call_tree_test.rb +31 -0
  81. data/test/printer_flat_test.rb +68 -0
  82. data/test/printer_graph_html_test.rb +60 -0
  83. data/test/printer_graph_test.rb +41 -0
  84. data/test/printers_test.rb +32 -166
  85. data/test/printing_recursive_graph_test.rb +26 -72
  86. data/test/recursive_test.rb +68 -77
  87. data/test/stack_printer_test.rb +2 -15
  88. data/test/start_stop_test.rb +22 -25
  89. data/test/test_helper.rb +6 -261
  90. data/test/thread_test.rb +11 -54
  91. data/test/unique_call_path_test.rb +25 -107
  92. data/test/yarv_test.rb +1 -0
  93. metadata +43 -41
  94. data/examples/flat.txt +0 -50
  95. data/examples/graph.dot +0 -84
  96. data/examples/graph.html +0 -823
  97. data/examples/graph.txt +0 -139
  98. data/examples/multi.flat.txt +0 -23
  99. data/examples/multi.graph.html +0 -760
  100. data/examples/multi.grind.dat +0 -114
  101. data/examples/multi.stack.html +0 -547
  102. data/examples/stack.html +0 -547
  103. data/ext/ruby_prof/rp_call_info.c +0 -425
  104. data/ext/ruby_prof/rp_call_info.h +0 -53
  105. data/ext/ruby_prof/rp_measure.c +0 -40
  106. data/ext/ruby_prof/rp_measure.h +0 -45
  107. data/ext/ruby_prof/rp_measure_cpu_time.c +0 -136
  108. data/ext/ruby_prof/rp_measure_gc_runs.c +0 -73
  109. data/ext/ruby_prof/rp_measure_gc_time.c +0 -60
  110. data/lib/ruby-prof/aggregate_call_info.rb +0 -76
  111. data/lib/ruby-prof/assets/call_stack_printer.css.html +0 -117
  112. data/lib/ruby-prof/assets/call_stack_printer.js.html +0 -385
  113. data/lib/ruby-prof/call_info.rb +0 -115
  114. data/lib/ruby-prof/call_info_visitor.rb +0 -40
  115. data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +0 -83
  116. data/lib/ruby-prof/profile/exclude_common_methods.rb +0 -207
  117. data/lib/ruby-prof/profile/legacy_method_elimination.rb +0 -50
  118. data/test/aggregate_test.rb +0 -136
  119. data/test/block_test.rb +0 -74
  120. data/test/call_info_test.rb +0 -78
  121. data/test/call_info_visitor_test.rb +0 -31
  122. data/test/issue137_test.rb +0 -63
  123. data/test/measure_cpu_time_test.rb +0 -212
  124. data/test/measure_gc_runs_test.rb +0 -32
  125. data/test/measure_gc_time_test.rb +0 -36
  126. data/test/measure_memory_test.rb +0 -33
  127. data/test/method_elimination_test.rb +0 -84
  128. data/test/module_test.rb +0 -45
  129. data/test/stack_test.rb +0 -138
@@ -5,11 +5,17 @@ module RubyProf
5
5
  # one profiling run. Currently prints a flat profile, a callgrind
6
6
  # profile, a call stack profile and a graph profile.
7
7
  class MultiPrinter
8
- def initialize(result, printers = [:stack, :graph, :tree, :flat])
9
- @stack_printer = CallStackPrinter.new(result) if printers.include?(:stack)
10
- @graph_printer = GraphHtmlPrinter.new(result) if printers.include?(:graph)
11
- @tree_printer = CallTreePrinter.new(result) if printers.include?(:tree)
8
+ def initialize(result, printers = [:flat, :graph_html])
12
9
  @flat_printer = FlatPrinter.new(result) if printers.include?(:flat)
10
+
11
+ @graph_printer = GraphPrinter.new(result) if printers.include?(:graph)
12
+ @graph_html_printer = GraphHtmlPrinter.new(result) if printers.include?(:graph_html)
13
+
14
+ @tree_printer = CallTreePrinter.new(result) if printers.include?(:tree)
15
+ @call_info_printer = CallInfoPrinter.new(result) if printers.include?(:call_tree)
16
+
17
+ @stack_printer = CallStackPrinter.new(result) if printers.include?(:stack)
18
+ @dot_printer = DotPrinter.new(result) if printers.include?(:dot)
13
19
  end
14
20
 
15
21
  def self.needs_dir?
@@ -18,48 +24,79 @@ module RubyProf
18
24
 
19
25
  # create profile files under options[:path] or the current
20
26
  # directory. options[:profile] is used as the base name for the
21
- # pofile file, defaults to "profile".
27
+ # profile file, defaults to "profile".
22
28
  def print(options)
23
29
  validate_print_params(options)
24
30
 
25
31
  @profile = options.delete(:profile) || "profile"
26
32
  @directory = options.delete(:path) || File.expand_path(".")
27
33
 
28
- print_to_stack(options) if @stack_printer
34
+ print_to_flat(options) if @flat_printer
35
+
29
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
30
41
  print_to_tree(options) if @tree_printer
31
- print_to_flat(options) if @flat_printer
42
+ print_to_dot(options) if @dot_printer
32
43
  end
33
44
 
34
- # the name of the call stack profile file
35
- def stack_profile
36
- "#{@directory}/#{@profile}.stack.html"
45
+ # the name of the flat profile file
46
+ def flat_report
47
+ "#{@directory}/#{@profile}.flat.txt"
37
48
  end
38
49
 
39
50
  # the name of the graph profile file
40
- def graph_profile
51
+ def graph_report
52
+ "#{@directory}/#{@profile}.graph.txt"
53
+ end
54
+
55
+ def graph_html_report
41
56
  "#{@directory}/#{@profile}.graph.html"
42
57
  end
43
58
 
59
+ # the name of the callinfo profile file
60
+ def call_info_report
61
+ "#{@directory}/#{@profile}.call_tree.txt"
62
+ end
63
+
44
64
  # the name of the callgrind profile file
45
- def tree_profile
65
+ def tree_report
46
66
  "#{@directory}/#{@profile}.callgrind.out.#{$$}"
47
67
  end
48
68
 
49
- # the name of the flat profile file
50
- def flat_profile
51
- "#{@directory}/#{@profile}.flat.txt"
69
+ # the name of the call stack profile file
70
+ def stack_report
71
+ "#{@directory}/#{@profile}.stack.html"
52
72
  end
53
73
 
54
- def print_to_stack(options)
55
- File.open(stack_profile, "w") do |f|
56
- @stack_printer.print(f, options.merge(:graph => "#{@profile}.graph.html"))
74
+ # the name of the call stack profile file
75
+ def dot_report
76
+ "#{@directory}/#{@profile}.dot"
77
+ end
78
+
79
+ def print_to_flat(options)
80
+ File.open(flat_report, "wb") do |file|
81
+ @flat_printer.print(file, options)
57
82
  end
58
83
  end
59
84
 
60
85
  def print_to_graph(options)
61
- File.open(graph_profile, "w") do |f|
62
- @graph_printer.print(f, 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)
63
100
  end
64
101
  end
65
102
 
@@ -67,9 +104,15 @@ module RubyProf
67
104
  @tree_printer.print(options.merge(:path => @directory, :profile => @profile))
68
105
  end
69
106
 
70
- def print_to_flat(options)
71
- File.open(flat_profile, "w") do |f|
72
- @flat_printer.print(f, options)
107
+ def print_to_stack(options)
108
+ File.open(stack_report, "wb") do |file|
109
+ @stack_printer.print(file, options.merge(:graph => "#{@profile}.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)
73
116
  end
74
117
  end
75
118
 
@@ -1,11 +1,18 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'ruby-prof/profile/exclude_common_methods'
4
- require 'ruby-prof/profile/legacy_method_elimination'
3
+ require 'ruby-prof/exclude_common_methods'
5
4
 
6
5
  module RubyProf
7
6
  class Profile
8
- include LegacyMethodElimination
7
+ # :nodoc:
8
+ def measure_mode_string
9
+ case self.measure_mode
10
+ when WALL_TIME then "wall_time"
11
+ when PROCESS_TIME then "process_time"
12
+ when ALLOCATIONS then "allocations"
13
+ when MEMORY then "memory"
14
+ end
15
+ end
9
16
 
10
17
  # Hides methods that, when represented as a call graph, have
11
18
  # extremely large in and out degrees and make navigation impossible.
@@ -1,32 +1,17 @@
1
1
  module RubyProf
2
2
  class Thread
3
- def top_methods
4
- self.methods.select do |method_info|
5
- method_info.call_infos.detect(&:root?)
6
- end
7
- end
8
-
9
- def top_call_infos
10
- top_methods.map(&:call_infos).flatten.select(&:root?)
11
- end
12
-
3
+ # Returns the total time this thread was executed.
13
4
  def total_time
14
- self.top_methods.inject(0) do |sum, method_info|
15
- method_info.call_infos.each do |call_info|
16
- if call_info.parent.nil?
17
- sum += call_info.total_time
18
- end
19
- end
20
- sum
21
- end
5
+ self.call_tree.total_time
22
6
  end
23
7
 
8
+ # Returns the amount of time this thread waited while other thread executed.
24
9
  def wait_time
25
10
  # wait_time, like self:time, is always method local
26
11
  # thus we need to sum over all methods and call infos
27
12
  self.methods.inject(0) do |sum, method_info|
28
- method_info.call_infos.each do |call_info|
29
- sum += call_info.wait_time
13
+ method_info.callers.each do |call_tree|
14
+ sum += call_tree.wait_time
30
15
  end
31
16
  sum
32
17
  end
@@ -1,3 +1,3 @@
1
1
  module RubyProf
2
- VERSION = "0.18.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -19,6 +19,13 @@ EOF
19
19
  spec.license = 'BSD-2-Clause'
20
20
  spec.version = RubyProf::VERSION
21
21
 
22
+ spec.metadata = {
23
+ "bug_tracker_uri" => "https://github.com/ruby-prof/ruby-prof/issues",
24
+ "changelog_uri" => "https://github.com/ruby-prof/ruby-prof/blob/master/CHANGES",
25
+ "documentation_uri" => "https://ruby-prof.github.io/",
26
+ "source_code_uri" => "https://github.com/ruby-prof/ruby-prof/tree/v#{spec.version}",
27
+ }
28
+
22
29
  spec.author = "Shugo Maeda, Charlie Savage, Roger Pack, Stefan Kaes"
23
30
  spec.email = "shugo@ruby-lang.org, cfis@savagexi.com, rogerdpack@gmail.com, skaes@railsexpress.de"
24
31
  spec.platform = Gem::Platform::RUBY
@@ -43,13 +50,13 @@ EOF
43
50
  'lib/ruby-prof.rb',
44
51
  'lib/unprof.rb',
45
52
  'lib/ruby-prof/*.rb',
46
- 'lib/ruby-prof/assets/*.{html,png}',
53
+ 'lib/ruby-prof/assets/*',
47
54
  'lib/ruby-prof/profile/*.rb',
48
55
  'lib/ruby-prof/printers/*.rb',
49
56
  'test/*.rb']
50
57
 
51
58
  spec.test_files = Dir["test/test_*.rb"]
52
- spec.required_ruby_version = '>= 1.9.3'
59
+ spec.required_ruby_version = '>= 2.4.0'
53
60
  spec.date = Time.now.strftime('%Y-%m-%d')
54
61
  spec.homepage = 'https://github.com/ruby-prof/ruby-prof'
55
62
  spec.add_development_dependency('minitest')
@@ -11,33 +11,6 @@ class AbstractPrinterTest < TestCase
11
11
  @printer.setup_options(@options)
12
12
  end
13
13
 
14
- def test_editor_uri
15
- env = {}
16
-
17
- with_const_stubbed('ENV', env) do
18
- @options[:editor_uri] = 'nvim'
19
-
20
- env['RUBY_PROF_EDITOR_URI'] = 'atm'
21
- assert_equal('atm', @printer.editor_uri)
22
-
23
- env['RUBY_PROF_EDITOR_URI'] = nil
24
- assert_equal(false, @printer.editor_uri)
25
-
26
- env.delete('RUBY_PROF_EDITOR_URI')
27
- assert_equal('nvim', @printer.editor_uri)
28
-
29
- with_const_stubbed('RUBY_PLATFORM', 'x86_64-darwin18') do
30
- assert_equal('nvim', @printer.editor_uri)
31
-
32
- @options.delete(:editor_uri)
33
- assert_equal('txmt', @printer.editor_uri)
34
- end
35
- with_const_stubbed('RUBY_PLATFORM', 'windows') do
36
- assert_equal(false, @printer.editor_uri)
37
- end
38
- end
39
- end
40
-
41
14
  private
42
15
 
43
16
  def with_const_stubbed(name, value)
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path("../test_helper", __FILE__)
5
+
6
+ class AliasTest < TestCase
7
+ class TestMe
8
+ def some_method
9
+ sleep(0.1)
10
+ end
11
+
12
+ alias :some_method_original :some_method
13
+ def some_method
14
+ some_method_original
15
+ end
16
+ end
17
+
18
+ def setup
19
+ # Need to use wall time for this test due to the sleep calls
20
+ RubyProf::measure_mode = RubyProf::WALL_TIME
21
+ end
22
+
23
+ # This test only correct works on Ruby 2.5 and higher because - see:
24
+ # https://bugs.ruby-lang.org/issues/12747
25
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.5.0')
26
+ def test_alias
27
+ result = RubyProf.profile do
28
+ TestMe.new.some_method
29
+ end
30
+
31
+ methods = result.threads.first.methods
32
+ assert_equal(6, methods.count)
33
+
34
+ # Method 0
35
+ method = methods[0]
36
+ assert_equal('AliasTest#test_alias', method.full_name)
37
+ assert_equal(28, method.line)
38
+ refute(method.recursive?)
39
+
40
+ assert_equal(0, method.call_trees.callers.count)
41
+
42
+ assert_equal(2, method.call_trees.callees.count)
43
+ call_tree = method.call_trees.callees[0]
44
+ assert_equal('Class#new', call_tree.target.full_name)
45
+ assert_equal(28, call_tree.line)
46
+
47
+ call_tree = method.call_trees.callees[1]
48
+ assert_equal('AliasTest::TestMe#some_method', call_tree.target.full_name)
49
+ assert_equal(28, call_tree.line)
50
+
51
+ # Method 1
52
+ method = methods[1]
53
+ assert_equal('Class#new', method.full_name)
54
+ assert_equal(0, method.line)
55
+ refute(method.recursive?)
56
+
57
+ assert_equal(1, method.call_trees.callers.count)
58
+ call_tree = method.call_trees.callers[0]
59
+ assert_equal('AliasTest#test_alias', call_tree.parent.target.full_name)
60
+ assert_equal(28, call_tree.line)
61
+
62
+ assert_equal(1, method.call_trees.callees.count)
63
+ call_tree = method.call_trees.callees[0]
64
+ assert_equal('BasicObject#initialize', call_tree.target.full_name)
65
+ assert_equal(0, call_tree.line)
66
+
67
+ # Method 2
68
+ method = methods[2]
69
+ assert_equal('BasicObject#initialize', method.full_name)
70
+ assert_equal(0, method.line)
71
+ refute(method.recursive?)
72
+
73
+ assert_equal(1, method.call_trees.callers.count)
74
+ call_tree = method.call_trees.callers[0]
75
+ assert_equal('Class#new', call_tree.parent.target.full_name)
76
+ assert_equal(0, call_tree.line)
77
+
78
+ assert_equal(0, method.call_trees.callees.count)
79
+
80
+ # Method 3
81
+ method = methods[3]
82
+ assert_equal('AliasTest::TestMe#some_method', method.full_name)
83
+ assert_equal(13, method.line)
84
+ refute(method.recursive?)
85
+
86
+ assert_equal(1, method.call_trees.callers.count)
87
+ call_tree = method.call_trees.callers[0]
88
+ assert_equal('AliasTest#test_alias', call_tree.parent.target.full_name)
89
+ assert_equal(28, call_tree.line)
90
+
91
+ assert_equal(1, method.call_trees.callees.count)
92
+ call_tree = method.call_trees.callees[0]
93
+ assert_equal('AliasTest::TestMe#some_method_original', call_tree.target.full_name)
94
+ assert_equal(14, call_tree.line)
95
+
96
+ # Method 4
97
+ method = methods[4]
98
+ assert_equal('AliasTest::TestMe#some_method_original', method.full_name)
99
+ assert_equal(8, method.line)
100
+ refute(method.recursive?)
101
+
102
+ assert_equal(1, method.call_trees.callers.count)
103
+ call_tree = method.call_trees.callers[0]
104
+ assert_equal('AliasTest::TestMe#some_method', call_tree.parent.target.full_name)
105
+ assert_equal(14, call_tree.line)
106
+
107
+ assert_equal(1, method.call_trees.callees.count)
108
+ call_tree = method.call_trees.callees[0]
109
+ assert_equal('Kernel#sleep', call_tree.target.full_name)
110
+ assert_equal(9, call_tree.line)
111
+
112
+ # Method 5
113
+ method = methods[5]
114
+ assert_equal('Kernel#sleep', method.full_name)
115
+ assert_equal(0, method.line)
116
+ refute(method.recursive?)
117
+
118
+ assert_equal(1, method.call_trees.callers.count)
119
+ call_tree = method.call_trees.callers[0]
120
+ assert_equal('AliasTest::TestMe#some_method_original', call_tree.parent.target.full_name)
121
+ assert_equal(9, call_tree.line)
122
+
123
+ assert_equal(0, method.call_trees.callees.count)
124
+ end
125
+ end
126
+ end
@@ -2,6 +2,7 @@
2
2
  # encoding: UTF-8
3
3
 
4
4
  require File.expand_path('../test_helper', __FILE__)
5
+ require_relative './measure_times'
5
6
 
6
7
  class BasicTest < TestCase
7
8
  def setup
@@ -9,11 +10,6 @@ class BasicTest < TestCase
9
10
  RubyProf::measure_mode = RubyProf::WALL_TIME
10
11
  end
11
12
 
12
- def start
13
- RubyProf.start
14
- RubyProf::C1.hello
15
- end
16
-
17
13
  def test_running
18
14
  assert(!RubyProf.running?)
19
15
  RubyProf.start
@@ -44,85 +40,4 @@ class BasicTest < TestCase
44
40
 
45
41
  RubyProf.stop
46
42
  end
47
-
48
- def test_leave_method
49
- start
50
- sleep 0.15
51
- profile = RubyProf.stop
52
-
53
- assert_equal(1, profile.threads.count)
54
-
55
- thread = profile.threads.first
56
- assert_in_delta(0.25, thread.total_time, 0.015)
57
-
58
- top_methods = thread.top_methods.sort
59
- assert_equal(2, top_methods.count)
60
- assert_equal("BasicTest#start", top_methods[0].full_name)
61
- assert_equal("BasicTest#test_leave_method", top_methods[1].full_name)
62
-
63
- assert_equal(4, thread.methods.length)
64
- methods = profile.threads.first.methods.sort
65
-
66
- # Check times
67
- assert_equal("<Class::RubyProf::C1>#hello", methods[0].full_name)
68
- assert_in_delta(0.1, methods[0].total_time, 0.015)
69
- assert_in_delta(0.0, methods[0].wait_time, 0.015)
70
- assert_in_delta(0.0, methods[0].self_time, 0.015)
71
-
72
- assert_equal("BasicTest#start", methods[1].full_name)
73
- assert_in_delta(0.1, methods[1].total_time, 0.015)
74
- assert_in_delta(0.0, methods[1].wait_time, 0.015)
75
- assert_in_delta(0.0, methods[1].self_time, 0.015)
76
-
77
- assert_equal("BasicTest#test_leave_method", methods[2].full_name)
78
- assert_in_delta(0.15, methods[2].total_time, 0.015)
79
- assert_in_delta(0.0, methods[2].wait_time, 0.015)
80
- assert_in_delta(0.0, methods[2].self_time, 0.015)
81
-
82
- assert_equal("Kernel#sleep", methods[3].full_name)
83
- assert_in_delta(0.25, methods[3].total_time, 0.015)
84
- assert_in_delta(0.0, methods[3].wait_time, 0.015)
85
- assert_in_delta(0.25, methods[3].self_time, 0.015)
86
- end
87
-
88
- def test_leave_method_2
89
- start
90
- RubyProf::C1.hello
91
- RubyProf::C1.hello
92
- profile = RubyProf.stop
93
-
94
- assert_equal(1, profile.threads.count)
95
-
96
- thread = profile.threads.first
97
- assert_in_delta(0.3, thread.total_time, 0.015)
98
-
99
- top_methods = thread.top_methods.sort
100
- assert_equal(2, top_methods.count)
101
- assert_equal("BasicTest#start", top_methods[0].full_name)
102
- assert_equal("BasicTest#test_leave_method_2", top_methods[1].full_name)
103
-
104
- assert_equal(4, thread.methods.length)
105
- methods = profile.threads.first.methods.sort
106
-
107
- # Check times
108
- assert_equal("BasicTest#start", methods[0].full_name)
109
- assert_in_delta(0.1, methods[0].total_time, 0.015)
110
- assert_in_delta(0.0, methods[0].wait_time, 0.015)
111
- assert_in_delta(0.0, methods[0].self_time, 0.015)
112
-
113
- assert_equal("BasicTest#test_leave_method_2", methods[1].full_name)
114
- assert_in_delta(0.2, methods[1].total_time, 0.015)
115
- assert_in_delta(0.0, methods[1].wait_time, 0.015)
116
- assert_in_delta(0.0, methods[1].self_time, 0.015)
117
-
118
- assert_equal("Kernel#sleep", methods[2].full_name)
119
- assert_in_delta(0.3, methods[2].total_time, 0.015)
120
- assert_in_delta(0.0, methods[2].wait_time, 0.015)
121
- assert_in_delta(0.3, methods[2].self_time, 0.015)
122
-
123
- assert_equal("<Class::RubyProf::C1>#hello", methods[3].full_name)
124
- assert_in_delta(0.3, methods[3].total_time, 0.015)
125
- assert_in_delta(0.0, methods[3].wait_time, 0.015)
126
- assert_in_delta(0.0, methods[3].self_time, 0.015)
127
- end
128
43
  end