ruby-prof 0.11.2-x86-mingw32 → 0.12.1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/CHANGES +27 -0
  2. data/README.rdoc +15 -15
  3. data/Rakefile +5 -0
  4. data/bin/ruby-prof +274 -265
  5. data/ext/ruby_prof/rp_call_info.c +33 -24
  6. data/ext/ruby_prof/rp_call_info.h +2 -1
  7. data/ext/ruby_prof/rp_measure.c +1 -1
  8. data/ext/ruby_prof/rp_measure.h +1 -1
  9. data/ext/ruby_prof/rp_measure_allocations.c +1 -1
  10. data/ext/ruby_prof/rp_measure_cpu_time.c +1 -1
  11. data/ext/ruby_prof/rp_measure_gc_runs.c +1 -1
  12. data/ext/ruby_prof/rp_measure_gc_time.c +1 -1
  13. data/ext/ruby_prof/rp_measure_memory.c +1 -1
  14. data/ext/ruby_prof/rp_measure_process_time.c +2 -2
  15. data/ext/ruby_prof/rp_measure_wall_time.c +2 -2
  16. data/ext/ruby_prof/rp_method.c +11 -24
  17. data/ext/ruby_prof/rp_method.h +2 -3
  18. data/ext/ruby_prof/rp_stack.c +55 -14
  19. data/ext/ruby_prof/rp_stack.h +10 -10
  20. data/ext/ruby_prof/rp_thread.c +30 -21
  21. data/ext/ruby_prof/rp_thread.h +3 -3
  22. data/ext/ruby_prof/ruby_prof.c +9 -88
  23. data/ext/ruby_prof/ruby_prof.h +1 -1
  24. data/ext/ruby_prof/vc/ruby_prof.sln +12 -6
  25. data/ext/ruby_prof/vc/ruby_prof_18.vcxproj +2 -0
  26. data/ext/ruby_prof/vc/{ruby_prof.vcxproj → ruby_prof_19.vcxproj} +4 -1
  27. data/ext/ruby_prof/vc/ruby_prof_20.vcxproj +112 -0
  28. data/ext/ruby_prof/version.h +4 -4
  29. data/lib/1.8/ruby_prof.so +0 -0
  30. data/lib/1.9/ruby_prof.so +0 -0
  31. data/lib/2.0/ruby_prof.so +0 -0
  32. data/lib/ruby-prof.rb +1 -0
  33. data/lib/ruby-prof/call_info.rb +1 -1
  34. data/lib/ruby-prof/call_info_visitor.rb +4 -2
  35. data/lib/ruby-prof/compatibility.rb +13 -3
  36. data/lib/ruby-prof/method_info.rb +1 -1
  37. data/lib/ruby-prof/printers/call_info_printer.rb +1 -1
  38. data/lib/ruby-prof/printers/call_stack_printer.rb +3 -3
  39. data/lib/ruby-prof/printers/dot_printer.rb +2 -2
  40. data/lib/ruby-prof/printers/flat_printer.rb +4 -4
  41. data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +2 -2
  42. data/lib/ruby-prof/printers/graph_html_printer.rb +3 -4
  43. data/lib/ruby-prof/printers/graph_printer.rb +15 -15
  44. data/lib/ruby-prof/profile.rb +1 -1
  45. data/lib/ruby-prof/rack.rb +0 -5
  46. data/lib/ruby-prof/thread.rb +22 -0
  47. data/ruby-prof.gemspec +2 -1
  48. data/test/basic_test.rb +77 -45
  49. data/test/call_info_test.rb +78 -0
  50. data/test/call_info_visitor_test.rb +1 -1
  51. data/test/dynamic_method_test.rb +14 -8
  52. data/test/measure_cpu_time_test.rb +23 -12
  53. data/test/measure_process_time_test.rb +21 -170
  54. data/test/measure_wall_time_test.rb +59 -13
  55. data/test/method_elimination_test.rb +30 -19
  56. data/test/pause_resume_test.rb +129 -22
  57. data/test/prime.rb +1 -2
  58. data/test/printers_test.rb +8 -17
  59. data/test/recursive_test.rb +6 -50
  60. data/test/test_helper.rb +30 -10
  61. data/test/test_suite.rb +1 -2
  62. metadata +23 -7
  63. data/test/bug_test.rb +0 -6
  64. data/test/gc_test.rb +0 -35
  65. data/test/pause_test.rb +0 -57
  66. data/test/prime_test.rb +0 -13
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+
6
+ class CallInfoTest < Test::Unit::TestCase
7
+ def setup
8
+ # Need to use wall time for this test due to the sleep calls
9
+ RubyProf::measure_mode = RubyProf::WALL_TIME
10
+ end
11
+
12
+ # def test_clone
13
+ # result = RubyProf.profile do
14
+ # RubyProf::C1.hello
15
+ # end
16
+ #
17
+ # method = result.threads.first.top_methods.first
18
+ # call_info = method.call_infos.first
19
+ # call_info_clone = call_info.clone
20
+ #
21
+ ## assert_equal(call_info.target, call_info_clone.target)
22
+ # assert_equal(call_info.total_time, call_info_clone.total_time)
23
+ # end
24
+
25
+ def test_merge
26
+ result1 = RubyProf.profile do
27
+ RubyProf::C1.hello
28
+ end
29
+
30
+ methods = result1.threads.first.methods.sort.reverse
31
+ assert_equal(3, methods.length)
32
+
33
+ assert_equal('CallInfoTest#test_merge', methods[0].full_name)
34
+ assert_in_delta(0.1, methods[0].total_time, 0.01)
35
+ assert_in_delta(0, methods[0].wait_time, 0.01)
36
+ assert_in_delta(0, methods[0].self_time, 0.01)
37
+ assert_equal(1, methods[0].called)
38
+
39
+ assert_equal('<Class::RubyProf::C1>#hello', methods[1].full_name)
40
+ assert_in_delta(0.1, methods[1].total_time, 0.01)
41
+ assert_in_delta(0, methods[1].wait_time, 0.01)
42
+ assert_in_delta(0, methods[1].self_time, 0.01)
43
+ assert_equal(1, methods[1].called)
44
+
45
+ assert_equal('Kernel#sleep', methods[2].full_name)
46
+ assert_in_delta(0.1, methods[2].total_time, 0.01)
47
+ assert_in_delta(0, methods[2].wait_time, 0.01)
48
+ assert_in_delta(0.1, methods[2].self_time, 0.01)
49
+ assert_equal(1, methods[2].called)
50
+
51
+ result2 = RubyProf.profile do
52
+ RubyProf::C1.hello
53
+ end
54
+
55
+ # Merge the trees
56
+ methods = result1.threads.first.methods.sort.reverse
57
+ assert_equal(3, methods.length)
58
+
59
+ assert_equal('CallInfoTest#test_merge', methods[0].full_name)
60
+ assert_in_delta(0.1, methods[0].total_time, 0.01)
61
+ assert_in_delta(0, methods[0].wait_time, 0.01)
62
+ assert_in_delta(0, methods[0].self_time, 0.01)
63
+ assert_equal(1, methods[0].called)
64
+
65
+ assert_equal('<Class::RubyProf::C1>#hello', methods[1].full_name)
66
+ assert_in_delta(0.1, methods[1].total_time, 0.01)
67
+ assert_in_delta(0, methods[1].wait_time, 0.01)
68
+ assert_in_delta(0, methods[1].self_time, 0.01)
69
+ assert_equal(1, methods[1].called)
70
+
71
+ assert_equal('Kernel#sleep', methods[2].full_name)
72
+ assert_in_delta(0.1, methods[2].total_time, 0.01)
73
+ assert_in_delta(0, methods[2].wait_time, 0.01)
74
+ assert_in_delta(0.1, methods[2].self_time, 0.01)
75
+ assert_equal(1, methods[2].called)
76
+ end
77
+ end
78
+
@@ -6,7 +6,7 @@ require File.expand_path('../test_helper', __FILE__)
6
6
  class CallInfoVisitorTest < Test::Unit::TestCase
7
7
  def setup
8
8
  # Need to use wall time for this test due to the sleep calls
9
- RubyProf::measure_mode = RubyProf::CPU_TIME
9
+ RubyProf::measure_mode = RubyProf::WALL_TIME
10
10
  end
11
11
 
12
12
  def test_visit
@@ -3,8 +3,12 @@
3
3
 
4
4
  require File.expand_path("../test_helper", __FILE__)
5
5
 
6
-
7
6
  class DynamicMethodTest < Test::Unit::TestCase
7
+ def setup
8
+ # Need to use wall time for this test due to the sleep calls
9
+ RubyProf::measure_mode = RubyProf::WALL_TIME
10
+ end
11
+
8
12
  def test_dynamic_method
9
13
  result = RubyProf.profile do
10
14
  1.times {RubyProf::C1.new.hello}
@@ -13,14 +17,14 @@ class DynamicMethodTest < Test::Unit::TestCase
13
17
  # Methods called
14
18
  # Kernel#sleep
15
19
  # <Class::BasicObject>#allocate
16
- # BasicObject#initialize
20
+ # #{RubyProf.parent_object}
17
21
  # RubyProf::C1#hello
18
22
  # Class#new
19
23
  # Integer#times
20
24
  # DynamicMethodTest#test_dynamic_method
21
25
 
22
26
  methods = result.threads.first.methods.sort.reverse
23
- assert_equal(7, methods.length)
27
+ assert_equal(RubyProf.ruby_2? ? 6 : 7, methods.length)
24
28
 
25
29
  # Check times
26
30
  assert_equal("DynamicMethodTest#test_dynamic_method", methods[0].full_name)
@@ -48,14 +52,16 @@ class DynamicMethodTest < Test::Unit::TestCase
48
52
  assert_in_delta(0.0, methods[4].wait_time, 0.01)
49
53
  assert_in_delta(0.0, methods[4].self_time, 0.01)
50
54
 
51
- assert_equal("<Class::#{RubyProf::PARENT}>#allocate", methods[5].full_name)
55
+ assert_equal("#{RubyProf.parent_object}#initialize", methods[5].full_name)
52
56
  assert_in_delta(0.0, methods[5].total_time, 0.01)
53
57
  assert_in_delta(0.0, methods[5].wait_time, 0.01)
54
58
  assert_in_delta(0.0, methods[5].self_time, 0.01)
55
59
 
56
- assert_equal("#{RubyProf::PARENT}#initialize", methods[6].full_name)
57
- assert_in_delta(0.0, methods[5].total_time, 0.01)
58
- assert_in_delta(0.0, methods[5].wait_time, 0.01)
59
- assert_in_delta(0.0, methods[5].self_time, 0.01)
60
+ unless RubyProf.ruby_2?
61
+ assert_equal("<Class::#{RubyProf.parent_object}>#allocate", methods[6].full_name)
62
+ assert_in_delta(0.0, methods[6].total_time, 0.01)
63
+ assert_in_delta(0.0, methods[6].wait_time, 0.01)
64
+ assert_in_delta(0.0, methods[6].self_time, 0.01)
65
+ end
60
66
  end
61
67
  end
@@ -64,15 +64,18 @@ class MeasureCpuTimeTest < Test::Unit::TestCase
64
64
  # Kernel#sleep
65
65
 
66
66
  methods = result.threads.first.methods.sort.reverse
67
- assert_equal(6, methods.length)
67
+ assert_equal(RubyProf.ruby_2? ? 5 : 6, methods.length)
68
68
  names = methods.map(&:full_name)
69
69
  assert_equal('MeasureCpuTimeTest#test_instance_methods', names[0])
70
70
  assert_equal('RubyProf::C1#hello', names[1])
71
71
  assert_equal('Kernel#sleep', names[2])
72
72
  assert_equal('Class#new', names[3])
73
+
73
74
  # order can differ
74
- assert(names.include?("<Class::#{RubyProf::PARENT}>#allocate"))
75
- assert(names.include?("#{RubyProf::PARENT}#initialize"))
75
+ assert(names.include?("#{RubyProf.parent_object}#initialize"))
76
+ unless RubyProf.ruby_2?
77
+ assert(names.include?("<Class::#{RubyProf.parent_object}>#allocate"))
78
+ end
76
79
 
77
80
  # Check times
78
81
  assert_in_delta(0.2, methods[0].total_time, 0.02)
@@ -95,9 +98,11 @@ class MeasureCpuTimeTest < Test::Unit::TestCase
95
98
  assert_in_delta(0, methods[4].wait_time, 0.01)
96
99
  assert_in_delta(0, methods[4].self_time, 0.01)
97
100
 
98
- assert_in_delta(0, methods[5].total_time, 0.01)
99
- assert_in_delta(0, methods[5].wait_time, 0.01)
100
- assert_in_delta(0, methods[5].self_time, 0.01)
101
+ unless RubyProf.ruby_2?
102
+ assert_in_delta(0, methods[5].total_time, 0.01)
103
+ assert_in_delta(0, methods[5].wait_time, 0.01)
104
+ assert_in_delta(0, methods[5].self_time, 0.01)
105
+ end
101
106
  end
102
107
 
103
108
  def test_module_methods
@@ -145,14 +150,18 @@ class MeasureCpuTimeTest < Test::Unit::TestCase
145
150
  # Kernel#sleep
146
151
 
147
152
  methods = result.threads.first.methods.sort.reverse
148
- assert_equal(6, methods.length)
153
+ assert_equal(RubyProf.ruby_2? ? 5 : 6, methods.length)
149
154
  names = methods.map(&:full_name)
150
155
  assert_equal('MeasureCpuTimeTest#test_module_instance_methods', names[0])
151
156
  assert_equal('RubyProf::M1#hello', names[1])
152
157
  assert_equal('Kernel#sleep', names[2])
153
158
  assert_equal('Class#new', names[3])
154
- assert(names.include?("<Class::#{RubyProf::PARENT}>#allocate"))
155
- assert(names.include?("#{RubyProf::PARENT}#initialize"))
159
+
160
+ # order can differ
161
+ assert(names.include?("#{RubyProf.parent_object}#initialize"))
162
+ unless RubyProf.ruby_2?
163
+ assert(names.include?("<Class::#{RubyProf.parent_object}>#allocate"))
164
+ end
156
165
 
157
166
  # Check times
158
167
  assert_in_delta(0.3, methods[0].total_time, 0.1)
@@ -175,9 +184,11 @@ class MeasureCpuTimeTest < Test::Unit::TestCase
175
184
  assert_in_delta(0, methods[4].wait_time, 0.01)
176
185
  assert_in_delta(0, methods[4].self_time, 0.01)
177
186
 
178
- assert_in_delta(0, methods[5].total_time, 0.01)
179
- assert_in_delta(0, methods[5].wait_time, 0.01)
180
- assert_in_delta(0, methods[5].self_time, 0.01)
187
+ unless RubyProf.ruby_2?
188
+ assert_in_delta(0, methods[5].total_time, 0.01)
189
+ assert_in_delta(0, methods[5].wait_time, 0.01)
190
+ assert_in_delta(0, methods[5].self_time, 0.01)
191
+ end
181
192
  end
182
193
 
183
194
  def test_singleton
@@ -5,7 +5,7 @@ require File.expand_path('../test_helper', __FILE__)
5
5
 
6
6
  class MeasureProcessTimeTest < Test::Unit::TestCase
7
7
  def setup
8
- # Need to use wall time for this test due to the sleep calls
8
+ # Need to fix this for linux (windows works since PROCESS_TIME is WALL_TIME anyway)
9
9
  RubyProf::measure_mode = RubyProf::PROCESS_TIME
10
10
  end
11
11
 
@@ -18,188 +18,39 @@ class MeasureProcessTimeTest < Test::Unit::TestCase
18
18
  assert(defined?(RubyProf::PROCESS_TIME_ENABLED))
19
19
  end
20
20
 
21
- def test_class_methods
21
+ def test_primes
22
+ start = Process.times
22
23
  result = RubyProf.profile do
23
- RubyProf::C1.hello
24
+ run_primes(10000)
24
25
  end
26
+ finish = Process.times
25
27
 
26
- # Length should be 3:
27
- # MeasureProcessTimeTest#test_class_methods
28
- # <Class::RubyProf::C1>#hello
29
- # Kernel#sleep
28
+ total_time = (finish.utime - start.utime) + (finish.stime - start.stime)
30
29
 
31
- methods = result.threads.first.methods.sort.reverse
32
- puts methods[0].total_time
33
-
34
- assert_equal(3, methods.length)
35
-
36
- # Check times
37
- assert_equal("MeasureProcessTimeTest#test_class_methods", methods[0].full_name)
38
- assert_in_delta(0.1, methods[0].total_time, 0.01)
39
- assert_in_delta(0.0, methods[0].wait_time, 0.01)
40
- assert_in_delta(0.0, methods[0].self_time, 0.01)
41
-
42
- assert_equal("<Class::RubyProf::C1>#hello", methods[1].full_name)
43
- assert_in_delta(0.1, methods[1].total_time, 0.01)
44
- assert_in_delta(0.0, methods[1].wait_time, 0.01)
45
- assert_in_delta(0.0, methods[1].self_time, 0.01)
46
-
47
- assert_equal("Kernel#sleep", methods[2].full_name)
48
- assert_in_delta(0.1, methods[2].total_time, 0.01)
49
- assert_in_delta(0.0, methods[2].wait_time, 0.01)
50
- assert_in_delta(0.1, methods[2].self_time, 0.01)
51
- end
52
-
53
- def test_instance_methods
54
- result = RubyProf.profile do
55
- RubyProf::C1.new.hello
56
- end
57
-
58
- # Methods called
59
- # MeasureProcessTimeTest#test_instance_methods
60
- # Class.new
61
- # Class:Object#allocate
62
- # for Object#initialize
63
- # C1#hello
64
- # Kernel#sleep
65
-
66
- methods = result.threads.first.methods.sort.reverse
67
- assert_equal(6, methods.length)
68
-
69
- # Check times
70
- assert_equal("MeasureProcessTimeTest#test_instance_methods", methods[0].full_name)
71
- assert_in_delta(0.2, methods[0].total_time, 0.02)
72
- assert_in_delta(0.0, methods[0].wait_time, 0.02)
73
- assert_in_delta(0.0, methods[0].self_time, 0.02)
74
-
75
- assert_equal("RubyProf::C1#hello", methods[1].full_name)
76
- assert_in_delta(0.2, methods[1].total_time, 0.02)
77
- assert_in_delta(0.0, methods[1].wait_time, 0.02)
78
- assert_in_delta(0.0, methods[1].self_time, 0.02)
79
-
80
- assert_equal("Kernel#sleep", methods[2].full_name)
81
- assert_in_delta(0.2, methods[2].total_time, 0.02)
82
- assert_in_delta(0.0, methods[2].wait_time, 0.02)
83
- assert_in_delta(0.2, methods[2].self_time, 0.02)
84
-
85
- assert_equal("Class#new", methods[3].full_name)
86
- assert_in_delta(0.0, methods[3].total_time, 0.01)
87
- assert_in_delta(0.0, methods[3].wait_time, 0.01)
88
- assert_in_delta(0.0, methods[3].self_time, 0.01)
89
-
90
- assert_equal("<Class::#{RubyProf::PARENT}>#allocate", methods[4].full_name)
91
- assert_in_delta(0.0, methods[4].total_time, 0.01)
92
- assert_in_delta(0.0, methods[4].wait_time, 0.01)
93
- assert_in_delta(0.0, methods[4].self_time, 0.01)
94
-
95
- assert_equal("#{RubyProf::PARENT}#initialize", methods[5].full_name)
96
- assert_in_delta(0.0, methods[5].total_time, 0.01)
97
- assert_in_delta(0.0, methods[5].wait_time, 0.01)
98
- assert_in_delta(0.0, methods[5].self_time, 0.01)
99
- end
100
-
101
- def test_module_methods
102
- result = RubyProf.profile do
103
- RubyProf::C2.hello
104
- end
105
-
106
- # Methods:
107
- # MeasureProcessTimeTest#test_module_methods
108
- # M1#hello
109
- # Kernel#sleep
30
+ thread = result.threads.first
31
+ assert_in_delta(total_time, thread.total_time, 0.01)
110
32
 
111
33
  methods = result.threads.first.methods.sort.reverse
112
- assert_equal(3, methods.length)
113
34
 
114
- # Check times
115
- assert_equal("MeasureProcessTimeTest#test_module_methods", methods[0].full_name)
116
- assert_in_delta(0.3, methods[0].total_time, 0.1)
117
- assert_in_delta(0.0, methods[0].wait_time, 0.02)
118
- assert_in_delta(0.0, methods[0].self_time, 0.02)
119
-
120
- assert_equal("RubyProf::M1#hello", methods[1].full_name)
121
- assert_in_delta(0.3, methods[1].total_time, 0.1)
122
- assert_in_delta(0.0, methods[1].wait_time, 0.02)
123
- assert_in_delta(0.0, methods[1].self_time, 0.02)
124
-
125
- assert_equal("Kernel#sleep", methods[2].full_name)
126
- assert_in_delta(0.3, methods[2].total_time, 0.1)
127
- assert_in_delta(0.0, methods[2].wait_time, 0.02)
128
- assert_in_delta(0.3, methods[2].self_time, 0.1)
129
- end
130
-
131
- def test_module_instance_methods
132
- result = RubyProf.profile do
133
- RubyProf::C2.new.hello
134
- end
135
-
136
- # Methods:
137
- # MeasureProcessTimeTest#test_module_instance_methods
138
- # Class#new
139
- # <Class::Object>#allocate
140
- # Object#initialize
141
- # M1#hello
142
- # Kernel#sleep
143
-
144
- methods = result.threads.first.methods.sort.reverse
145
- assert_equal(6, methods.length)
35
+ assert_equal(RubyProf.ruby_2? ? 15 : 16, methods.length)
146
36
 
147
37
  # Check times
148
- assert_equal("MeasureProcessTimeTest#test_module_instance_methods", methods[0].full_name)
149
- assert_in_delta(0.3, methods[0].total_time, 0.1)
150
- assert_in_delta(0.0, methods[0].wait_time, 0.1)
151
- assert_in_delta(0.0, methods[0].self_time, 0.1)
152
-
153
- assert_equal("RubyProf::M1#hello", methods[1].full_name)
154
- assert_in_delta(0.3, methods[1].total_time, 0.02)
155
- assert_in_delta(0.0, methods[1].wait_time, 0.01)
156
- assert_in_delta(0.0, methods[1].self_time, 0.01)
157
-
158
- assert_equal("Kernel#sleep", methods[2].full_name)
159
- assert_in_delta(0.3, methods[2].total_time, 0.02)
160
- assert_in_delta(0.0, methods[2].wait_time, 0.01)
161
- assert_in_delta(0.3, methods[2].self_time, 0.02)
162
-
163
- assert_equal("Class#new", methods[3].full_name)
164
- assert_in_delta(0.0, methods[3].total_time, 0.01)
165
- assert_in_delta(0.0, methods[3].wait_time, 0.01)
166
- assert_in_delta(0.0, methods[3].self_time, 0.01)
167
-
168
- assert_equal("<Class::#{RubyProf::PARENT}>#allocate", methods[4].full_name)
169
- assert_in_delta(0.0, methods[4].total_time, 0.01)
170
- assert_in_delta(0.0, methods[4].wait_time, 0.01)
171
- assert_in_delta(0.0, methods[4].self_time, 0.01)
172
-
173
- assert_equal("#{RubyProf::PARENT}#initialize", methods[5].full_name)
174
- assert_in_delta(0.0, methods[5].total_time, 0.01)
175
- assert_in_delta(0.0, methods[5].wait_time, 0.01)
176
- assert_in_delta(0.0, methods[5].self_time, 0.01)
177
- end
178
-
179
- def test_singleton
180
- c3 = RubyProf::C3.new
181
-
182
- class << c3
183
- def hello
184
- end
185
- end
186
-
187
- result = RubyProf.profile do
188
- c3.hello
189
- end
190
-
191
- methods = result.threads.first.methods.sort.reverse
192
- assert_equal(2, methods.length)
193
-
194
- assert_equal("MeasureProcessTimeTest#test_singleton", methods[0].full_name)
195
- assert_equal("<Object::RubyProf::C3>#hello", methods[1].full_name)
196
-
197
- assert_in_delta(0.0, methods[0].total_time, 0.01)
38
+ assert_equal("MeasureProcessTimeTest#test_primes", methods[0].full_name)
39
+ assert_in_delta(total_time, methods[0].total_time, 0.01)
198
40
  assert_in_delta(0.0, methods[0].wait_time, 0.01)
199
41
  assert_in_delta(0.0, methods[0].self_time, 0.01)
200
42
 
201
- assert_in_delta(0.0, methods[1].total_time, 0.01)
43
+ assert_equal("Object#run_primes", methods[1].full_name)
44
+ assert_in_delta(total_time, methods[1].total_time, 0.01)
202
45
  assert_in_delta(0.0, methods[1].wait_time, 0.01)
203
46
  assert_in_delta(0.0, methods[1].self_time, 0.01)
47
+
48
+ assert_equal("Object#find_primes", methods[2].full_name)
49
+ assert_equal("Array#select", methods[3].full_name)
50
+ assert_equal("Object#is_prime", methods[4].full_name)
51
+ assert_equal("Integer#upto", methods[5].full_name)
52
+ assert_equal("Object#make_random_array", methods[6].full_name)
53
+ assert_equal("Array#each_index", methods[7].full_name)
54
+ assert_equal("Kernel#rand", methods[8].full_name)
204
55
  end
205
56
  end
@@ -23,6 +23,13 @@ class MeasureWallTimeTest < Test::Unit::TestCase
23
23
  RubyProf::C1.hello
24
24
  end
25
25
 
26
+ thread = result.threads.first
27
+ assert_in_delta(0.1, thread.total_time, 0.01)
28
+
29
+ top_methods = thread.top_methods
30
+ assert_equal(1, top_methods.count)
31
+ assert_equal("MeasureWallTimeTest#test_class_methods", top_methods[0].full_name)
32
+
26
33
  # Length should be 3:
27
34
  # MeasureWallTimeTest#test_class_methods
28
35
  # <Class::RubyProf::C1>#hello
@@ -55,6 +62,13 @@ class MeasureWallTimeTest < Test::Unit::TestCase
55
62
  RubyProf::C1.new.hello
56
63
  end
57
64
 
65
+ thread = result.threads.first
66
+ assert_in_delta(0.2, thread.total_time, 0.01)
67
+
68
+ top_methods = thread.top_methods
69
+ assert_equal(1, top_methods.count)
70
+ assert_equal("MeasureWallTimeTest#test_instance_methods", top_methods[0].full_name)
71
+
58
72
  # Methods called
59
73
  # MeasureWallTimeTest#test_instance_methods
60
74
  # Class.new
@@ -64,15 +78,18 @@ class MeasureWallTimeTest < Test::Unit::TestCase
64
78
  # Kernel#sleep
65
79
 
66
80
  methods = result.threads.first.methods.sort.reverse
67
- assert_equal(6, methods.length)
81
+ assert_equal(RubyProf.ruby_2? ? 5 : 6, methods.length)
68
82
  names = methods.map(&:full_name)
69
83
  assert_equal('MeasureWallTimeTest#test_instance_methods', names[0])
70
84
  assert_equal('RubyProf::C1#hello', names[1])
71
85
  assert_equal('Kernel#sleep', names[2])
72
86
  assert_equal('Class#new', names[3])
87
+
73
88
  # order can differ
74
- assert(names.include?("<Class::#{RubyProf::PARENT}>#allocate"))
75
- assert(names.include?("#{RubyProf::PARENT}#initialize"))
89
+ assert(names.include?("#{RubyProf.parent_object}#initialize"))
90
+ unless RubyProf.ruby_2?
91
+ assert(names.include?("<Class::#{RubyProf.parent_object}>#allocate"))
92
+ end
76
93
 
77
94
  # Check times
78
95
  assert_in_delta(0.2, methods[0].total_time, 0.02)
@@ -95,9 +112,11 @@ class MeasureWallTimeTest < Test::Unit::TestCase
95
112
  assert_in_delta(0, methods[4].wait_time, 0.01)
96
113
  assert_in_delta(0, methods[4].self_time, 0.01)
97
114
 
98
- assert_in_delta(0, methods[5].total_time, 0.01)
99
- assert_in_delta(0, methods[5].wait_time, 0.01)
100
- assert_in_delta(0, methods[5].self_time, 0.01)
115
+ unless RubyProf.ruby_2?
116
+ assert_in_delta(0, methods[5].total_time, 0.01)
117
+ assert_in_delta(0, methods[5].wait_time, 0.01)
118
+ assert_in_delta(0, methods[5].self_time, 0.01)
119
+ end
101
120
  end
102
121
 
103
122
  def test_module_methods
@@ -105,6 +124,13 @@ class MeasureWallTimeTest < Test::Unit::TestCase
105
124
  RubyProf::C2.hello
106
125
  end
107
126
 
127
+ thread = result.threads.first
128
+ assert_in_delta(0.3, thread.total_time, 0.01)
129
+
130
+ top_methods = thread.top_methods
131
+ assert_equal(1, top_methods.count)
132
+ assert_equal("MeasureWallTimeTest#test_module_methods", top_methods[0].full_name)
133
+
108
134
  # Methods:
109
135
  # MeasureWallTimeTest#test_module_methods
110
136
  # M1#hello
@@ -136,6 +162,13 @@ class MeasureWallTimeTest < Test::Unit::TestCase
136
162
  RubyProf::C2.new.hello
137
163
  end
138
164
 
165
+ thread = result.threads.first
166
+ assert_in_delta(0.3, thread.total_time, 0.01)
167
+
168
+ top_methods = thread.top_methods
169
+ assert_equal(1, top_methods.count)
170
+ assert_equal("MeasureWallTimeTest#test_module_instance_methods", top_methods[0].full_name)
171
+
139
172
  # Methods:
140
173
  # MeasureWallTimeTest#test_module_instance_methods
141
174
  # Class#new
@@ -145,14 +178,18 @@ class MeasureWallTimeTest < Test::Unit::TestCase
145
178
  # Kernel#sleep
146
179
 
147
180
  methods = result.threads.first.methods.sort.reverse
148
- assert_equal(6, methods.length)
181
+ assert_equal(RubyProf.ruby_2? ? 5 : 6, methods.length)
149
182
  names = methods.map(&:full_name)
150
183
  assert_equal('MeasureWallTimeTest#test_module_instance_methods', names[0])
151
184
  assert_equal('RubyProf::M1#hello', names[1])
152
185
  assert_equal('Kernel#sleep', names[2])
153
186
  assert_equal('Class#new', names[3])
154
- assert(names.include?("<Class::#{RubyProf::PARENT}>#allocate"))
155
- assert(names.include?("#{RubyProf::PARENT}#initialize"))
187
+
188
+ # order can differ
189
+ assert(names.include?("#{RubyProf.parent_object}#initialize"))
190
+ unless RubyProf.ruby_2?
191
+ assert(names.include?("<Class::#{RubyProf.parent_object}>#allocate"))
192
+ end
156
193
 
157
194
  # Check times
158
195
  assert_in_delta(0.3, methods[0].total_time, 0.1)
@@ -175,9 +212,11 @@ class MeasureWallTimeTest < Test::Unit::TestCase
175
212
  assert_in_delta(0, methods[4].wait_time, 0.01)
176
213
  assert_in_delta(0, methods[4].self_time, 0.01)
177
214
 
178
- assert_in_delta(0, methods[5].total_time, 0.01)
179
- assert_in_delta(0, methods[5].wait_time, 0.01)
180
- assert_in_delta(0, methods[5].self_time, 0.01)
215
+ unless RubyProf.ruby_2?
216
+ assert_in_delta(0, methods[5].total_time, 0.01)
217
+ assert_in_delta(0, methods[5].wait_time, 0.01)
218
+ assert_in_delta(0, methods[5].self_time, 0.01)
219
+ end
181
220
  end
182
221
 
183
222
  def test_singleton
@@ -192,6 +231,13 @@ class MeasureWallTimeTest < Test::Unit::TestCase
192
231
  c3.hello
193
232
  end
194
233
 
234
+ thread = result.threads.first
235
+ assert_in_delta(0.0, thread.total_time, 0.01)
236
+
237
+ top_methods = thread.top_methods
238
+ assert_equal(1, top_methods.count)
239
+ assert_equal("MeasureWallTimeTest#test_singleton", top_methods[0].full_name)
240
+
195
241
  methods = result.threads.first.methods.sort.reverse
196
242
  assert_equal(2, methods.length)
197
243
 
@@ -206,4 +252,4 @@ class MeasureWallTimeTest < Test::Unit::TestCase
206
252
  assert_in_delta(0, methods[1].wait_time, 0.01)
207
253
  assert_in_delta(0, methods[1].self_time, 0.01)
208
254
  end
209
- end
255
+ end