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
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
require File.expand_path('../test_helper', __FILE__)
|
|
5
5
|
|
|
6
|
-
class
|
|
6
|
+
class MeasureGCRunsTest < Test::Unit::TestCase
|
|
7
|
+
include MemoryTestHelper
|
|
8
|
+
|
|
7
9
|
def test_gc_runs_mode
|
|
8
10
|
RubyProf::measure_mode = RubyProf::GC_RUNS
|
|
9
11
|
assert_equal(RubyProf::GC_RUNS, RubyProf::measure_mode)
|
|
@@ -18,6 +20,7 @@ class MeasuremeGCRunsTest < Test::Unit::TestCase
|
|
|
18
20
|
t = RubyProf.measure_gc_runs
|
|
19
21
|
assert_kind_of Integer, t
|
|
20
22
|
|
|
23
|
+
GC.enable_stats
|
|
21
24
|
GC.start
|
|
22
25
|
|
|
23
26
|
u = RubyProf.measure_gc_runs
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
require File.expand_path('../test_helper', __FILE__)
|
|
5
5
|
|
|
6
6
|
class MeasureGCTimeTest < Test::Unit::TestCase
|
|
7
|
+
include MemoryTestHelper
|
|
8
|
+
|
|
7
9
|
def test_gc_time_mode
|
|
8
10
|
RubyProf::measure_mode = RubyProf::GC_TIME
|
|
9
11
|
assert_equal(RubyProf::GC_TIME, RubyProf::measure_mode)
|
|
@@ -15,15 +17,20 @@ class MeasureGCTimeTest < Test::Unit::TestCase
|
|
|
15
17
|
|
|
16
18
|
if RubyProf::GC_TIME_ENABLED
|
|
17
19
|
def test_gc_time
|
|
20
|
+
RubyProf::measure_mode = RubyProf::GC_TIME
|
|
21
|
+
RubyProf.enable_gc_stats_if_needed
|
|
22
|
+
|
|
18
23
|
t = RubyProf.measure_gc_time
|
|
19
|
-
assert_kind_of
|
|
24
|
+
assert_kind_of Float, t
|
|
20
25
|
|
|
21
26
|
GC.start
|
|
22
27
|
|
|
23
28
|
u = RubyProf.measure_gc_time
|
|
24
29
|
assert u > t, [t, u].inspect
|
|
25
|
-
|
|
30
|
+
|
|
26
31
|
memory_test_helper
|
|
32
|
+
ensure
|
|
33
|
+
RubyProf.disable_gc_stats_if_needed
|
|
27
34
|
end
|
|
28
35
|
end
|
|
29
|
-
end
|
|
36
|
+
end
|
data/test/measure_memory_test.rb
CHANGED
|
@@ -4,12 +4,7 @@
|
|
|
4
4
|
require File.expand_path('../test_helper', __FILE__)
|
|
5
5
|
|
|
6
6
|
class MeasureMemoryTest < Test::Unit::TestCase
|
|
7
|
-
|
|
8
|
-
result = RubyProf.profile {Array.new}
|
|
9
|
-
total = result.threads.values.first.inject(0) { |sum, m| sum + m.total_time }
|
|
10
|
-
assert(total < 1_000_000, 'Total should not have subtract overflow error')
|
|
11
|
-
total
|
|
12
|
-
end
|
|
7
|
+
include MemoryTestHelper
|
|
13
8
|
|
|
14
9
|
def test_memory_mode
|
|
15
10
|
RubyProf::measure_mode = RubyProf::MEMORY
|
|
@@ -23,10 +18,10 @@ class MeasureMemoryTest < Test::Unit::TestCase
|
|
|
23
18
|
if RubyProf::MEMORY_ENABLED
|
|
24
19
|
def test_memory
|
|
25
20
|
t = RubyProf.measure_memory
|
|
26
|
-
assert_kind_of
|
|
21
|
+
assert_kind_of Float, t
|
|
27
22
|
|
|
28
23
|
u = RubyProf.measure_memory
|
|
29
|
-
assert(u
|
|
24
|
+
assert(u > t, [t, u].inspect)
|
|
30
25
|
RubyProf::measure_mode = RubyProf::MEMORY
|
|
31
26
|
total = memory_test_helper
|
|
32
27
|
assert(total > 0, 'Should measure more than zero kilobytes of memory usage')
|
|
@@ -5,12 +5,11 @@ require File.expand_path('../test_helper', __FILE__)
|
|
|
5
5
|
|
|
6
6
|
class MeasureProcessTimeTest < Test::Unit::TestCase
|
|
7
7
|
def setup
|
|
8
|
-
# Need to
|
|
8
|
+
# Need to fix this for linux (windows works since PROCESS_TIME is WALL_TIME anyway)
|
|
9
9
|
RubyProf::measure_mode = RubyProf::PROCESS_TIME
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def test_mode
|
|
13
|
-
RubyProf::measure_mode = RubyProf::PROCESS_TIME
|
|
14
13
|
assert_equal(RubyProf::PROCESS_TIME, RubyProf::measure_mode)
|
|
15
14
|
end
|
|
16
15
|
|
|
@@ -18,188 +17,46 @@ class MeasureProcessTimeTest < Test::Unit::TestCase
|
|
|
18
17
|
assert(defined?(RubyProf::PROCESS_TIME_ENABLED))
|
|
19
18
|
end
|
|
20
19
|
|
|
21
|
-
def
|
|
20
|
+
def test_primes
|
|
21
|
+
start = Process.times
|
|
22
22
|
result = RubyProf.profile do
|
|
23
|
-
|
|
23
|
+
run_primes(10000)
|
|
24
24
|
end
|
|
25
|
+
finish = Process.times
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
# MeasureProcessTimeTest#test_class_methods
|
|
28
|
-
# <Class::RubyProf::C1>#hello
|
|
29
|
-
# Kernel#sleep
|
|
30
|
-
|
|
31
|
-
methods = result.threads.first.methods.sort.reverse
|
|
32
|
-
puts methods[0].total_time
|
|
33
|
-
|
|
34
|
-
assert_equal(3, methods.length)
|
|
35
|
-
|
|
36
|
-
# Check times
|
|
37
|
-
assert_equal("MeasureProcessTimeTest#test_class_methods", methods[0].full_name)
|
|
38
|
-
assert_in_delta(0.1, methods[0].total_time, 0.01)
|
|
39
|
-
assert_in_delta(0.0, methods[0].wait_time, 0.01)
|
|
40
|
-
assert_in_delta(0.0, methods[0].self_time, 0.01)
|
|
27
|
+
total_time = (finish.utime - start.utime) + (finish.stime - start.stime)
|
|
41
28
|
|
|
42
|
-
|
|
43
|
-
assert_in_delta(
|
|
44
|
-
assert_in_delta(0.0, methods[1].wait_time, 0.01)
|
|
45
|
-
assert_in_delta(0.0, methods[1].self_time, 0.01)
|
|
46
|
-
|
|
47
|
-
assert_equal("Kernel#sleep", methods[2].full_name)
|
|
48
|
-
assert_in_delta(0.1, methods[2].total_time, 0.01)
|
|
49
|
-
assert_in_delta(0.0, methods[2].wait_time, 0.01)
|
|
50
|
-
assert_in_delta(0.1, methods[2].self_time, 0.01)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def test_instance_methods
|
|
54
|
-
result = RubyProf.profile do
|
|
55
|
-
RubyProf::C1.new.hello
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# Methods called
|
|
59
|
-
# MeasureProcessTimeTest#test_instance_methods
|
|
60
|
-
# Class.new
|
|
61
|
-
# Class:Object#allocate
|
|
62
|
-
# for Object#initialize
|
|
63
|
-
# C1#hello
|
|
64
|
-
# Kernel#sleep
|
|
29
|
+
thread = result.threads.first
|
|
30
|
+
assert_in_delta(total_time, thread.total_time, 0.03)
|
|
65
31
|
|
|
66
32
|
methods = result.threads.first.methods.sort.reverse
|
|
67
|
-
assert_equal(6, methods.length)
|
|
68
|
-
|
|
69
|
-
# Check times
|
|
70
|
-
assert_equal("MeasureProcessTimeTest#test_instance_methods", methods[0].full_name)
|
|
71
|
-
assert_in_delta(0.2, methods[0].total_time, 0.02)
|
|
72
|
-
assert_in_delta(0.0, methods[0].wait_time, 0.02)
|
|
73
|
-
assert_in_delta(0.0, methods[0].self_time, 0.02)
|
|
74
|
-
|
|
75
|
-
assert_equal("RubyProf::C1#hello", methods[1].full_name)
|
|
76
|
-
assert_in_delta(0.2, methods[1].total_time, 0.02)
|
|
77
|
-
assert_in_delta(0.0, methods[1].wait_time, 0.02)
|
|
78
|
-
assert_in_delta(0.0, methods[1].self_time, 0.02)
|
|
79
|
-
|
|
80
|
-
assert_equal("Kernel#sleep", methods[2].full_name)
|
|
81
|
-
assert_in_delta(0.2, methods[2].total_time, 0.02)
|
|
82
|
-
assert_in_delta(0.0, methods[2].wait_time, 0.02)
|
|
83
|
-
assert_in_delta(0.2, methods[2].self_time, 0.02)
|
|
84
|
-
|
|
85
|
-
assert_equal("Class#new", methods[3].full_name)
|
|
86
|
-
assert_in_delta(0.0, methods[3].total_time, 0.01)
|
|
87
|
-
assert_in_delta(0.0, methods[3].wait_time, 0.01)
|
|
88
|
-
assert_in_delta(0.0, methods[3].self_time, 0.01)
|
|
89
|
-
|
|
90
|
-
assert_equal("<Class::#{RubyProf::PARENT}>#allocate", methods[4].full_name)
|
|
91
|
-
assert_in_delta(0.0, methods[4].total_time, 0.01)
|
|
92
|
-
assert_in_delta(0.0, methods[4].wait_time, 0.01)
|
|
93
|
-
assert_in_delta(0.0, methods[4].self_time, 0.01)
|
|
94
33
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
assert_in_delta(0.0, methods[5].wait_time, 0.01)
|
|
98
|
-
assert_in_delta(0.0, methods[5].self_time, 0.01)
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def test_module_methods
|
|
102
|
-
result = RubyProf.profile do
|
|
103
|
-
RubyProf::C2.hello
|
|
34
|
+
if RUBY_VERSION =~ /^1\.8/
|
|
35
|
+
methods.reject!{|m| m.full_name =~ /^Fixnum/ || m.full_name == 'Object#find_largest'}
|
|
104
36
|
end
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
# Kernel#sleep
|
|
110
|
-
|
|
111
|
-
methods = result.threads.first.methods.sort.reverse
|
|
112
|
-
assert_equal(3, methods.length)
|
|
113
|
-
|
|
114
|
-
# Check times
|
|
115
|
-
assert_equal("MeasureProcessTimeTest#test_module_methods", methods[0].full_name)
|
|
116
|
-
assert_in_delta(0.3, methods[0].total_time, 0.1)
|
|
117
|
-
assert_in_delta(0.0, methods[0].wait_time, 0.02)
|
|
118
|
-
assert_in_delta(0.0, methods[0].self_time, 0.02)
|
|
119
|
-
|
|
120
|
-
assert_equal("RubyProf::M1#hello", methods[1].full_name)
|
|
121
|
-
assert_in_delta(0.3, methods[1].total_time, 0.1)
|
|
122
|
-
assert_in_delta(0.0, methods[1].wait_time, 0.02)
|
|
123
|
-
assert_in_delta(0.0, methods[1].self_time, 0.02)
|
|
124
|
-
|
|
125
|
-
assert_equal("Kernel#sleep", methods[2].full_name)
|
|
126
|
-
assert_in_delta(0.3, methods[2].total_time, 0.1)
|
|
127
|
-
assert_in_delta(0.0, methods[2].wait_time, 0.02)
|
|
128
|
-
assert_in_delta(0.3, methods[2].self_time, 0.1)
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
def test_module_instance_methods
|
|
132
|
-
result = RubyProf.profile do
|
|
133
|
-
RubyProf::C2.new.hello
|
|
37
|
+
if RUBY_VERSION =~ /^(1\.9\.2|2\.0)/
|
|
38
|
+
assert_equal 15, methods.length
|
|
39
|
+
else
|
|
40
|
+
assert_equal 16, methods.length
|
|
134
41
|
end
|
|
135
42
|
|
|
136
|
-
# Methods:
|
|
137
|
-
# MeasureProcessTimeTest#test_module_instance_methods
|
|
138
|
-
# Class#new
|
|
139
|
-
# <Class::Object>#allocate
|
|
140
|
-
# Object#initialize
|
|
141
|
-
# M1#hello
|
|
142
|
-
# Kernel#sleep
|
|
143
|
-
|
|
144
|
-
methods = result.threads.first.methods.sort.reverse
|
|
145
|
-
assert_equal(6, methods.length)
|
|
146
|
-
|
|
147
43
|
# Check times
|
|
148
|
-
assert_equal("MeasureProcessTimeTest#
|
|
149
|
-
assert_in_delta(
|
|
150
|
-
assert_in_delta(0.0, methods[0].wait_time, 0.1)
|
|
151
|
-
assert_in_delta(0.0, methods[0].self_time, 0.1)
|
|
152
|
-
|
|
153
|
-
assert_equal("RubyProf::M1#hello", methods[1].full_name)
|
|
154
|
-
assert_in_delta(0.3, methods[1].total_time, 0.02)
|
|
155
|
-
assert_in_delta(0.0, methods[1].wait_time, 0.01)
|
|
156
|
-
assert_in_delta(0.0, methods[1].self_time, 0.01)
|
|
157
|
-
|
|
158
|
-
assert_equal("Kernel#sleep", methods[2].full_name)
|
|
159
|
-
assert_in_delta(0.3, methods[2].total_time, 0.02)
|
|
160
|
-
assert_in_delta(0.0, methods[2].wait_time, 0.01)
|
|
161
|
-
assert_in_delta(0.3, methods[2].self_time, 0.02)
|
|
162
|
-
|
|
163
|
-
assert_equal("Class#new", methods[3].full_name)
|
|
164
|
-
assert_in_delta(0.0, methods[3].total_time, 0.01)
|
|
165
|
-
assert_in_delta(0.0, methods[3].wait_time, 0.01)
|
|
166
|
-
assert_in_delta(0.0, methods[3].self_time, 0.01)
|
|
167
|
-
|
|
168
|
-
assert_equal("<Class::#{RubyProf::PARENT}>#allocate", methods[4].full_name)
|
|
169
|
-
assert_in_delta(0.0, methods[4].total_time, 0.01)
|
|
170
|
-
assert_in_delta(0.0, methods[4].wait_time, 0.01)
|
|
171
|
-
assert_in_delta(0.0, methods[4].self_time, 0.01)
|
|
172
|
-
|
|
173
|
-
assert_equal("#{RubyProf::PARENT}#initialize", methods[5].full_name)
|
|
174
|
-
assert_in_delta(0.0, methods[5].total_time, 0.01)
|
|
175
|
-
assert_in_delta(0.0, methods[5].wait_time, 0.01)
|
|
176
|
-
assert_in_delta(0.0, methods[5].self_time, 0.01)
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
def test_singleton
|
|
180
|
-
c3 = RubyProf::C3.new
|
|
181
|
-
|
|
182
|
-
class << c3
|
|
183
|
-
def hello
|
|
184
|
-
end
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
result = RubyProf.profile do
|
|
188
|
-
c3.hello
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
methods = result.threads.first.methods.sort.reverse
|
|
192
|
-
assert_equal(2, methods.length)
|
|
193
|
-
|
|
194
|
-
assert_equal("MeasureProcessTimeTest#test_singleton", methods[0].full_name)
|
|
195
|
-
assert_equal("<Object::RubyProf::C3>#hello", methods[1].full_name)
|
|
196
|
-
|
|
197
|
-
assert_in_delta(0.0, methods[0].total_time, 0.01)
|
|
44
|
+
assert_equal("MeasureProcessTimeTest#test_primes", methods[0].full_name)
|
|
45
|
+
assert_in_delta(total_time, methods[0].total_time, 0.02)
|
|
198
46
|
assert_in_delta(0.0, methods[0].wait_time, 0.01)
|
|
199
47
|
assert_in_delta(0.0, methods[0].self_time, 0.01)
|
|
200
48
|
|
|
201
|
-
|
|
49
|
+
assert_equal("Object#run_primes", methods[1].full_name)
|
|
50
|
+
assert_in_delta(total_time, methods[1].total_time, 0.02)
|
|
202
51
|
assert_in_delta(0.0, methods[1].wait_time, 0.01)
|
|
203
52
|
assert_in_delta(0.0, methods[1].self_time, 0.01)
|
|
53
|
+
|
|
54
|
+
assert_equal("Object#find_primes", methods[2].full_name)
|
|
55
|
+
assert_equal("Array#select", methods[3].full_name)
|
|
56
|
+
assert_equal("Object#is_prime", methods[4].full_name)
|
|
57
|
+
assert_equal("Integer#upto", methods[5].full_name)
|
|
58
|
+
assert_equal("Object#make_random_array", methods[6].full_name)
|
|
59
|
+
assert_equal("Array#each_index", methods[7].full_name)
|
|
60
|
+
assert_equal("Kernel#rand", methods[8].full_name)
|
|
204
61
|
end
|
|
205
|
-
end
|
|
62
|
+
end
|
|
@@ -23,6 +23,13 @@ class MeasureWallTimeTest < Test::Unit::TestCase
|
|
|
23
23
|
RubyProf::C1.hello
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
+
thread = result.threads.first
|
|
27
|
+
assert_in_delta(0.1, thread.total_time, 0.01)
|
|
28
|
+
|
|
29
|
+
top_methods = thread.top_methods
|
|
30
|
+
assert_equal(1, top_methods.count)
|
|
31
|
+
assert_equal("MeasureWallTimeTest#test_class_methods", top_methods[0].full_name)
|
|
32
|
+
|
|
26
33
|
# Length should be 3:
|
|
27
34
|
# MeasureWallTimeTest#test_class_methods
|
|
28
35
|
# <Class::RubyProf::C1>#hello
|
|
@@ -55,6 +62,13 @@ class MeasureWallTimeTest < Test::Unit::TestCase
|
|
|
55
62
|
RubyProf::C1.new.hello
|
|
56
63
|
end
|
|
57
64
|
|
|
65
|
+
thread = result.threads.first
|
|
66
|
+
assert_in_delta(0.2, thread.total_time, 0.01)
|
|
67
|
+
|
|
68
|
+
top_methods = thread.top_methods
|
|
69
|
+
assert_equal(1, top_methods.count)
|
|
70
|
+
assert_equal("MeasureWallTimeTest#test_instance_methods", top_methods[0].full_name)
|
|
71
|
+
|
|
58
72
|
# Methods called
|
|
59
73
|
# MeasureWallTimeTest#test_instance_methods
|
|
60
74
|
# Class.new
|
|
@@ -64,15 +78,18 @@ class MeasureWallTimeTest < Test::Unit::TestCase
|
|
|
64
78
|
# Kernel#sleep
|
|
65
79
|
|
|
66
80
|
methods = result.threads.first.methods.sort.reverse
|
|
67
|
-
assert_equal(6, methods.length)
|
|
81
|
+
assert_equal(RubyProf.ruby_2? ? 5 : 6, methods.length)
|
|
68
82
|
names = methods.map(&:full_name)
|
|
69
83
|
assert_equal('MeasureWallTimeTest#test_instance_methods', names[0])
|
|
70
84
|
assert_equal('RubyProf::C1#hello', names[1])
|
|
71
85
|
assert_equal('Kernel#sleep', names[2])
|
|
72
86
|
assert_equal('Class#new', names[3])
|
|
87
|
+
|
|
73
88
|
# order can differ
|
|
74
|
-
assert(names.include?("
|
|
75
|
-
|
|
89
|
+
assert(names.include?("#{RubyProf.parent_object}#initialize"))
|
|
90
|
+
unless RubyProf.ruby_2?
|
|
91
|
+
assert(names.include?("<Class::#{RubyProf.parent_object}>#allocate"))
|
|
92
|
+
end
|
|
76
93
|
|
|
77
94
|
# Check times
|
|
78
95
|
assert_in_delta(0.2, methods[0].total_time, 0.02)
|
|
@@ -95,9 +112,11 @@ class MeasureWallTimeTest < Test::Unit::TestCase
|
|
|
95
112
|
assert_in_delta(0, methods[4].wait_time, 0.01)
|
|
96
113
|
assert_in_delta(0, methods[4].self_time, 0.01)
|
|
97
114
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
115
|
+
unless RubyProf.ruby_2?
|
|
116
|
+
assert_in_delta(0, methods[5].total_time, 0.01)
|
|
117
|
+
assert_in_delta(0, methods[5].wait_time, 0.01)
|
|
118
|
+
assert_in_delta(0, methods[5].self_time, 0.01)
|
|
119
|
+
end
|
|
101
120
|
end
|
|
102
121
|
|
|
103
122
|
def test_module_methods
|
|
@@ -105,6 +124,13 @@ class MeasureWallTimeTest < Test::Unit::TestCase
|
|
|
105
124
|
RubyProf::C2.hello
|
|
106
125
|
end
|
|
107
126
|
|
|
127
|
+
thread = result.threads.first
|
|
128
|
+
assert_in_delta(0.3, thread.total_time, 0.01)
|
|
129
|
+
|
|
130
|
+
top_methods = thread.top_methods
|
|
131
|
+
assert_equal(1, top_methods.count)
|
|
132
|
+
assert_equal("MeasureWallTimeTest#test_module_methods", top_methods[0].full_name)
|
|
133
|
+
|
|
108
134
|
# Methods:
|
|
109
135
|
# MeasureWallTimeTest#test_module_methods
|
|
110
136
|
# M1#hello
|
|
@@ -136,6 +162,13 @@ class MeasureWallTimeTest < Test::Unit::TestCase
|
|
|
136
162
|
RubyProf::C2.new.hello
|
|
137
163
|
end
|
|
138
164
|
|
|
165
|
+
thread = result.threads.first
|
|
166
|
+
assert_in_delta(0.3, thread.total_time, 0.01)
|
|
167
|
+
|
|
168
|
+
top_methods = thread.top_methods
|
|
169
|
+
assert_equal(1, top_methods.count)
|
|
170
|
+
assert_equal("MeasureWallTimeTest#test_module_instance_methods", top_methods[0].full_name)
|
|
171
|
+
|
|
139
172
|
# Methods:
|
|
140
173
|
# MeasureWallTimeTest#test_module_instance_methods
|
|
141
174
|
# Class#new
|
|
@@ -145,14 +178,18 @@ class MeasureWallTimeTest < Test::Unit::TestCase
|
|
|
145
178
|
# Kernel#sleep
|
|
146
179
|
|
|
147
180
|
methods = result.threads.first.methods.sort.reverse
|
|
148
|
-
assert_equal(6, methods.length)
|
|
181
|
+
assert_equal(RubyProf.ruby_2? ? 5 : 6, methods.length)
|
|
149
182
|
names = methods.map(&:full_name)
|
|
150
183
|
assert_equal('MeasureWallTimeTest#test_module_instance_methods', names[0])
|
|
151
184
|
assert_equal('RubyProf::M1#hello', names[1])
|
|
152
185
|
assert_equal('Kernel#sleep', names[2])
|
|
153
186
|
assert_equal('Class#new', names[3])
|
|
154
|
-
|
|
155
|
-
|
|
187
|
+
|
|
188
|
+
# order can differ
|
|
189
|
+
assert(names.include?("#{RubyProf.parent_object}#initialize"))
|
|
190
|
+
unless RubyProf.ruby_2?
|
|
191
|
+
assert(names.include?("<Class::#{RubyProf.parent_object}>#allocate"))
|
|
192
|
+
end
|
|
156
193
|
|
|
157
194
|
# Check times
|
|
158
195
|
assert_in_delta(0.3, methods[0].total_time, 0.1)
|
|
@@ -175,9 +212,11 @@ class MeasureWallTimeTest < Test::Unit::TestCase
|
|
|
175
212
|
assert_in_delta(0, methods[4].wait_time, 0.01)
|
|
176
213
|
assert_in_delta(0, methods[4].self_time, 0.01)
|
|
177
214
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
215
|
+
unless RubyProf.ruby_2?
|
|
216
|
+
assert_in_delta(0, methods[5].total_time, 0.01)
|
|
217
|
+
assert_in_delta(0, methods[5].wait_time, 0.01)
|
|
218
|
+
assert_in_delta(0, methods[5].self_time, 0.01)
|
|
219
|
+
end
|
|
181
220
|
end
|
|
182
221
|
|
|
183
222
|
def test_singleton
|
|
@@ -192,6 +231,13 @@ class MeasureWallTimeTest < Test::Unit::TestCase
|
|
|
192
231
|
c3.hello
|
|
193
232
|
end
|
|
194
233
|
|
|
234
|
+
thread = result.threads.first
|
|
235
|
+
assert_in_delta(0.0, thread.total_time, 0.01)
|
|
236
|
+
|
|
237
|
+
top_methods = thread.top_methods
|
|
238
|
+
assert_equal(1, top_methods.count)
|
|
239
|
+
assert_equal("MeasureWallTimeTest#test_singleton", top_methods[0].full_name)
|
|
240
|
+
|
|
195
241
|
methods = result.threads.first.methods.sort.reverse
|
|
196
242
|
assert_equal(2, methods.length)
|
|
197
243
|
|
|
@@ -206,4 +252,4 @@ class MeasureWallTimeTest < Test::Unit::TestCase
|
|
|
206
252
|
assert_in_delta(0, methods[1].wait_time, 0.01)
|
|
207
253
|
assert_in_delta(0, methods[1].self_time, 0.01)
|
|
208
254
|
end
|
|
209
|
-
end
|
|
255
|
+
end
|
|
@@ -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
|
|
@@ -11,19 +10,17 @@ require 'tmpdir'
|
|
|
11
10
|
# \
|
|
12
11
|
# B
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
def a
|
|
16
|
-
|
|
17
|
-
300.times{c}
|
|
18
|
-
c;c;c
|
|
13
|
+
module MethodElimination
|
|
14
|
+
def self.a
|
|
15
|
+
1.times {|i| c}
|
|
19
16
|
end
|
|
20
17
|
|
|
21
|
-
def b
|
|
22
|
-
sleep 0
|
|
18
|
+
def self.b
|
|
19
|
+
sleep 0.1
|
|
23
20
|
end
|
|
24
21
|
|
|
25
|
-
def c
|
|
26
|
-
|
|
22
|
+
def self.c
|
|
23
|
+
1.times {|i| b}
|
|
27
24
|
end
|
|
28
25
|
end
|
|
29
26
|
|
|
@@ -37,27 +34,40 @@ class MethodEliminationTest < Test::Unit::TestCase
|
|
|
37
34
|
result = RubyProf.profile do
|
|
38
35
|
1000.times { 1+1 }
|
|
39
36
|
end
|
|
40
|
-
method_infos = result.threads.first.methods
|
|
37
|
+
method_infos = result.threads.first.methods.sort.reverse
|
|
41
38
|
assert(m1 = method_infos[0])
|
|
42
39
|
assert(c1 = m1.call_infos.first)
|
|
43
|
-
|
|
44
|
-
assert_equal c1, c1.parent
|
|
40
|
+
assert_nil(c1.parent)
|
|
45
41
|
end
|
|
46
42
|
|
|
47
43
|
def test_methods_can_be_eliminated
|
|
48
44
|
RubyProf.start
|
|
49
|
-
5.times{
|
|
45
|
+
5.times {MethodElimination.a}
|
|
50
46
|
result = RubyProf.stop
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
47
|
+
|
|
48
|
+
methods = result.threads.first.methods.sort.reverse
|
|
49
|
+
|
|
50
|
+
assert_equal(6, methods.count)
|
|
51
|
+
assert_equal('MethodEliminationTest#test_methods_can_be_eliminated', methods[0].full_name)
|
|
52
|
+
assert_equal('Integer#times', methods[1].full_name)
|
|
53
|
+
assert_equal('<Module::MethodElimination>#a', methods[2].full_name)
|
|
54
|
+
assert_equal('<Module::MethodElimination>#c', methods[3].full_name)
|
|
55
|
+
assert_equal('<Module::MethodElimination>#b', methods[4].full_name)
|
|
56
|
+
assert_equal('Kernel#sleep', methods[5].full_name)
|
|
57
|
+
|
|
58
|
+
result.eliminate_methods!([/Integer#times/])
|
|
59
|
+
|
|
60
|
+
methods = result.threads.first.methods.sort.reverse
|
|
61
|
+
assert_equal(5, methods.count)
|
|
62
|
+
assert_equal('MethodEliminationTest#test_methods_can_be_eliminated', methods[0].full_name)
|
|
63
|
+
assert_equal('<Module::MethodElimination>#a', methods[1].full_name)
|
|
64
|
+
assert_equal('<Module::MethodElimination>#c', methods[2].full_name)
|
|
65
|
+
assert_equal('<Module::MethodElimination>#b', methods[3].full_name)
|
|
66
|
+
assert_equal('Kernel#sleep', methods[4].full_name)
|
|
58
67
|
end
|
|
59
68
|
|
|
60
69
|
private
|
|
70
|
+
|
|
61
71
|
def assert_method_has_been_eliminated(result, eliminated_method)
|
|
62
72
|
result.threads.each do |thread|
|
|
63
73
|
thread.methods.each do |method|
|
data/test/module_test.rb
CHANGED
|
File without changes
|
data/test/multi_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
|
|
@@ -46,24 +45,26 @@ class MultiPrinterTest < Test::Unit::TestCase
|
|
|
46
45
|
\s*<table>
|
|
47
46
|
\s*<tr>
|
|
48
47
|
\s*<th>Thread ID</th>
|
|
48
|
+
\s*(<th>Fiber ID</th>)?
|
|
49
49
|
\s*<th>Total Time</th>
|
|
50
50
|
\s*</tr>
|
|
51
51
|
\s*
|
|
52
52
|
\s*<tr>
|
|
53
|
-
\s
|
|
54
|
-
\s*<td
|
|
53
|
+
\s*(<td>([\.0-9]+)</td>)?
|
|
54
|
+
\s*<td><a href="#-?\d+">-?\d+</a></td>
|
|
55
|
+
\s*<td>([\.0-9e]+)</td>
|
|
55
56
|
\s*</tr>
|
|
56
57
|
\s*
|
|
57
58
|
\s*</table>')
|
|
58
|
-
|
|
59
|
-
display_time = $
|
|
60
|
-
assert_in_delta expected_time, display_time, 0.
|
|
59
|
+
assert_match(re, graph)
|
|
60
|
+
display_time = $4.to_f
|
|
61
|
+
assert_in_delta expected_time, display_time, 0.5
|
|
61
62
|
end
|
|
62
63
|
|
|
63
64
|
private
|
|
64
65
|
def print(result)
|
|
65
66
|
test = caller.first =~ /in `(.*)'/ ? $1 : "test"
|
|
66
|
-
path =
|
|
67
|
+
path = RubyProf.tmpdir
|
|
67
68
|
profile = "ruby_prof_#{test}"
|
|
68
69
|
printer = RubyProf::MultiPrinter.new(result)
|
|
69
70
|
printer.print(:path => path, :profile => profile,
|
|
@@ -75,6 +76,6 @@ class MultiPrinterTest < Test::Unit::TestCase
|
|
|
75
76
|
GC.start
|
|
76
77
|
GC.dump_file_and_line_info("heap.dump")
|
|
77
78
|
end
|
|
78
|
-
[File.
|
|
79
|
+
[File.read(printer.stack_profile), File.read(printer.graph_profile)]
|
|
79
80
|
end
|
|
80
81
|
end
|
|
File without changes
|