ruby-prof 1.5.0-x64-mingw-ucrt → 1.6.2-x64-mingw-ucrt
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +19 -0
- data/bin/ruby-prof +105 -87
- data/ext/ruby_prof/rp_allocation.c +136 -81
- data/ext/ruby_prof/rp_allocation.h +8 -6
- data/ext/ruby_prof/rp_call_tree.c +502 -457
- data/ext/ruby_prof/rp_call_tree.h +47 -44
- data/ext/ruby_prof/rp_call_trees.c +1 -1
- data/ext/ruby_prof/rp_measurement.c +10 -3
- data/ext/ruby_prof/rp_method.c +86 -79
- data/ext/ruby_prof/rp_method.h +63 -62
- data/ext/ruby_prof/rp_profile.c +933 -948
- data/ext/ruby_prof/rp_profile.h +1 -0
- data/ext/ruby_prof/rp_thread.c +433 -410
- data/ext/ruby_prof/rp_thread.h +39 -39
- data/ext/ruby_prof/vc/ruby_prof.vcxproj +6 -3
- data/lib/3.1/ruby_prof.so +0 -0
- data/lib/3.2/ruby_prof.so +0 -0
- data/lib/ruby-prof/compatibility.rb +14 -0
- data/lib/ruby-prof/printers/abstract_printer.rb +2 -1
- data/lib/ruby-prof/printers/call_tree_printer.rb +1 -1
- data/lib/ruby-prof/printers/multi_printer.rb +17 -17
- data/lib/ruby-prof/profile.rb +70 -70
- data/lib/ruby-prof/rack.rb +31 -21
- data/lib/ruby-prof/version.rb +1 -1
- data/test/abstract_printer_test.rb +1 -0
- data/test/alias_test.rb +6 -11
- data/test/call_tree_test.rb +94 -197
- data/test/call_tree_visitor_test.rb +1 -6
- data/test/call_trees_test.rb +2 -2
- data/test/{basic_test.rb → compatibility_test.rb} +8 -2
- data/test/duplicate_names_test.rb +1 -1
- data/test/dynamic_method_test.rb +1 -6
- data/test/enumerable_test.rb +1 -1
- data/test/exceptions_test.rb +2 -2
- data/test/exclude_methods_test.rb +3 -8
- data/test/exclude_threads_test.rb +4 -9
- data/test/fiber_test.rb +2 -58
- data/test/gc_test.rb +2 -2
- data/test/inverse_call_tree_test.rb +33 -34
- data/test/line_number_test.rb +1 -1
- data/test/marshal_test.rb +3 -3
- data/test/measure_allocations_test.rb +8 -17
- data/test/measure_memory_test.rb +3 -12
- data/test/measure_process_time_test.rb +32 -36
- data/test/measure_wall_time_test.rb +176 -181
- data/test/merge_test.rb +146 -0
- data/test/multi_printer_test.rb +0 -5
- data/test/no_method_class_test.rb +1 -1
- data/test/pause_resume_test.rb +12 -16
- data/test/printer_call_stack_test.rb +2 -2
- data/test/printer_call_tree_test.rb +2 -2
- data/test/printer_flat_test.rb +1 -1
- data/test/printer_graph_html_test.rb +2 -2
- data/test/printer_graph_test.rb +2 -2
- data/test/printers_test.rb +14 -20
- data/test/printing_recursive_graph_test.rb +2 -2
- data/test/recursive_test.rb +2 -7
- data/test/scheduler.rb +9 -0
- data/test/singleton_test.rb +1 -1
- data/test/stack_printer_test.rb +5 -8
- data/test/start_stop_test.rb +11 -14
- data/test/test_helper.rb +7 -0
- data/test/thread_test.rb +84 -19
- data/test/unique_call_path_test.rb +4 -4
- data/test/yarv_test.rb +3 -3
- metadata +6 -5
data/test/merge_test.rb
ADDED
@@ -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/multi_printer_test.rb
CHANGED
@@ -27,11 +27,6 @@ class MSTPT
|
|
27
27
|
end
|
28
28
|
|
29
29
|
class MultiPrinterTest < TestCase
|
30
|
-
def setup
|
31
|
-
# Need to use wall time for this test due to the sleep calls
|
32
|
-
RubyProf::measure_mode = RubyProf::WALL_TIME
|
33
|
-
end
|
34
|
-
|
35
30
|
def test_refuses_io_objects
|
36
31
|
# we don't need a real profile for this test
|
37
32
|
p = RubyProf::MultiPrinter.new nil
|
data/test/pause_resume_test.rb
CHANGED
@@ -5,26 +5,22 @@ require File.expand_path('../test_helper', __FILE__)
|
|
5
5
|
require_relative 'measure_times'
|
6
6
|
|
7
7
|
class PauseResumeTest < TestCase
|
8
|
-
def setup
|
9
|
-
# Need to use wall time for this test due to the sleep calls
|
10
|
-
RubyProf::measure_mode = RubyProf::WALL_TIME
|
11
|
-
end
|
12
|
-
|
13
8
|
def test_pause_resume
|
9
|
+
profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
|
14
10
|
# Measured
|
15
|
-
|
11
|
+
profile.start
|
16
12
|
RubyProf::C1.sleep_wait
|
17
13
|
|
18
14
|
# Not measured
|
19
|
-
|
15
|
+
profile.pause
|
20
16
|
sleep 1
|
21
17
|
RubyProf::C1.sleep_wait
|
22
18
|
|
23
19
|
# Measured
|
24
|
-
|
20
|
+
profile.resume
|
25
21
|
RubyProf::C1.sleep_wait
|
26
22
|
|
27
|
-
result =
|
23
|
+
result = profile.stop
|
28
24
|
|
29
25
|
# Length should be 3:
|
30
26
|
# PauseResumeTest#test_pause_resume
|
@@ -59,7 +55,7 @@ class PauseResumeTest < TestCase
|
|
59
55
|
|
60
56
|
# pause/resume in the same frame
|
61
57
|
def test_pause_resume_1
|
62
|
-
profile = RubyProf::Profile.new
|
58
|
+
profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
|
63
59
|
|
64
60
|
profile.start
|
65
61
|
method_1a
|
@@ -79,7 +75,7 @@ class PauseResumeTest < TestCase
|
|
79
75
|
|
80
76
|
# pause in parent frame, resume in child
|
81
77
|
def test_pause_resume_2
|
82
|
-
profile = RubyProf::Profile.new
|
78
|
+
profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
|
83
79
|
|
84
80
|
profile.start
|
85
81
|
method_2a
|
@@ -96,7 +92,7 @@ class PauseResumeTest < TestCase
|
|
96
92
|
|
97
93
|
# pause in child frame, resume in parent
|
98
94
|
def test_pause_resume_3
|
99
|
-
profile = RubyProf::Profile.new
|
95
|
+
profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
|
100
96
|
|
101
97
|
profile.start
|
102
98
|
method_3a(profile)
|
@@ -120,7 +116,7 @@ class PauseResumeTest < TestCase
|
|
120
116
|
end
|
121
117
|
|
122
118
|
def test_pause_seq
|
123
|
-
profile = RubyProf::Profile.new
|
119
|
+
profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
|
124
120
|
profile.start ; assert !profile.paused?
|
125
121
|
profile.pause ; assert profile.paused?
|
126
122
|
profile.resume; assert !profile.paused?
|
@@ -132,7 +128,7 @@ class PauseResumeTest < TestCase
|
|
132
128
|
end
|
133
129
|
|
134
130
|
def test_pause_block
|
135
|
-
profile = RubyProf::Profile.new
|
131
|
+
profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
|
136
132
|
profile.start
|
137
133
|
profile.pause
|
138
134
|
assert profile.paused?
|
@@ -151,7 +147,7 @@ class PauseResumeTest < TestCase
|
|
151
147
|
end
|
152
148
|
|
153
149
|
def test_pause_block_with_error
|
154
|
-
profile = RubyProf::Profile.new
|
150
|
+
profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
|
155
151
|
profile.start
|
156
152
|
profile.pause
|
157
153
|
assert profile.paused?
|
@@ -167,7 +163,7 @@ class PauseResumeTest < TestCase
|
|
167
163
|
end
|
168
164
|
|
169
165
|
def test_resume_when_not_paused
|
170
|
-
profile = RubyProf::Profile.new
|
166
|
+
profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
|
171
167
|
profile.start ; assert !profile.paused?
|
172
168
|
profile.resume; assert !profile.paused?
|
173
169
|
profile.stop ; assert !profile.paused?
|
@@ -9,9 +9,9 @@ require_relative 'prime'
|
|
9
9
|
# -- Tests ----
|
10
10
|
class PrinterCallStackTest < TestCase
|
11
11
|
def setup
|
12
|
+
super
|
12
13
|
# WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
|
13
|
-
RubyProf::measure_mode
|
14
|
-
@result = RubyProf.profile do
|
14
|
+
@result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
|
15
15
|
run_primes(1000, 5000)
|
16
16
|
end
|
17
17
|
end
|
@@ -9,9 +9,9 @@ require_relative 'prime'
|
|
9
9
|
# -- Tests ----
|
10
10
|
class PrinterCallTreeTest < TestCase
|
11
11
|
def setup
|
12
|
+
super
|
12
13
|
# WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
|
13
|
-
RubyProf::measure_mode
|
14
|
-
@result = RubyProf.profile do
|
14
|
+
@result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
|
15
15
|
run_primes(1000, 5000)
|
16
16
|
end
|
17
17
|
end
|
data/test/printer_flat_test.rb
CHANGED
@@ -10,7 +10,7 @@ require_relative 'prime'
|
|
10
10
|
# -- Tests ----
|
11
11
|
class PrinterFlatTest < TestCase
|
12
12
|
def run_profile
|
13
|
-
RubyProf.profile(:measure_mode => RubyProf::WALL_TIME) do
|
13
|
+
RubyProf::Profile.profile(:measure_mode => RubyProf::WALL_TIME) do
|
14
14
|
run_primes(1000, 5000)
|
15
15
|
end
|
16
16
|
end
|
@@ -9,9 +9,9 @@ require_relative 'prime'
|
|
9
9
|
# -- Tests ----
|
10
10
|
class PrinterGraphHtmlTest < TestCase
|
11
11
|
def setup
|
12
|
+
super
|
12
13
|
# WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
|
13
|
-
RubyProf::measure_mode
|
14
|
-
@result = RubyProf.profile do
|
14
|
+
@result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
|
15
15
|
run_primes(1000, 5000)
|
16
16
|
end
|
17
17
|
end
|
data/test/printer_graph_test.rb
CHANGED
@@ -9,9 +9,9 @@ require_relative 'prime'
|
|
9
9
|
# -- Tests ----
|
10
10
|
class PrinterGraphTest < TestCase
|
11
11
|
def setup
|
12
|
+
super
|
12
13
|
# WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
|
13
|
-
RubyProf::measure_mode
|
14
|
-
@result = RubyProf.profile do
|
14
|
+
@result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
|
15
15
|
run_primes(1000, 5000)
|
16
16
|
end
|
17
17
|
end
|
data/test/printers_test.rb
CHANGED
@@ -10,9 +10,9 @@ require_relative 'prime'
|
|
10
10
|
# -- Tests ----
|
11
11
|
class PrintersTest < TestCase
|
12
12
|
def setup
|
13
|
+
super
|
13
14
|
# WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
|
14
|
-
RubyProf::measure_mode
|
15
|
-
@result = RubyProf.profile do
|
15
|
+
@result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
|
16
16
|
run_primes(1000, 5000)
|
17
17
|
end
|
18
18
|
end
|
@@ -24,7 +24,7 @@ class PrintersTest < TestCase
|
|
24
24
|
printer.print(output)
|
25
25
|
|
26
26
|
printer = RubyProf::CallTreePrinter.new(@result)
|
27
|
-
printer.print()
|
27
|
+
printer.print(:path => Dir.tmpdir)
|
28
28
|
|
29
29
|
printer = RubyProf::FlatPrinter.new(@result)
|
30
30
|
printer.print(output)
|
@@ -37,25 +37,19 @@ class PrintersTest < TestCase
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def test_print_to_files
|
40
|
-
output_dir = 'tmp/examples2'
|
41
|
-
|
42
|
-
if ENV['SAVE_NEW_PRINTER_EXAMPLES']
|
43
|
-
output_dir = 'tmp/examples'
|
44
|
-
end
|
45
|
-
FileUtils.mkdir_p output_dir
|
46
|
-
|
47
40
|
printer = RubyProf::DotPrinter.new(@result)
|
48
|
-
File.open("#{
|
41
|
+
File.open("#{Dir.tmpdir}/graph.dot", "w") {|f| printer.print(f)}
|
49
42
|
|
50
43
|
printer = RubyProf::CallStackPrinter.new(@result)
|
51
|
-
File.open("#{
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
44
|
+
File.open("#{Dir.tmpdir}/stack.html", "w") {|f| printer.print(f, :application => "primes")}
|
45
|
+
|
46
|
+
printer = RubyProf::MultiPrinter.new(@result)
|
47
|
+
printer.print(:path => Dir.tmpdir, :profile => "multi", :application => "primes")
|
48
|
+
|
49
|
+
['graph.dot', 'multi.flat.txt', 'multi.graph.html', "multi.callgrind.out.#{$$}", 'multi.stack.html', 'stack.html'].each do |file_name|
|
50
|
+
file_path = File.join(Dir.tmpdir, file_name)
|
51
|
+
refute(File.empty?(file_path))
|
52
|
+
end
|
59
53
|
end
|
60
54
|
|
61
55
|
def test_refuses_io_objects
|
@@ -124,7 +118,7 @@ class PrintersTest < TestCase
|
|
124
118
|
end
|
125
119
|
|
126
120
|
def test_all_with_small_percentiles
|
127
|
-
result = RubyProf.profile do
|
121
|
+
result = RubyProf::Profile.profile do
|
128
122
|
sleep 2
|
129
123
|
do_nothing
|
130
124
|
end
|
@@ -63,9 +63,9 @@ Sort by:
|
|
63
63
|
|
64
64
|
class PrintingRecursiveGraphTest < TestCase
|
65
65
|
def setup
|
66
|
+
super
|
66
67
|
# WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
|
67
|
-
RubyProf::measure_mode
|
68
|
-
@result = RubyProf.profile do
|
68
|
+
@result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
|
69
69
|
PRGT.run
|
70
70
|
end
|
71
71
|
end
|
data/test/recursive_test.rb
CHANGED
@@ -33,15 +33,10 @@ end
|
|
33
33
|
|
34
34
|
# -- Tests ----
|
35
35
|
class RecursiveTest < TestCase
|
36
|
-
def setup
|
37
|
-
# Need to use wall time for this test due to the sleep calls
|
38
|
-
RubyProf::measure_mode = RubyProf::WALL_TIME
|
39
|
-
end
|
40
|
-
|
41
36
|
include SimpleRecursion
|
42
37
|
|
43
38
|
def test_simple
|
44
|
-
result = RubyProf.profile do
|
39
|
+
result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
|
45
40
|
simple(1)
|
46
41
|
end
|
47
42
|
|
@@ -201,7 +196,7 @@ class RecursiveTest < TestCase
|
|
201
196
|
end
|
202
197
|
|
203
198
|
def test_cycle
|
204
|
-
result = RubyProf.profile do
|
199
|
+
result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
|
205
200
|
render
|
206
201
|
end
|
207
202
|
|
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/singleton_test.rb
CHANGED
data/test/stack_printer_test.rb
CHANGED
@@ -27,16 +27,12 @@ class STPT
|
|
27
27
|
end
|
28
28
|
|
29
29
|
class StackPrinterTest < TestCase
|
30
|
-
def setup
|
31
|
-
# Need to use wall time for this test due to the sleep calls
|
32
|
-
RubyProf::measure_mode = RubyProf::WALL_TIME
|
33
|
-
end
|
34
|
-
|
35
30
|
def test_stack_can_be_printed
|
36
31
|
start_time = Time.now
|
37
|
-
RubyProf.
|
38
|
-
|
39
|
-
|
32
|
+
result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
|
33
|
+
5.times{STPT.new.a}
|
34
|
+
end
|
35
|
+
|
40
36
|
end_time = Time.now
|
41
37
|
expected_time = end_time - start_time
|
42
38
|
|
@@ -50,6 +46,7 @@ class StackPrinterTest < TestCase
|
|
50
46
|
end
|
51
47
|
|
52
48
|
private
|
49
|
+
|
53
50
|
def print(result)
|
54
51
|
test = caller.first =~ /in `(.*)'/ ? $1 : "test"
|
55
52
|
testfile_name = "#{Dir.tmpdir}/ruby_prof_#{test}.html"
|
data/test/start_stop_test.rb
CHANGED
@@ -5,37 +5,34 @@ require File.expand_path('../test_helper', __FILE__)
|
|
5
5
|
|
6
6
|
class StartStopTest < TestCase
|
7
7
|
def setup
|
8
|
+
super
|
8
9
|
# Need to use wall time for this test due to the sleep calls
|
9
|
-
RubyProf::measure_mode
|
10
|
+
@profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
|
10
11
|
end
|
11
12
|
|
12
13
|
def method1
|
13
|
-
|
14
|
-
|
14
|
+
@profile.start
|
15
|
+
method2
|
15
16
|
end
|
16
17
|
|
17
18
|
def method2
|
18
|
-
|
19
|
+
method3
|
19
20
|
end
|
20
21
|
|
21
22
|
def method3
|
22
23
|
sleep(2)
|
23
|
-
@result =
|
24
|
+
@result = @profile.stop
|
24
25
|
end
|
25
26
|
|
26
27
|
def test_extra_stop_should_raise
|
27
|
-
|
28
|
+
@profile.start
|
28
29
|
assert_raises(RuntimeError) do
|
29
|
-
|
30
|
+
@profile.start
|
30
31
|
end
|
31
32
|
|
33
|
+
@profile.stop # ok
|
32
34
|
assert_raises(RuntimeError) do
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
RubyProf.stop # ok
|
37
|
-
assert_raises(RuntimeError) do
|
38
|
-
RubyProf.stop
|
35
|
+
@profile.stop
|
39
36
|
end
|
40
37
|
end
|
41
38
|
|
@@ -43,7 +40,7 @@ class StartStopTest < TestCase
|
|
43
40
|
method1
|
44
41
|
|
45
42
|
# Ruby prof should be stopped
|
46
|
-
assert_equal(false,
|
43
|
+
assert_equal(false, @profile.running?)
|
47
44
|
|
48
45
|
methods = @result.threads.first.methods.sort.reverse
|
49
46
|
assert_equal(4, methods.length)
|
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
|