ruby-prof 1.4.3 → 1.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +59 -9
- data/{README.rdoc → README.md} +2 -2
- data/Rakefile +4 -4
- data/bin/ruby-prof +100 -87
- data/ext/ruby_prof/rp_allocation.c +140 -85
- data/ext/ruby_prof/rp_allocation.h +8 -6
- data/ext/ruby_prof/rp_call_tree.c +502 -369
- data/ext/ruby_prof/rp_call_tree.h +47 -43
- data/ext/ruby_prof/rp_call_trees.c +16 -8
- data/ext/ruby_prof/rp_measure_allocations.c +10 -13
- data/ext/ruby_prof/rp_measure_memory.c +8 -4
- data/ext/ruby_prof/rp_measure_process_time.c +7 -6
- data/ext/ruby_prof/rp_measurement.c +147 -20
- data/ext/ruby_prof/rp_measurement.h +4 -1
- data/ext/ruby_prof/rp_method.c +142 -83
- data/ext/ruby_prof/rp_method.h +63 -62
- data/ext/ruby_prof/rp_profile.c +933 -900
- data/ext/ruby_prof/rp_profile.h +1 -0
- data/ext/ruby_prof/rp_thread.c +433 -362
- data/ext/ruby_prof/rp_thread.h +39 -39
- data/ext/ruby_prof/ruby_prof.c +0 -2
- data/ext/ruby_prof/ruby_prof.h +8 -0
- data/ext/ruby_prof/vc/ruby_prof.vcxproj +11 -8
- data/lib/ruby-prof/assets/call_stack_printer.html.erb +2 -1
- data/lib/ruby-prof/compatibility.rb +14 -0
- data/lib/ruby-prof/method_info.rb +8 -1
- data/lib/ruby-prof/printers/abstract_printer.rb +2 -1
- data/lib/ruby-prof/printers/call_tree_printer.rb +4 -10
- data/lib/ruby-prof/printers/graph_html_printer.rb +1 -1
- data/lib/ruby-prof/printers/multi_printer.rb +17 -17
- data/lib/ruby-prof/profile.rb +70 -37
- data/lib/ruby-prof/rack.rb +31 -21
- data/lib/ruby-prof/version.rb +1 -1
- data/lib/ruby-prof.rb +1 -1
- data/ruby-prof.gemspec +2 -3
- data/test/abstract_printer_test.rb +1 -0
- data/test/alias_test.rb +97 -106
- data/test/call_tree_builder.rb +126 -0
- data/test/call_tree_test.rb +94 -0
- data/test/call_tree_visitor_test.rb +1 -6
- data/test/call_trees_test.rb +6 -6
- data/test/{basic_test.rb → compatibility_test.rb} +8 -2
- data/test/duplicate_names_test.rb +5 -5
- data/test/dynamic_method_test.rb +24 -15
- 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 +74 -8
- data/test/gc_test.rb +11 -9
- data/test/inverse_call_tree_test.rb +33 -34
- data/test/line_number_test.rb +37 -61
- data/test/marshal_test.rb +16 -3
- data/test/measure_allocations.rb +1 -5
- data/test/measure_allocations_test.rb +642 -357
- data/test/{measure_memory_trace_test.rb → measure_memory_test.rb} +180 -616
- data/test/measure_process_time_test.rb +1566 -741
- data/test/measure_wall_time_test.rb +179 -193
- data/test/measurement_test.rb +82 -0
- data/test/merge_test.rb +146 -0
- data/test/method_info_test.rb +95 -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 +4 -4
- 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/profile_test.rb +85 -0
- data/test/recursive_test.rb +374 -155
- data/test/scheduler.rb +363 -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 +11 -8
- data/test/thread_test.rb +106 -15
- data/test/unique_call_path_test.rb +28 -12
- data/test/yarv_test.rb +11 -7
- metadata +17 -29
- data/ext/ruby_prof/rp_aggregate_call_tree.c +0 -59
- data/ext/ruby_prof/rp_aggregate_call_tree.h +0 -13
- data/test/measure_allocations_trace_test.rb +0 -375
- data/test/temp.rb +0 -20
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
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('../test_helper', __FILE__)
|
4
|
+
require 'base64'
|
5
|
+
|
6
|
+
class MethodInfoTest < Minitest::Test
|
7
|
+
def test_initialize
|
8
|
+
method_info = RubyProf::MethodInfo.new(Base64, :encode64)
|
9
|
+
assert_equal("Base64", method_info.klass_name)
|
10
|
+
assert_equal(:encode64, method_info.method_name)
|
11
|
+
assert_equal("Base64#encode64", method_info.full_name)
|
12
|
+
assert_equal(0, method_info.klass_flags)
|
13
|
+
assert_match(/base64\.rb/, method_info.source_file)
|
14
|
+
assert_kind_of(Integer, method_info.line)
|
15
|
+
refute(method_info.recursive?)
|
16
|
+
|
17
|
+
assert_kind_of(RubyProf::Measurement, method_info.measurement)
|
18
|
+
assert_kind_of(RubyProf::CallTrees, method_info.call_trees)
|
19
|
+
assert_empty(method_info.allocations)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_initialize_nil_klass
|
23
|
+
error = assert_raises(NoMethodError) do
|
24
|
+
RubyProf::MethodInfo.new(nil, nil)
|
25
|
+
end
|
26
|
+
assert_match(/undefined method `instance_method' for nil:NilClass/, error.message)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_initialize_nil_method_name
|
30
|
+
error = assert_raises(TypeError) do
|
31
|
+
RubyProf::MethodInfo.new(Base64, nil)
|
32
|
+
end
|
33
|
+
assert_equal("nil is not a symbol nor a string", error.to_s)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_initialize_unknown_location
|
37
|
+
method_info = RubyProf::MethodInfo.new(Array, :size)
|
38
|
+
assert_equal('Array', method_info.klass_name)
|
39
|
+
assert_equal(:size, method_info.method_name)
|
40
|
+
assert_nil(method_info.source_file)
|
41
|
+
assert_equal(0, method_info.line)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_measurement
|
45
|
+
method_info = RubyProf::MethodInfo.new(Base64, :encode64)
|
46
|
+
assert_equal(0, method_info.total_time)
|
47
|
+
assert_equal(0, method_info.self_time)
|
48
|
+
assert_equal(0, method_info.wait_time)
|
49
|
+
assert_equal(0, method_info.children_time)
|
50
|
+
assert_equal(0, method_info.called)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_compare
|
54
|
+
method_info_1 = RubyProf::MethodInfo.new(Base64, :encode64)
|
55
|
+
method_info_2 = RubyProf::MethodInfo.new(Base64, :encode64)
|
56
|
+
assert_equal(0, method_info_1 <=> method_info_2)
|
57
|
+
|
58
|
+
method_info_1 = RubyProf::MethodInfo.new(Base64, :decode64)
|
59
|
+
method_info_2 = RubyProf::MethodInfo.new(Base64, :encode64)
|
60
|
+
assert_equal(-1, method_info_1 <=> method_info_2)
|
61
|
+
|
62
|
+
method_info_1 = RubyProf::MethodInfo.new(Base64, :encode64)
|
63
|
+
method_info_2 = RubyProf::MethodInfo.new(Base64, :decode64)
|
64
|
+
assert_equal(1, method_info_1 <=> method_info_2)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_eql?
|
68
|
+
method_info_1 = RubyProf::MethodInfo.new(Base64, :encode64)
|
69
|
+
method_info_2 = RubyProf::MethodInfo.new(Base64, :encode64)
|
70
|
+
assert(method_info_1.eql?(method_info_2))
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_equal?
|
74
|
+
method_info_1 = RubyProf::MethodInfo.new(Base64, :encode64)
|
75
|
+
method_info_2 = RubyProf::MethodInfo.new(Base64, :encode64)
|
76
|
+
refute(method_info_1.equal?(method_info_2))
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_equality
|
80
|
+
method_info_1 = RubyProf::MethodInfo.new(Base64, :encode64)
|
81
|
+
method_info_2 = RubyProf::MethodInfo.new(Base64, :encode64)
|
82
|
+
assert(method_info_1 == method_info_2)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_hash
|
86
|
+
method_info_1 = RubyProf::MethodInfo.new(Base64, :encode64)
|
87
|
+
method_info_2 = RubyProf::MethodInfo.new(Base64, :encode64)
|
88
|
+
assert_equal(method_info_1.hash, method_info_2.hash)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_to_s
|
92
|
+
method_info = RubyProf::MethodInfo.new(Base64, :encode64)
|
93
|
+
assert_equal("Base64#encode64 (c: 0, tt: 0.0, st: 0.0, wt: 0.0, ct: 0.0)", method_info.to_s)
|
94
|
+
end
|
95
|
+
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
|
@@ -19,8 +19,8 @@ class PrinterCallTreeTest < TestCase
|
|
19
19
|
def test_call_tree_string
|
20
20
|
printer = RubyProf::CallTreePrinter.new(@result)
|
21
21
|
|
22
|
-
printer.print(:
|
23
|
-
main_output_file_name = File.join(Dir.tmpdir, "
|
22
|
+
printer.print(:path => Dir.tmpdir)
|
23
|
+
main_output_file_name = File.join(Dir.tmpdir, "callgrind.out.#{$$}")
|
24
24
|
assert(File.exist?(main_output_file_name))
|
25
25
|
output = File.read(main_output_file_name)
|
26
26
|
assert_match(/fn=Object::find_primes/i, output)
|
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/profile_test.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
# encoding: UTF-8
|
3
3
|
|
4
4
|
require File.expand_path('../test_helper', __FILE__)
|
5
|
+
require_relative './call_tree_builder'
|
5
6
|
|
6
7
|
class ProfileTest < TestCase
|
7
8
|
def test_measure_mode
|
@@ -13,4 +14,88 @@ class ProfileTest < TestCase
|
|
13
14
|
profile = RubyProf::Profile.new(:measure_mode => RubyProf::PROCESS_TIME)
|
14
15
|
assert_equal("process_time", profile.measure_mode_string)
|
15
16
|
end
|
17
|
+
|
18
|
+
def test_add_thread
|
19
|
+
profile = RubyProf::Profile.new
|
20
|
+
assert_empty(profile.threads)
|
21
|
+
|
22
|
+
method_info = RubyProf::MethodInfo.new(Array, :size)
|
23
|
+
call_tree = RubyProf::CallTree.new(method_info)
|
24
|
+
thread = RubyProf::Thread.new(call_tree, Thread.current, Fiber.current)
|
25
|
+
|
26
|
+
profile.add_thread(thread)
|
27
|
+
assert_equal(1, profile.threads.size)
|
28
|
+
assert(thread.equal?(profile.threads.first))
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_add_threads
|
32
|
+
call_tree_1 = create_call_tree_1
|
33
|
+
ruby_thread_1 = Thread.new { }
|
34
|
+
thread_1 = RubyProf::Thread.new(call_tree_1, ruby_thread_1, Fiber.current)
|
35
|
+
|
36
|
+
call_tree_2 = create_call_tree_2
|
37
|
+
ruby_thread_2 = Thread.new { }
|
38
|
+
thread_2 = RubyProf::Thread.new(call_tree_2, ruby_thread_2, Fiber.current)
|
39
|
+
|
40
|
+
profile = RubyProf::Profile.new
|
41
|
+
profile.add_thread(thread_1)
|
42
|
+
profile.add_thread(thread_2)
|
43
|
+
assert_equal(1, profile.threads.count)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_add_fibers
|
47
|
+
call_tree_1 = create_call_tree_1
|
48
|
+
fiber_1 = Fiber.new { }
|
49
|
+
thread_1 = RubyProf::Thread.new(call_tree_1, Thread.current, fiber_1)
|
50
|
+
|
51
|
+
call_tree_2 = create_call_tree_2
|
52
|
+
fiber_2 = Fiber.new { }
|
53
|
+
thread_2 = RubyProf::Thread.new(call_tree_2, Thread.current, fiber_2)
|
54
|
+
|
55
|
+
profile = RubyProf::Profile.new
|
56
|
+
profile.add_thread(thread_1)
|
57
|
+
profile.add_thread(thread_2)
|
58
|
+
assert_equal(2, profile.threads.count)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_remove_thread
|
62
|
+
profile = RubyProf::Profile.new
|
63
|
+
assert_empty(profile.threads)
|
64
|
+
|
65
|
+
method_info = RubyProf::MethodInfo.new(Array, :size)
|
66
|
+
call_tree = RubyProf::CallTree.new(method_info)
|
67
|
+
thread = RubyProf::Thread.new(call_tree, Thread.current, Fiber.current)
|
68
|
+
|
69
|
+
profile.add_thread(thread)
|
70
|
+
assert_equal(1, profile.threads.size)
|
71
|
+
assert(thread.equal?(profile.threads.first))
|
72
|
+
|
73
|
+
removed = profile.remove_thread(thread)
|
74
|
+
assert_equal(0, profile.threads.size)
|
75
|
+
assert(removed.equal?(thread))
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_merge
|
79
|
+
call_tree_1 = create_call_tree_1
|
80
|
+
fiber_1 = Thread.new { }
|
81
|
+
thread_1 = RubyProf::Thread.new(call_tree_1, Thread.current, fiber_1)
|
82
|
+
|
83
|
+
call_tree_2 = create_call_tree_2
|
84
|
+
fiber_2 = Thread.new { }
|
85
|
+
thread_2 = RubyProf::Thread.new(call_tree_2, Thread.current, fiber_2)
|
86
|
+
|
87
|
+
profile = RubyProf::Profile.new
|
88
|
+
profile.add_thread(thread_1)
|
89
|
+
profile.add_thread(thread_2)
|
90
|
+
|
91
|
+
profile.merge!
|
92
|
+
assert_equal(1, profile.threads.count)
|
93
|
+
|
94
|
+
assert_equal(thread_1, profile.threads.first)
|
95
|
+
|
96
|
+
assert_in_delta(11.6, thread_1.call_tree.total_time, 0.00001)
|
97
|
+
assert_in_delta(0, thread_1.call_tree.self_time, 0.00001)
|
98
|
+
assert_in_delta(0.0, thread_1.call_tree.wait_time, 0.00001)
|
99
|
+
assert_in_delta(11.6, thread_1.call_tree.children_time, 0.00001)
|
100
|
+
end
|
16
101
|
end
|