ruby-prof 1.7.1 → 1.7.2

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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +8 -0
  3. data/ext/ruby_prof/extconf.rb +23 -22
  4. data/ext/ruby_prof/rp_call_trees.c +296 -296
  5. data/ext/ruby_prof/rp_call_trees.h +28 -28
  6. data/ext/ruby_prof/rp_measure_allocations.c +47 -47
  7. data/ext/ruby_prof/rp_measure_process_time.c +64 -66
  8. data/ext/ruby_prof/rp_measure_wall_time.c +52 -64
  9. data/ext/ruby_prof/rp_method.c +551 -551
  10. data/ext/ruby_prof/rp_stack.c +212 -212
  11. data/ext/ruby_prof/ruby_prof.c +50 -50
  12. data/ext/ruby_prof/ruby_prof.h +3 -2
  13. data/ext/ruby_prof/vc/ruby_prof.vcxproj +3 -3
  14. data/lib/ruby-prof/compatibility.rb +113 -113
  15. data/lib/ruby-prof/exclude_common_methods.rb +204 -204
  16. data/lib/ruby-prof/printers/abstract_printer.rb +156 -138
  17. data/lib/ruby-prof/version.rb +3 -3
  18. data/ruby-prof.gemspec +66 -65
  19. data/test/dynamic_method_test.rb +9 -21
  20. data/test/enumerable_test.rb +23 -21
  21. data/test/exclude_methods_test.rb +363 -257
  22. data/test/fiber_test.rb +195 -195
  23. data/test/gc_test.rb +104 -102
  24. data/test/line_number_test.rb +426 -289
  25. data/test/measure_allocations_test.rb +1172 -1081
  26. data/test/measure_memory_test.rb +1193 -1456
  27. data/test/measure_process_time_test.rb +3330 -2477
  28. data/test/measure_wall_time_test.rb +634 -568
  29. data/test/merge_test.rb +146 -146
  30. data/test/method_info_test.rb +100 -95
  31. data/test/printers_test.rb +178 -135
  32. data/test/recursive_test.rb +796 -622
  33. data/test/start_stop_test.rb +4 -4
  34. data/test/test_helper.rb +20 -20
  35. data/test/thread_test.rb +229 -231
  36. data/test/unique_call_path_test.rb +9 -22
  37. data/test/yarv_test.rb +1 -5
  38. metadata +19 -9
  39. data/test/crash2.rb +0 -144
data/test/fiber_test.rb CHANGED
@@ -1,195 +1,195 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- require File.expand_path('../test_helper', __FILE__)
5
- require 'fiber'
6
- require 'timeout'
7
- require 'set'
8
-
9
- # -- Tests ----
10
- class FiberTest < TestCase
11
- def enumerator_with_fibers
12
- enum = Enumerator.new do |yielder|
13
- [1,2].each do |x|
14
- yielder.yield x
15
- end
16
- end
17
-
18
- enum.next
19
- enum.next
20
- end
21
-
22
- def fiber_yield_resume
23
- fiber = Fiber.new do
24
- Fiber.yield 1
25
- Fiber.yield 2
26
- end
27
-
28
- fiber.resume
29
- fiber.resume
30
- end
31
-
32
- def test_fibers
33
- result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) { enumerator_with_fibers }
34
-
35
- assert_equal(2, result.threads.size)
36
-
37
- thread1 = result.threads[0]
38
- methods = thread1.methods.sort.reverse
39
- assert_equal(5, methods.count)
40
-
41
- method = methods[0]
42
- assert_equal('FiberTest#test_fibers', method.full_name)
43
- assert_equal(1, method.called)
44
- assert_in_delta(0, method.total_time)
45
- assert_in_delta(0, method.self_time)
46
- assert_in_delta(0, method.wait_time)
47
- assert_in_delta(0, method.children_time)
48
-
49
- method = methods[1]
50
- assert_equal('FiberTest#enumerator_with_fibers', method.full_name)
51
- assert_equal(1, method.called)
52
- assert_in_delta(0, method.total_time)
53
- assert_in_delta(0, method.self_time)
54
- assert_in_delta(0, method.wait_time)
55
- assert_in_delta(0, method.children_time)
56
-
57
- method = methods[2]
58
- assert_equal('Enumerator#next', method.full_name)
59
- assert_equal(2, method.called)
60
- assert_in_delta(0, method.total_time)
61
- assert_in_delta(0, method.self_time)
62
- assert_in_delta(0, method.wait_time)
63
- assert_in_delta(0, method.children_time)
64
-
65
- method = methods[3]
66
- assert_equal('Class#new', method.full_name)
67
- assert_equal(1, method.called)
68
- assert_in_delta(0, method.total_time)
69
- assert_in_delta(0, method.self_time)
70
- assert_in_delta(0, method.wait_time)
71
- assert_in_delta(0, method.children_time)
72
-
73
- method = methods[4]
74
- assert_equal('Enumerator#initialize', method.full_name)
75
- assert_equal(1, method.called)
76
- assert_in_delta(0, method.total_time)
77
- assert_in_delta(0, method.self_time)
78
- assert_in_delta(0, method.wait_time)
79
- assert_in_delta(0, method.children_time)
80
-
81
- thread2 = result.threads[1]
82
- methods = thread2.methods.sort.reverse
83
- assert_equal(4, methods.count)
84
- assert_in_delta(0, method.total_time)
85
- assert_in_delta(0, method.self_time)
86
- assert_in_delta(0, method.wait_time)
87
- assert_in_delta(0, method.children_time)
88
-
89
- method = methods[0]
90
- assert_equal('Enumerator#each', method.full_name)
91
- assert_equal(1, method.called)
92
- assert_in_delta(0, method.total_time)
93
- assert_in_delta(0, method.self_time)
94
- assert_in_delta(0, method.wait_time)
95
- assert_in_delta(0, method.children_time)
96
-
97
- method = methods[1]
98
- assert_equal('Enumerator::Generator#each', method.full_name)
99
- assert_equal(1, method.called)
100
- assert_in_delta(0, method.total_time)
101
- assert_in_delta(0, method.self_time)
102
- assert_in_delta(0, method.wait_time)
103
- assert_in_delta(0, method.children_time)
104
-
105
- method = methods[2]
106
- assert_equal('Array#each', method.full_name)
107
- assert_equal(1, method.called)
108
- assert_in_delta(0, method.total_time)
109
- assert_in_delta(0, method.self_time)
110
- assert_in_delta(0, method.wait_time)
111
- assert_in_delta(0, method.children_time)
112
-
113
- method = methods[3]
114
- assert_equal('Enumerator::Yielder#yield', method.full_name)
115
- assert_equal(2, method.called)
116
- assert_in_delta(0, method.total_time)
117
- assert_in_delta(0, method.self_time)
118
- assert_in_delta(0, method.wait_time)
119
- assert_in_delta(0, method.children_time)
120
- end
121
-
122
- def test_fiber_resume
123
- result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) { fiber_yield_resume }
124
-
125
- assert_equal(2, result.threads.size)
126
-
127
- thread1 = result.threads[0]
128
- methods = thread1.methods.sort.reverse
129
- assert_equal(5, methods.count)
130
-
131
- method = methods[0]
132
- assert_equal('FiberTest#test_fiber_resume', method.full_name)
133
- assert_equal(1, method.called)
134
- assert_in_delta(0, method.total_time)
135
- assert_in_delta(0, method.self_time)
136
- assert_in_delta(0, method.wait_time)
137
- assert_in_delta(0, method.children_time)
138
-
139
- method = methods[1]
140
- assert_equal('FiberTest#fiber_yield_resume', method.full_name)
141
- assert_equal(1, method.called)
142
- assert_in_delta(0, method.total_time)
143
- assert_in_delta(0, method.self_time)
144
- assert_in_delta(0, method.wait_time)
145
- assert_in_delta(0, method.children_time)
146
-
147
- method = methods[2]
148
- assert_equal('Fiber#resume', method.full_name)
149
- assert_equal(2, method.called)
150
- assert_in_delta(0, method.total_time)
151
- assert_in_delta(0, method.self_time)
152
- assert_in_delta(0, method.wait_time)
153
- assert_in_delta(0, method.children_time)
154
-
155
- method = methods[3]
156
- assert_equal('Class#new', method.full_name)
157
- assert_equal(1, method.called)
158
- assert_in_delta(0, method.total_time)
159
- assert_in_delta(0, method.self_time)
160
- assert_in_delta(0, method.wait_time)
161
- assert_in_delta(0, method.children_time)
162
-
163
- method = methods[4]
164
- assert_equal('Fiber#initialize', method.full_name)
165
- assert_equal(1, method.called)
166
- assert_in_delta(0, method.total_time)
167
- assert_in_delta(0, method.self_time)
168
- assert_in_delta(0, method.wait_time)
169
- assert_in_delta(0, method.children_time)
170
-
171
- thread1 = result.threads[1]
172
- methods = thread1.methods.sort.reverse
173
- assert_equal(2, methods.count)
174
- assert_in_delta(0, method.total_time)
175
- assert_in_delta(0, method.self_time)
176
- assert_in_delta(0, method.wait_time)
177
- assert_in_delta(0, method.children_time)
178
-
179
- method = methods[0]
180
- assert_equal('FiberTest#fiber_yield_resume', method.full_name)
181
- assert_equal(1, method.called)
182
- assert_in_delta(0, method.total_time)
183
- assert_in_delta(0, method.self_time)
184
- assert_in_delta(0, method.wait_time)
185
- assert_in_delta(0, method.children_time)
186
-
187
- method = methods[1]
188
- assert_equal('<Class::Fiber>#yield', method.full_name)
189
- assert_equal(2, method.called)
190
- assert_in_delta(0, method.total_time)
191
- assert_in_delta(0, method.self_time)
192
- assert_in_delta(0, method.wait_time)
193
- assert_in_delta(0, method.children_time)
194
- end
195
- end
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+ require 'fiber'
6
+ require 'timeout'
7
+ require 'set'
8
+
9
+ # -- Tests ----
10
+ class FiberTest < TestCase
11
+ def enumerator_with_fibers
12
+ enum = Enumerator.new do |yielder|
13
+ [1,2].each do |x|
14
+ yielder.yield x
15
+ end
16
+ end
17
+
18
+ enum.next
19
+ enum.next
20
+ end
21
+
22
+ def fiber_yield_resume
23
+ fiber = Fiber.new do
24
+ Fiber.yield 1
25
+ Fiber.yield 2
26
+ end
27
+
28
+ fiber.resume
29
+ fiber.resume
30
+ end
31
+
32
+ def test_fibers
33
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) { enumerator_with_fibers }
34
+
35
+ assert_equal(2, result.threads.size)
36
+
37
+ thread1 = result.threads[0]
38
+ methods = thread1.methods.sort.reverse
39
+ assert_equal(5, methods.count)
40
+
41
+ method = methods[0]
42
+ assert_equal('FiberTest#test_fibers', method.full_name)
43
+ assert_equal(1, method.called)
44
+ assert_in_delta(0, method.total_time)
45
+ assert_in_delta(0, method.self_time)
46
+ assert_in_delta(0, method.wait_time)
47
+ assert_in_delta(0, method.children_time)
48
+
49
+ method = methods[1]
50
+ assert_equal('FiberTest#enumerator_with_fibers', method.full_name)
51
+ assert_equal(1, method.called)
52
+ assert_in_delta(0, method.total_time)
53
+ assert_in_delta(0, method.self_time)
54
+ assert_in_delta(0, method.wait_time)
55
+ assert_in_delta(0, method.children_time)
56
+
57
+ method = methods[2]
58
+ assert_equal('Enumerator#next', method.full_name)
59
+ assert_equal(2, method.called)
60
+ assert_in_delta(0, method.total_time)
61
+ assert_in_delta(0, method.self_time)
62
+ assert_in_delta(0, method.wait_time)
63
+ assert_in_delta(0, method.children_time)
64
+
65
+ method = methods[3]
66
+ assert_equal('Class#new', method.full_name)
67
+ assert_equal(1, method.called)
68
+ assert_in_delta(0, method.total_time)
69
+ assert_in_delta(0, method.self_time)
70
+ assert_in_delta(0, method.wait_time)
71
+ assert_in_delta(0, method.children_time)
72
+
73
+ method = methods[4]
74
+ assert_equal('Enumerator#initialize', method.full_name)
75
+ assert_equal(1, method.called)
76
+ assert_in_delta(0, method.total_time)
77
+ assert_in_delta(0, method.self_time)
78
+ assert_in_delta(0, method.wait_time)
79
+ assert_in_delta(0, method.children_time)
80
+
81
+ thread2 = result.threads[1]
82
+ methods = thread2.methods.sort.reverse
83
+ assert_equal(4, methods.count)
84
+ assert_in_delta(0, method.total_time)
85
+ assert_in_delta(0, method.self_time)
86
+ assert_in_delta(0, method.wait_time)
87
+ assert_in_delta(0, method.children_time)
88
+
89
+ method = methods[0]
90
+ assert_equal('Enumerator#each', method.full_name)
91
+ assert_equal(1, method.called)
92
+ assert_in_delta(0, method.total_time)
93
+ assert_in_delta(0, method.self_time)
94
+ assert_in_delta(0, method.wait_time)
95
+ assert_in_delta(0, method.children_time)
96
+
97
+ method = methods[1]
98
+ assert_equal('Enumerator::Generator#each', method.full_name)
99
+ assert_equal(1, method.called)
100
+ assert_in_delta(0, method.total_time)
101
+ assert_in_delta(0, method.self_time)
102
+ assert_in_delta(0, method.wait_time)
103
+ assert_in_delta(0, method.children_time)
104
+
105
+ method = methods[2]
106
+ assert_equal('Array#each', method.full_name)
107
+ assert_equal(1, method.called)
108
+ assert_in_delta(0, method.total_time)
109
+ assert_in_delta(0, method.self_time)
110
+ assert_in_delta(0, method.wait_time)
111
+ assert_in_delta(0, method.children_time)
112
+
113
+ method = methods[3]
114
+ assert_equal('Enumerator::Yielder#yield', method.full_name)
115
+ assert_equal(2, method.called)
116
+ assert_in_delta(0, method.total_time)
117
+ assert_in_delta(0, method.self_time)
118
+ assert_in_delta(0, method.wait_time)
119
+ assert_in_delta(0, method.children_time)
120
+ end
121
+
122
+ def test_fiber_resume
123
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) { fiber_yield_resume }
124
+
125
+ assert_equal(2, result.threads.size)
126
+
127
+ thread1 = result.threads[0]
128
+ methods = thread1.methods.sort.reverse
129
+ assert_equal(5, methods.count)
130
+
131
+ method = methods[0]
132
+ assert_equal('FiberTest#test_fiber_resume', method.full_name)
133
+ assert_equal(1, method.called)
134
+ assert_in_delta(0, method.total_time)
135
+ assert_in_delta(0, method.self_time)
136
+ assert_in_delta(0, method.wait_time)
137
+ assert_in_delta(0, method.children_time)
138
+
139
+ method = methods[1]
140
+ assert_equal('FiberTest#fiber_yield_resume', method.full_name)
141
+ assert_equal(1, method.called)
142
+ assert_in_delta(0, method.total_time)
143
+ assert_in_delta(0, method.self_time)
144
+ assert_in_delta(0, method.wait_time)
145
+ assert_in_delta(0, method.children_time)
146
+
147
+ method = methods[2]
148
+ assert_equal('Fiber#resume', method.full_name)
149
+ assert_equal(2, method.called)
150
+ assert_in_delta(0, method.total_time)
151
+ assert_in_delta(0, method.self_time)
152
+ assert_in_delta(0, method.wait_time)
153
+ assert_in_delta(0, method.children_time)
154
+
155
+ method = methods[3]
156
+ assert_equal('Class#new', method.full_name)
157
+ assert_equal(1, method.called)
158
+ assert_in_delta(0, method.total_time)
159
+ assert_in_delta(0, method.self_time)
160
+ assert_in_delta(0, method.wait_time)
161
+ assert_in_delta(0, method.children_time)
162
+
163
+ method = methods[4]
164
+ assert_equal('Fiber#initialize', method.full_name)
165
+ assert_equal(1, method.called)
166
+ assert_in_delta(0, method.total_time)
167
+ assert_in_delta(0, method.self_time)
168
+ assert_in_delta(0, method.wait_time)
169
+ assert_in_delta(0, method.children_time)
170
+
171
+ thread1 = result.threads[1]
172
+ methods = thread1.methods.sort.reverse
173
+ assert_equal(2, methods.count)
174
+ assert_in_delta(0, method.total_time)
175
+ assert_in_delta(0, method.self_time)
176
+ assert_in_delta(0, method.wait_time)
177
+ assert_in_delta(0, method.children_time)
178
+
179
+ method = methods[0]
180
+ assert_equal('FiberTest#fiber_yield_resume', method.full_name)
181
+ assert_equal(1, method.called)
182
+ assert_in_delta(0, method.total_time)
183
+ assert_in_delta(0, method.self_time)
184
+ assert_in_delta(0, method.wait_time)
185
+ assert_in_delta(0, method.children_time)
186
+
187
+ method = methods[1]
188
+ assert_equal('<Class::Fiber>#yield', method.full_name)
189
+ assert_equal(2, method.called)
190
+ assert_in_delta(0, method.total_time)
191
+ assert_in_delta(0, method.self_time)
192
+ assert_in_delta(0, method.wait_time)
193
+ assert_in_delta(0, method.children_time)
194
+ end
195
+ end
data/test/gc_test.rb CHANGED
@@ -1,102 +1,104 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- require File.expand_path('../test_helper', __FILE__)
5
- Minitest::Test.i_suck_and_my_tests_are_order_dependent!
6
-
7
- class GcTest < TestCase
8
- def setup
9
- super
10
- GC.stress = true
11
- end
12
-
13
- def teardown
14
- GC.stress = false
15
- end
16
-
17
- def some_method
18
- Array.new(3 * 4)
19
- end
20
-
21
- def run_profile
22
- RubyProf::Profile.profile do
23
- self.some_method
24
- end
25
- end
26
-
27
- def test_hold_onto_thread
28
- threads = 5.times.reduce(Array.new) do |array, i|
29
- array.concat(run_profile.threads)
30
- array
31
- end
32
-
33
- GC.start
34
-
35
- threads.each do |thread|
36
- refute_nil(thread.id)
37
- end
38
- end
39
-
40
- def test_hold_onto_method
41
- methods = 5.times.reduce(Array.new) do |array, i|
42
- profile = run_profile
43
- array.concat(profile.threads.map(&:methods).flatten)
44
- array
45
- end
46
-
47
- GC.start
48
-
49
- methods.each do |method|
50
- refute_nil(method.method_name)
51
- end
52
- end
53
-
54
- def test_hold_onto_call_trees
55
- method_call_infos = 5.times.reduce(Array.new) do |array, i|
56
- profile = run_profile
57
- call_trees = profile.threads.map(&:methods).flatten.map(&:call_trees).flatten
58
- array.concat(call_trees)
59
- array
60
- end
61
-
62
- GC.start
63
-
64
- method_call_infos.each do |call_trees|
65
- refute_empty(call_trees.call_trees)
66
- end
67
- end
68
-
69
- def test_hold_onto_measurements
70
- # Run a profile
71
- profile = run_profile
72
-
73
- # Get measurement objects
74
- measurements = profile.threads.map(&:methods).flatten.map(&:measurement)
75
-
76
- # Free the profiles which frees the measurements
77
- profile = nil
78
-
79
- GC.start
80
-
81
- measurements.each_with_index do |measurement|
82
- error = assert_raises(RuntimeError) do
83
- measurement.total_time
84
- end
85
- assert_match(/RubyProf::Measurement instance has already been freed/, error.message)
86
- end
87
- assert(true)
88
- end
89
-
90
- def test_hold_onto_root_call_tree
91
- call_trees = 5.times.reduce(Array.new) do |array, i|
92
- array.concat(run_profile.threads.map(&:call_tree))
93
- array
94
- end
95
-
96
- GC.start
97
-
98
- call_trees.each do |call_tree|
99
- refute_nil(call_tree.source_file)
100
- end
101
- end
102
- end
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+ Minitest::Test.i_suck_and_my_tests_are_order_dependent!
6
+
7
+ class GcTest < TestCase
8
+ def setup
9
+ super
10
+ GC.stress = true
11
+ end
12
+
13
+ def teardown
14
+ GC.stress = false
15
+ end
16
+
17
+ def some_method
18
+ Array.new(3 * 4)
19
+ end
20
+
21
+ def run_profile
22
+ RubyProf::Profile.profile do
23
+ self.some_method
24
+ end
25
+ end
26
+
27
+ def test_hold_onto_thread
28
+ threads = 5.times.reduce(Array.new) do |array, i|
29
+ array.concat(run_profile.threads)
30
+ array
31
+ end
32
+
33
+ GC.start
34
+
35
+ threads.each do |thread|
36
+ refute_nil(thread.id)
37
+ end
38
+ end
39
+
40
+ def test_hold_onto_method
41
+ methods = 5.times.reduce(Array.new) do |array, i|
42
+ profile = run_profile
43
+ array.concat(profile.threads.map(&:methods).flatten)
44
+ array
45
+ end
46
+
47
+ GC.start
48
+
49
+ methods.each do |method|
50
+ refute_nil(method.method_name)
51
+ end
52
+ end
53
+
54
+ def test_hold_onto_call_trees
55
+ method_call_infos = 5.times.reduce(Array.new) do |array, i|
56
+ profile = run_profile
57
+ call_trees = profile.threads.map(&:methods).flatten.map(&:call_trees).flatten
58
+ array.concat(call_trees)
59
+ array
60
+ end
61
+
62
+ GC.start
63
+
64
+ method_call_infos.each do |call_trees|
65
+ refute_empty(call_trees.call_trees)
66
+ end
67
+ end
68
+
69
+ unless windows?
70
+ def test_hold_onto_measurements
71
+ # Run a profile
72
+ profile = run_profile
73
+
74
+ # Get measurement objects
75
+ measurements = profile.threads.map(&:methods).flatten.map(&:measurement)
76
+
77
+ # Free the profiles which frees the measurements
78
+ profile = nil
79
+
80
+ GC.start
81
+
82
+ measurements.each_with_index do |measurement|
83
+ error = assert_raises(RuntimeError) do
84
+ measurement.total_time
85
+ end
86
+ assert_match(/RubyProf::Measurement instance has already been freed/, error.message)
87
+ end
88
+ assert(true)
89
+ end
90
+ end
91
+
92
+ def test_hold_onto_root_call_tree
93
+ call_trees = 5.times.reduce(Array.new) do |array, i|
94
+ array.concat(run_profile.threads.map(&:call_tree))
95
+ array
96
+ end
97
+
98
+ GC.start
99
+
100
+ call_trees.each do |call_tree|
101
+ refute_nil(call_tree.source_file)
102
+ end
103
+ end
104
+ end