ruby-prof 1.6.1-x64-mingw-ucrt → 1.6.3-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,146 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+
6
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.1.0')
7
+
8
+ require_relative './scheduler'
9
+
10
+ # -- Tests ----
11
+ class MergeTest < TestCase
12
+ def worker1
13
+ sleep(0.5)
14
+ end
15
+
16
+ def worker2
17
+ sleep(0.5)
18
+ sleep(0.5)
19
+ end
20
+
21
+ def worker3
22
+ sleep(0.5)
23
+ end
24
+
25
+ def concurrency_single_worker
26
+ scheduler = Scheduler.new
27
+ Fiber.set_scheduler(scheduler)
28
+
29
+ 3.times do
30
+ Fiber.schedule do
31
+ worker1
32
+ end
33
+ end
34
+ Fiber.scheduler.close
35
+ end
36
+
37
+ def concurrency_multiple_workers
38
+ scheduler = Scheduler.new
39
+ Fiber.set_scheduler(scheduler)
40
+
41
+ 3.times do |i|
42
+ Fiber.schedule do
43
+ method = "worker#{i + 1}".to_sym
44
+ send(method)
45
+ end
46
+ end
47
+ Fiber.scheduler.close
48
+ end
49
+
50
+ def test_single_worker_unmerged
51
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) { concurrency_single_worker }
52
+ assert_equal(4, result.threads.size)
53
+
54
+ thread = result.threads[0]
55
+ assert_in_delta(0.5, thread.call_tree.target.total_time, 0.1)
56
+ assert_in_delta(0.0, thread.call_tree.target.self_time, 0.1)
57
+ assert_in_delta(0.0, thread.call_tree.target.wait_time, 0.1)
58
+ assert_in_delta(0.5, thread.call_tree.target.children_time, 0.1)
59
+
60
+ thread = result.threads[1]
61
+ assert_in_delta(0.5, thread.call_tree.target.total_time, 0.1)
62
+ assert_in_delta(0.0, thread.call_tree.target.self_time, 0.1)
63
+ assert_in_delta(0.0, thread.call_tree.target.wait_time, 0.1)
64
+ assert_in_delta(0.5, thread.call_tree.target.children_time, 0.1)
65
+
66
+ thread = result.threads[2]
67
+ assert_in_delta(0.5, thread.call_tree.target.total_time, 0.1)
68
+ assert_in_delta(0.0, thread.call_tree.target.self_time, 0.1)
69
+ assert_in_delta(0.0, thread.call_tree.target.wait_time, 0.1)
70
+ assert_in_delta(0.5, thread.call_tree.target.children_time, 0.1)
71
+
72
+ thread = result.threads[3]
73
+ assert_in_delta(0.5, thread.call_tree.target.total_time, 0.1)
74
+ assert_in_delta(0.0, thread.call_tree.target.self_time, 0.1)
75
+ assert_in_delta(0.0, thread.call_tree.target.wait_time, 0.1)
76
+ assert_in_delta(0.5, thread.call_tree.target.children_time, 0.1)
77
+ end
78
+
79
+ def test_single_worker_merged
80
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) { concurrency_single_worker }
81
+ result.merge!
82
+
83
+ assert_equal(2, result.threads.size)
84
+
85
+ thread = result.threads[0]
86
+ assert_in_delta(0.5, thread.call_tree.target.total_time, 0.1)
87
+ assert_in_delta(0.0, thread.call_tree.target.self_time, 0.1)
88
+ assert_in_delta(0.0, thread.call_tree.target.wait_time, 0.1)
89
+ assert_in_delta(0.5, thread.call_tree.target.children_time, 0.1)
90
+
91
+ thread = result.threads[1]
92
+ assert_in_delta(1.5, thread.call_tree.target.total_time, 0.1)
93
+ assert_in_delta(0.0, thread.call_tree.target.self_time, 0.1)
94
+ assert_in_delta(0.0, thread.call_tree.target.wait_time, 0.1)
95
+ assert_in_delta(1.5, thread.call_tree.target.children_time, 0.1)
96
+ end
97
+
98
+ def test_multiple_workers_unmerged
99
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) { concurrency_multiple_workers }
100
+ assert_equal(4, result.threads.count)
101
+
102
+ thread = result.threads[0]
103
+ assert_in_delta(1.0, thread.call_tree.target.total_time, 0.1)
104
+ assert_in_delta(0.0, thread.call_tree.target.self_time, 0.1)
105
+ assert_in_delta(0.0, thread.call_tree.target.wait_time, 0.1)
106
+ assert_in_delta(1.0, thread.call_tree.target.children_time, 0.1)
107
+
108
+ thread = result.threads[1]
109
+ assert_in_delta(1.0, thread.call_tree.target.total_time, 0.1)
110
+ assert_in_delta(0.0, thread.call_tree.target.self_time, 0.1)
111
+ assert_in_delta(0.5, thread.call_tree.target.wait_time, 0.1)
112
+ assert_in_delta(0.5, thread.call_tree.target.children_time, 0.1)
113
+
114
+ thread = result.threads[2]
115
+ assert_in_delta(1.0, thread.call_tree.target.total_time, 0.1)
116
+ assert_in_delta(0.0, thread.call_tree.target.self_time, 0.1)
117
+ assert_in_delta(0.0, thread.call_tree.target.wait_time, 0.1)
118
+ assert_in_delta(1.0, thread.call_tree.target.children_time, 0.1)
119
+
120
+ thread = result.threads[3]
121
+ assert_in_delta(1.0, thread.call_tree.target.total_time, 0.1)
122
+ assert_in_delta(0.0, thread.call_tree.target.self_time, 0.1)
123
+ assert_in_delta(0.5, thread.call_tree.target.wait_time, 0.1)
124
+ assert_in_delta(0.5, thread.call_tree.target.children_time, 0.1)
125
+ end
126
+
127
+ def test_multiple_workers_merged
128
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) { concurrency_multiple_workers }
129
+ result.merge!
130
+
131
+ assert_equal(2, result.threads.count)
132
+
133
+ thread = result.threads[0]
134
+ assert_in_delta(1.0, thread.call_tree.target.total_time, 0.1)
135
+ assert_in_delta(0.0, thread.call_tree.target.self_time, 0.1)
136
+ assert_in_delta(0.0, thread.call_tree.target.wait_time, 0.1)
137
+ assert_in_delta(1.0, thread.call_tree.target.children_time, 0.1)
138
+
139
+ thread = result.threads[1]
140
+ assert_in_delta(3.0, thread.call_tree.target.total_time, 0.1)
141
+ assert_in_delta(0.0, thread.call_tree.target.self_time, 0.1)
142
+ assert_in_delta(1.0, thread.call_tree.target.wait_time, 0.1)
143
+ assert_in_delta(2.0, thread.call_tree.target.children_time, 0.1)
144
+ end
145
+ end
146
+ end
data/test/scheduler.rb CHANGED
@@ -14,6 +14,14 @@ rescue LoadError
14
14
  end
15
15
 
16
16
  class Scheduler
17
+ experimental = Warning[:experimental]
18
+ begin
19
+ Warning[:experimental] = false
20
+ IO::Buffer.new(0)
21
+ ensure
22
+ Warning[:experimental] = experimental
23
+ end
24
+
17
25
  def initialize
18
26
  @readable = {}
19
27
  @writable = {}
@@ -199,6 +207,7 @@ class Scheduler
199
207
  # Used for Kernel#sleep and Thread::Mutex#sleep
200
208
  def kernel_sleep(duration = nil)
201
209
  # $stderr.puts [__method__, duration, Fiber.current].inspect
210
+
202
211
  self.block(:sleep, duration)
203
212
 
204
213
  return true
data/test/test_helper.rb CHANGED
@@ -1,6 +1,13 @@
1
1
  # encoding: UTF-8
2
2
 
3
+ # To make testing/debugging easier test within this source tree versus an installed gem
3
4
  require 'bundler/setup'
5
+
6
+ # Add ext directory to load path to make it easier to test locally built extensions
7
+ ext_path = File.expand_path(File.join(__dir__, '..', 'ext', 'ruby_prof'))
8
+ $LOAD_PATH.unshift(File.expand_path(ext_path))
9
+
10
+ # Now load code
4
11
  require 'ruby-prof'
5
12
 
6
13
  # Disable minitest parallel tests. The problem is the thread switching will change test results
data/test/thread_test.rb CHANGED
@@ -17,20 +17,87 @@ class ThreadTest < TestCase
17
17
  assert(thread)
18
18
  assert(thread.id)
19
19
  assert(thread.fiber_id)
20
+
21
+ assert_equal(1, thread.methods.size)
22
+ assert_same(method_info, thread.methods[0])
20
23
  end
21
24
 
22
25
  def test_merge
23
26
  call_tree_1 = create_call_tree_1
24
27
  thread_1 = RubyProf::Thread.new(call_tree_1, Thread.current, Fiber.current)
28
+ assert_equal(6, thread_1.methods.size)
25
29
 
26
30
  call_tree_2 = create_call_tree_2
27
31
  thread_2 = RubyProf::Thread.new(call_tree_2, Thread.current, Fiber.current)
32
+ assert_equal(6, thread_2.methods.size)
28
33
 
29
34
  thread_1.merge!(thread_2)
30
- assert_in_delta(11.6, thread_1.call_tree.total_time, 0.00001)
31
- assert_in_delta(0, thread_1.call_tree.self_time, 0.00001)
32
- assert_in_delta(0.0, thread_1.call_tree.wait_time, 0.00001)
33
- assert_in_delta(11.6, thread_1.call_tree.children_time, 0.00001)
35
+ assert_equal(7, thread_1.methods.size)
36
+
37
+ # Method times
38
+ assert_in_delta(11.6, thread_1.methods[0].total_time, 0.00001) # root
39
+ assert_in_delta(4.1, thread_1.methods[1].total_time, 0.00001) # a
40
+ assert_in_delta(1.5, thread_1.methods[2].total_time, 0.00001) # aa
41
+ assert_in_delta(2.6, thread_1.methods[3].total_time, 0.00001) # ab
42
+ assert_in_delta(7.5, thread_1.methods[4].total_time, 0.00001) # b
43
+ assert_in_delta(6.6, thread_1.methods[5].total_time, 0.00001) # bb
44
+ assert_in_delta(0.9, thread_1.methods[6].total_time, 0.00001) # ba
45
+
46
+ # Root
47
+ call_tree = call_tree_1
48
+ assert_equal(:root, call_tree.target.method_name)
49
+ assert_in_delta(11.6, call_tree.total_time, 0.00001)
50
+ assert_in_delta(0, call_tree.self_time, 0.00001)
51
+ assert_in_delta(0.0, call_tree.wait_time, 0.00001)
52
+ assert_in_delta(11.6, call_tree.children_time, 0.00001)
53
+
54
+ # a
55
+ call_tree = call_tree_1.children[0]
56
+ assert_equal(:a, call_tree.target.method_name)
57
+ assert_in_delta(4.1, call_tree.total_time, 0.00001)
58
+ assert_in_delta(0, call_tree.self_time, 0.00001)
59
+ assert_in_delta(0.0, call_tree.wait_time, 0.00001)
60
+ assert_in_delta(4.1, call_tree.children_time, 0.00001)
61
+
62
+ # aa
63
+ call_tree = call_tree_1.children[0].children[0]
64
+ assert_equal(:aa, call_tree.target.method_name)
65
+ assert_in_delta(1.5, call_tree.total_time, 0.00001)
66
+ assert_in_delta(1.5, call_tree.self_time, 0.00001)
67
+ assert_in_delta(0.0, call_tree.wait_time, 0.00001)
68
+ assert_in_delta(0.0, call_tree.children_time, 0.00001)
69
+
70
+ # ab
71
+ call_tree = call_tree_1.children[0].children[1]
72
+ assert_equal(:ab, call_tree.target.method_name)
73
+ assert_in_delta(2.6, call_tree.total_time, 0.00001)
74
+ assert_in_delta(2.6, call_tree.self_time, 0.00001)
75
+ assert_in_delta(0.0, call_tree.wait_time, 0.00001)
76
+ assert_in_delta(0.0, call_tree.children_time, 0.00001)
77
+
78
+ # # b
79
+ # call_tree = call_tree_1.children[1]
80
+ # assert_equal(:b, call_tree.target.method_name)
81
+ # assert_in_delta(7.5, call_tree.total_time, 0.00001)
82
+ # assert_in_delta(0, call_tree.self_time, 0.00001)
83
+ # assert_in_delta(0.0, call_tree.wait_time, 0.00001)
84
+ # assert_in_delta(7.5, call_tree.children_time, 0.00001)
85
+
86
+ # bb
87
+ # call_tree = call_tree_1.children[1].children[0]
88
+ # assert_equal(:bb, call_tree.target.method_name)
89
+ # assert_in_delta(6.6, call_tree.total_time, 0.00001)
90
+ # assert_in_delta(6.6, call_tree.self_time, 0.00001)
91
+ # assert_in_delta(0.0, call_tree.wait_time, 0.00001)
92
+ # assert_in_delta(0.0, call_tree.children_time, 0.00001)
93
+
94
+ # ba
95
+ call_tree = call_tree_1.children[1].children[1]
96
+ assert_equal(:ba, call_tree.target.method_name)
97
+ assert_in_delta(0.9, call_tree.total_time, 0.00001)
98
+ assert_in_delta(0.7, call_tree.self_time, 0.00001)
99
+ assert_in_delta(0.2, call_tree.wait_time, 0.00001)
100
+ assert_in_delta(0.0, call_tree.children_time, 0.00001)
34
101
  end
35
102
 
36
103
  def test_thread_count
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.6.1
4
+ version: 1.6.3
5
5
  platform: x64-mingw-ucrt
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: 2023-02-21 00:00:00.000000000 Z
11
+ date: 2023-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -136,6 +136,7 @@ files:
136
136
  - test/measure_times.rb
137
137
  - test/measure_wall_time_test.rb
138
138
  - test/measurement_test.rb
139
+ - test/merge_test.rb
139
140
  - test/method_info_test.rb
140
141
  - test/multi_printer_test.rb
141
142
  - test/no_method_class_test.rb
@@ -167,7 +168,7 @@ metadata:
167
168
  bug_tracker_uri: https://github.com/ruby-prof/ruby-prof/issues
168
169
  changelog_uri: https://github.com/ruby-prof/ruby-prof/blob/master/CHANGES
169
170
  documentation_uri: https://ruby-prof.github.io/
170
- source_code_uri: https://github.com/ruby-prof/ruby-prof/tree/v1.6.1
171
+ source_code_uri: https://github.com/ruby-prof/ruby-prof/tree/v1.6.3
171
172
  post_install_message:
172
173
  rdoc_options: []
173
174
  require_paths:
@@ -183,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
184
  - !ruby/object:Gem::Version
184
185
  version: '0'
185
186
  requirements: []
186
- rubygems_version: 3.4.6
187
+ rubygems_version: 3.4.8
187
188
  signing_key:
188
189
  specification_version: 4
189
190
  summary: Fast Ruby profiler