ruby-prof 1.7.1 → 1.7.2
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/CHANGES +8 -0
- data/ext/ruby_prof/extconf.rb +23 -22
- data/ext/ruby_prof/rp_call_trees.c +296 -296
- data/ext/ruby_prof/rp_call_trees.h +28 -28
- data/ext/ruby_prof/rp_measure_allocations.c +47 -47
- data/ext/ruby_prof/rp_measure_process_time.c +64 -66
- data/ext/ruby_prof/rp_measure_wall_time.c +52 -64
- data/ext/ruby_prof/rp_method.c +551 -551
- data/ext/ruby_prof/rp_stack.c +212 -212
- data/ext/ruby_prof/ruby_prof.c +50 -50
- data/ext/ruby_prof/ruby_prof.h +3 -2
- data/ext/ruby_prof/vc/ruby_prof.vcxproj +3 -3
- data/lib/ruby-prof/compatibility.rb +113 -113
- data/lib/ruby-prof/exclude_common_methods.rb +204 -204
- data/lib/ruby-prof/printers/abstract_printer.rb +156 -138
- data/lib/ruby-prof/version.rb +3 -3
- data/ruby-prof.gemspec +66 -65
- data/test/dynamic_method_test.rb +9 -21
- data/test/enumerable_test.rb +23 -21
- data/test/exclude_methods_test.rb +363 -257
- data/test/fiber_test.rb +195 -195
- data/test/gc_test.rb +104 -102
- data/test/line_number_test.rb +426 -289
- data/test/measure_allocations_test.rb +1172 -1081
- data/test/measure_memory_test.rb +1193 -1456
- data/test/measure_process_time_test.rb +3330 -2477
- data/test/measure_wall_time_test.rb +634 -568
- data/test/merge_test.rb +146 -146
- data/test/method_info_test.rb +100 -95
- data/test/printers_test.rb +178 -135
- data/test/recursive_test.rb +796 -622
- data/test/start_stop_test.rb +4 -4
- data/test/test_helper.rb +20 -20
- data/test/thread_test.rb +229 -231
- data/test/unique_call_path_test.rb +9 -22
- data/test/yarv_test.rb +1 -5
- metadata +19 -9
- data/test/crash2.rb +0 -144
data/test/printers_test.rb
CHANGED
@@ -1,135 +1,178 @@
|
|
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 PrintersTest < TestCase
|
12
|
-
def setup
|
13
|
-
super
|
14
|
-
# WALL_TIME
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
printer = RubyProf::
|
30
|
-
printer.print(output)
|
31
|
-
|
32
|
-
printer = RubyProf::
|
33
|
-
printer.print(
|
34
|
-
|
35
|
-
printer = RubyProf::
|
36
|
-
printer.print(output)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
printer = RubyProf::
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
output
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
def
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
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 PrintersTest < TestCase
|
12
|
+
def setup
|
13
|
+
super
|
14
|
+
# WALL_TIME, PROCESS_TIME, ALLOCATIONS and MEMORY as types of measuremen
|
15
|
+
measure_modes = {wall_time: RubyProf::WALL_TIME, process_time: RubyProf::PROCESS_TIME, allocations: RubyProf::ALLOCATIONS, memory: RubyProf::MEMORY}
|
16
|
+
|
17
|
+
@results = {}
|
18
|
+
|
19
|
+
measure_modes.each do |key, value|
|
20
|
+
@results[key] = RubyProf::Profile.profile(measure_mode: value) do
|
21
|
+
run_primes(1000, 5000)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_printers
|
27
|
+
output = ENV['SHOW_RUBY_PROF_PRINTER_OUTPUT'] == "1" ? STDOUT : StringIO.new('')
|
28
|
+
|
29
|
+
printer = RubyProf::CallStackPrinter.new(@results[:wall_time])
|
30
|
+
printer.print(output)
|
31
|
+
|
32
|
+
printer = RubyProf::CallTreePrinter.new(@results[:wall_time])
|
33
|
+
printer.print(:path => Dir.tmpdir)
|
34
|
+
|
35
|
+
printer = RubyProf::FlatPrinter.new(@results[:wall_time])
|
36
|
+
printer.print(output)
|
37
|
+
|
38
|
+
printer = RubyProf::GraphHtmlPrinter.new(@results[:wall_time])
|
39
|
+
printer.print(output)
|
40
|
+
|
41
|
+
printer = RubyProf::GraphPrinter.new(@results[:wall_time])
|
42
|
+
printer.print(output)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_print_to_files
|
46
|
+
printer = RubyProf::DotPrinter.new(@results[:wall_time])
|
47
|
+
File.open("#{Dir.tmpdir}/graph.dot", "w") {|f| printer.print(f)}
|
48
|
+
|
49
|
+
printer = RubyProf::CallStackPrinter.new(@results[:wall_time])
|
50
|
+
File.open("#{Dir.tmpdir}/stack.html", "w") {|f| printer.print(f, :application => "primes")}
|
51
|
+
|
52
|
+
printer = RubyProf::MultiPrinter.new(@results[:wall_time])
|
53
|
+
printer.print(:path => Dir.tmpdir, :profile => "multi", :application => "primes")
|
54
|
+
|
55
|
+
['graph.dot', 'multi.flat.txt', 'multi.graph.html', "multi.callgrind.out.#{$$}", 'multi.stack.html', 'stack.html'].each do |file_name|
|
56
|
+
file_path = File.join(Dir.tmpdir, file_name)
|
57
|
+
refute(File.empty?(file_path))
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_refuses_io_objects
|
62
|
+
p = RubyProf::MultiPrinter.new(@results[:wall_time])
|
63
|
+
begin
|
64
|
+
p.print(STDOUT)
|
65
|
+
flunk "should have raised an ArgumentError"
|
66
|
+
rescue ArgumentError => e
|
67
|
+
assert_match(/IO/, e.to_s)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_refuses_non_hashes
|
72
|
+
p = RubyProf::MultiPrinter.new (@results[:wall_time])
|
73
|
+
begin
|
74
|
+
p.print([])
|
75
|
+
flunk "should have raised an ArgumentError"
|
76
|
+
rescue ArgumentError => e
|
77
|
+
assert_match(/hash/, e.to_s)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_flat_string
|
82
|
+
output = helper_test_flat_string(RubyProf::FlatPrinter)
|
83
|
+
assert_match(/prime.rb/, output)
|
84
|
+
end
|
85
|
+
|
86
|
+
def helper_test_flat_string(klass)
|
87
|
+
output = ''
|
88
|
+
|
89
|
+
printer = klass.new(@results[:wall_time])
|
90
|
+
printer.print(output)
|
91
|
+
|
92
|
+
assert_match(/Thread ID: -?\d+/i, output)
|
93
|
+
assert_match(/Fiber ID: -?\d+/i, output)
|
94
|
+
assert_match(/Total: \d+\.\d+/i, output)
|
95
|
+
assert_match(/Object#run_primes/i, output)
|
96
|
+
output
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_graph_html_string
|
100
|
+
output = ''
|
101
|
+
printer = RubyProf::GraphHtmlPrinter.new(@results[:wall_time])
|
102
|
+
printer.print(output)
|
103
|
+
|
104
|
+
assert_match(/<!DOCTYPE html>/i, output)
|
105
|
+
assert_match( %r{<th>Total</th>}i, output)
|
106
|
+
assert_match(/Object#run_primes/i, output)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_graph_string
|
110
|
+
output = ''
|
111
|
+
printer = RubyProf::GraphPrinter.new(@results[:wall_time])
|
112
|
+
printer.print(output)
|
113
|
+
|
114
|
+
assert_match(/Thread ID: -?\d+/i, output)
|
115
|
+
assert_match(/Fiber ID: -?\d+/i, output)
|
116
|
+
assert_match(/Total Time: \d+\.\d+/i, output)
|
117
|
+
assert_match(/Object#run_primes/i, output)
|
118
|
+
end
|
119
|
+
|
120
|
+
def do_nothing
|
121
|
+
start = Time.now
|
122
|
+
while(Time.now == start)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_all_with_small_percentiles
|
127
|
+
result = RubyProf::Profile.profile do
|
128
|
+
sleep 2
|
129
|
+
do_nothing
|
130
|
+
end
|
131
|
+
|
132
|
+
# RubyProf::CallTreePrinter doesn't "do" a min_percent
|
133
|
+
# RubyProf::FlatPrinter only outputs if self time > percent...
|
134
|
+
for klass in [RubyProf::GraphPrinter, RubyProf::GraphHtmlPrinter]
|
135
|
+
printer = klass.new(result)
|
136
|
+
out = ''
|
137
|
+
printer.print(out, :min_percent => 0.00000001)
|
138
|
+
assert_match(/do_nothing/, out)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_print_footer
|
143
|
+
results_keys = [:wall_time, :process_time, :allocations, :memory]
|
144
|
+
expected_matches = [
|
145
|
+
"The percentage of time spent by this method relative to the total time in the entire program.",
|
146
|
+
"The total time spent by this method and its children.",
|
147
|
+
"The time spent by this method.",
|
148
|
+
"The time spent by this method's children.",
|
149
|
+
"The percentage of allocations made by this method relative to the total allocations in the entire program.",
|
150
|
+
"The total number of allocations made by this method and its children.",
|
151
|
+
"The number of allocations made by this method.",
|
152
|
+
"The number of allocations made by this method's children.",
|
153
|
+
"The percentage of memory used by this method relative to the total memory in the entire program.",
|
154
|
+
"The total memory used by this method and its children.",
|
155
|
+
"The memory used by this method.",
|
156
|
+
"The memory used by this method's children."
|
157
|
+
]
|
158
|
+
|
159
|
+
results_keys.each do |key|
|
160
|
+
output = ''
|
161
|
+
printer = RubyProf::GraphPrinter.new(@results[key])
|
162
|
+
printer.print(output)
|
163
|
+
|
164
|
+
case key
|
165
|
+
when :wall_time, :process_time
|
166
|
+
matches = expected_matches[0..3]
|
167
|
+
when :allocations
|
168
|
+
matches = expected_matches[4..7]
|
169
|
+
when :memory
|
170
|
+
matches = expected_matches[8..11]
|
171
|
+
end
|
172
|
+
|
173
|
+
matches.each do |pattern|
|
174
|
+
assert_match(pattern, output)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|