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/alias_test.rb
CHANGED
@@ -15,112 +15,103 @@ class AliasTest < TestCase
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
# This test only correct works on Ruby 2.5 and higher because - see:
|
24
|
-
# https://bugs.ruby-lang.org/issues/12747
|
25
|
-
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.5.0')
|
26
|
-
def test_alias
|
27
|
-
result = RubyProf.profile do
|
28
|
-
TestMe.new.some_method
|
29
|
-
end
|
30
|
-
|
31
|
-
methods = result.threads.first.methods
|
32
|
-
assert_equal(6, methods.count)
|
33
|
-
|
34
|
-
# Method 0
|
35
|
-
method = methods[0]
|
36
|
-
assert_equal('AliasTest#test_alias', method.full_name)
|
37
|
-
assert_equal(28, method.line)
|
38
|
-
refute(method.recursive?)
|
39
|
-
|
40
|
-
assert_equal(0, method.call_trees.callers.count)
|
41
|
-
|
42
|
-
assert_equal(2, method.call_trees.callees.count)
|
43
|
-
call_tree = method.call_trees.callees[0]
|
44
|
-
assert_equal('Class#new', call_tree.target.full_name)
|
45
|
-
assert_equal(28, call_tree.line)
|
46
|
-
|
47
|
-
call_tree = method.call_trees.callees[1]
|
48
|
-
assert_equal('AliasTest::TestMe#some_method', call_tree.target.full_name)
|
49
|
-
assert_equal(28, call_tree.line)
|
50
|
-
|
51
|
-
# Method 1
|
52
|
-
method = methods[1]
|
53
|
-
assert_equal('Class#new', method.full_name)
|
54
|
-
assert_equal(0, method.line)
|
55
|
-
refute(method.recursive?)
|
56
|
-
|
57
|
-
assert_equal(1, method.call_trees.callers.count)
|
58
|
-
call_tree = method.call_trees.callers[0]
|
59
|
-
assert_equal('AliasTest#test_alias', call_tree.parent.target.full_name)
|
60
|
-
assert_equal(28, call_tree.line)
|
61
|
-
|
62
|
-
assert_equal(1, method.call_trees.callees.count)
|
63
|
-
call_tree = method.call_trees.callees[0]
|
64
|
-
assert_equal('BasicObject#initialize', call_tree.target.full_name)
|
65
|
-
assert_equal(0, call_tree.line)
|
66
|
-
|
67
|
-
# Method 2
|
68
|
-
method = methods[2]
|
69
|
-
assert_equal('BasicObject#initialize', method.full_name)
|
70
|
-
assert_equal(0, method.line)
|
71
|
-
refute(method.recursive?)
|
72
|
-
|
73
|
-
assert_equal(1, method.call_trees.callers.count)
|
74
|
-
call_tree = method.call_trees.callers[0]
|
75
|
-
assert_equal('Class#new', call_tree.parent.target.full_name)
|
76
|
-
assert_equal(0, call_tree.line)
|
77
|
-
|
78
|
-
assert_equal(0, method.call_trees.callees.count)
|
79
|
-
|
80
|
-
# Method 3
|
81
|
-
method = methods[3]
|
82
|
-
assert_equal('AliasTest::TestMe#some_method', method.full_name)
|
83
|
-
assert_equal(13, method.line)
|
84
|
-
refute(method.recursive?)
|
85
|
-
|
86
|
-
assert_equal(1, method.call_trees.callers.count)
|
87
|
-
call_tree = method.call_trees.callers[0]
|
88
|
-
assert_equal('AliasTest#test_alias', call_tree.parent.target.full_name)
|
89
|
-
assert_equal(28, call_tree.line)
|
90
|
-
|
91
|
-
assert_equal(1, method.call_trees.callees.count)
|
92
|
-
call_tree = method.call_trees.callees[0]
|
93
|
-
assert_equal('AliasTest::TestMe#some_method_original', call_tree.target.full_name)
|
94
|
-
assert_equal(14, call_tree.line)
|
95
|
-
|
96
|
-
# Method 4
|
97
|
-
method = methods[4]
|
98
|
-
assert_equal('AliasTest::TestMe#some_method_original', method.full_name)
|
99
|
-
assert_equal(8, method.line)
|
100
|
-
refute(method.recursive?)
|
101
|
-
|
102
|
-
assert_equal(1, method.call_trees.callers.count)
|
103
|
-
call_tree = method.call_trees.callers[0]
|
104
|
-
assert_equal('AliasTest::TestMe#some_method', call_tree.parent.target.full_name)
|
105
|
-
assert_equal(14, call_tree.line)
|
106
|
-
|
107
|
-
assert_equal(1, method.call_trees.callees.count)
|
108
|
-
call_tree = method.call_trees.callees[0]
|
109
|
-
assert_equal('Kernel#sleep', call_tree.target.full_name)
|
110
|
-
assert_equal(9, call_tree.line)
|
111
|
-
|
112
|
-
# Method 5
|
113
|
-
method = methods[5]
|
114
|
-
assert_equal('Kernel#sleep', method.full_name)
|
115
|
-
assert_equal(0, method.line)
|
116
|
-
refute(method.recursive?)
|
117
|
-
|
118
|
-
assert_equal(1, method.call_trees.callers.count)
|
119
|
-
call_tree = method.call_trees.callers[0]
|
120
|
-
assert_equal('AliasTest::TestMe#some_method_original', call_tree.parent.target.full_name)
|
121
|
-
assert_equal(9, call_tree.line)
|
122
|
-
|
123
|
-
assert_equal(0, method.call_trees.callees.count)
|
18
|
+
def test_alias
|
19
|
+
result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
|
20
|
+
TestMe.new.some_method
|
124
21
|
end
|
22
|
+
|
23
|
+
methods = result.threads.first.methods
|
24
|
+
assert_equal(6, methods.count)
|
25
|
+
|
26
|
+
# Method 0
|
27
|
+
method = methods[0]
|
28
|
+
assert_equal('AliasTest#test_alias', method.full_name)
|
29
|
+
assert_equal(20, method.line)
|
30
|
+
refute(method.recursive?)
|
31
|
+
|
32
|
+
assert_equal(0, method.call_trees.callers.count)
|
33
|
+
|
34
|
+
assert_equal(2, method.call_trees.callees.count)
|
35
|
+
call_tree = method.call_trees.callees[0]
|
36
|
+
assert_equal('Class#new', call_tree.target.full_name)
|
37
|
+
assert_equal(20, call_tree.line)
|
38
|
+
|
39
|
+
call_tree = method.call_trees.callees[1]
|
40
|
+
assert_equal('AliasTest::TestMe#some_method', call_tree.target.full_name)
|
41
|
+
assert_equal(20, call_tree.line)
|
42
|
+
|
43
|
+
# Method 1
|
44
|
+
method = methods[1]
|
45
|
+
assert_equal('Class#new', method.full_name)
|
46
|
+
assert_equal(0, method.line)
|
47
|
+
refute(method.recursive?)
|
48
|
+
|
49
|
+
assert_equal(1, method.call_trees.callers.count)
|
50
|
+
call_tree = method.call_trees.callers[0]
|
51
|
+
assert_equal('AliasTest#test_alias', call_tree.parent.target.full_name)
|
52
|
+
assert_equal(20, call_tree.line)
|
53
|
+
|
54
|
+
assert_equal(1, method.call_trees.callees.count)
|
55
|
+
call_tree = method.call_trees.callees[0]
|
56
|
+
assert_equal('BasicObject#initialize', call_tree.target.full_name)
|
57
|
+
assert_equal(0, call_tree.line)
|
58
|
+
|
59
|
+
# Method 2
|
60
|
+
method = methods[2]
|
61
|
+
assert_equal('BasicObject#initialize', method.full_name)
|
62
|
+
assert_equal(0, method.line)
|
63
|
+
refute(method.recursive?)
|
64
|
+
|
65
|
+
assert_equal(1, method.call_trees.callers.count)
|
66
|
+
call_tree = method.call_trees.callers[0]
|
67
|
+
assert_equal('Class#new', call_tree.parent.target.full_name)
|
68
|
+
assert_equal(0, call_tree.line)
|
69
|
+
|
70
|
+
assert_equal(0, method.call_trees.callees.count)
|
71
|
+
|
72
|
+
# Method 3
|
73
|
+
method = methods[3]
|
74
|
+
assert_equal('AliasTest::TestMe#some_method', method.full_name)
|
75
|
+
assert_equal(13, method.line)
|
76
|
+
refute(method.recursive?)
|
77
|
+
|
78
|
+
assert_equal(1, method.call_trees.callers.count)
|
79
|
+
call_tree = method.call_trees.callers[0]
|
80
|
+
assert_equal('AliasTest#test_alias', call_tree.parent.target.full_name)
|
81
|
+
assert_equal(20, call_tree.line)
|
82
|
+
|
83
|
+
assert_equal(1, method.call_trees.callees.count)
|
84
|
+
call_tree = method.call_trees.callees[0]
|
85
|
+
assert_equal('AliasTest::TestMe#some_method_original', call_tree.target.full_name)
|
86
|
+
assert_equal(14, call_tree.line)
|
87
|
+
|
88
|
+
# Method 4
|
89
|
+
method = methods[4]
|
90
|
+
assert_equal('AliasTest::TestMe#some_method_original', method.full_name)
|
91
|
+
assert_equal(8, method.line)
|
92
|
+
refute(method.recursive?)
|
93
|
+
|
94
|
+
assert_equal(1, method.call_trees.callers.count)
|
95
|
+
call_tree = method.call_trees.callers[0]
|
96
|
+
assert_equal('AliasTest::TestMe#some_method', call_tree.parent.target.full_name)
|
97
|
+
assert_equal(14, call_tree.line)
|
98
|
+
|
99
|
+
assert_equal(1, method.call_trees.callees.count)
|
100
|
+
call_tree = method.call_trees.callees[0]
|
101
|
+
assert_equal('Kernel#sleep', call_tree.target.full_name)
|
102
|
+
assert_equal(9, call_tree.line)
|
103
|
+
|
104
|
+
# Method 5
|
105
|
+
method = methods[5]
|
106
|
+
assert_equal('Kernel#sleep', method.full_name)
|
107
|
+
assert_equal(0, method.line)
|
108
|
+
refute(method.recursive?)
|
109
|
+
|
110
|
+
assert_equal(1, method.call_trees.callers.count)
|
111
|
+
call_tree = method.call_trees.callers[0]
|
112
|
+
assert_equal('AliasTest::TestMe#some_method_original', call_tree.parent.target.full_name)
|
113
|
+
assert_equal(9, call_tree.line)
|
114
|
+
|
115
|
+
assert_equal(0, method.call_trees.callees.count)
|
125
116
|
end
|
126
117
|
end
|
@@ -0,0 +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
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('../test_helper', __FILE__)
|
4
|
+
require_relative './call_tree_builder'
|
5
|
+
require 'base64'
|
6
|
+
|
7
|
+
class CallTreeTest < Minitest::Test
|
8
|
+
def test_initialize
|
9
|
+
method_info = RubyProf::MethodInfo.new(Base64, :encode64)
|
10
|
+
call_tree = RubyProf::CallTree.new(method_info)
|
11
|
+
assert_equal(method_info, call_tree.target)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_measurement
|
15
|
+
method_info = RubyProf::MethodInfo.new(Base64, :encode64)
|
16
|
+
call_tree = RubyProf::CallTree.new(method_info)
|
17
|
+
|
18
|
+
assert_equal(0, call_tree.total_time)
|
19
|
+
assert_equal(0, call_tree.self_time)
|
20
|
+
assert_equal(0, call_tree.wait_time)
|
21
|
+
assert_equal(0, call_tree.children_time)
|
22
|
+
assert_equal(0, call_tree.called)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_compare
|
26
|
+
method_info_1 = RubyProf::MethodInfo.new(Base64, :encode64)
|
27
|
+
call_tree_1 = RubyProf::CallTree.new(method_info_1)
|
28
|
+
method_info_2 = RubyProf::MethodInfo.new(Base64, :encode64)
|
29
|
+
call_tree_2 = RubyProf::CallTree.new(method_info_2)
|
30
|
+
assert_equal(0, call_tree_1 <=> call_tree_2)
|
31
|
+
|
32
|
+
method_info_1 = RubyProf::MethodInfo.new(Base64, :decode64)
|
33
|
+
call_tree_1 = RubyProf::CallTree.new(method_info_1)
|
34
|
+
call_tree_1.measurement.total_time = 1
|
35
|
+
method_info_2 = RubyProf::MethodInfo.new(Base64, :encode64)
|
36
|
+
call_tree_2 = RubyProf::CallTree.new(method_info_2)
|
37
|
+
assert_equal(1, call_tree_1 <=> call_tree_2)
|
38
|
+
|
39
|
+
method_info_1 = RubyProf::MethodInfo.new(Base64, :decode64)
|
40
|
+
call_tree_1 = RubyProf::CallTree.new(method_info_1)
|
41
|
+
method_info_2 = RubyProf::MethodInfo.new(Base64, :encode64)
|
42
|
+
call_tree_2 = RubyProf::CallTree.new(method_info_2)
|
43
|
+
call_tree_2.measurement.total_time = 1
|
44
|
+
assert_equal(-1, call_tree_1 <=> call_tree_2)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_to_s
|
48
|
+
method_info = RubyProf::MethodInfo.new(Base64, :encode64)
|
49
|
+
call_tree = RubyProf::CallTree.new(method_info)
|
50
|
+
assert_equal("<RubyProf::CallTree - Base64#encode64>", call_tree.to_s)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_add_child
|
54
|
+
method_info_parent = RubyProf::MethodInfo.new(Base64, :encode64)
|
55
|
+
call_tree_parent = RubyProf::CallTree.new(method_info_parent)
|
56
|
+
|
57
|
+
method_info_child = RubyProf::MethodInfo.new(Array, :pack)
|
58
|
+
call_tree_child = RubyProf::CallTree.new(method_info_child)
|
59
|
+
|
60
|
+
assert_equal(0, call_tree_parent.children.size)
|
61
|
+
assert_nil(call_tree_child.parent)
|
62
|
+
|
63
|
+
result = call_tree_parent.add_child(call_tree_child)
|
64
|
+
assert_equal(1, call_tree_parent.children.size)
|
65
|
+
assert_equal(call_tree_child, call_tree_parent.children.first)
|
66
|
+
assert_equal(call_tree_child, result)
|
67
|
+
assert_equal(call_tree_parent, call_tree_child.parent)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_add_child_gc
|
71
|
+
GC.stress = true
|
72
|
+
|
73
|
+
begin
|
74
|
+
method_info_parent = RubyProf::MethodInfo.new(Base64, :encode64)
|
75
|
+
call_tree_parent = RubyProf::CallTree.new(method_info_parent)
|
76
|
+
|
77
|
+
method_info_child = RubyProf::MethodInfo.new(Array, :pack)
|
78
|
+
call_tree_child = RubyProf::CallTree.new(method_info_child)
|
79
|
+
call_tree_parent.add_child(call_tree_child)
|
80
|
+
|
81
|
+
# Free the child first
|
82
|
+
call_tree_child = nil
|
83
|
+
GC.start
|
84
|
+
|
85
|
+
# Now free the parent and make sure it doesn't free the child a second time
|
86
|
+
call_tree_parent = nil
|
87
|
+
GC.start
|
88
|
+
|
89
|
+
assert(true)
|
90
|
+
ensure
|
91
|
+
GC.stress = false
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -5,13 +5,8 @@ require File.expand_path('../test_helper', __FILE__)
|
|
5
5
|
require_relative './measure_times'
|
6
6
|
|
7
7
|
class CallTreeVisitorTest < 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_visit
|
14
|
-
result = RubyProf.profile do
|
9
|
+
result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
|
15
10
|
RubyProf::C1.sleep_wait
|
16
11
|
end
|
17
12
|
|
data/test/call_trees_test.rb
CHANGED
@@ -13,7 +13,7 @@ class CallTreesTest < TestCase
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_call_infos
|
16
|
-
result = RubyProf.profile do
|
16
|
+
result = RubyProf::Profile.profile do
|
17
17
|
some_method_1
|
18
18
|
end
|
19
19
|
|
@@ -26,7 +26,7 @@ class CallTreesTest < TestCase
|
|
26
26
|
call_trees = method.call_trees
|
27
27
|
assert_empty(call_trees.callers)
|
28
28
|
assert_equal(1, call_trees.callees.length)
|
29
|
-
assert_kind_of(RubyProf::
|
29
|
+
assert_kind_of(RubyProf::CallTree, call_trees.callees[0])
|
30
30
|
assert_equal('CallTreesTest#some_method_1', call_trees.callees[0].target.full_name)
|
31
31
|
|
32
32
|
method = thread.methods[1]
|
@@ -34,10 +34,10 @@ class CallTreesTest < TestCase
|
|
34
34
|
|
35
35
|
call_trees = method.call_trees
|
36
36
|
assert_equal(1, call_trees.callers.length)
|
37
|
-
assert_kind_of(RubyProf::
|
37
|
+
assert_kind_of(RubyProf::CallTree, call_trees.callers[0])
|
38
38
|
assert_equal('CallTreesTest#test_call_infos', call_trees.callers[0].parent.target.full_name)
|
39
39
|
assert_equal(1, call_trees.callees.length)
|
40
|
-
assert_kind_of(RubyProf::
|
40
|
+
assert_kind_of(RubyProf::CallTree, call_trees.callees[0])
|
41
41
|
assert_equal('CallTreesTest#some_method_2', call_trees.callees[0].target.full_name)
|
42
42
|
|
43
43
|
method = thread.methods[2]
|
@@ -45,13 +45,13 @@ class CallTreesTest < TestCase
|
|
45
45
|
|
46
46
|
call_trees = method.call_trees
|
47
47
|
assert_equal(1, call_trees.callers.length)
|
48
|
-
assert_kind_of(RubyProf::
|
48
|
+
assert_kind_of(RubyProf::CallTree, call_trees.callers[0])
|
49
49
|
assert_equal('CallTreesTest#some_method_1', call_trees.callers[0].parent.target.full_name)
|
50
50
|
assert_empty(call_trees.callees)
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_gc
|
54
|
-
result = RubyProf.profile do
|
54
|
+
result = RubyProf::Profile.profile do
|
55
55
|
some_method_1
|
56
56
|
end
|
57
57
|
|
@@ -4,12 +4,18 @@
|
|
4
4
|
require File.expand_path('../test_helper', __FILE__)
|
5
5
|
require_relative './measure_times'
|
6
6
|
|
7
|
-
class
|
7
|
+
class CompatibilityTest < TestCase
|
8
8
|
def setup
|
9
|
-
|
9
|
+
super
|
10
|
+
Gem::Deprecate.skip = true
|
10
11
|
RubyProf::measure_mode = RubyProf::WALL_TIME
|
11
12
|
end
|
12
13
|
|
14
|
+
def teardown
|
15
|
+
super
|
16
|
+
Gem::Deprecate.skip = false
|
17
|
+
end
|
18
|
+
|
13
19
|
def test_running
|
14
20
|
assert(!RubyProf.running?)
|
15
21
|
RubyProf.start
|
@@ -3,18 +3,18 @@
|
|
3
3
|
|
4
4
|
require File.expand_path('../test_helper', __FILE__)
|
5
5
|
|
6
|
-
class
|
6
|
+
class DuplicateNamesTest < TestCase
|
7
7
|
def test_names
|
8
|
-
result = RubyProf::profile do
|
8
|
+
result = RubyProf::Profile.profile do
|
9
9
|
str = %{module Foo; class Bar; def foo; end end end}
|
10
10
|
|
11
11
|
eval str
|
12
12
|
Foo::Bar.new.foo
|
13
|
-
|
13
|
+
DuplicateNamesTest.class_eval {remove_const :Foo}
|
14
14
|
|
15
15
|
eval str
|
16
16
|
Foo::Bar.new.foo
|
17
|
-
|
17
|
+
DuplicateNamesTest.class_eval {remove_const :Foo}
|
18
18
|
|
19
19
|
eval str
|
20
20
|
Foo::Bar.new.foo
|
@@ -24,7 +24,7 @@ class DuplicateNames < TestCase
|
|
24
24
|
methods = result.threads.first.methods.sort.reverse
|
25
25
|
|
26
26
|
methods = methods.select do |method|
|
27
|
-
method.full_name == '
|
27
|
+
method.full_name == 'DuplicateNamesTest::Foo::Bar#foo'
|
28
28
|
end
|
29
29
|
|
30
30
|
assert_equal(3, methods.length)
|
data/test/dynamic_method_test.rb
CHANGED
@@ -24,14 +24,9 @@ class DynamicMethodTest < TestCase
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def setup
|
28
|
-
# Need to use wall time for this test due to the sleep calls
|
29
|
-
RubyProf::measure_mode = RubyProf::WALL_TIME
|
30
|
-
end
|
31
|
-
|
32
27
|
def test_dynamic_method
|
33
28
|
medley = FruitMedley.new
|
34
|
-
result = RubyProf.profile do
|
29
|
+
result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
|
35
30
|
medley.apple
|
36
31
|
medley.orange
|
37
32
|
medley.banana
|
@@ -39,15 +34,29 @@ class DynamicMethodTest < TestCase
|
|
39
34
|
end
|
40
35
|
|
41
36
|
methods = result.threads.first.methods.sort.reverse
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
37
|
+
|
38
|
+
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.1')
|
39
|
+
expected_method_names = %w(
|
40
|
+
DynamicMethodTest#test_dynamic_method
|
41
|
+
Kernel#sleep
|
42
|
+
DynamicMethodTest::FruitMedley#peach
|
43
|
+
DynamicMethodTest::FruitMedley#banana
|
44
|
+
DynamicMethodTest::FruitMedley#orange
|
45
|
+
DynamicMethodTest::FruitMedley#apple
|
46
|
+
Symbol#to_s
|
47
|
+
)
|
48
|
+
else
|
49
|
+
expected_method_names = %w(
|
50
|
+
DynamicMethodTest#test_dynamic_method
|
51
|
+
Kernel#sleep
|
52
|
+
DynamicMethodTest::FruitMedley#peach
|
53
|
+
DynamicMethodTest::FruitMedley#banana
|
54
|
+
DynamicMethodTest::FruitMedley#orange
|
55
|
+
DynamicMethodTest::FruitMedley#apple
|
56
|
+
Integer#==
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
51
60
|
assert_equal expected_method_names.join("\n"), methods.map(&:full_name).join("\n")
|
52
61
|
end
|
53
62
|
end
|
data/test/enumerable_test.rb
CHANGED
@@ -8,7 +8,7 @@ require File.expand_path('../test_helper', __FILE__)
|
|
8
8
|
|
9
9
|
class EnumerableTest < TestCase
|
10
10
|
def test_enumerable
|
11
|
-
result = RubyProf.profile do
|
11
|
+
result = RubyProf::Profile.profile do
|
12
12
|
3.times { [1,2,3].any? {|n| n} }
|
13
13
|
end
|
14
14
|
methods = if RUBY_VERSION >= "2.2.0"
|
data/test/exceptions_test.rb
CHANGED
@@ -6,7 +6,7 @@ require File.expand_path('../test_helper', __FILE__)
|
|
6
6
|
class ExceptionsTest < TestCase
|
7
7
|
def test_profile
|
8
8
|
result = begin
|
9
|
-
RubyProf.profile do
|
9
|
+
RubyProf::Profile.profile do
|
10
10
|
raise(RuntimeError, 'Test error')
|
11
11
|
end
|
12
12
|
rescue
|
@@ -16,7 +16,7 @@ class ExceptionsTest < TestCase
|
|
16
16
|
|
17
17
|
def test_profile_allows_exceptions
|
18
18
|
assert_raises(RuntimeError) do
|
19
|
-
RubyProf.profile(:allow_exceptions => true) do
|
19
|
+
RubyProf::Profile.profile(:allow_exceptions => true) do
|
20
20
|
raise(RuntimeError, 'Test error')
|
21
21
|
end
|
22
22
|
end
|
@@ -34,14 +34,9 @@ class ExcludeMethodsClass
|
|
34
34
|
end
|
35
35
|
|
36
36
|
class ExcludeMethodsTest < TestCase
|
37
|
-
def setup
|
38
|
-
# Need to use wall time for this test due to the sleep calls
|
39
|
-
RubyProf::measure_mode = RubyProf::WALL_TIME
|
40
|
-
end
|
41
|
-
|
42
37
|
def test_methods_can_be_profiled
|
43
38
|
obj = ExcludeMethodsClass.new
|
44
|
-
prf = RubyProf::Profile.new
|
39
|
+
prf = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
|
45
40
|
|
46
41
|
result = prf.profile {obj.a}
|
47
42
|
methods = result.threads.first.methods.sort.reverse
|
@@ -102,7 +97,7 @@ class ExcludeMethodsTest < TestCase
|
|
102
97
|
|
103
98
|
def test_exclude_common_methods1
|
104
99
|
obj = ExcludeMethodsClass.new
|
105
|
-
prf = RubyProf::Profile.new
|
100
|
+
prf = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
|
106
101
|
|
107
102
|
prf.exclude_common_methods!
|
108
103
|
|
@@ -124,7 +119,7 @@ class ExcludeMethodsTest < TestCase
|
|
124
119
|
def test_exclude_common_methods2
|
125
120
|
obj = ExcludeMethodsClass.new
|
126
121
|
|
127
|
-
result = RubyProf.profile(exclude_common: true) { 5.times {obj.a} }
|
122
|
+
result = RubyProf::Profile.profile(exclude_common: true) { 5.times {obj.a} }
|
128
123
|
methods = result.threads.first.methods.sort.reverse
|
129
124
|
|
130
125
|
assert_equal(9, methods.count)
|
@@ -26,15 +26,10 @@ class ExcludeThreadsTest < TestCase
|
|
26
26
|
thread2_proc
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
thread1.join
|
35
|
-
thread2.join
|
36
|
-
|
37
|
-
result = RubyProf.stop
|
29
|
+
result = RubyProf::Profile.profile(exclude_threads: [thread2]) do
|
30
|
+
thread1.join
|
31
|
+
thread2.join
|
32
|
+
end
|
38
33
|
|
39
34
|
assert_equal(2, result.threads.length)
|
40
35
|
|