ruby-prof 0.11.2 → 0.13.0
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.
- data/CHANGES +31 -0
- data/README.rdoc +17 -17
- data/Rakefile +28 -5
- data/bin/ruby-prof +274 -265
- data/doc/LICENSE.html +155 -0
- data/doc/README_rdoc.html +640 -0
- data/doc/Rack/RubyProf.html +319 -0
- data/doc/Rack.html +167 -0
- data/doc/RubyProf/AbstractPrinter.html +580 -0
- data/doc/RubyProf/AggregateCallInfo.html +570 -0
- data/doc/RubyProf/CallInfo.html +512 -0
- data/doc/RubyProf/CallInfoPrinter.html +190 -0
- data/doc/RubyProf/CallInfoVisitor.html +332 -0
- data/doc/RubyProf/CallStackPrinter.html +1600 -0
- data/doc/RubyProf/CallTreePrinter.html +413 -0
- data/doc/RubyProf/Cmd.html +669 -0
- data/doc/RubyProf/DotPrinter.html +312 -0
- data/doc/RubyProf/FlatPrinter.html +229 -0
- data/doc/RubyProf/FlatPrinterWithLineNumbers.html +267 -0
- data/doc/RubyProf/GraphHtmlPrinter.html +631 -0
- data/doc/RubyProf/GraphPrinter.html +209 -0
- data/doc/RubyProf/MethodInfo.html +713 -0
- data/doc/RubyProf/MultiPrinter.html +407 -0
- data/doc/RubyProf/Profile.html +821 -0
- data/doc/RubyProf/ProfileTask.html +532 -0
- data/doc/RubyProf/Test.html +578 -0
- data/doc/RubyProf/Thread.html +262 -0
- data/doc/RubyProf.html +999 -0
- data/doc/created.rid +32 -0
- data/doc/examples/flat_txt.html +191 -0
- data/doc/examples/graph_txt.html +305 -0
- data/doc/images/add.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +639 -0
- data/doc/js/darkfish.js +155 -0
- data/doc/js/jquery.js +18 -0
- data/doc/js/navigation.js +142 -0
- data/doc/js/search.js +94 -0
- data/doc/js/search_index.js +1 -0
- data/doc/js/searcher.js +228 -0
- data/doc/rdoc.css +543 -0
- data/doc/table_of_contents.html +462 -0
- data/examples/empty.png +0 -0
- data/examples/minus.png +0 -0
- data/examples/plus.png +0 -0
- data/ext/ruby_prof/extconf.rb +7 -1
- data/ext/ruby_prof/rp_call_info.c +33 -24
- data/ext/ruby_prof/rp_call_info.h +2 -1
- data/ext/ruby_prof/rp_measure.c +1 -1
- data/ext/ruby_prof/rp_measure.h +1 -1
- data/ext/ruby_prof/rp_measure_allocations.c +1 -1
- data/ext/ruby_prof/rp_measure_cpu_time.c +1 -1
- data/ext/ruby_prof/rp_measure_gc_runs.c +1 -1
- data/ext/ruby_prof/rp_measure_gc_time.c +7 -11
- data/ext/ruby_prof/rp_measure_memory.c +1 -2
- data/ext/ruby_prof/rp_measure_process_time.c +2 -2
- data/ext/ruby_prof/rp_measure_wall_time.c +2 -2
- data/ext/ruby_prof/rp_method.c +11 -24
- data/ext/ruby_prof/rp_method.h +2 -3
- data/ext/ruby_prof/rp_stack.c +50 -14
- data/ext/ruby_prof/rp_stack.h +10 -10
- data/ext/ruby_prof/rp_thread.c +54 -29
- data/ext/ruby_prof/rp_thread.h +8 -7
- data/ext/ruby_prof/ruby_prof.c +35 -98
- data/ext/ruby_prof/ruby_prof.h +1 -1
- data/ext/ruby_prof/vc/ruby_prof.sln +12 -6
- data/ext/ruby_prof/vc/{ruby_prof.vcxproj → ruby_prof_19.vcxproj} +1 -0
- data/ext/ruby_prof/vc/ruby_prof_20.vcxproj +110 -0
- data/ext/ruby_prof/version.h +4 -4
- data/lib/ruby-prof/call_info.rb +1 -1
- data/lib/ruby-prof/call_info_visitor.rb +4 -2
- data/lib/ruby-prof/compatibility.rb +21 -6
- data/lib/ruby-prof/images/empty.png +0 -0
- data/lib/ruby-prof/images/minus.png +0 -0
- data/lib/ruby-prof/images/plus.png +0 -0
- data/lib/ruby-prof/method_info.rb +1 -1
- data/lib/ruby-prof/printers/call_info_printer.rb +3 -2
- data/lib/ruby-prof/printers/call_stack_printer.rb +10 -7
- data/lib/ruby-prof/printers/dot_printer.rb +2 -2
- data/lib/ruby-prof/printers/flat_printer.rb +5 -4
- data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +2 -2
- data/lib/ruby-prof/printers/graph_html_printer.rb +16 -8
- data/lib/ruby-prof/printers/graph_printer.rb +17 -16
- data/lib/ruby-prof/profile.rb +1 -1
- data/lib/ruby-prof/rack.rb +1 -6
- data/lib/ruby-prof/task.rb +0 -0
- data/lib/ruby-prof/thread.rb +22 -0
- data/lib/ruby-prof.rb +1 -0
- data/ruby-prof.gemspec +5 -3
- data/test/aggregate_test.rb +0 -0
- data/test/basic_test.rb +77 -45
- data/test/call_info_test.rb +78 -0
- data/test/call_info_visitor_test.rb +1 -1
- data/test/duplicate_names_test.rb +0 -0
- data/test/dynamic_method_test.rb +21 -8
- data/test/enumerable_test.rb +0 -0
- data/test/exceptions_test.rb +0 -0
- data/test/exclude_threads_test.rb +0 -0
- data/test/exec_test.rb +0 -0
- data/test/fiber_test.rb +65 -0
- data/test/line_number_test.rb +0 -0
- data/test/measure_cpu_time_test.rb +23 -12
- data/test/measure_gc_runs_test.rb +4 -1
- data/test/measure_gc_time_test.rb +10 -3
- data/test/measure_memory_test.rb +3 -8
- data/test/measure_process_time_test.rb +27 -170
- data/test/measure_wall_time_test.rb +59 -13
- data/test/method_elimination_test.rb +31 -21
- data/test/module_test.rb +0 -0
- data/test/multi_printer_test.rb +9 -8
- data/test/no_method_class_test.rb +0 -0
- data/test/pause_resume_test.rb +125 -20
- data/test/prime.rb +1 -2
- data/test/printers_test.rb +10 -17
- data/test/recursive_test.rb +6 -50
- data/test/singleton_test.rb +0 -0
- data/test/stack_printer_test.rb +9 -6
- data/test/stack_test.rb +0 -0
- data/test/start_stop_test.rb +0 -0
- data/test/test_helper.rb +45 -11
- data/test/test_suite.rb +1 -2
- data/test/thread_test.rb +0 -0
- data/test/unique_call_path_test.rb +0 -0
- metadata +107 -12
- data/test/bug_test.rb +0 -6
- data/test/gc_test.rb +0 -35
- data/test/pause_test.rb +0 -57
- data/test/prime_test.rb +0 -13
data/test/pause_resume_test.rb
CHANGED
|
@@ -4,22 +4,73 @@
|
|
|
4
4
|
require File.expand_path('../test_helper', __FILE__)
|
|
5
5
|
|
|
6
6
|
class PauseResumeTest < Test::Unit::TestCase
|
|
7
|
+
def setup
|
|
8
|
+
# Need to use wall time for this test due to the sleep calls
|
|
9
|
+
RubyProf::measure_mode = RubyProf::WALL_TIME
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_pause_resume
|
|
13
|
+
# Measured
|
|
14
|
+
RubyProf.start
|
|
15
|
+
RubyProf::C1.hello
|
|
16
|
+
|
|
17
|
+
# Not measured
|
|
18
|
+
RubyProf.pause
|
|
19
|
+
sleep 1
|
|
20
|
+
RubyProf::C1.hello
|
|
21
|
+
|
|
22
|
+
# Measured
|
|
23
|
+
RubyProf.resume
|
|
24
|
+
RubyProf::C1.hello
|
|
25
|
+
|
|
26
|
+
result = RubyProf.stop
|
|
27
|
+
|
|
28
|
+
# Length should be 3:
|
|
29
|
+
# PauseResumeTest#test_pause_resume
|
|
30
|
+
# <Class::RubyProf::C1>#hello
|
|
31
|
+
# Kernel#sleep
|
|
32
|
+
|
|
33
|
+
methods = result.threads.first.methods.sort_by {|method_info| method_info.full_name}
|
|
34
|
+
# remove methods called by pause/resume
|
|
35
|
+
called_methods = ['Array#include?', 'Fixnum#==', 'Kernel#respond_to?', 'Kernel#respond_to_missing?']
|
|
36
|
+
methods.reject!{|m| called_methods.include?(m.full_name) }
|
|
37
|
+
# TODO: fix pause/resume to not include those methods in the first place
|
|
38
|
+
assert_equal(3, methods.length)
|
|
39
|
+
|
|
40
|
+
# Check the names
|
|
41
|
+
assert_equal('<Class::RubyProf::C1>#hello', methods[0].full_name)
|
|
42
|
+
assert_equal('Kernel#sleep', methods[1].full_name)
|
|
43
|
+
assert_equal('PauseResumeTest#test_pause_resume', methods[2].full_name)
|
|
44
|
+
|
|
45
|
+
# Check times
|
|
46
|
+
assert_in_delta(0.2, methods[0].total_time, 0.01)
|
|
47
|
+
assert_in_delta(0, methods[0].wait_time, 0.01)
|
|
48
|
+
assert_in_delta(0, methods[0].self_time, 0.01)
|
|
49
|
+
|
|
50
|
+
assert_in_delta(0.2, methods[1].total_time, 0.01)
|
|
51
|
+
assert_in_delta(0, methods[1].wait_time, 0.01)
|
|
52
|
+
assert_in_delta(0.2, methods[1].self_time, 0.01)
|
|
53
|
+
|
|
54
|
+
assert_in_delta(0.2, methods[2].total_time, 0.01)
|
|
55
|
+
assert_in_delta(0, methods[2].wait_time, 0.01)
|
|
56
|
+
assert_in_delta(0, methods[2].self_time, 0.01)
|
|
57
|
+
end
|
|
7
58
|
|
|
8
59
|
# pause/resume in the same frame
|
|
9
60
|
def test_pause_resume_1
|
|
10
|
-
|
|
61
|
+
profile = RubyProf::Profile.new(RubyProf::WALL_TIME,[])
|
|
11
62
|
|
|
12
|
-
|
|
63
|
+
profile.start
|
|
13
64
|
method_1a
|
|
14
65
|
|
|
15
|
-
|
|
66
|
+
profile.pause
|
|
16
67
|
method_1b
|
|
17
68
|
|
|
18
|
-
|
|
69
|
+
profile.resume
|
|
19
70
|
method_1c
|
|
20
71
|
|
|
21
|
-
|
|
22
|
-
assert_in_delta(0.6,
|
|
72
|
+
result = profile.stop
|
|
73
|
+
assert_in_delta(0.6, result.threads[0].methods.select{|m| m.full_name =~ /test_pause_resume_1$/}[0].total_time, 0.05)
|
|
23
74
|
end
|
|
24
75
|
def method_1a; sleep 0.2 end
|
|
25
76
|
def method_1b; sleep 1 end
|
|
@@ -27,35 +78,89 @@ class PauseResumeTest < Test::Unit::TestCase
|
|
|
27
78
|
|
|
28
79
|
# pause in parent frame, resume in child
|
|
29
80
|
def test_pause_resume_2
|
|
30
|
-
|
|
81
|
+
profile = RubyProf::Profile.new(RubyProf::WALL_TIME,[])
|
|
31
82
|
|
|
32
|
-
|
|
83
|
+
profile.start
|
|
33
84
|
method_2a
|
|
34
85
|
|
|
35
|
-
|
|
86
|
+
profile.pause
|
|
36
87
|
sleep 0.5
|
|
37
|
-
method_2b(
|
|
88
|
+
method_2b(profile)
|
|
38
89
|
|
|
39
|
-
|
|
40
|
-
assert_in_delta(0.6,
|
|
90
|
+
result = profile.stop
|
|
91
|
+
assert_in_delta(0.6, result.threads[0].methods.select{|m| m.full_name =~ /test_pause_resume_2$/}[0].total_time, 0.05)
|
|
41
92
|
end
|
|
42
93
|
def method_2a; sleep 0.2 end
|
|
43
|
-
def method_2b(
|
|
94
|
+
def method_2b(profile); sleep 0.5; profile.resume; sleep 0.4 end
|
|
44
95
|
|
|
45
96
|
# pause in child frame, resume in parent
|
|
46
97
|
def test_pause_resume_3
|
|
47
|
-
|
|
98
|
+
profile = RubyProf::Profile.new(RubyProf::WALL_TIME,[])
|
|
48
99
|
|
|
49
|
-
|
|
50
|
-
method_3a(
|
|
100
|
+
profile.start
|
|
101
|
+
method_3a(profile)
|
|
51
102
|
|
|
52
103
|
sleep 0.5
|
|
53
|
-
|
|
104
|
+
profile.resume
|
|
54
105
|
method_3b
|
|
55
106
|
|
|
56
|
-
|
|
57
|
-
assert_in_delta(0.6,
|
|
107
|
+
result = profile.stop
|
|
108
|
+
assert_in_delta(0.6, result.threads[0].methods.select{|m| m.full_name =~ /test_pause_resume_3$/}[0].total_time, 0.05)
|
|
58
109
|
end
|
|
59
|
-
def method_3a(
|
|
110
|
+
def method_3a(profile); sleep 0.2; profile.pause; sleep 0.5 end
|
|
60
111
|
def method_3b; sleep 0.4 end
|
|
112
|
+
|
|
113
|
+
def test_pause_seq
|
|
114
|
+
profile = RubyProf::Profile.new(RubyProf::WALL_TIME,[])
|
|
115
|
+
profile.start ; assert !profile.paused?
|
|
116
|
+
profile.pause ; assert profile.paused?
|
|
117
|
+
profile.resume; assert !profile.paused?
|
|
118
|
+
profile.pause ; assert profile.paused?
|
|
119
|
+
profile.pause ; assert profile.paused?
|
|
120
|
+
profile.resume; assert !profile.paused?
|
|
121
|
+
profile.resume; assert !profile.paused?
|
|
122
|
+
profile.stop ; assert !profile.paused?
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def test_pause_block
|
|
126
|
+
profile = RubyProf::Profile.new(RubyProf::WALL_TIME,[])
|
|
127
|
+
profile.start
|
|
128
|
+
profile.pause
|
|
129
|
+
assert profile.paused?
|
|
130
|
+
|
|
131
|
+
times_block_invoked = 0
|
|
132
|
+
retval= profile.resume{
|
|
133
|
+
times_block_invoked += 1
|
|
134
|
+
120 + times_block_invoked
|
|
135
|
+
}
|
|
136
|
+
assert_equal 1, times_block_invoked
|
|
137
|
+
assert profile.paused?
|
|
138
|
+
|
|
139
|
+
assert_equal 121, retval, "resume() should return the result of the given block."
|
|
140
|
+
|
|
141
|
+
profile.stop
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def test_pause_block_with_error
|
|
145
|
+
profile = RubyProf::Profile.new(RubyProf::WALL_TIME,[])
|
|
146
|
+
profile.start
|
|
147
|
+
profile.pause
|
|
148
|
+
assert profile.paused?
|
|
149
|
+
|
|
150
|
+
begin
|
|
151
|
+
profile.resume{ raise }
|
|
152
|
+
flunk 'Exception expected.'
|
|
153
|
+
rescue
|
|
154
|
+
assert profile.paused?
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
profile.stop
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def test_resume_when_not_paused
|
|
161
|
+
profile = RubyProf::Profile.new(RubyProf::WALL_TIME,[])
|
|
162
|
+
profile.start ; assert !profile.paused?
|
|
163
|
+
profile.resume; assert !profile.paused?
|
|
164
|
+
profile.stop ; assert !profile.paused?
|
|
165
|
+
end
|
|
61
166
|
end
|
data/test/prime.rb
CHANGED
|
@@ -34,7 +34,6 @@ def find_largest(primes)
|
|
|
34
34
|
# Intentionally use upto for example purposes
|
|
35
35
|
# (upto is also called from is_prime)
|
|
36
36
|
0.upto(primes.length-1) do |i|
|
|
37
|
-
sleep(0.02)
|
|
38
37
|
prime = primes[i]
|
|
39
38
|
if prime > largest
|
|
40
39
|
largest = prime
|
|
@@ -51,5 +50,5 @@ def run_primes(length=10, maxnum=1000)
|
|
|
51
50
|
primes = find_primes(random_array)
|
|
52
51
|
|
|
53
52
|
# Find the largest primes
|
|
54
|
-
|
|
53
|
+
find_largest(primes)
|
|
55
54
|
end
|
data/test/printers_test.rb
CHANGED
|
@@ -7,20 +7,11 @@ require 'fileutils'
|
|
|
7
7
|
|
|
8
8
|
# -- Tests ----
|
|
9
9
|
class PrintersTest < Test::Unit::TestCase
|
|
10
|
-
def go
|
|
11
|
-
run_primes(1000)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
10
|
def setup
|
|
15
11
|
# WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
|
|
16
12
|
RubyProf::measure_mode = RubyProf::WALL_TIME
|
|
17
13
|
@result = RubyProf.profile do
|
|
18
|
-
|
|
19
|
-
run_primes(1000)
|
|
20
|
-
go
|
|
21
|
-
rescue => e
|
|
22
|
-
p e
|
|
23
|
-
end
|
|
14
|
+
run_primes(200)
|
|
24
15
|
end
|
|
25
16
|
end
|
|
26
17
|
|
|
@@ -45,7 +36,6 @@ class PrintersTest < Test::Unit::TestCase
|
|
|
45
36
|
|
|
46
37
|
printer = RubyProf::GraphPrinter.new(@result)
|
|
47
38
|
printer.print(output)
|
|
48
|
-
|
|
49
39
|
end
|
|
50
40
|
end
|
|
51
41
|
|
|
@@ -85,6 +75,7 @@ class PrintersTest < Test::Unit::TestCase
|
|
|
85
75
|
printer.print(output)
|
|
86
76
|
|
|
87
77
|
assert_match(/Thread ID: -?\d+/i, output)
|
|
78
|
+
assert_match(/Fiber ID: -?\d+/i, output) unless RUBY_VERSION =~ /^1.8/
|
|
88
79
|
assert_match(/Total: \d+\.\d+/i, output)
|
|
89
80
|
assert_match(/Object#run_primes/i, output)
|
|
90
81
|
output
|
|
@@ -111,9 +102,9 @@ class PrintersTest < Test::Unit::TestCase
|
|
|
111
102
|
printer = RubyProf::GraphHtmlPrinter.new(@result)
|
|
112
103
|
printer.print(output)
|
|
113
104
|
|
|
114
|
-
assert_match(
|
|
115
|
-
assert_match( %r{<th>Total Time</th>}i, output
|
|
116
|
-
assert_match(
|
|
105
|
+
assert_match(/DTD HTML 4\.01/i, output)
|
|
106
|
+
assert_match( %r{<th>Total Time</th>}i, output)
|
|
107
|
+
assert_match(/Object#run_primes/i, output)
|
|
117
108
|
end
|
|
118
109
|
|
|
119
110
|
def test_graph_string
|
|
@@ -121,9 +112,10 @@ class PrintersTest < Test::Unit::TestCase
|
|
|
121
112
|
printer = RubyProf::GraphPrinter.new(@result)
|
|
122
113
|
printer.print(output)
|
|
123
114
|
|
|
124
|
-
assert_match(
|
|
125
|
-
assert_match(
|
|
126
|
-
assert_match(
|
|
115
|
+
assert_match(/Thread ID: -?\d+/i, output)
|
|
116
|
+
assert_match(/Fiber ID: -?\d+/i, output) unless RUBY_VERSION =~ /^1.8/
|
|
117
|
+
assert_match(/Total Time: \d+\.\d+/i, output)
|
|
118
|
+
assert_match(/Object#run_primes/i, output)
|
|
127
119
|
end
|
|
128
120
|
|
|
129
121
|
def test_call_tree_string
|
|
@@ -259,6 +251,7 @@ class PrintersTest < Test::Unit::TestCase
|
|
|
259
251
|
end
|
|
260
252
|
|
|
261
253
|
def assert_sorted array
|
|
254
|
+
array = array.map{|n| n.to_f} # allow for > 10s times to sort right, since lexographically 4.0 > 10.0
|
|
262
255
|
assert_equal array, array.sort.reverse, "Array #{array.inspect} is not sorted"
|
|
263
256
|
end
|
|
264
257
|
end
|
data/test/recursive_test.rb
CHANGED
|
@@ -43,17 +43,13 @@ class RecursiveTest < Test::Unit::TestCase
|
|
|
43
43
|
simple(2)
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
methods = result.threads.first.methods.dup
|
|
47
|
-
|
|
48
46
|
# Remove Fixnum+, Fixnum== for less than Ruby 1.9
|
|
49
|
-
|
|
50
|
-
method.full_name.match(/Fixnum/)
|
|
51
|
-
end
|
|
47
|
+
result.eliminate_methods!(%w(Fixnum#== Fixnum#-))
|
|
52
48
|
|
|
49
|
+
methods = result.threads.first.methods.sort.reverse
|
|
53
50
|
assert_equal(3, methods.length)
|
|
54
51
|
|
|
55
52
|
# Method 0: RecursiveTest#test_simple
|
|
56
|
-
methods.sort!.reverse!
|
|
57
53
|
method = methods[0]
|
|
58
54
|
assert_equal('RecursiveTest#test_simple', method.full_name)
|
|
59
55
|
assert_equal(1, method.called)
|
|
@@ -80,12 +76,12 @@ class RecursiveTest < Test::Unit::TestCase
|
|
|
80
76
|
assert_equal(2, method.call_infos.length)
|
|
81
77
|
|
|
82
78
|
call_info = method.call_infos.first
|
|
83
|
-
assert_equal(2
|
|
79
|
+
assert_equal(2, call_info.children.length)
|
|
84
80
|
assert_equal('RecursiveTest#test_simple->Object#simple', call_info.call_sequence)
|
|
85
81
|
assert(!call_info.recursive)
|
|
86
82
|
|
|
87
83
|
call_info = method.call_infos.last
|
|
88
|
-
assert_equal(1
|
|
84
|
+
assert_equal(1, call_info.children.length)
|
|
89
85
|
assert_equal('RecursiveTest#test_simple->Object#simple->Object#simple', call_info.call_sequence)
|
|
90
86
|
assert(call_info.recursive)
|
|
91
87
|
|
|
@@ -107,43 +103,6 @@ class RecursiveTest < Test::Unit::TestCase
|
|
|
107
103
|
assert_equal('RecursiveTest#test_simple->Object#simple->Object#simple->Kernel#sleep', call_info.call_sequence)
|
|
108
104
|
assert_equal(0, call_info.children.length)
|
|
109
105
|
assert(!call_info.recursive)
|
|
110
|
-
|
|
111
|
-
if RUBY_VERSION < '1.9'
|
|
112
|
-
methods = result.threads.first.methods.dup.sort!.reverse!
|
|
113
|
-
method = methods[3]
|
|
114
|
-
assert_equal('Fixnum#-', method.full_name)
|
|
115
|
-
assert_equal(2, method.called)
|
|
116
|
-
assert_in_delta(0, method.total_time, 0.01)
|
|
117
|
-
assert_in_delta(0, method.self_time, 0.01)
|
|
118
|
-
assert_in_delta(0, method.wait_time, 0.01)
|
|
119
|
-
assert_in_delta(0, method.children_time, 0.01)
|
|
120
|
-
|
|
121
|
-
assert_equal(2, method.call_infos.length)
|
|
122
|
-
call_info = method.call_infos[0]
|
|
123
|
-
assert_equal('RecursiveTest#test_simple->Object#simple->Fixnum#-', call_info.call_sequence)
|
|
124
|
-
assert_equal(0, call_info.children.length)
|
|
125
|
-
|
|
126
|
-
call_info = method.call_infos[1]
|
|
127
|
-
assert_equal('RecursiveTest#test_simple->Object#simple->Object#simple->Fixnum#-', call_info.call_sequence)
|
|
128
|
-
assert_equal(0, call_info.children.length)
|
|
129
|
-
|
|
130
|
-
method = methods[4]
|
|
131
|
-
assert_equal('Fixnum#==', method.full_name)
|
|
132
|
-
assert_equal(2, method.called)
|
|
133
|
-
assert_in_delta(0, method.total_time, 0.01)
|
|
134
|
-
assert_in_delta(0, method.self_time, 0.01)
|
|
135
|
-
assert_in_delta(0, method.wait_time, 0.01)
|
|
136
|
-
assert_in_delta(0, method.children_time, 0.01)
|
|
137
|
-
|
|
138
|
-
assert_equal(2, method.call_infos.length)
|
|
139
|
-
call_info = method.call_infos[0]
|
|
140
|
-
assert_equal('RecursiveTest#test_simple->Object#simple->Fixnum#==', call_info.call_sequence)
|
|
141
|
-
assert_equal(0, call_info.children.length)
|
|
142
|
-
|
|
143
|
-
call_info = method.call_infos[1]
|
|
144
|
-
assert_equal('RecursiveTest#test_simple->Object#simple->Object#simple->Fixnum#==', call_info.call_sequence)
|
|
145
|
-
assert_equal(0, call_info.children.length)
|
|
146
|
-
end
|
|
147
106
|
end
|
|
148
107
|
|
|
149
108
|
def test_cycle
|
|
@@ -151,9 +110,6 @@ class RecursiveTest < Test::Unit::TestCase
|
|
|
151
110
|
render
|
|
152
111
|
end
|
|
153
112
|
|
|
154
|
-
printer = RubyProf::GraphPrinter.new(result)
|
|
155
|
-
printer.print(STDOUT)
|
|
156
|
-
|
|
157
113
|
methods = result.threads.first.methods.sort.reverse
|
|
158
114
|
if RUBY_VERSION < '1.9' # Fixnum#+, Fixnum#===, Kernel#===
|
|
159
115
|
assert_equal(8, methods.length)
|
|
@@ -214,7 +170,7 @@ class RecursiveTest < Test::Unit::TestCase
|
|
|
214
170
|
assert_in_delta(5, method.total_time, 0.1)
|
|
215
171
|
assert_in_delta(0, method.self_time, 0.1)
|
|
216
172
|
assert_in_delta(0, method.wait_time, 0.01)
|
|
217
|
-
assert_in_delta(5, method.children_time, 0.
|
|
173
|
+
assert_in_delta(5, method.children_time, 0.05)
|
|
218
174
|
|
|
219
175
|
assert_equal(3, method.call_infos.length)
|
|
220
176
|
call_info = method.call_infos[0]
|
|
@@ -256,4 +212,4 @@ class RecursiveTest < Test::Unit::TestCase
|
|
|
256
212
|
assert_equal(0, call_info.children.length)
|
|
257
213
|
assert(!call_info.recursive)
|
|
258
214
|
end
|
|
259
|
-
end
|
|
215
|
+
end
|
data/test/singleton_test.rb
CHANGED
|
File without changes
|
data/test/stack_printer_test.rb
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
# encoding: UTF-8
|
|
3
3
|
|
|
4
4
|
require File.expand_path('../test_helper', __FILE__)
|
|
5
|
-
require 'tmpdir'
|
|
6
5
|
|
|
7
6
|
# Test data
|
|
8
7
|
# A
|
|
@@ -43,9 +42,10 @@ class StackPrinterTest < Test::Unit::TestCase
|
|
|
43
42
|
|
|
44
43
|
file_contents = nil
|
|
45
44
|
assert_nothing_raised { file_contents = print(result) }
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
# TODO: why are thread ids negative on travis-ci.org (32 bit build maybe?)
|
|
46
|
+
assert_match(/Thread: (-?\d+)(, Fiber: (-?\d+))? \(100\.00% ~ ([\.0-9]+)\)/, file_contents)
|
|
47
|
+
actual_time = $4.to_f
|
|
48
|
+
assert_in_delta(expected_time, actual_time, 0.5)
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
def test_method_elimination
|
|
@@ -64,10 +64,13 @@ class StackPrinterTest < Test::Unit::TestCase
|
|
|
64
64
|
private
|
|
65
65
|
def print(result)
|
|
66
66
|
test = caller.first =~ /in `(.*)'/ ? $1 : "test"
|
|
67
|
-
testfile_name = "#{
|
|
67
|
+
testfile_name = "#{RubyProf.tmpdir}/ruby_prof_#{test}.html"
|
|
68
|
+
# puts "printing to #{testfile_name}"
|
|
68
69
|
printer = RubyProf::CallStackPrinter.new(result)
|
|
69
70
|
File.open(testfile_name, "w") {|f| printer.print(f, :threshold => 0, :min_percent => 0, :title => "ruby_prof #{test}")}
|
|
70
71
|
system("open '#{testfile_name}'") if RUBY_PLATFORM =~ /darwin/ && ENV['SHOW_RUBY_PROF_PRINTER_OUTPUT']=="1"
|
|
71
|
-
File.
|
|
72
|
+
assert File.exist?(testfile_name), "#{testfile_name} does not exist"
|
|
73
|
+
assert File.readable?(testfile_name), "#{testfile_name} is no readable"
|
|
74
|
+
File.read(testfile_name)
|
|
72
75
|
end
|
|
73
76
|
end
|
data/test/stack_test.rb
CHANGED
|
File without changes
|
data/test/start_stop_test.rb
CHANGED
|
File without changes
|
data/test/test_helper.rb
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
# encoding: UTF-8
|
|
2
2
|
|
|
3
3
|
# Make RubyMine happy
|
|
4
|
+
require "rubygems"
|
|
5
|
+
gem "minitest"
|
|
6
|
+
|
|
4
7
|
if ENV["RM_INFO"] || ENV["TEAMCITY_VERSION"]
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
if RUBY_PLATFORM =~ /(win32|mingw)/
|
|
9
|
+
gem "win32console"
|
|
10
|
+
end
|
|
11
|
+
gem "minitest-reporters"
|
|
7
12
|
require 'minitest/reporters'
|
|
8
|
-
MiniTest::
|
|
9
|
-
MiniTest::Unit.runner.reporters << MiniTest::Reporters::RubyMineReporter.new
|
|
13
|
+
MiniTest::Reporters.use!
|
|
10
14
|
end
|
|
11
15
|
|
|
12
|
-
|
|
16
|
+
require "minitest/pride"
|
|
13
17
|
|
|
18
|
+
# To make testing/debugging easier, test within this source tree versus an installed gem
|
|
14
19
|
dir = File.dirname(__FILE__)
|
|
15
20
|
root = File.expand_path(File.join(dir, '..'))
|
|
16
21
|
lib = File.expand_path(File.join(root, 'lib'))
|
|
@@ -71,11 +76,40 @@ module RubyProf
|
|
|
71
76
|
goodbye
|
|
72
77
|
end
|
|
73
78
|
end
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
PARENT = BasicObject
|
|
79
|
+
|
|
80
|
+
def self.ruby_major_version
|
|
81
|
+
match = RUBY_VERSION.match(/(\d)\.(\d)/)
|
|
82
|
+
return Integer(match[1])
|
|
79
83
|
end
|
|
80
84
|
|
|
81
|
-
|
|
85
|
+
def self.ruby_minor_version
|
|
86
|
+
match = RUBY_VERSION.match(/(\d)\.(\d)/)
|
|
87
|
+
return Integer(match[2])
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def self.parent_object
|
|
91
|
+
if ruby_major_version == 1 && ruby_minor_version == 8
|
|
92
|
+
Object
|
|
93
|
+
else
|
|
94
|
+
BasicObject
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def self.ruby_2?
|
|
99
|
+
ruby_major_version == 2
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# store printer output in this directory
|
|
103
|
+
def self.tmpdir
|
|
104
|
+
File.expand_path('../../tmp', __FILE__)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
module MemoryTestHelper
|
|
109
|
+
def memory_test_helper
|
|
110
|
+
result = RubyProf.profile {Array.new}
|
|
111
|
+
total = result.threads.first.methods.inject(0) { |sum, m| sum + m.total_time }
|
|
112
|
+
assert(total < 1_000_000, 'Total should not have subtract overflow error')
|
|
113
|
+
total
|
|
114
|
+
end
|
|
115
|
+
end
|
data/test/test_suite.rb
CHANGED
data/test/thread_test.rb
CHANGED
|
File without changes
|
|
File without changes
|