ruby-prof 2.0.0 → 2.0.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/bin/ruby-prof-check-trace +45 -45
- data/docs/advanced-usage.md +132 -132
- data/docs/best-practices.md +27 -27
- data/docs/getting-started.md +130 -130
- data/docs/index.md +45 -45
- data/docs/profiling-rails.md +64 -64
- data/docs/public/examples/generate_reports.rb +92 -92
- data/docs/public/examples/reports/call_stack.html +835 -835
- data/docs/public/examples/reports/graph.html +1319 -1319
- data/docs/reports.md +150 -150
- data/lib/ruby-prof/version.rb +1 -1
- data/ruby-prof.gemspec +66 -66
- data/test/call_tree_builder.rb +126 -126
- data/test/exceptions_test.rb +24 -24
- data/test/marshal_test.rb +144 -144
- data/test/printer_call_stack_test.rb +28 -28
- data/test/printer_flame_graph_test.rb +82 -82
- data/test/printer_flat_test.rb +99 -99
- data/test/printer_graph_html_test.rb +62 -62
- data/test/printer_graph_test.rb +42 -42
- data/test/printers_test.rb +162 -162
- data/test/printing_recursive_graph_test.rb +81 -81
- data/test/profile_test.rb +101 -101
- data/test/rack_test.rb +103 -103
- data/test/scheduler.rb +367 -367
- data/test/singleton_test.rb +39 -39
- data/test/thread_test.rb +229 -229
- data/test/yarv_test.rb +56 -56
- metadata +3 -3
data/test/call_tree_builder.rb
CHANGED
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require File.expand_path('../test_helper', __FILE__)
|
|
4
|
-
require 'base64'
|
|
5
|
-
|
|
6
|
-
# Create a DummyClass with methods so we can create call trees in the test_merge method below
|
|
7
|
-
class DummyClass
|
|
8
|
-
%i[root a b aa ab ba bb].each do |method_name|
|
|
9
|
-
define_method(method_name) do
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def create_call_tree(method_name)
|
|
15
|
-
method_info = RubyProf::MethodInfo.new(DummyClass, method_name)
|
|
16
|
-
RubyProf::CallTree.new(method_info)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def build_call_tree(tree_hash)
|
|
20
|
-
# tree_hash is a hash keyed on the parent method_name whose values are
|
|
21
|
-
# child methods. Example:
|
|
22
|
-
#
|
|
23
|
-
# tree_hash = {root: [:a, :b],
|
|
24
|
-
# a: [:aa, :ab],
|
|
25
|
-
# b: [:bb]}
|
|
26
|
-
#
|
|
27
|
-
# Note this is a simplified structure for testing. It assumes methods
|
|
28
|
-
# are only called from one call_tree.
|
|
29
|
-
|
|
30
|
-
call_trees = Hash.new
|
|
31
|
-
tree_hash.each do |method_name, children|
|
|
32
|
-
parent = call_trees[method_name] ||= create_call_tree(method_name)
|
|
33
|
-
children.each do |child_method_name|
|
|
34
|
-
child = call_trees[child_method_name] ||= create_call_tree(child_method_name)
|
|
35
|
-
parent.add_child(child)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
call_trees
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def create_call_tree_1
|
|
43
|
-
#
|
|
44
|
-
# root
|
|
45
|
-
# / \
|
|
46
|
-
# a b
|
|
47
|
-
# / \ \
|
|
48
|
-
# aa ab bb
|
|
49
|
-
#
|
|
50
|
-
|
|
51
|
-
# ------ Call Trees 1 -------------
|
|
52
|
-
tree_hash = {root: [:a, :b],
|
|
53
|
-
a: [:aa, :ab],
|
|
54
|
-
b: [:bb]}
|
|
55
|
-
|
|
56
|
-
call_trees = build_call_tree(tree_hash)
|
|
57
|
-
|
|
58
|
-
# Setup times
|
|
59
|
-
call_trees[:aa].measurement.total_time = 1.5
|
|
60
|
-
call_trees[:aa].measurement.self_time = 1.5
|
|
61
|
-
call_trees[:ab].measurement.total_time = 2.2
|
|
62
|
-
call_trees[:ab].measurement.self_time = 2.2
|
|
63
|
-
call_trees[:a].measurement.total_time = 3.7
|
|
64
|
-
|
|
65
|
-
call_trees[:aa].target.measurement.total_time = 1.5
|
|
66
|
-
call_trees[:aa].target.measurement.self_time = 1.5
|
|
67
|
-
call_trees[:ab].target.measurement.total_time = 2.2
|
|
68
|
-
call_trees[:ab].target.measurement.self_time = 2.2
|
|
69
|
-
call_trees[:a].target.measurement.total_time = 3.7
|
|
70
|
-
|
|
71
|
-
call_trees[:bb].measurement.total_time = 4.3
|
|
72
|
-
call_trees[:bb].measurement.self_time = 4.3
|
|
73
|
-
call_trees[:b].measurement.total_time = 4.3
|
|
74
|
-
|
|
75
|
-
call_trees[:bb].target.measurement.total_time = 4.3
|
|
76
|
-
call_trees[:bb].target.measurement.self_time = 4.3
|
|
77
|
-
call_trees[:b].target.measurement.total_time = 4.3
|
|
78
|
-
|
|
79
|
-
call_trees[:root].measurement.total_time = 8.0
|
|
80
|
-
call_trees[:root].target.measurement.total_time = 8.0
|
|
81
|
-
|
|
82
|
-
call_trees[:root]
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def create_call_tree_2
|
|
86
|
-
#
|
|
87
|
-
# root
|
|
88
|
-
# / \
|
|
89
|
-
# a b
|
|
90
|
-
# \ / \
|
|
91
|
-
# ab ba bb
|
|
92
|
-
|
|
93
|
-
tree_hash = {root: [:a, :b],
|
|
94
|
-
a: [:ab],
|
|
95
|
-
b: [:ba, :bb]}
|
|
96
|
-
|
|
97
|
-
call_trees = build_call_tree(tree_hash)
|
|
98
|
-
|
|
99
|
-
# Setup times
|
|
100
|
-
call_trees[:ab].measurement.total_time = 0.4
|
|
101
|
-
call_trees[:ab].measurement.self_time = 0.4
|
|
102
|
-
call_trees[:a].measurement.total_time = 0.4
|
|
103
|
-
|
|
104
|
-
call_trees[:ab].target.measurement.total_time = 0.4
|
|
105
|
-
call_trees[:ab].target.measurement.self_time = 0.4
|
|
106
|
-
call_trees[:a].target.measurement.total_time = 0.4
|
|
107
|
-
|
|
108
|
-
call_trees[:ba].measurement.total_time = 0.9
|
|
109
|
-
call_trees[:ba].measurement.self_time = 0.7
|
|
110
|
-
call_trees[:ba].measurement.wait_time = 0.2
|
|
111
|
-
call_trees[:bb].measurement.total_time = 2.3
|
|
112
|
-
call_trees[:bb].measurement.self_time = 2.3
|
|
113
|
-
call_trees[:b].measurement.total_time = 3.2
|
|
114
|
-
|
|
115
|
-
call_trees[:ba].target.measurement.total_time = 0.9
|
|
116
|
-
call_trees[:ba].target.measurement.self_time = 0.7
|
|
117
|
-
call_trees[:ba].target.measurement.wait_time = 0.2
|
|
118
|
-
call_trees[:bb].target.measurement.total_time = 2.3
|
|
119
|
-
call_trees[:bb].target.measurement.self_time = 2.3
|
|
120
|
-
call_trees[:b].target.measurement.total_time = 3.2
|
|
121
|
-
|
|
122
|
-
call_trees[:root].measurement.total_time = 3.6
|
|
123
|
-
call_trees[:root].target.measurement.total_time = 3.6
|
|
124
|
-
|
|
125
|
-
call_trees[:root]
|
|
126
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path('../test_helper', __FILE__)
|
|
4
|
+
require 'base64'
|
|
5
|
+
|
|
6
|
+
# Create a DummyClass with methods so we can create call trees in the test_merge method below
|
|
7
|
+
class DummyClass
|
|
8
|
+
%i[root a b aa ab ba bb].each do |method_name|
|
|
9
|
+
define_method(method_name) do
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def create_call_tree(method_name)
|
|
15
|
+
method_info = RubyProf::MethodInfo.new(DummyClass, method_name)
|
|
16
|
+
RubyProf::CallTree.new(method_info)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def build_call_tree(tree_hash)
|
|
20
|
+
# tree_hash is a hash keyed on the parent method_name whose values are
|
|
21
|
+
# child methods. Example:
|
|
22
|
+
#
|
|
23
|
+
# tree_hash = {root: [:a, :b],
|
|
24
|
+
# a: [:aa, :ab],
|
|
25
|
+
# b: [:bb]}
|
|
26
|
+
#
|
|
27
|
+
# Note this is a simplified structure for testing. It assumes methods
|
|
28
|
+
# are only called from one call_tree.
|
|
29
|
+
|
|
30
|
+
call_trees = Hash.new
|
|
31
|
+
tree_hash.each do |method_name, children|
|
|
32
|
+
parent = call_trees[method_name] ||= create_call_tree(method_name)
|
|
33
|
+
children.each do |child_method_name|
|
|
34
|
+
child = call_trees[child_method_name] ||= create_call_tree(child_method_name)
|
|
35
|
+
parent.add_child(child)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
call_trees
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def create_call_tree_1
|
|
43
|
+
#
|
|
44
|
+
# root
|
|
45
|
+
# / \
|
|
46
|
+
# a b
|
|
47
|
+
# / \ \
|
|
48
|
+
# aa ab bb
|
|
49
|
+
#
|
|
50
|
+
|
|
51
|
+
# ------ Call Trees 1 -------------
|
|
52
|
+
tree_hash = {root: [:a, :b],
|
|
53
|
+
a: [:aa, :ab],
|
|
54
|
+
b: [:bb]}
|
|
55
|
+
|
|
56
|
+
call_trees = build_call_tree(tree_hash)
|
|
57
|
+
|
|
58
|
+
# Setup times
|
|
59
|
+
call_trees[:aa].measurement.total_time = 1.5
|
|
60
|
+
call_trees[:aa].measurement.self_time = 1.5
|
|
61
|
+
call_trees[:ab].measurement.total_time = 2.2
|
|
62
|
+
call_trees[:ab].measurement.self_time = 2.2
|
|
63
|
+
call_trees[:a].measurement.total_time = 3.7
|
|
64
|
+
|
|
65
|
+
call_trees[:aa].target.measurement.total_time = 1.5
|
|
66
|
+
call_trees[:aa].target.measurement.self_time = 1.5
|
|
67
|
+
call_trees[:ab].target.measurement.total_time = 2.2
|
|
68
|
+
call_trees[:ab].target.measurement.self_time = 2.2
|
|
69
|
+
call_trees[:a].target.measurement.total_time = 3.7
|
|
70
|
+
|
|
71
|
+
call_trees[:bb].measurement.total_time = 4.3
|
|
72
|
+
call_trees[:bb].measurement.self_time = 4.3
|
|
73
|
+
call_trees[:b].measurement.total_time = 4.3
|
|
74
|
+
|
|
75
|
+
call_trees[:bb].target.measurement.total_time = 4.3
|
|
76
|
+
call_trees[:bb].target.measurement.self_time = 4.3
|
|
77
|
+
call_trees[:b].target.measurement.total_time = 4.3
|
|
78
|
+
|
|
79
|
+
call_trees[:root].measurement.total_time = 8.0
|
|
80
|
+
call_trees[:root].target.measurement.total_time = 8.0
|
|
81
|
+
|
|
82
|
+
call_trees[:root]
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def create_call_tree_2
|
|
86
|
+
#
|
|
87
|
+
# root
|
|
88
|
+
# / \
|
|
89
|
+
# a b
|
|
90
|
+
# \ / \
|
|
91
|
+
# ab ba bb
|
|
92
|
+
|
|
93
|
+
tree_hash = {root: [:a, :b],
|
|
94
|
+
a: [:ab],
|
|
95
|
+
b: [:ba, :bb]}
|
|
96
|
+
|
|
97
|
+
call_trees = build_call_tree(tree_hash)
|
|
98
|
+
|
|
99
|
+
# Setup times
|
|
100
|
+
call_trees[:ab].measurement.total_time = 0.4
|
|
101
|
+
call_trees[:ab].measurement.self_time = 0.4
|
|
102
|
+
call_trees[:a].measurement.total_time = 0.4
|
|
103
|
+
|
|
104
|
+
call_trees[:ab].target.measurement.total_time = 0.4
|
|
105
|
+
call_trees[:ab].target.measurement.self_time = 0.4
|
|
106
|
+
call_trees[:a].target.measurement.total_time = 0.4
|
|
107
|
+
|
|
108
|
+
call_trees[:ba].measurement.total_time = 0.9
|
|
109
|
+
call_trees[:ba].measurement.self_time = 0.7
|
|
110
|
+
call_trees[:ba].measurement.wait_time = 0.2
|
|
111
|
+
call_trees[:bb].measurement.total_time = 2.3
|
|
112
|
+
call_trees[:bb].measurement.self_time = 2.3
|
|
113
|
+
call_trees[:b].measurement.total_time = 3.2
|
|
114
|
+
|
|
115
|
+
call_trees[:ba].target.measurement.total_time = 0.9
|
|
116
|
+
call_trees[:ba].target.measurement.self_time = 0.7
|
|
117
|
+
call_trees[:ba].target.measurement.wait_time = 0.2
|
|
118
|
+
call_trees[:bb].target.measurement.total_time = 2.3
|
|
119
|
+
call_trees[:bb].target.measurement.self_time = 2.3
|
|
120
|
+
call_trees[:b].target.measurement.total_time = 3.2
|
|
121
|
+
|
|
122
|
+
call_trees[:root].measurement.total_time = 3.6
|
|
123
|
+
call_trees[:root].target.measurement.total_time = 3.6
|
|
124
|
+
|
|
125
|
+
call_trees[:root]
|
|
126
|
+
end
|
data/test/exceptions_test.rb
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# encoding: UTF-8
|
|
3
|
-
|
|
4
|
-
require File.expand_path('../test_helper', __FILE__)
|
|
5
|
-
|
|
6
|
-
class ExceptionsTest < TestCase
|
|
7
|
-
def test_profile
|
|
8
|
-
result = begin
|
|
9
|
-
RubyProf::Profile.profile do
|
|
10
|
-
raise(RuntimeError, 'Test error')
|
|
11
|
-
end
|
|
12
|
-
rescue
|
|
13
|
-
end
|
|
14
|
-
assert_kind_of(RubyProf::Profile, result)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def test_profile_allows_exceptions
|
|
18
|
-
assert_raises(RuntimeError) do
|
|
19
|
-
RubyProf::Profile.profile(allow_exceptions: true) do
|
|
20
|
-
raise(RuntimeError, 'Test error')
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# encoding: UTF-8
|
|
3
|
+
|
|
4
|
+
require File.expand_path('../test_helper', __FILE__)
|
|
5
|
+
|
|
6
|
+
class ExceptionsTest < TestCase
|
|
7
|
+
def test_profile
|
|
8
|
+
result = begin
|
|
9
|
+
RubyProf::Profile.profile do
|
|
10
|
+
raise(RuntimeError, 'Test error')
|
|
11
|
+
end
|
|
12
|
+
rescue
|
|
13
|
+
end
|
|
14
|
+
assert_kind_of(RubyProf::Profile, result)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_profile_allows_exceptions
|
|
18
|
+
assert_raises(RuntimeError) do
|
|
19
|
+
RubyProf::Profile.profile(allow_exceptions: true) do
|
|
20
|
+
raise(RuntimeError, 'Test error')
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
data/test/marshal_test.rb
CHANGED
|
@@ -1,144 +1,144 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# encoding: UTF-8
|
|
3
|
-
|
|
4
|
-
require File.expand_path("../test_helper", __FILE__)
|
|
5
|
-
class MarshalTest < TestCase
|
|
6
|
-
def verify_profile(profile_1, profile_2)
|
|
7
|
-
verify_threads(profile_1.threads, profile_2.threads)
|
|
8
|
-
assert_equal(profile_1.measure_mode, profile_2.measure_mode)
|
|
9
|
-
assert_equal(profile_1.track_allocations?, profile_2.track_allocations?)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def verify_threads(threads_1, threads_2)
|
|
13
|
-
assert_equal(threads_1.count, threads_2.count)
|
|
14
|
-
threads_1.count.times do |i|
|
|
15
|
-
thread_1 = threads_1[i]
|
|
16
|
-
thread_2 = threads_2[i]
|
|
17
|
-
assert_nil(thread_2.id)
|
|
18
|
-
assert_equal(thread_1.fiber_id, thread_2.fiber_id)
|
|
19
|
-
verify_call_info(thread_1.call_tree, thread_2.call_tree)
|
|
20
|
-
|
|
21
|
-
verify_methods(thread_1.methods, thread_2.methods)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def verify_methods(methods_1, methods_2)
|
|
26
|
-
assert_equal(methods_1.count, methods_2.count)
|
|
27
|
-
|
|
28
|
-
methods_1.count.times do |i|
|
|
29
|
-
method_1 = methods_1[i]
|
|
30
|
-
method_2 = methods_2[i]
|
|
31
|
-
|
|
32
|
-
assert_equal(method_1.klass_name, method_2.klass_name)
|
|
33
|
-
assert_equal(method_1.klass_flags, method_2.klass_flags)
|
|
34
|
-
|
|
35
|
-
assert_equal(method_1.method_name, method_2.method_name)
|
|
36
|
-
assert_equal(method_1.full_name, method_2.full_name)
|
|
37
|
-
|
|
38
|
-
assert_equal(method_1.recursive?, method_2.recursive?)
|
|
39
|
-
|
|
40
|
-
if method_1.source_file
|
|
41
|
-
assert_equal(method_1.source_file, method_2.source_file)
|
|
42
|
-
else
|
|
43
|
-
assert_nil(method_1.source_file)
|
|
44
|
-
assert_nil(method_2.source_file)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
assert_equal(method_1.line, method_2.line)
|
|
48
|
-
|
|
49
|
-
verify_measurement(method_1.measurement, method_2.measurement)
|
|
50
|
-
verify_call_infos(method_1.call_trees, method_2.call_trees)
|
|
51
|
-
verify_allocations(method_1.allocations, method_2.allocations)
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def verify_allocations(allocations_1, allocations_2)
|
|
56
|
-
assert_equal(allocations_1.count, allocations_2.count)
|
|
57
|
-
|
|
58
|
-
allocations_1.count.times do |i|
|
|
59
|
-
allocation_1 = allocations_1[i]
|
|
60
|
-
allocation_2 = allocations_2[i]
|
|
61
|
-
|
|
62
|
-
assert_equal(allocation_1.klass_name, allocation_2.klass_name)
|
|
63
|
-
assert_equal(allocation_1.klass_flags, allocation_2.klass_flags)
|
|
64
|
-
|
|
65
|
-
assert_equal(allocation_1.count, allocation_2.count)
|
|
66
|
-
|
|
67
|
-
assert_equal(allocation_1.source_file, allocation_2.source_file)
|
|
68
|
-
assert_equal(allocation_1.line, allocation_2.line)
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def verify_call_infos(call_infos_1, call_infos_2)
|
|
73
|
-
assert_equal(call_infos_1.call_trees.count, call_infos_2.call_trees.count)
|
|
74
|
-
call_infos_1.call_trees.count.times do |i|
|
|
75
|
-
call_info_1 = call_infos_1.call_trees[i]
|
|
76
|
-
call_info_2 = call_infos_2.call_trees[i]
|
|
77
|
-
verify_call_info(call_info_1, call_info_2)
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def verify_call_info(call_info_1, call_info_2)
|
|
82
|
-
assert_equal(call_info_1.target, call_info_2.target)
|
|
83
|
-
|
|
84
|
-
if call_info_1.parent&.target
|
|
85
|
-
assert_equal(call_info_1.parent&.target, call_info_2.parent&.target)
|
|
86
|
-
else
|
|
87
|
-
assert_nil(call_info_1.parent&.target)
|
|
88
|
-
assert_nil(call_info_2.parent&.target)
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
assert_equal(call_info_1.depth, call_info_2.depth)
|
|
92
|
-
|
|
93
|
-
if call_info_1.source_file
|
|
94
|
-
assert_equal(call_info_1.source_file, call_info_2.source_file) #
|
|
95
|
-
else
|
|
96
|
-
assert_nil(call_info_1.source_file)
|
|
97
|
-
assert_nil(call_info_2.source_file)
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
assert_equal(call_info_1.line, call_info_2.line)
|
|
101
|
-
|
|
102
|
-
verify_measurement(call_info_1.measurement, call_info_2.measurement)
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def verify_measurement(measurement_1, measurement_2)
|
|
106
|
-
assert_equal(measurement_1.total_time, measurement_2.total_time)
|
|
107
|
-
assert_equal(measurement_1.self_time, measurement_2.self_time)
|
|
108
|
-
assert_equal(measurement_1.wait_time, measurement_2.wait_time)
|
|
109
|
-
assert_equal(measurement_1.called, measurement_2.called)
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
def test_marshal_1
|
|
113
|
-
profile_1 = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
|
|
114
|
-
1.times { RubyProf::C1.new.sleep_wait }
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
data = Marshal.dump(profile_1)
|
|
118
|
-
profile_2 = Marshal.load(data)
|
|
119
|
-
|
|
120
|
-
verify_profile(profile_1, profile_2)
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
def test_marshal_2
|
|
124
|
-
profile_1 = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME, track_allocations: true) do
|
|
125
|
-
1.times { RubyProf::C1.new.sleep_wait }
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
data = Marshal.dump(profile_1)
|
|
129
|
-
profile_2 = Marshal.load(data)
|
|
130
|
-
|
|
131
|
-
verify_profile(profile_1, profile_2)
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
def test_singleton
|
|
135
|
-
profile_1 = RubyProf::Profile.profile do
|
|
136
|
-
SingletonTest.instance.busy_wait
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
data = Marshal.dump(profile_1)
|
|
140
|
-
profile_2 = Marshal.load(data)
|
|
141
|
-
|
|
142
|
-
verify_profile(profile_1, profile_2)
|
|
143
|
-
end
|
|
144
|
-
end
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# encoding: UTF-8
|
|
3
|
+
|
|
4
|
+
require File.expand_path("../test_helper", __FILE__)
|
|
5
|
+
class MarshalTest < TestCase
|
|
6
|
+
def verify_profile(profile_1, profile_2)
|
|
7
|
+
verify_threads(profile_1.threads, profile_2.threads)
|
|
8
|
+
assert_equal(profile_1.measure_mode, profile_2.measure_mode)
|
|
9
|
+
assert_equal(profile_1.track_allocations?, profile_2.track_allocations?)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def verify_threads(threads_1, threads_2)
|
|
13
|
+
assert_equal(threads_1.count, threads_2.count)
|
|
14
|
+
threads_1.count.times do |i|
|
|
15
|
+
thread_1 = threads_1[i]
|
|
16
|
+
thread_2 = threads_2[i]
|
|
17
|
+
assert_nil(thread_2.id)
|
|
18
|
+
assert_equal(thread_1.fiber_id, thread_2.fiber_id)
|
|
19
|
+
verify_call_info(thread_1.call_tree, thread_2.call_tree)
|
|
20
|
+
|
|
21
|
+
verify_methods(thread_1.methods, thread_2.methods)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def verify_methods(methods_1, methods_2)
|
|
26
|
+
assert_equal(methods_1.count, methods_2.count)
|
|
27
|
+
|
|
28
|
+
methods_1.count.times do |i|
|
|
29
|
+
method_1 = methods_1[i]
|
|
30
|
+
method_2 = methods_2[i]
|
|
31
|
+
|
|
32
|
+
assert_equal(method_1.klass_name, method_2.klass_name)
|
|
33
|
+
assert_equal(method_1.klass_flags, method_2.klass_flags)
|
|
34
|
+
|
|
35
|
+
assert_equal(method_1.method_name, method_2.method_name)
|
|
36
|
+
assert_equal(method_1.full_name, method_2.full_name)
|
|
37
|
+
|
|
38
|
+
assert_equal(method_1.recursive?, method_2.recursive?)
|
|
39
|
+
|
|
40
|
+
if method_1.source_file
|
|
41
|
+
assert_equal(method_1.source_file, method_2.source_file)
|
|
42
|
+
else
|
|
43
|
+
assert_nil(method_1.source_file)
|
|
44
|
+
assert_nil(method_2.source_file)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
assert_equal(method_1.line, method_2.line)
|
|
48
|
+
|
|
49
|
+
verify_measurement(method_1.measurement, method_2.measurement)
|
|
50
|
+
verify_call_infos(method_1.call_trees, method_2.call_trees)
|
|
51
|
+
verify_allocations(method_1.allocations, method_2.allocations)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def verify_allocations(allocations_1, allocations_2)
|
|
56
|
+
assert_equal(allocations_1.count, allocations_2.count)
|
|
57
|
+
|
|
58
|
+
allocations_1.count.times do |i|
|
|
59
|
+
allocation_1 = allocations_1[i]
|
|
60
|
+
allocation_2 = allocations_2[i]
|
|
61
|
+
|
|
62
|
+
assert_equal(allocation_1.klass_name, allocation_2.klass_name)
|
|
63
|
+
assert_equal(allocation_1.klass_flags, allocation_2.klass_flags)
|
|
64
|
+
|
|
65
|
+
assert_equal(allocation_1.count, allocation_2.count)
|
|
66
|
+
|
|
67
|
+
assert_equal(allocation_1.source_file, allocation_2.source_file)
|
|
68
|
+
assert_equal(allocation_1.line, allocation_2.line)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def verify_call_infos(call_infos_1, call_infos_2)
|
|
73
|
+
assert_equal(call_infos_1.call_trees.count, call_infos_2.call_trees.count)
|
|
74
|
+
call_infos_1.call_trees.count.times do |i|
|
|
75
|
+
call_info_1 = call_infos_1.call_trees[i]
|
|
76
|
+
call_info_2 = call_infos_2.call_trees[i]
|
|
77
|
+
verify_call_info(call_info_1, call_info_2)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def verify_call_info(call_info_1, call_info_2)
|
|
82
|
+
assert_equal(call_info_1.target, call_info_2.target)
|
|
83
|
+
|
|
84
|
+
if call_info_1.parent&.target
|
|
85
|
+
assert_equal(call_info_1.parent&.target, call_info_2.parent&.target)
|
|
86
|
+
else
|
|
87
|
+
assert_nil(call_info_1.parent&.target)
|
|
88
|
+
assert_nil(call_info_2.parent&.target)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
assert_equal(call_info_1.depth, call_info_2.depth)
|
|
92
|
+
|
|
93
|
+
if call_info_1.source_file
|
|
94
|
+
assert_equal(call_info_1.source_file, call_info_2.source_file) #
|
|
95
|
+
else
|
|
96
|
+
assert_nil(call_info_1.source_file)
|
|
97
|
+
assert_nil(call_info_2.source_file)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
assert_equal(call_info_1.line, call_info_2.line)
|
|
101
|
+
|
|
102
|
+
verify_measurement(call_info_1.measurement, call_info_2.measurement)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def verify_measurement(measurement_1, measurement_2)
|
|
106
|
+
assert_equal(measurement_1.total_time, measurement_2.total_time)
|
|
107
|
+
assert_equal(measurement_1.self_time, measurement_2.self_time)
|
|
108
|
+
assert_equal(measurement_1.wait_time, measurement_2.wait_time)
|
|
109
|
+
assert_equal(measurement_1.called, measurement_2.called)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def test_marshal_1
|
|
113
|
+
profile_1 = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
|
|
114
|
+
1.times { RubyProf::C1.new.sleep_wait }
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
data = Marshal.dump(profile_1)
|
|
118
|
+
profile_2 = Marshal.load(data)
|
|
119
|
+
|
|
120
|
+
verify_profile(profile_1, profile_2)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def test_marshal_2
|
|
124
|
+
profile_1 = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME, track_allocations: true) do
|
|
125
|
+
1.times { RubyProf::C1.new.sleep_wait }
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
data = Marshal.dump(profile_1)
|
|
129
|
+
profile_2 = Marshal.load(data)
|
|
130
|
+
|
|
131
|
+
verify_profile(profile_1, profile_2)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def test_singleton
|
|
135
|
+
profile_1 = RubyProf::Profile.profile do
|
|
136
|
+
SingletonTest.instance.busy_wait
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
data = Marshal.dump(profile_1)
|
|
140
|
+
profile_2 = Marshal.load(data)
|
|
141
|
+
|
|
142
|
+
verify_profile(profile_1, profile_2)
|
|
143
|
+
end
|
|
144
|
+
end
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# encoding: UTF-8
|
|
3
|
-
|
|
4
|
-
require File.expand_path('../test_helper', __FILE__)
|
|
5
|
-
require 'fileutils'
|
|
6
|
-
require 'stringio'
|
|
7
|
-
require 'tmpdir'
|
|
8
|
-
require_relative 'prime'
|
|
9
|
-
|
|
10
|
-
# -- Tests ----
|
|
11
|
-
class PrinterCallStackTest < TestCase
|
|
12
|
-
def setup
|
|
13
|
-
super
|
|
14
|
-
# WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
|
|
15
|
-
@result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
|
|
16
|
-
run_primes(1000, 5000)
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def test_graph_html_string
|
|
21
|
-
output = StringIO.new
|
|
22
|
-
printer = RubyProf::CallStackPrinter.new(@result)
|
|
23
|
-
printer.print(output)
|
|
24
|
-
|
|
25
|
-
assert_match(/<!DOCTYPE html>/i, output.string)
|
|
26
|
-
assert_match(/Object#run_primes/i, output.string)
|
|
27
|
-
end
|
|
28
|
-
end
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# encoding: UTF-8
|
|
3
|
+
|
|
4
|
+
require File.expand_path('../test_helper', __FILE__)
|
|
5
|
+
require 'fileutils'
|
|
6
|
+
require 'stringio'
|
|
7
|
+
require 'tmpdir'
|
|
8
|
+
require_relative 'prime'
|
|
9
|
+
|
|
10
|
+
# -- Tests ----
|
|
11
|
+
class PrinterCallStackTest < TestCase
|
|
12
|
+
def setup
|
|
13
|
+
super
|
|
14
|
+
# WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
|
|
15
|
+
@result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
|
|
16
|
+
run_primes(1000, 5000)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_graph_html_string
|
|
21
|
+
output = StringIO.new
|
|
22
|
+
printer = RubyProf::CallStackPrinter.new(@result)
|
|
23
|
+
printer.print(output)
|
|
24
|
+
|
|
25
|
+
assert_match(/<!DOCTYPE html>/i, output.string)
|
|
26
|
+
assert_match(/Object#run_primes/i, output.string)
|
|
27
|
+
end
|
|
28
|
+
end
|