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
|
@@ -40,7 +40,6 @@ module RubyProf
|
|
|
40
40
|
def print(output = STDOUT, options = {})
|
|
41
41
|
@output = output
|
|
42
42
|
setup_options(options)
|
|
43
|
-
_erbout = @output
|
|
44
43
|
@output << @erb.result(binding)
|
|
45
44
|
end
|
|
46
45
|
|
|
@@ -49,7 +48,7 @@ module RubyProf
|
|
|
49
48
|
# specified by the user, since they will not be
|
|
50
49
|
# printed out.
|
|
51
50
|
def create_link(thread, method)
|
|
52
|
-
overall_time = thread.
|
|
51
|
+
overall_time = thread.total_time
|
|
53
52
|
total_percent = (method.total_time/overall_time) * 100
|
|
54
53
|
if total_percent < min_percent
|
|
55
54
|
# Just return name
|
|
@@ -61,7 +60,7 @@ module RubyProf
|
|
|
61
60
|
end
|
|
62
61
|
|
|
63
62
|
def method_href(thread, method)
|
|
64
|
-
h(method.full_name.gsub(/[><#\.\?=:]/,"_") + "_" + thread.
|
|
63
|
+
h(method.full_name.gsub(/[><#\.\?=:]/,"_") + "_" + thread.fiber_id.to_s)
|
|
65
64
|
end
|
|
66
65
|
|
|
67
66
|
def file_link(path, linenum)
|
|
@@ -140,12 +139,18 @@ module RubyProf
|
|
|
140
139
|
<table>
|
|
141
140
|
<tr>
|
|
142
141
|
<th>Thread ID</th>
|
|
142
|
+
<% if RUBY_VERSION >= "1.9" %>
|
|
143
|
+
<th>Fiber ID</th>
|
|
144
|
+
<% end %>
|
|
143
145
|
<th>Total Time</th>
|
|
144
146
|
</tr>
|
|
145
147
|
<% for thread in @result.threads %>
|
|
146
148
|
<tr>
|
|
147
|
-
|
|
148
|
-
<td><%= thread.
|
|
149
|
+
<% if RUBY_VERSION >= "1.9" %>
|
|
150
|
+
<td><%= thread.id %></td>
|
|
151
|
+
<% end %>
|
|
152
|
+
<td><a href="#<%= thread.fiber_id %>"><%= thread.fiber_id %></a></td>
|
|
153
|
+
<td><%= thread.total_time %></td>
|
|
149
154
|
</tr>
|
|
150
155
|
<% end %>
|
|
151
156
|
</table>
|
|
@@ -153,9 +158,12 @@ module RubyProf
|
|
|
153
158
|
<!-- Methods Tables -->
|
|
154
159
|
<% for thread in @result.threads
|
|
155
160
|
methods = thread.methods
|
|
156
|
-
total_time = thread.
|
|
157
|
-
|
|
158
|
-
|
|
161
|
+
total_time = thread.total_time %>
|
|
162
|
+
<% if RUBY_VERSION >= "1.9" %>
|
|
163
|
+
<h2><a name="<%= thread.fiber_id %>">Thread <%= thread.id %>, Fiber: <%= thread.fiber_id %></a></h2>
|
|
164
|
+
<% else %>
|
|
165
|
+
<h2><a name="<%= thread.fiber_id %>">Thread <%= thread.fiber_id %></a></h2>
|
|
166
|
+
<% end %>
|
|
159
167
|
<table>
|
|
160
168
|
<thead>
|
|
161
169
|
<tr>
|
|
@@ -15,14 +15,15 @@ module RubyProf
|
|
|
15
15
|
|
|
16
16
|
class GraphPrinter < AbstractPrinter
|
|
17
17
|
PERCENTAGE_WIDTH = 8
|
|
18
|
-
TIME_WIDTH =
|
|
18
|
+
TIME_WIDTH = 11
|
|
19
19
|
CALL_WIDTH = 17
|
|
20
20
|
|
|
21
21
|
private
|
|
22
22
|
|
|
23
23
|
def print_header(thread)
|
|
24
24
|
@output << "Thread ID: #{thread.id}\n"
|
|
25
|
-
@output << "
|
|
25
|
+
@output << "Fiber ID: #{thread.fiber_id}\n" unless thread.id == thread.fiber_id
|
|
26
|
+
@output << "Total Time: #{thread.total_time}\n"
|
|
26
27
|
@output << "Sort by: #{sort_method}\n"
|
|
27
28
|
@output << "\n"
|
|
28
29
|
|
|
@@ -39,7 +40,7 @@ module RubyProf
|
|
|
39
40
|
end
|
|
40
41
|
|
|
41
42
|
def print_methods(thread)
|
|
42
|
-
total_time = thread.
|
|
43
|
+
total_time = thread.total_time
|
|
43
44
|
# Sort methods from longest to shortest total time
|
|
44
45
|
methods = thread.methods.sort_by(&sort_method)
|
|
45
46
|
|
|
@@ -57,10 +58,10 @@ module RubyProf
|
|
|
57
58
|
# 1 is for % sign
|
|
58
59
|
@output << sprintf("%#{PERCENTAGE_WIDTH-1}.2f\%", total_percentage)
|
|
59
60
|
@output << sprintf("%#{PERCENTAGE_WIDTH-1}.2f\%", self_percentage)
|
|
60
|
-
@output << sprintf("%#{TIME_WIDTH}.
|
|
61
|
-
@output << sprintf("%#{TIME_WIDTH}.
|
|
62
|
-
@output << sprintf("%#{TIME_WIDTH}.
|
|
63
|
-
@output << sprintf("%#{TIME_WIDTH}.
|
|
61
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", method.total_time)
|
|
62
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", method.self_time)
|
|
63
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", method.wait_time)
|
|
64
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", method.children_time)
|
|
64
65
|
@output << sprintf("%#{CALL_WIDTH}i", method.called)
|
|
65
66
|
@output << sprintf(" %s", method.recursive? ? "*" : " ")
|
|
66
67
|
@output << sprintf("%s", method_name(method))
|
|
@@ -77,10 +78,10 @@ module RubyProf
|
|
|
77
78
|
method.aggregate_parents.sort_by(&:total_time).each do |caller|
|
|
78
79
|
next unless caller.parent
|
|
79
80
|
@output << " " * 2 * PERCENTAGE_WIDTH
|
|
80
|
-
@output << sprintf("%#{TIME_WIDTH}.
|
|
81
|
-
@output << sprintf("%#{TIME_WIDTH}.
|
|
82
|
-
@output << sprintf("%#{TIME_WIDTH}.
|
|
83
|
-
@output << sprintf("%#{TIME_WIDTH}.
|
|
81
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", caller.total_time)
|
|
82
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", caller.self_time)
|
|
83
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", caller.wait_time)
|
|
84
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", caller.children_time)
|
|
84
85
|
|
|
85
86
|
call_called = "#{caller.called}/#{method.called}"
|
|
86
87
|
@output << sprintf("%#{CALL_WIDTH}s", call_called)
|
|
@@ -95,10 +96,10 @@ module RubyProf
|
|
|
95
96
|
|
|
96
97
|
@output << " " * 2 * PERCENTAGE_WIDTH
|
|
97
98
|
|
|
98
|
-
@output << sprintf("%#{TIME_WIDTH}.
|
|
99
|
-
@output << sprintf("%#{TIME_WIDTH}.
|
|
100
|
-
@output << sprintf("%#{TIME_WIDTH}.
|
|
101
|
-
@output << sprintf("%#{TIME_WIDTH}.
|
|
99
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", child.total_time)
|
|
100
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", child.self_time)
|
|
101
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", child.wait_time)
|
|
102
|
+
@output << sprintf("%#{TIME_WIDTH}.3f", child.children_time)
|
|
102
103
|
|
|
103
104
|
call_called = "#{child.called}/#{child.target.called}"
|
|
104
105
|
@output << sprintf("%#{CALL_WIDTH}s", call_called)
|
|
@@ -112,4 +113,4 @@ module RubyProf
|
|
|
112
113
|
@output << "* indicates recursively called methods\n"
|
|
113
114
|
end
|
|
114
115
|
end
|
|
115
|
-
end
|
|
116
|
+
end
|
data/lib/ruby-prof/profile.rb
CHANGED
|
@@ -49,7 +49,7 @@ module RubyProf
|
|
|
49
49
|
# read regexps from file
|
|
50
50
|
def read_regexps_from_file(file_name)
|
|
51
51
|
matchers = []
|
|
52
|
-
File.open(
|
|
52
|
+
File.open(file_name).each_line do |l|
|
|
53
53
|
next if (l =~ /^(#.*|\s*)$/) # emtpy lines and lines starting with #
|
|
54
54
|
matchers << Regexp.new(l.strip)
|
|
55
55
|
end
|
data/lib/ruby-prof/rack.rb
CHANGED
|
@@ -13,12 +13,7 @@ module Rack
|
|
|
13
13
|
::RubyProf::GraphHtmlPrinter => 'graph.html',
|
|
14
14
|
::RubyProf::CallStackPrinter => 'call_stack.html'}
|
|
15
15
|
|
|
16
|
-
@
|
|
17
|
-
::RubyProf::GraphPrinter => 'graph.txt',
|
|
18
|
-
::RubyProf::GraphHtmlPrinter => 'graph.html',
|
|
19
|
-
::RubyProf::CallStackPrinter => 'call_stack.html'}
|
|
20
|
-
|
|
21
|
-
@skip_paths = options[:skip_paths] || [%r{^/assets}, %r{\.css$}, %r{\.js}, %r{\.png}, %r{\.jpeg}]
|
|
16
|
+
@skip_paths = options[:skip_paths] || [%r{^/assets}, %r{\.css$}, %r{\.js$}, %r{\.png$}, %r{\.jpeg$}, %r{\.jpg$}, %r{\.gif$}]
|
|
22
17
|
end
|
|
23
18
|
|
|
24
19
|
def call(env)
|
data/lib/ruby-prof/task.rb
CHANGED
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module RubyProf
|
|
2
|
+
class Thread
|
|
3
|
+
def top_methods
|
|
4
|
+
self.methods.select do |method_info|
|
|
5
|
+
method_info.call_infos.detect do |call_info|
|
|
6
|
+
call_info.parent.nil?
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def total_time
|
|
12
|
+
self.top_methods.inject(0) do |sum, method_info|
|
|
13
|
+
method_info.call_infos.each do |call_info|
|
|
14
|
+
if call_info.parent.nil?
|
|
15
|
+
sum += call_info.total_time
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
sum
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/ruby-prof.rb
CHANGED
data/ruby-prof.gemspec
CHANGED
|
@@ -53,7 +53,9 @@ EOF
|
|
|
53
53
|
|
|
54
54
|
spec.test_files = Dir["test/test_*.rb"]
|
|
55
55
|
spec.required_ruby_version = '>= 1.8.7'
|
|
56
|
-
spec.date =
|
|
56
|
+
spec.date = Time.now.strftime('%Y-%m-%d')
|
|
57
57
|
spec.homepage = 'https://github.com/rdp/ruby-prof'
|
|
58
|
-
spec.add_development_dependency
|
|
59
|
-
|
|
58
|
+
spec.add_development_dependency('minitest')
|
|
59
|
+
spec.add_development_dependency('rake-compiler')
|
|
60
|
+
spec.add_development_dependency('rdoc')
|
|
61
|
+
end
|
data/test/aggregate_test.rb
CHANGED
|
File without changes
|
data/test/basic_test.rb
CHANGED
|
@@ -9,6 +9,11 @@ class BasicTest < Test::Unit::TestCase
|
|
|
9
9
|
RubyProf::measure_mode = RubyProf::WALL_TIME
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
def start
|
|
13
|
+
RubyProf.start
|
|
14
|
+
RubyProf::C1.hello
|
|
15
|
+
end
|
|
16
|
+
|
|
12
17
|
def test_running
|
|
13
18
|
assert(!RubyProf.running?)
|
|
14
19
|
RubyProf.start
|
|
@@ -40,57 +45,84 @@ class BasicTest < Test::Unit::TestCase
|
|
|
40
45
|
RubyProf.stop
|
|
41
46
|
end
|
|
42
47
|
|
|
43
|
-
def
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
p.resume; assert !p.paused?
|
|
48
|
-
p.pause ; assert p.paused?
|
|
49
|
-
p.pause ; assert p.paused?
|
|
50
|
-
p.resume; assert !p.paused?
|
|
51
|
-
p.resume; assert !p.paused?
|
|
52
|
-
p.stop ; assert !p.paused?
|
|
53
|
-
end
|
|
48
|
+
def test_leave_method
|
|
49
|
+
start
|
|
50
|
+
sleep 0.15
|
|
51
|
+
profile = RubyProf.stop
|
|
54
52
|
|
|
55
|
-
|
|
56
|
-
p= RubyProf::Profile.new(RubyProf::WALL_TIME,[])
|
|
57
|
-
p.start
|
|
58
|
-
p.pause
|
|
59
|
-
assert p.paused?
|
|
53
|
+
assert_equal(1, profile.threads.count)
|
|
60
54
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
times_block_invoked += 1
|
|
64
|
-
120 + times_block_invoked
|
|
65
|
-
}
|
|
66
|
-
assert_equal 1, times_block_invoked
|
|
67
|
-
assert p.paused?
|
|
55
|
+
thread = profile.threads.first
|
|
56
|
+
assert_in_delta(0.25, thread.total_time, 0.01)
|
|
68
57
|
|
|
69
|
-
|
|
58
|
+
top_methods = thread.top_methods.sort
|
|
59
|
+
assert_equal(2, top_methods.count)
|
|
60
|
+
assert_equal("BasicTest#start", top_methods[0].full_name)
|
|
61
|
+
assert_equal("BasicTest#test_leave_method", top_methods[1].full_name)
|
|
70
62
|
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
assert_equal(4, thread.methods.length)
|
|
64
|
+
methods = profile.threads.first.methods.sort
|
|
73
65
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
66
|
+
# Check times
|
|
67
|
+
assert_equal("<Class::RubyProf::C1>#hello", methods[0].full_name)
|
|
68
|
+
assert_in_delta(0.1, methods[0].total_time, 0.01)
|
|
69
|
+
assert_in_delta(0.0, methods[0].wait_time, 0.01)
|
|
70
|
+
assert_in_delta(0.0, methods[0].self_time, 0.01)
|
|
71
|
+
|
|
72
|
+
assert_equal("BasicTest#start", methods[1].full_name)
|
|
73
|
+
assert_in_delta(0.1, methods[1].total_time, 0.01)
|
|
74
|
+
assert_in_delta(0.0, methods[1].wait_time, 0.01)
|
|
75
|
+
assert_in_delta(0.0, methods[1].self_time, 0.01)
|
|
76
|
+
|
|
77
|
+
assert_equal("BasicTest#test_leave_method", methods[2].full_name)
|
|
78
|
+
assert_in_delta(0.15, methods[2].total_time, 0.01)
|
|
79
|
+
assert_in_delta(0.0, methods[2].wait_time, 0.01)
|
|
80
|
+
assert_in_delta(0.0, methods[2].self_time, 0.01)
|
|
86
81
|
|
|
87
|
-
|
|
82
|
+
assert_equal("Kernel#sleep", methods[3].full_name)
|
|
83
|
+
assert_in_delta(0.25, methods[3].total_time, 0.01)
|
|
84
|
+
assert_in_delta(0.0, methods[3].wait_time, 0.01)
|
|
85
|
+
assert_in_delta(0.25, methods[3].self_time, 0.01)
|
|
88
86
|
end
|
|
89
87
|
|
|
90
|
-
def
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
def test_leave_method_2
|
|
89
|
+
start
|
|
90
|
+
RubyProf::C1.hello
|
|
91
|
+
RubyProf::C1.hello
|
|
92
|
+
profile = RubyProf.stop
|
|
93
|
+
|
|
94
|
+
assert_equal(1, profile.threads.count)
|
|
95
|
+
|
|
96
|
+
thread = profile.threads.first
|
|
97
|
+
assert_in_delta(0.3, thread.total_time, 0.01)
|
|
98
|
+
|
|
99
|
+
top_methods = thread.top_methods.sort
|
|
100
|
+
assert_equal(2, top_methods.count)
|
|
101
|
+
assert_equal("BasicTest#start", top_methods[0].full_name)
|
|
102
|
+
assert_equal("BasicTest#test_leave_method_2", top_methods[1].full_name)
|
|
103
|
+
|
|
104
|
+
assert_equal(4, thread.methods.length)
|
|
105
|
+
methods = profile.threads.first.methods.sort
|
|
106
|
+
|
|
107
|
+
# Check times
|
|
108
|
+
assert_equal("BasicTest#start", methods[0].full_name)
|
|
109
|
+
assert_in_delta(0.1, methods[0].total_time, 0.01)
|
|
110
|
+
assert_in_delta(0.0, methods[0].wait_time, 0.01)
|
|
111
|
+
assert_in_delta(0.0, methods[0].self_time, 0.01)
|
|
112
|
+
|
|
113
|
+
assert_equal("BasicTest#test_leave_method_2", methods[1].full_name)
|
|
114
|
+
assert_in_delta(0.2, methods[1].total_time, 0.01)
|
|
115
|
+
assert_in_delta(0.0, methods[1].wait_time, 0.01)
|
|
116
|
+
assert_in_delta(0.0, methods[1].self_time, 0.01)
|
|
117
|
+
|
|
118
|
+
assert_equal("Kernel#sleep", methods[2].full_name)
|
|
119
|
+
assert_in_delta(0.3, methods[2].total_time, 0.01)
|
|
120
|
+
assert_in_delta(0.0, methods[2].wait_time, 0.01)
|
|
121
|
+
assert_in_delta(0.3, methods[2].self_time, 0.01)
|
|
122
|
+
|
|
123
|
+
assert_equal("<Class::RubyProf::C1>#hello", methods[3].full_name)
|
|
124
|
+
assert_in_delta(0.3, methods[3].total_time, 0.01)
|
|
125
|
+
assert_in_delta(0.0, methods[3].wait_time, 0.01)
|
|
126
|
+
assert_in_delta(0.0, methods[3].self_time, 0.01)
|
|
95
127
|
end
|
|
96
|
-
end
|
|
128
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# encoding: UTF-8
|
|
3
|
+
|
|
4
|
+
require File.expand_path('../test_helper', __FILE__)
|
|
5
|
+
|
|
6
|
+
class CallInfoTest < 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_clone
|
|
13
|
+
# result = RubyProf.profile do
|
|
14
|
+
# RubyProf::C1.hello
|
|
15
|
+
# end
|
|
16
|
+
#
|
|
17
|
+
# method = result.threads.first.top_methods.first
|
|
18
|
+
# call_info = method.call_infos.first
|
|
19
|
+
# call_info_clone = call_info.clone
|
|
20
|
+
#
|
|
21
|
+
## assert_equal(call_info.target, call_info_clone.target)
|
|
22
|
+
# assert_equal(call_info.total_time, call_info_clone.total_time)
|
|
23
|
+
# end
|
|
24
|
+
|
|
25
|
+
def test_merge
|
|
26
|
+
result1 = RubyProf.profile do
|
|
27
|
+
RubyProf::C1.hello
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
methods = result1.threads.first.methods.sort.reverse
|
|
31
|
+
assert_equal(3, methods.length)
|
|
32
|
+
|
|
33
|
+
assert_equal('CallInfoTest#test_merge', methods[0].full_name)
|
|
34
|
+
assert_in_delta(0.1, methods[0].total_time, 0.01)
|
|
35
|
+
assert_in_delta(0, methods[0].wait_time, 0.01)
|
|
36
|
+
assert_in_delta(0, methods[0].self_time, 0.01)
|
|
37
|
+
assert_equal(1, methods[0].called)
|
|
38
|
+
|
|
39
|
+
assert_equal('<Class::RubyProf::C1>#hello', methods[1].full_name)
|
|
40
|
+
assert_in_delta(0.1, methods[1].total_time, 0.01)
|
|
41
|
+
assert_in_delta(0, methods[1].wait_time, 0.01)
|
|
42
|
+
assert_in_delta(0, methods[1].self_time, 0.01)
|
|
43
|
+
assert_equal(1, methods[1].called)
|
|
44
|
+
|
|
45
|
+
assert_equal('Kernel#sleep', methods[2].full_name)
|
|
46
|
+
assert_in_delta(0.1, methods[2].total_time, 0.01)
|
|
47
|
+
assert_in_delta(0, methods[2].wait_time, 0.01)
|
|
48
|
+
assert_in_delta(0.1, methods[2].self_time, 0.01)
|
|
49
|
+
assert_equal(1, methods[2].called)
|
|
50
|
+
|
|
51
|
+
result2 = RubyProf.profile do
|
|
52
|
+
RubyProf::C1.hello
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Merge the trees
|
|
56
|
+
methods = result1.threads.first.methods.sort.reverse
|
|
57
|
+
assert_equal(3, methods.length)
|
|
58
|
+
|
|
59
|
+
assert_equal('CallInfoTest#test_merge', methods[0].full_name)
|
|
60
|
+
assert_in_delta(0.1, methods[0].total_time, 0.01)
|
|
61
|
+
assert_in_delta(0, methods[0].wait_time, 0.01)
|
|
62
|
+
assert_in_delta(0, methods[0].self_time, 0.01)
|
|
63
|
+
assert_equal(1, methods[0].called)
|
|
64
|
+
|
|
65
|
+
assert_equal('<Class::RubyProf::C1>#hello', methods[1].full_name)
|
|
66
|
+
assert_in_delta(0.1, methods[1].total_time, 0.01)
|
|
67
|
+
assert_in_delta(0, methods[1].wait_time, 0.01)
|
|
68
|
+
assert_in_delta(0, methods[1].self_time, 0.01)
|
|
69
|
+
assert_equal(1, methods[1].called)
|
|
70
|
+
|
|
71
|
+
assert_equal('Kernel#sleep', methods[2].full_name)
|
|
72
|
+
assert_in_delta(0.1, methods[2].total_time, 0.01)
|
|
73
|
+
assert_in_delta(0, methods[2].wait_time, 0.01)
|
|
74
|
+
assert_in_delta(0.1, methods[2].self_time, 0.01)
|
|
75
|
+
assert_equal(1, methods[2].called)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
@@ -6,7 +6,7 @@ require File.expand_path('../test_helper', __FILE__)
|
|
|
6
6
|
class CallInfoVisitorTest < Test::Unit::TestCase
|
|
7
7
|
def setup
|
|
8
8
|
# Need to use wall time for this test due to the sleep calls
|
|
9
|
-
RubyProf::measure_mode = RubyProf::
|
|
9
|
+
RubyProf::measure_mode = RubyProf::WALL_TIME
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def test_visit
|
|
File without changes
|
data/test/dynamic_method_test.rb
CHANGED
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
require File.expand_path("../test_helper", __FILE__)
|
|
5
5
|
|
|
6
|
-
|
|
7
6
|
class DynamicMethodTest < 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
|
+
|
|
8
12
|
def test_dynamic_method
|
|
9
13
|
result = RubyProf.profile do
|
|
10
14
|
1.times {RubyProf::C1.new.hello}
|
|
@@ -13,14 +17,14 @@ class DynamicMethodTest < Test::Unit::TestCase
|
|
|
13
17
|
# Methods called
|
|
14
18
|
# Kernel#sleep
|
|
15
19
|
# <Class::BasicObject>#allocate
|
|
16
|
-
#
|
|
20
|
+
# #{RubyProf.parent_object}#inizialize
|
|
17
21
|
# RubyProf::C1#hello
|
|
18
22
|
# Class#new
|
|
19
23
|
# Integer#times
|
|
20
24
|
# DynamicMethodTest#test_dynamic_method
|
|
21
25
|
|
|
22
26
|
methods = result.threads.first.methods.sort.reverse
|
|
23
|
-
assert_equal(7, methods.length)
|
|
27
|
+
assert_equal(RubyProf.ruby_2? ? 6 : 7, methods.length)
|
|
24
28
|
|
|
25
29
|
# Check times
|
|
26
30
|
assert_equal("DynamicMethodTest#test_dynamic_method", methods[0].full_name)
|
|
@@ -48,14 +52,23 @@ class DynamicMethodTest < Test::Unit::TestCase
|
|
|
48
52
|
assert_in_delta(0.0, methods[4].wait_time, 0.01)
|
|
49
53
|
assert_in_delta(0.0, methods[4].self_time, 0.01)
|
|
50
54
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
# the timing difference between #initialize and #allocate is so small
|
|
56
|
+
# that we cannot rely on #initialize appearing first.
|
|
57
|
+
# so switch them, if necessary
|
|
58
|
+
if methods[5].full_name =~ /#allocate/
|
|
59
|
+
methods[5], methods[6] = methods[6], methods[5]
|
|
60
|
+
end
|
|
55
61
|
|
|
56
|
-
assert_equal("#{RubyProf
|
|
62
|
+
assert_equal("#{RubyProf.parent_object}#initialize", methods[5].full_name)
|
|
57
63
|
assert_in_delta(0.0, methods[5].total_time, 0.01)
|
|
58
64
|
assert_in_delta(0.0, methods[5].wait_time, 0.01)
|
|
59
65
|
assert_in_delta(0.0, methods[5].self_time, 0.01)
|
|
66
|
+
|
|
67
|
+
unless RubyProf.ruby_2?
|
|
68
|
+
assert_equal("<Class::#{RubyProf.parent_object}>#allocate", methods[6].full_name)
|
|
69
|
+
assert_in_delta(0.0, methods[6].total_time, 0.01)
|
|
70
|
+
assert_in_delta(0.0, methods[6].wait_time, 0.01)
|
|
71
|
+
assert_in_delta(0.0, methods[6].self_time, 0.01)
|
|
72
|
+
end
|
|
60
73
|
end
|
|
61
74
|
end
|
data/test/enumerable_test.rb
CHANGED
|
File without changes
|
data/test/exceptions_test.rb
CHANGED
|
File without changes
|
|
File without changes
|
data/test/exec_test.rb
CHANGED
|
File without changes
|
data/test/fiber_test.rb
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# encoding: UTF-8
|
|
3
|
+
|
|
4
|
+
require File.expand_path('../test_helper', __FILE__)
|
|
5
|
+
require 'timeout'
|
|
6
|
+
require 'set'
|
|
7
|
+
begin
|
|
8
|
+
require 'fiber'
|
|
9
|
+
rescue LoadError
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# -- Tests ----
|
|
13
|
+
class FiberTest < Test::Unit::TestCase
|
|
14
|
+
|
|
15
|
+
def fiber_test
|
|
16
|
+
@fiber_ids << Fiber.current.object_id
|
|
17
|
+
enum = Enumerator.new do |yielder|
|
|
18
|
+
[1,2].each do |x|
|
|
19
|
+
@fiber_ids << Fiber.current.object_id
|
|
20
|
+
sleep 0.1
|
|
21
|
+
yielder.yield x
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
while true
|
|
25
|
+
begin
|
|
26
|
+
x = enum.next
|
|
27
|
+
rescue StopIteration
|
|
28
|
+
break
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
sleep 0.1
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def setup
|
|
35
|
+
# Need to use wall time for this test due to the sleep calls
|
|
36
|
+
RubyProf::measure_mode = RubyProf::WALL_TIME
|
|
37
|
+
@fiber_ids = Set.new
|
|
38
|
+
@root_fiber = Fiber.current.object_id
|
|
39
|
+
@thread_id = Thread.current.object_id
|
|
40
|
+
@result = RubyProf.profile { fiber_test }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_fibers
|
|
44
|
+
profiled_fiber_ids = @result.threads.map(&:fiber_id)
|
|
45
|
+
assert_equal(2, @result.threads.length)
|
|
46
|
+
assert_equal([@thread_id], @result.threads.map(&:id).uniq)
|
|
47
|
+
assert_equal(@fiber_ids, Set.new(profiled_fiber_ids))
|
|
48
|
+
|
|
49
|
+
assert profiled_fiber_ids.include?(@root_fiber)
|
|
50
|
+
assert(root_fiber_profile = @result.threads.detect{|t| t.fiber_id == @root_fiber})
|
|
51
|
+
assert(enum_fiber_profile = @result.threads.detect{|t| t.fiber_id != @root_fiber})
|
|
52
|
+
|
|
53
|
+
assert_in_delta(0.3, root_fiber_profile.total_time, 0.01)
|
|
54
|
+
assert_in_delta(0.2, enum_fiber_profile.total_time, 0.01)
|
|
55
|
+
|
|
56
|
+
assert(method_next = root_fiber_profile.methods.detect{|m| m.full_name == "Enumerator#next"})
|
|
57
|
+
assert(method_each = enum_fiber_profile.methods.detect{|m| m.full_name == "Enumerator#each"})
|
|
58
|
+
|
|
59
|
+
assert_in_delta(0.2, method_next.total_time, 0.01)
|
|
60
|
+
assert_in_delta(0.2, method_each.total_time, 0.01)
|
|
61
|
+
|
|
62
|
+
# RubyProf::CallInfoPrinter.new(@result).print
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end if RUBY_VERSION >= "1.9"
|
data/test/line_number_test.rb
CHANGED
|
File without changes
|
|
@@ -64,15 +64,18 @@ class MeasureCpuTimeTest < Test::Unit::TestCase
|
|
|
64
64
|
# Kernel#sleep
|
|
65
65
|
|
|
66
66
|
methods = result.threads.first.methods.sort.reverse
|
|
67
|
-
assert_equal(6, methods.length)
|
|
67
|
+
assert_equal(RubyProf.ruby_2? ? 5 : 6, methods.length)
|
|
68
68
|
names = methods.map(&:full_name)
|
|
69
69
|
assert_equal('MeasureCpuTimeTest#test_instance_methods', names[0])
|
|
70
70
|
assert_equal('RubyProf::C1#hello', names[1])
|
|
71
71
|
assert_equal('Kernel#sleep', names[2])
|
|
72
72
|
assert_equal('Class#new', names[3])
|
|
73
|
+
|
|
73
74
|
# order can differ
|
|
74
|
-
assert(names.include?("
|
|
75
|
-
|
|
75
|
+
assert(names.include?("#{RubyProf.parent_object}#initialize"))
|
|
76
|
+
unless RubyProf.ruby_2?
|
|
77
|
+
assert(names.include?("<Class::#{RubyProf.parent_object}>#allocate"))
|
|
78
|
+
end
|
|
76
79
|
|
|
77
80
|
# Check times
|
|
78
81
|
assert_in_delta(0.2, methods[0].total_time, 0.02)
|
|
@@ -95,9 +98,11 @@ class MeasureCpuTimeTest < Test::Unit::TestCase
|
|
|
95
98
|
assert_in_delta(0, methods[4].wait_time, 0.01)
|
|
96
99
|
assert_in_delta(0, methods[4].self_time, 0.01)
|
|
97
100
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
unless RubyProf.ruby_2?
|
|
102
|
+
assert_in_delta(0, methods[5].total_time, 0.01)
|
|
103
|
+
assert_in_delta(0, methods[5].wait_time, 0.01)
|
|
104
|
+
assert_in_delta(0, methods[5].self_time, 0.01)
|
|
105
|
+
end
|
|
101
106
|
end
|
|
102
107
|
|
|
103
108
|
def test_module_methods
|
|
@@ -145,14 +150,18 @@ class MeasureCpuTimeTest < Test::Unit::TestCase
|
|
|
145
150
|
# Kernel#sleep
|
|
146
151
|
|
|
147
152
|
methods = result.threads.first.methods.sort.reverse
|
|
148
|
-
assert_equal(6, methods.length)
|
|
153
|
+
assert_equal(RubyProf.ruby_2? ? 5 : 6, methods.length)
|
|
149
154
|
names = methods.map(&:full_name)
|
|
150
155
|
assert_equal('MeasureCpuTimeTest#test_module_instance_methods', names[0])
|
|
151
156
|
assert_equal('RubyProf::M1#hello', names[1])
|
|
152
157
|
assert_equal('Kernel#sleep', names[2])
|
|
153
158
|
assert_equal('Class#new', names[3])
|
|
154
|
-
|
|
155
|
-
|
|
159
|
+
|
|
160
|
+
# order can differ
|
|
161
|
+
assert(names.include?("#{RubyProf.parent_object}#initialize"))
|
|
162
|
+
unless RubyProf.ruby_2?
|
|
163
|
+
assert(names.include?("<Class::#{RubyProf.parent_object}>#allocate"))
|
|
164
|
+
end
|
|
156
165
|
|
|
157
166
|
# Check times
|
|
158
167
|
assert_in_delta(0.3, methods[0].total_time, 0.1)
|
|
@@ -175,9 +184,11 @@ class MeasureCpuTimeTest < Test::Unit::TestCase
|
|
|
175
184
|
assert_in_delta(0, methods[4].wait_time, 0.01)
|
|
176
185
|
assert_in_delta(0, methods[4].self_time, 0.01)
|
|
177
186
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
187
|
+
unless RubyProf.ruby_2?
|
|
188
|
+
assert_in_delta(0, methods[5].total_time, 0.01)
|
|
189
|
+
assert_in_delta(0, methods[5].wait_time, 0.01)
|
|
190
|
+
assert_in_delta(0, methods[5].self_time, 0.01)
|
|
191
|
+
end
|
|
181
192
|
end
|
|
182
193
|
|
|
183
194
|
def test_singleton
|