ruby-prof 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,7 @@
8
8
  #include "rp_stack.h"
9
9
 
10
10
  /* Profiling information for a thread. */
11
- typedef struct
11
+ typedef struct thread_data_t
12
12
  {
13
13
  // Runtime
14
14
  VALUE object; /* Cache to wrapped object */
@@ -27,6 +27,8 @@ st_table* threads_table_create(void);
27
27
  thread_data_t* threads_table_lookup(void* profile, VALUE fiber);
28
28
  thread_data_t* threads_table_insert(void* profile, VALUE fiber);
29
29
  void threads_table_free(st_table* table);
30
+
31
+ thread_data_t* prof_get_thread(VALUE self);
30
32
  VALUE prof_thread_wrap(thread_data_t* thread);
31
33
  void prof_thread_mark(void* data);
32
34
 
@@ -1,3 +1,3 @@
1
1
  module RubyProf
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -8,7 +8,7 @@ require 'set'
8
8
 
9
9
  # -- Tests ----
10
10
  class FiberTest < TestCase
11
- def fiber_test
11
+ def enumerator_with_fibers
12
12
  @fiber_ids << Fiber.current.object_id
13
13
  enum = Enumerator.new do |yielder|
14
14
  [1,2].each do |x|
@@ -36,7 +36,7 @@ class FiberTest < TestCase
36
36
  end
37
37
 
38
38
  def test_fibers
39
- result = RubyProf.profile { fiber_test }
39
+ result = RubyProf.profile { enumerator_with_fibers }
40
40
 
41
41
  profiled_fiber_ids = result.threads.map(&:fiber_id)
42
42
  assert_equal(2, result.threads.length)
@@ -61,7 +61,7 @@ class FiberTest < TestCase
61
61
  assert_in_delta(0.33, method.children_time, 0.05)
62
62
 
63
63
  method = methods[1]
64
- assert_equal('FiberTest#fiber_test', method.full_name)
64
+ assert_equal('FiberTest#enumerator_with_fibers', method.full_name)
65
65
  assert_equal(1, method.called)
66
66
  assert_in_delta(0.33, method.total_time, 0.05)
67
67
  assert_in_delta(0, method.self_time, 0.05)
@@ -85,7 +85,7 @@ class FiberTest < TestCase
85
85
  assert_in_delta(0, method.children_time, 0.05)
86
86
 
87
87
  # Since these methods have such short times their order is a bit indeterminate
88
- method = methods.detect {|method| method.full_name == 'Class#new'}
88
+ method = methods.detect {|a_method| a_method.full_name == 'Class#new'}
89
89
  assert_equal('Class#new', method.full_name)
90
90
  assert_equal(1, method.called)
91
91
  assert_in_delta(0, method.total_time, 0.05)
@@ -94,16 +94,16 @@ class FiberTest < TestCase
94
94
  assert_in_delta(0, method.children_time, 0.05)
95
95
 
96
96
  if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.5.0')
97
- method = methods.detect {|method| method.full_name == 'Set#<<'}
98
- assert_equal('Set#<<', method.full_name)
99
- assert_equal(1, method.called)
100
- assert_in_delta(0, method.total_time, 0.05)
101
- assert_in_delta(0, method.self_time, 0.05)
102
- assert_in_delta(0, method.wait_time, 0.05)
103
- assert_in_delta(0, method.children_time, 0.05)
97
+ method = methods.detect {|a_method| a_method.full_name == 'Set#<<'}
98
+ assert_equal('Set#<<', method.full_name)
99
+ assert_equal(1, method.called)
100
+ assert_in_delta(0, method.total_time, 0.05)
101
+ assert_in_delta(0, method.self_time, 0.05)
102
+ assert_in_delta(0, method.wait_time, 0.05)
103
+ assert_in_delta(0, method.children_time, 0.05)
104
104
  end
105
105
 
106
- method = methods.detect {|method| method.full_name == 'Module#==='}
106
+ method = methods.detect {|a_method| a_method.full_name == 'Module#==='}
107
107
  assert_equal('Module#===', method.full_name)
108
108
  assert_equal(1, method.called)
109
109
  assert_in_delta(0, method.total_time, 0.05)
@@ -111,7 +111,7 @@ class FiberTest < TestCase
111
111
  assert_in_delta(0, method.wait_time, 0.05)
112
112
  assert_in_delta(0, method.children_time, 0.05)
113
113
 
114
- method = methods.detect {|method| method.full_name == 'Kernel#object_id'}
114
+ method = methods.detect {|a_method| a_method.full_name == 'Kernel#object_id'}
115
115
  assert_equal('Kernel#object_id', method.full_name)
116
116
  assert_equal(1, method.called)
117
117
  assert_in_delta(0, method.total_time, 0.05)
@@ -119,7 +119,7 @@ class FiberTest < TestCase
119
119
  assert_in_delta(0, method.wait_time, 0.05)
120
120
  assert_in_delta(0, method.children_time, 0.05)
121
121
 
122
- method = methods.detect {|method| method.full_name == '<Class::Fiber>#current'}
122
+ method = methods.detect {|a_method| a_method.full_name == '<Class::Fiber>#current'}
123
123
  assert_equal('<Class::Fiber>#current', method.full_name)
124
124
  assert_equal(1, method.called)
125
125
  assert_in_delta(0, method.total_time, 0.05)
@@ -127,7 +127,7 @@ class FiberTest < TestCase
127
127
  assert_in_delta(0, method.wait_time, 0.05)
128
128
  assert_in_delta(0, method.children_time, 0.05)
129
129
 
130
- method = methods.detect {|method| method.full_name == 'Exception#exception'}
130
+ method = methods.detect {|a_method| a_method.full_name == 'Exception#exception'}
131
131
  assert_equal('Exception#exception', method.full_name)
132
132
  assert_equal(1, method.called)
133
133
  assert_in_delta(0, method.total_time, 0.05)
@@ -135,7 +135,7 @@ class FiberTest < TestCase
135
135
  assert_in_delta(0, method.wait_time, 0.05)
136
136
  assert_in_delta(0, method.children_time, 0.05)
137
137
 
138
- method = methods.detect {|method| method.full_name == 'Exception#backtrace'}
138
+ method = methods.detect {|a_method| a_method.full_name == 'Exception#backtrace'}
139
139
  assert_equal('Exception#backtrace', method.full_name)
140
140
  assert_equal(1, method.called)
141
141
  assert_in_delta(0, method.total_time, 0.05)
@@ -143,7 +143,7 @@ class FiberTest < TestCase
143
143
  assert_in_delta(0, method.wait_time, 0.05)
144
144
  assert_in_delta(0, method.children_time, 0.05)
145
145
 
146
- method = methods.detect {|method| method.full_name == 'Enumerator#initialize'}
146
+ method = methods.detect {|a_method| a_method.full_name == 'Enumerator#initialize'}
147
147
  assert_equal('Enumerator#initialize', method.full_name)
148
148
  assert_equal(1, method.called)
149
149
  assert_in_delta(0, method.total_time, 0.05)
@@ -200,7 +200,7 @@ class FiberTest < TestCase
200
200
  assert_in_delta(0, method.children_time, 0.05)
201
201
 
202
202
  # Since these methods have such short times their order is a bit indeterminate
203
- method = methods.detect {|method| method.full_name == 'Exception#initialize'}
203
+ method = methods.detect {|a_method| a_method.full_name == 'Exception#initialize'}
204
204
  assert_equal('Exception#initialize', method.full_name)
205
205
  assert_equal(1, method.called)
206
206
  assert_in_delta(0, method.total_time, 0.05)
@@ -209,7 +209,7 @@ class FiberTest < TestCase
209
209
  assert_in_delta(0, method.children_time, 0.05)
210
210
 
211
211
  if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.5.0')
212
- method = methods.detect {|method| method.full_name == 'Set#<<'}
212
+ method = methods.detect {|a_method| a_method.full_name == 'Set#<<'}
213
213
  assert_equal('Set#<<', method.full_name)
214
214
  assert_equal(2, method.called)
215
215
  assert_in_delta(0, method.total_time, 0.05)
@@ -218,7 +218,7 @@ class FiberTest < TestCase
218
218
  assert_in_delta(0, method.children_time, 0.05)
219
219
  end
220
220
 
221
- method = methods.detect {|method| method.full_name == 'Kernel#object_id'}
221
+ method = methods.detect {|a_method| a_method.full_name == 'Kernel#object_id'}
222
222
  assert_equal('Kernel#object_id', method.full_name)
223
223
  assert_equal(2, method.called)
224
224
  assert_in_delta(0, method.total_time, 0.05)
@@ -226,7 +226,7 @@ class FiberTest < TestCase
226
226
  assert_in_delta(0, method.wait_time, 0.05)
227
227
  assert_in_delta(0, method.children_time, 0.05)
228
228
 
229
- method = methods.detect {|method| method.full_name == 'Enumerator::Yielder#yield'}
229
+ method = methods.detect {|a_method| a_method.full_name == 'Enumerator::Yielder#yield'}
230
230
  assert_equal('Enumerator::Yielder#yield', method.full_name)
231
231
  assert_equal(2, method.called)
232
232
  assert_in_delta(0, method.total_time, 0.05)
@@ -234,27 +234,18 @@ class FiberTest < TestCase
234
234
  assert_in_delta(0, method.wait_time, 0.05)
235
235
  assert_in_delta(0, method.children_time, 0.05)
236
236
 
237
- method = methods.detect {|method| method.full_name == '<Class::Fiber>#current'}
237
+ method = methods.detect {|a_method| a_method.full_name == '<Class::Fiber>#current'}
238
238
  assert_equal('<Class::Fiber>#current', method.full_name)
239
239
  assert_equal(2, method.called)
240
240
  assert_in_delta(0, method.total_time, 0.05)
241
241
  assert_in_delta(0, method.self_time, 0.05)
242
242
  assert_in_delta(0, method.wait_time, 0.05)
243
243
  assert_in_delta(0, method.children_time, 0.05)
244
-
245
- #if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0')
246
- # method = methods.detect {|method| method.full_name == 'Numeric#eql?'}
247
- # assert_equal('Numeric#eql?', method.full_name)
248
- # assert_equal(1, method.called)
249
- # assert_in_delta(0, method.total_time, 0.05)
250
- # assert_in_delta(0, method.self_time, 0.05)
251
- # assert_in_delta(0, method.wait_time, 0.05)
252
- # assert_in_delta(0, method.children_time, 0.05)
253
- #end
254
244
  end
255
245
 
256
246
  def test_merged_fibers
257
- result = RubyProf.profile(merge_fibers: true) { fiber_test }
247
+ result = RubyProf.profile(merge_fibers: true) { enumerator_with_fibers }
248
+
258
249
  assert_equal(1, result.threads.length)
259
250
 
260
251
  thread = result.threads.first
@@ -2,6 +2,7 @@
2
2
  # encoding: UTF-8
3
3
 
4
4
  require File.expand_path('../test_helper', __FILE__)
5
+ Minitest::Test.i_suck_and_my_tests_are_order_dependent!
5
6
 
6
7
  class GcTest < TestCase
7
8
  def setup
@@ -29,44 +30,21 @@ class GcTest < TestCase
29
30
  end
30
31
 
31
32
  threads.each do |thread|
32
- error = assert_raises(RuntimeError) do
33
- thread.id
34
- end
35
- assert_match(/has already been freed/, error.message)
33
+ refute_nil(thread.id)
36
34
  end
37
- assert(true)
38
35
  end
39
36
 
40
- def test_hold_onto_root_call_info
41
- call_trees = 5.times.reduce(Array.new) do |array, i|
42
- array.concat(run_profile.threads.map(&:call_tree))
43
- array
44
- end
45
-
46
- call_trees.each do |call_tree|
47
- error = assert_raises(RuntimeError) do
48
- call_tree.source_file
49
- end
50
- assert_match(/has already been freed/, error.message)
51
- end
52
- assert(true)
53
- end
54
37
 
55
38
  def test_hold_onto_method
56
39
  methods = 5.times.reduce(Array.new) do |array, i|
57
40
  profile = run_profile
58
- methods_2 = profile.threads.map(&:methods).flatten
59
- array.concat(methods_2)
41
+ array.concat(profile.threads.map(&:methods).flatten)
60
42
  array
61
43
  end
62
44
 
63
45
  methods.each do |method|
64
- error = assert_raises(RuntimeError) do
65
- method.method_name
66
- end
67
- assert_match(/has already been freed/, error.message)
46
+ refute_nil(method.method_name)
68
47
  end
69
- assert(true)
70
48
  end
71
49
 
72
50
  def test_hold_onto_call_trees
@@ -78,12 +56,8 @@ class GcTest < TestCase
78
56
  end
79
57
 
80
58
  method_call_infos.each do |call_trees|
81
- error = assert_raises(RuntimeError) do
82
- call_trees.call_trees
83
- end
84
- assert_match(/has already been freed/, error.message)
59
+ refute_empty(call_trees.call_trees)
85
60
  end
86
- assert(true)
87
61
  end
88
62
 
89
63
  def test_hold_onto_measurements
@@ -98,8 +72,19 @@ class GcTest < TestCase
98
72
  error = assert_raises(RuntimeError) do
99
73
  measurement.total_time
100
74
  end
101
- assert_match(/has already been freed/, error.message)
75
+ assert_match(/RubyProf::Measurement instance has already been freed/, error.message)
102
76
  end
103
77
  assert(true)
104
78
  end
79
+
80
+ def test_hold_onto_root_call_tree
81
+ call_trees = 5.times.reduce(Array.new) do |array, i|
82
+ array.concat(run_profile.threads.map(&:call_tree))
83
+ array
84
+ end
85
+
86
+ call_trees.each do |call_tree|
87
+ refute_nil(call_tree.source_file)
88
+ end
89
+ end
105
90
  end
@@ -31,7 +31,7 @@ class InverseCallTreeTest < TestCase
31
31
  def test_inverse
32
32
  method_name = "method_#{INVERSE_DEPTH - 1}"
33
33
  self.send(method_name.to_sym)
34
- result = profile = RubyProf.stop
34
+ profile = RubyProf.stop
35
35
 
36
36
  assert_equal(1, profile.threads.count)
37
37
 
@@ -6,14 +6,14 @@ require File.expand_path('../test_helper', __FILE__)
6
6
  class LineNumbers
7
7
  def method_1
8
8
  method_2
9
- filler = 1
9
+ _filler = 1
10
10
  method_3
11
11
  end
12
12
 
13
13
  def method_2
14
- filler = 1
14
+ _filler = 1
15
15
  2.times do |i|
16
- filler = 2
16
+ _filler = 2
17
17
  method_3
18
18
  end
19
19
  end
@@ -396,14 +396,14 @@ class MeasureWallTimeTest < TestCase
396
396
  assert_in_delta(0.0, methods[2].children_time, 0.03)
397
397
 
398
398
  if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7')
399
- method = methods.detect {|method| method.full_name == '<Class::RubyProf::C3>#instance'}
399
+ method = methods.detect {|a_method| a_method.full_name == '<Class::RubyProf::C3>#instance'}
400
400
  assert_equal('<Class::RubyProf::C3>#instance', method.full_name)
401
401
  assert_in_delta(0.0, method.total_time, 0.03)
402
402
  assert_in_delta(0.0, method.wait_time, 0.03)
403
403
  assert_in_delta(0.0, method.self_time, 0.03)
404
404
  assert_in_delta(0.0, method.children_time, 0.03)
405
405
  else
406
- method = methods.detect {|method| method.full_name == 'Singleton::SingletonClassMethods#instance'}
406
+ method = methods.detect {|a_method| a_method.full_name == 'Singleton::SingletonClassMethods#instance'}
407
407
  assert_equal('Singleton::SingletonClassMethods#instance', method.full_name)
408
408
  assert_in_delta(0.0, method.total_time, 0.03)
409
409
  assert_in_delta(0.0, method.wait_time, 0.03)
@@ -411,21 +411,21 @@ class MeasureWallTimeTest < TestCase
411
411
  assert_in_delta(0.0, method.children_time, 0.03)
412
412
  end
413
413
 
414
- method = methods.detect {|method| method.full_name == 'Thread::Mutex#synchronize'}
414
+ method = methods.detect {|a_method| a_method.full_name == 'Thread::Mutex#synchronize'}
415
415
  assert_equal('Thread::Mutex#synchronize', method.full_name)
416
416
  assert_in_delta(0.0, method.total_time, 0.03)
417
417
  assert_in_delta(0.0, method.wait_time, 0.03)
418
418
  assert_in_delta(0.0, method.self_time, 0.03)
419
419
  assert_in_delta(0.0, method.children_time, 0.03)
420
420
 
421
- method = methods.detect {|method| method.full_name == 'Class#new'}
421
+ method = methods.detect {|a_method| a_method.full_name == 'Class#new'}
422
422
  assert_equal('Class#new', method.full_name)
423
423
  assert_in_delta(0.0, method.total_time, 0.03)
424
424
  assert_in_delta(0.0, method.wait_time, 0.03)
425
425
  assert_in_delta(0.0, method.self_time, 0.03)
426
426
  assert_in_delta(0.0, method.children_time, 0.03)
427
427
 
428
- method = methods.detect {|method| method.full_name == 'BasicObject#initialize'}
428
+ method = methods.detect {|a_method| a_method.full_name == 'BasicObject#initialize'}
429
429
  assert_equal('BasicObject#initialize', method.full_name)
430
430
  assert_in_delta(0.0, method.total_time, 0.03)
431
431
  assert_in_delta(0.0, method.wait_time, 0.03)
@@ -72,7 +72,7 @@ class UniqueCallPathTest < TestCase
72
72
  end
73
73
  refute_nil(call_info_a)
74
74
 
75
- children_of_a = call_info_a.children.inject(Array.new) do |array, c|
75
+ _children_of_a = call_info_a.children.inject(Array.new) do |array, c|
76
76
  if c.parent.eql?(call_info_a)
77
77
  array << c
78
78
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-prof
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shugo Maeda, Charlie Savage, Roger Pack, Stefan Kaes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-23 00:00:00.000000000 Z
11
+ date: 2020-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -177,7 +177,7 @@ metadata:
177
177
  bug_tracker_uri: https://github.com/ruby-prof/ruby-prof/issues
178
178
  changelog_uri: https://github.com/ruby-prof/ruby-prof/blob/master/CHANGES
179
179
  documentation_uri: https://ruby-prof.github.io/
180
- source_code_uri: https://github.com/ruby-prof/ruby-prof/tree/v1.2.0
180
+ source_code_uri: https://github.com/ruby-prof/ruby-prof/tree/v1.3.0
181
181
  post_install_message:
182
182
  rdoc_options: []
183
183
  require_paths: