ruby-prof 0.18.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +23 -0
  3. data/LICENSE +2 -2
  4. data/README.rdoc +1 -483
  5. data/Rakefile +3 -6
  6. data/bin/ruby-prof +65 -30
  7. data/ext/ruby_prof/extconf.rb +6 -38
  8. data/ext/ruby_prof/rp_allocation.c +292 -0
  9. data/ext/ruby_prof/rp_allocation.h +31 -0
  10. data/ext/ruby_prof/rp_call_info.c +137 -279
  11. data/ext/ruby_prof/rp_call_info.h +16 -34
  12. data/ext/ruby_prof/rp_measure_allocations.c +25 -49
  13. data/ext/ruby_prof/rp_measure_memory.c +21 -56
  14. data/ext/ruby_prof/rp_measure_process_time.c +28 -36
  15. data/ext/ruby_prof/rp_measure_wall_time.c +36 -19
  16. data/ext/ruby_prof/rp_measurement.c +236 -0
  17. data/ext/ruby_prof/rp_measurement.h +49 -0
  18. data/ext/ruby_prof/rp_method.c +395 -383
  19. data/ext/ruby_prof/rp_method.h +34 -39
  20. data/ext/ruby_prof/rp_profile.c +881 -0
  21. data/ext/ruby_prof/rp_profile.h +36 -0
  22. data/ext/ruby_prof/rp_stack.c +103 -80
  23. data/ext/ruby_prof/rp_stack.h +5 -12
  24. data/ext/ruby_prof/rp_thread.c +149 -88
  25. data/ext/ruby_prof/rp_thread.h +15 -6
  26. data/ext/ruby_prof/ruby_prof.c +11 -757
  27. data/ext/ruby_prof/ruby_prof.h +4 -47
  28. data/ext/ruby_prof/vc/ruby_prof.vcxproj +10 -8
  29. data/lib/ruby-prof.rb +2 -17
  30. data/lib/ruby-prof/assets/graph_printer.html.erb +356 -0
  31. data/lib/ruby-prof/call_info.rb +35 -93
  32. data/lib/ruby-prof/call_info_visitor.rb +19 -21
  33. data/lib/ruby-prof/compatibility.rb +37 -107
  34. data/lib/ruby-prof/exclude_common_methods.rb +198 -0
  35. data/lib/ruby-prof/measurement.rb +14 -0
  36. data/lib/ruby-prof/method_info.rb +52 -83
  37. data/lib/ruby-prof/printers/abstract_printer.rb +66 -52
  38. data/lib/ruby-prof/printers/call_info_printer.rb +13 -3
  39. data/lib/ruby-prof/printers/call_stack_printer.rb +32 -28
  40. data/lib/ruby-prof/printers/call_tree_printer.rb +20 -12
  41. data/lib/ruby-prof/printers/dot_printer.rb +5 -5
  42. data/lib/ruby-prof/printers/flat_printer.rb +6 -24
  43. data/lib/ruby-prof/printers/graph_html_printer.rb +7 -192
  44. data/lib/ruby-prof/printers/graph_printer.rb +13 -15
  45. data/lib/ruby-prof/printers/multi_printer.rb +66 -23
  46. data/lib/ruby-prof/profile.rb +10 -3
  47. data/lib/ruby-prof/rack.rb +0 -3
  48. data/lib/ruby-prof/thread.rb +12 -12
  49. data/lib/ruby-prof/version.rb +1 -1
  50. data/ruby-prof.gemspec +2 -2
  51. data/test/abstract_printer_test.rb +0 -27
  52. data/test/alias_test.rb +129 -0
  53. data/test/basic_test.rb +41 -40
  54. data/test/call_info_visitor_test.rb +3 -3
  55. data/test/dynamic_method_test.rb +0 -2
  56. data/test/line_number_test.rb +120 -39
  57. data/test/marshal_test.rb +119 -0
  58. data/test/measure_allocations.rb +30 -0
  59. data/test/measure_allocations_test.rb +371 -12
  60. data/test/measure_allocations_trace_test.rb +385 -0
  61. data/test/measure_memory_trace_test.rb +756 -0
  62. data/test/measure_process_time_test.rb +821 -33
  63. data/test/measure_times.rb +54 -0
  64. data/test/measure_wall_time_test.rb +349 -145
  65. data/test/multi_printer_test.rb +1 -34
  66. data/test/parser_timings.rb +24 -0
  67. data/test/pause_resume_test.rb +5 -5
  68. data/test/prime.rb +2 -0
  69. data/test/printer_call_tree_test.rb +31 -0
  70. data/test/printer_flat_test.rb +68 -0
  71. data/test/printer_graph_html_test.rb +60 -0
  72. data/test/printer_graph_test.rb +41 -0
  73. data/test/printers_test.rb +32 -166
  74. data/test/printing_recursive_graph_test.rb +26 -72
  75. data/test/recursive_test.rb +72 -77
  76. data/test/stack_printer_test.rb +2 -15
  77. data/test/start_stop_test.rb +22 -25
  78. data/test/test_helper.rb +5 -248
  79. data/test/thread_test.rb +11 -54
  80. data/test/unique_call_path_test.rb +16 -28
  81. data/test/yarv_test.rb +1 -0
  82. metadata +24 -34
  83. data/examples/flat.txt +0 -50
  84. data/examples/graph.dot +0 -84
  85. data/examples/graph.html +0 -823
  86. data/examples/graph.txt +0 -139
  87. data/examples/multi.flat.txt +0 -23
  88. data/examples/multi.graph.html +0 -760
  89. data/examples/multi.grind.dat +0 -114
  90. data/examples/multi.stack.html +0 -547
  91. data/examples/stack.html +0 -547
  92. data/ext/ruby_prof/rp_measure.c +0 -40
  93. data/ext/ruby_prof/rp_measure.h +0 -45
  94. data/ext/ruby_prof/rp_measure_cpu_time.c +0 -136
  95. data/ext/ruby_prof/rp_measure_gc_runs.c +0 -73
  96. data/ext/ruby_prof/rp_measure_gc_time.c +0 -60
  97. data/lib/ruby-prof/aggregate_call_info.rb +0 -76
  98. data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +0 -83
  99. data/lib/ruby-prof/profile/exclude_common_methods.rb +0 -207
  100. data/lib/ruby-prof/profile/legacy_method_elimination.rb +0 -50
  101. data/test/aggregate_test.rb +0 -136
  102. data/test/block_test.rb +0 -74
  103. data/test/call_info_test.rb +0 -78
  104. data/test/fiber_test.rb +0 -79
  105. data/test/issue137_test.rb +0 -63
  106. data/test/measure_cpu_time_test.rb +0 -212
  107. data/test/measure_gc_runs_test.rb +0 -32
  108. data/test/measure_gc_time_test.rb +0 -36
  109. data/test/measure_memory_test.rb +0 -33
  110. data/test/method_elimination_test.rb +0 -84
  111. data/test/module_test.rb +0 -45
  112. 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_info)
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_info.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.
@@ -126,9 +126,6 @@ module Rack
126
126
  if @options[:request_thread_only]
127
127
  options[:include_threads] = [Thread.current]
128
128
  end
129
- if @options[:merge_fibers]
130
- options[:merge_fibers] = true
131
- end
132
129
  options
133
130
  end
134
131
 
@@ -1,31 +1,31 @@
1
1
  module RubyProf
2
2
  class Thread
3
- def top_methods
3
+ # Returns the root methods (ie, methods that were not called by other methods) that were profiled while
4
+ # this thread was executing. Generally there is only one root method (multiple root methods can occur
5
+ # when Profile#pause is used). By starting with the root methods, you can descend down the profile
6
+ # call tree.
7
+ def root_methods
4
8
  self.methods.select do |method_info|
5
- method_info.call_infos.detect(&:root?)
9
+ method_info.root?
6
10
  end
7
11
  end
8
12
 
9
- def top_call_infos
10
- top_methods.map(&:call_infos).flatten.select(&:root?)
11
- end
12
-
13
+ # Returns the total time this thread was executed.
13
14
  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
15
+ self.root_methods.inject(0) do |sum, method_info|
16
+ method_info.callers.each do |call_info|
17
+ sum += call_info.total_time
19
18
  end
20
19
  sum
21
20
  end
22
21
  end
23
22
 
23
+ # Returns the amount of time this thread waited while other thread executed.
24
24
  def wait_time
25
25
  # wait_time, like self:time, is always method local
26
26
  # thus we need to sum over all methods and call infos
27
27
  self.methods.inject(0) do |sum, method_info|
28
- method_info.call_infos.each do |call_info|
28
+ method_info.callers.each do |call_info|
29
29
  sum += call_info.wait_time
30
30
  end
31
31
  sum
@@ -1,3 +1,3 @@
1
1
  module RubyProf
2
- VERSION = "0.18.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -43,13 +43,13 @@ EOF
43
43
  'lib/ruby-prof.rb',
44
44
  'lib/unprof.rb',
45
45
  'lib/ruby-prof/*.rb',
46
- 'lib/ruby-prof/assets/*.{html,png}',
46
+ 'lib/ruby-prof/assets/*',
47
47
  'lib/ruby-prof/profile/*.rb',
48
48
  'lib/ruby-prof/printers/*.rb',
49
49
  'test/*.rb']
50
50
 
51
51
  spec.test_files = Dir["test/test_*.rb"]
52
- spec.required_ruby_version = '>= 1.9.3'
52
+ spec.required_ruby_version = '>= 2.4.0'
53
53
  spec.date = Time.now.strftime('%Y-%m-%d')
54
54
  spec.homepage = 'https://github.com/ruby-prof/ruby-prof'
55
55
  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,129 @@
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(1, method.callers.count)
41
+ call_info = method.callers[0]
42
+ assert_nil(call_info.parent)
43
+ assert_equal(28, call_info.line)
44
+
45
+ assert_equal(2, method.callees.count)
46
+ call_info = method.callees[0]
47
+ assert_equal('Class#new', call_info.target.full_name)
48
+ assert_equal(28, call_info.line)
49
+
50
+ call_info = method.callees[1]
51
+ assert_equal('AliasTest::TestMe#some_method', call_info.target.full_name)
52
+ assert_equal(28, call_info.line)
53
+
54
+ # Method 1
55
+ method = methods[1]
56
+ assert_equal('Class#new', method.full_name)
57
+ assert_equal(0, method.line)
58
+ refute(method.recursive?)
59
+
60
+ assert_equal(1, method.callers.count)
61
+ call_info = method.callers[0]
62
+ assert_equal('AliasTest#test_alias', call_info.parent.full_name)
63
+ assert_equal(28, call_info.line)
64
+
65
+ assert_equal(1, method.callees.count)
66
+ call_info = method.callees[0]
67
+ assert_equal('BasicObject#initialize', call_info.target.full_name)
68
+ assert_equal(0, call_info.line)
69
+
70
+ # Method 2
71
+ method = methods[2]
72
+ assert_equal('BasicObject#initialize', method.full_name)
73
+ assert_equal(0, method.line)
74
+ refute(method.recursive?)
75
+
76
+ assert_equal(1, method.callers.count)
77
+ call_info = method.callers[0]
78
+ assert_equal('Class#new', call_info.parent.full_name)
79
+ assert_equal(0, call_info.line)
80
+
81
+ assert_equal(0, method.callees.count)
82
+
83
+ # Method 3
84
+ method = methods[3]
85
+ assert_equal('AliasTest::TestMe#some_method', method.full_name)
86
+ assert_equal(13, method.line)
87
+ refute(method.recursive?)
88
+
89
+ assert_equal(1, method.callers.count)
90
+ call_info = method.callers[0]
91
+ assert_equal('AliasTest#test_alias', call_info.parent.full_name)
92
+ assert_equal(28, call_info.line)
93
+
94
+ assert_equal(1, method.callees.count)
95
+ call_info = method.callees[0]
96
+ assert_equal('AliasTest::TestMe#some_method_original', call_info.target.full_name)
97
+ assert_equal(14, call_info.line)
98
+
99
+ # Method 4
100
+ method = methods[4]
101
+ assert_equal('AliasTest::TestMe#some_method_original', method.full_name)
102
+ assert_equal(8, method.line)
103
+ refute(method.recursive?)
104
+
105
+ assert_equal(1, method.callers.count)
106
+ call_info = method.callers[0]
107
+ assert_equal('AliasTest::TestMe#some_method', call_info.parent.full_name)
108
+ assert_equal(14, call_info.line)
109
+
110
+ assert_equal(1, method.callees.count)
111
+ call_info = method.callees[0]
112
+ assert_equal('Kernel#sleep', call_info.target.full_name)
113
+ assert_equal(9, call_info.line)
114
+
115
+ # Method 5
116
+ method = methods[5]
117
+ assert_equal('Kernel#sleep', method.full_name)
118
+ assert_equal(0, method.line)
119
+ refute(method.recursive?)
120
+
121
+ assert_equal(1, method.callers.count)
122
+ call_info = method.callers[0]
123
+ assert_equal('AliasTest::TestMe#some_method_original', call_info.parent.full_name)
124
+ assert_equal(9, call_info.line)
125
+
126
+ assert_equal(0, method.callees.count)
127
+ end
128
+ end
129
+ 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
@@ -11,7 +12,7 @@ class BasicTest < TestCase
11
12
 
12
13
  def start
13
14
  RubyProf.start
14
- RubyProf::C1.hello
15
+ RubyProf::C1.sleep_wait
15
16
  end
16
17
 
17
18
  def test_running
@@ -53,76 +54,76 @@ class BasicTest < TestCase
53
54
  assert_equal(1, profile.threads.count)
54
55
 
55
56
  thread = profile.threads.first
56
- assert_in_delta(0.25, thread.total_time, 0.015)
57
+ assert_in_delta(0.25, thread.total_time, 0.05)
57
58
 
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)
59
+ root_methods = thread.root_methods.sort
60
+ assert_equal(2, root_methods.count)
61
+ assert_equal("BasicTest#start", root_methods[0].full_name)
62
+ assert_equal("BasicTest#test_leave_method", root_methods[1].full_name)
62
63
 
63
64
  assert_equal(4, thread.methods.length)
64
65
  methods = profile.threads.first.methods.sort
65
66
 
66
67
  # 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)
68
+ assert_equal("<Class::RubyProf::C1>#sleep_wait", methods[0].full_name)
69
+ assert_in_delta(0.1, methods[0].total_time, 0.05)
70
+ assert_in_delta(0.0, methods[0].wait_time, 0.05)
71
+ assert_in_delta(0.0, methods[0].self_time, 0.05)
71
72
 
72
73
  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)
74
+ assert_in_delta(0.1, methods[1].total_time, 0.05)
75
+ assert_in_delta(0.0, methods[1].wait_time, 0.05)
76
+ assert_in_delta(0.0, methods[1].self_time, 0.05)
76
77
 
77
78
  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)
79
+ assert_in_delta(0.15, methods[2].total_time, 0.05)
80
+ assert_in_delta(0.0, methods[2].wait_time, 0.05)
81
+ assert_in_delta(0.0, methods[2].self_time, 0.05)
81
82
 
82
83
  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)
84
+ assert_in_delta(0.25, methods[3].total_time, 0.05)
85
+ assert_in_delta(0.0, methods[3].wait_time, 0.05)
86
+ assert_in_delta(0.25, methods[3].self_time, 0.05)
86
87
  end
87
88
 
88
89
  def test_leave_method_2
89
90
  start
90
- RubyProf::C1.hello
91
- RubyProf::C1.hello
91
+ RubyProf::C1.sleep_wait
92
+ RubyProf::C1.sleep_wait
92
93
  profile = RubyProf.stop
93
94
 
94
95
  assert_equal(1, profile.threads.count)
95
96
 
96
97
  thread = profile.threads.first
97
- assert_in_delta(0.3, thread.total_time, 0.015)
98
+ assert_in_delta(0.3, thread.total_time, 0.05)
98
99
 
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)
100
+ root_methods = thread.root_methods.sort
101
+ assert_equal(2, root_methods.count)
102
+ assert_equal("BasicTest#start", root_methods[0].full_name)
103
+ assert_equal("BasicTest#test_leave_method_2", root_methods[1].full_name)
103
104
 
104
105
  assert_equal(4, thread.methods.length)
105
106
  methods = profile.threads.first.methods.sort
106
107
 
107
108
  # Check times
108
109
  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)
110
+ assert_in_delta(0.1, methods[0].total_time, 0.05)
111
+ assert_in_delta(0.0, methods[0].wait_time, 0.05)
112
+ assert_in_delta(0.0, methods[0].self_time, 0.05)
112
113
 
113
114
  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)
115
+ assert_in_delta(0.2, methods[1].total_time, 0.05)
116
+ assert_in_delta(0.0, methods[1].wait_time, 0.05)
117
+ assert_in_delta(0.0, methods[1].self_time, 0.05)
117
118
 
118
119
  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)
120
+ assert_in_delta(0.3, methods[2].total_time, 0.05)
121
+ assert_in_delta(0.0, methods[2].wait_time, 0.05)
122
+ assert_in_delta(0.3, methods[2].self_time, 0.05)
123
+
124
+ assert_equal("<Class::RubyProf::C1>#sleep_wait", methods[3].full_name)
125
+ assert_in_delta(0.3, methods[3].total_time, 0.05)
126
+ assert_in_delta(0.0, methods[3].wait_time, 0.05)
127
+ assert_in_delta(0.0, methods[3].self_time, 0.05)
127
128
  end
128
129
  end