ruby-prof 0.18.0-x64-mingw32 → 1.1.0-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +32 -0
- data/LICENSE +2 -2
- data/README.rdoc +1 -483
- data/Rakefile +3 -6
- data/bin/ruby-prof +65 -30
- data/ext/ruby_prof/extconf.rb +6 -38
- data/ext/ruby_prof/rp_allocation.c +279 -0
- data/ext/ruby_prof/rp_allocation.h +31 -0
- data/ext/ruby_prof/rp_call_info.c +129 -283
- data/ext/ruby_prof/rp_call_info.h +16 -34
- data/ext/ruby_prof/rp_measure_allocations.c +25 -49
- data/ext/ruby_prof/rp_measure_memory.c +21 -56
- data/ext/ruby_prof/rp_measure_process_time.c +35 -39
- data/ext/ruby_prof/rp_measure_wall_time.c +36 -19
- data/ext/ruby_prof/rp_measurement.c +230 -0
- data/ext/ruby_prof/rp_measurement.h +50 -0
- data/ext/ruby_prof/rp_method.c +389 -389
- data/ext/ruby_prof/rp_method.h +34 -39
- data/ext/ruby_prof/rp_profile.c +895 -0
- data/ext/ruby_prof/rp_profile.h +37 -0
- data/ext/ruby_prof/rp_stack.c +103 -80
- data/ext/ruby_prof/rp_stack.h +5 -12
- data/ext/ruby_prof/rp_thread.c +143 -83
- data/ext/ruby_prof/rp_thread.h +15 -6
- data/ext/ruby_prof/ruby_prof.c +11 -757
- data/ext/ruby_prof/ruby_prof.h +4 -47
- data/ext/ruby_prof/vc/ruby_prof.vcxproj +10 -8
- data/lib/{2.6.3 → 2.6.5}/ruby_prof.so +0 -0
- data/lib/ruby-prof.rb +2 -18
- data/lib/ruby-prof/assets/call_stack_printer.html.erb +713 -0
- data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
- data/lib/ruby-prof/assets/graph_printer.html.erb +356 -0
- data/lib/ruby-prof/call_info.rb +35 -93
- data/lib/ruby-prof/call_info_visitor.rb +19 -21
- data/lib/ruby-prof/compatibility.rb +37 -107
- data/lib/ruby-prof/exclude_common_methods.rb +198 -0
- data/lib/ruby-prof/measurement.rb +14 -0
- data/lib/ruby-prof/method_info.rb +52 -83
- data/lib/ruby-prof/printers/abstract_printer.rb +73 -50
- data/lib/ruby-prof/printers/call_info_printer.rb +13 -3
- data/lib/ruby-prof/printers/call_stack_printer.rb +62 -145
- data/lib/ruby-prof/printers/call_tree_printer.rb +20 -12
- data/lib/ruby-prof/printers/dot_printer.rb +5 -5
- data/lib/ruby-prof/printers/flat_printer.rb +6 -24
- data/lib/ruby-prof/printers/graph_html_printer.rb +6 -192
- data/lib/ruby-prof/printers/graph_printer.rb +13 -15
- data/lib/ruby-prof/printers/multi_printer.rb +66 -23
- data/lib/ruby-prof/profile.rb +10 -3
- data/lib/ruby-prof/rack.rb +0 -3
- data/lib/ruby-prof/thread.rb +12 -12
- data/lib/ruby-prof/version.rb +1 -1
- data/ruby-prof.gemspec +2 -2
- data/test/abstract_printer_test.rb +0 -27
- data/test/alias_test.rb +129 -0
- data/test/basic_test.rb +41 -40
- data/test/call_info_visitor_test.rb +3 -3
- data/test/dynamic_method_test.rb +0 -2
- data/test/fiber_test.rb +11 -17
- data/test/gc_test.rb +96 -0
- data/test/line_number_test.rb +120 -39
- data/test/marshal_test.rb +119 -0
- data/test/measure_allocations.rb +30 -0
- data/test/measure_allocations_test.rb +371 -12
- data/test/measure_allocations_trace_test.rb +385 -0
- data/test/measure_memory_trace_test.rb +756 -0
- data/test/measure_process_time_test.rb +821 -33
- data/test/measure_times.rb +54 -0
- data/test/measure_wall_time_test.rb +349 -145
- data/test/multi_printer_test.rb +1 -34
- data/test/parser_timings.rb +24 -0
- data/test/pause_resume_test.rb +5 -5
- data/test/prime.rb +2 -0
- data/test/printer_call_stack_test.rb +28 -0
- data/test/printer_call_tree_test.rb +31 -0
- data/test/printer_flat_test.rb +68 -0
- data/test/printer_graph_html_test.rb +60 -0
- data/test/printer_graph_test.rb +41 -0
- data/test/printers_test.rb +32 -166
- data/test/printing_recursive_graph_test.rb +26 -72
- data/test/recursive_test.rb +72 -77
- data/test/stack_printer_test.rb +2 -15
- data/test/start_stop_test.rb +22 -25
- data/test/test_helper.rb +5 -248
- data/test/thread_test.rb +11 -54
- data/test/unique_call_path_test.rb +16 -28
- data/test/yarv_test.rb +1 -0
- metadata +28 -36
- data/examples/flat.txt +0 -50
- data/examples/graph.dot +0 -84
- data/examples/graph.html +0 -823
- data/examples/graph.txt +0 -139
- data/examples/multi.flat.txt +0 -23
- data/examples/multi.graph.html +0 -760
- data/examples/multi.grind.dat +0 -114
- data/examples/multi.stack.html +0 -547
- data/examples/stack.html +0 -547
- data/ext/ruby_prof/rp_measure.c +0 -40
- data/ext/ruby_prof/rp_measure.h +0 -45
- data/ext/ruby_prof/rp_measure_cpu_time.c +0 -136
- data/ext/ruby_prof/rp_measure_gc_runs.c +0 -73
- data/ext/ruby_prof/rp_measure_gc_time.c +0 -60
- data/lib/ruby-prof/aggregate_call_info.rb +0 -76
- data/lib/ruby-prof/assets/call_stack_printer.css.html +0 -117
- data/lib/ruby-prof/assets/call_stack_printer.js.html +0 -385
- data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +0 -83
- data/lib/ruby-prof/profile/exclude_common_methods.rb +0 -207
- data/lib/ruby-prof/profile/legacy_method_elimination.rb +0 -50
- data/test/aggregate_test.rb +0 -136
- data/test/block_test.rb +0 -74
- data/test/call_info_test.rb +0 -78
- data/test/issue137_test.rb +0 -63
- data/test/measure_cpu_time_test.rb +0 -212
- data/test/measure_gc_runs_test.rb +0 -32
- data/test/measure_gc_time_test.rb +0 -36
- data/test/measure_memory_test.rb +0 -33
- data/test/method_elimination_test.rb +0 -84
- data/test/module_test.rb +0 -45
- data/test/stack_test.rb +0 -138
@@ -5,11 +5,17 @@ module RubyProf
|
|
5
5
|
# one profiling run. Currently prints a flat profile, a callgrind
|
6
6
|
# profile, a call stack profile and a graph profile.
|
7
7
|
class MultiPrinter
|
8
|
-
def initialize(result, printers = [:
|
9
|
-
@stack_printer = CallStackPrinter.new(result) if printers.include?(:stack)
|
10
|
-
@graph_printer = GraphHtmlPrinter.new(result) if printers.include?(:graph)
|
11
|
-
@tree_printer = CallTreePrinter.new(result) if printers.include?(:tree)
|
8
|
+
def initialize(result, printers = [:flat, :graph_html])
|
12
9
|
@flat_printer = FlatPrinter.new(result) if printers.include?(:flat)
|
10
|
+
|
11
|
+
@graph_printer = GraphPrinter.new(result) if printers.include?(:graph)
|
12
|
+
@graph_html_printer = GraphHtmlPrinter.new(result) if printers.include?(:graph_html)
|
13
|
+
|
14
|
+
@tree_printer = CallTreePrinter.new(result) if printers.include?(:tree)
|
15
|
+
@call_info_printer = CallInfoPrinter.new(result) if printers.include?(:call_info)
|
16
|
+
|
17
|
+
@stack_printer = CallStackPrinter.new(result) if printers.include?(:stack)
|
18
|
+
@dot_printer = DotPrinter.new(result) if printers.include?(:dot)
|
13
19
|
end
|
14
20
|
|
15
21
|
def self.needs_dir?
|
@@ -18,48 +24,79 @@ module RubyProf
|
|
18
24
|
|
19
25
|
# create profile files under options[:path] or the current
|
20
26
|
# directory. options[:profile] is used as the base name for the
|
21
|
-
#
|
27
|
+
# profile file, defaults to "profile".
|
22
28
|
def print(options)
|
23
29
|
validate_print_params(options)
|
24
30
|
|
25
31
|
@profile = options.delete(:profile) || "profile"
|
26
32
|
@directory = options.delete(:path) || File.expand_path(".")
|
27
33
|
|
28
|
-
|
34
|
+
print_to_flat(options) if @flat_printer
|
35
|
+
|
29
36
|
print_to_graph(options) if @graph_printer
|
37
|
+
print_to_graph_html(options) if @graph_html_printer
|
38
|
+
|
39
|
+
print_to_stack(options) if @stack_printer
|
40
|
+
print_to_call_info(options) if @call_info_printer
|
30
41
|
print_to_tree(options) if @tree_printer
|
31
|
-
|
42
|
+
print_to_dot(options) if @dot_printer
|
32
43
|
end
|
33
44
|
|
34
|
-
# the name of the
|
35
|
-
def
|
36
|
-
"#{@directory}/#{@profile}.
|
45
|
+
# the name of the flat profile file
|
46
|
+
def flat_report
|
47
|
+
"#{@directory}/#{@profile}.flat.txt"
|
37
48
|
end
|
38
49
|
|
39
50
|
# the name of the graph profile file
|
40
|
-
def
|
51
|
+
def graph_report
|
52
|
+
"#{@directory}/#{@profile}.graph.txt"
|
53
|
+
end
|
54
|
+
|
55
|
+
def graph_html_report
|
41
56
|
"#{@directory}/#{@profile}.graph.html"
|
42
57
|
end
|
43
58
|
|
59
|
+
# the name of the callinfo profile file
|
60
|
+
def call_info_report
|
61
|
+
"#{@directory}/#{@profile}.call_info.txt"
|
62
|
+
end
|
63
|
+
|
44
64
|
# the name of the callgrind profile file
|
45
|
-
def
|
65
|
+
def tree_report
|
46
66
|
"#{@directory}/#{@profile}.callgrind.out.#{$$}"
|
47
67
|
end
|
48
68
|
|
49
|
-
# the name of the
|
50
|
-
def
|
51
|
-
"#{@directory}/#{@profile}.
|
69
|
+
# the name of the call stack profile file
|
70
|
+
def stack_report
|
71
|
+
"#{@directory}/#{@profile}.stack.html"
|
52
72
|
end
|
53
73
|
|
54
|
-
|
55
|
-
|
56
|
-
|
74
|
+
# the name of the call stack profile file
|
75
|
+
def dot_report
|
76
|
+
"#{@directory}/#{@profile}.dot"
|
77
|
+
end
|
78
|
+
|
79
|
+
def print_to_flat(options)
|
80
|
+
File.open(flat_report, "wb") do |file|
|
81
|
+
@flat_printer.print(file, options)
|
57
82
|
end
|
58
83
|
end
|
59
84
|
|
60
85
|
def print_to_graph(options)
|
61
|
-
File.open(
|
62
|
-
@graph_printer.print(
|
86
|
+
File.open(graph_report, "wb") do |file|
|
87
|
+
@graph_printer.print(file, options)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def print_to_graph_html(options)
|
92
|
+
File.open(graph_html_report, "wb") do |file|
|
93
|
+
@graph_html_printer.print(file, options)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def print_to_call_info(options)
|
98
|
+
File.open(call_info_report, "wb") do |file|
|
99
|
+
@call_info_printer.print(file, options)
|
63
100
|
end
|
64
101
|
end
|
65
102
|
|
@@ -67,9 +104,15 @@ module RubyProf
|
|
67
104
|
@tree_printer.print(options.merge(:path => @directory, :profile => @profile))
|
68
105
|
end
|
69
106
|
|
70
|
-
def
|
71
|
-
File.open(
|
72
|
-
@
|
107
|
+
def print_to_stack(options)
|
108
|
+
File.open(stack_report, "wb") do |file|
|
109
|
+
@stack_printer.print(file, options.merge(:graph => "#{@profile}.graph.html"))
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def print_to_dot(options)
|
114
|
+
File.open(dot_report, "wb") do |file|
|
115
|
+
@dot_printer.print(file, options)
|
73
116
|
end
|
74
117
|
end
|
75
118
|
|
data/lib/ruby-prof/profile.rb
CHANGED
@@ -1,11 +1,18 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'ruby-prof/
|
4
|
-
require 'ruby-prof/profile/legacy_method_elimination'
|
3
|
+
require 'ruby-prof/exclude_common_methods'
|
5
4
|
|
6
5
|
module RubyProf
|
7
6
|
class Profile
|
8
|
-
|
7
|
+
# :nodoc:
|
8
|
+
def measure_mode_string
|
9
|
+
case self.measure_mode
|
10
|
+
when WALL_TIME then "wall_time"
|
11
|
+
when PROCESS_TIME then "process_time"
|
12
|
+
when ALLOCATIONS then "allocations"
|
13
|
+
when MEMORY then "memory"
|
14
|
+
end
|
15
|
+
end
|
9
16
|
|
10
17
|
# Hides methods that, when represented as a call graph, have
|
11
18
|
# extremely large in and out degrees and make navigation impossible.
|
data/lib/ruby-prof/rack.rb
CHANGED
data/lib/ruby-prof/thread.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
module RubyProf
|
2
2
|
class Thread
|
3
|
-
|
3
|
+
# Returns the root methods (ie, methods that were not called by other methods) that were profiled while
|
4
|
+
# this thread was executing. Generally there is only one root method (multiple root methods can occur
|
5
|
+
# when Profile#pause is used). By starting with the root methods, you can descend down the profile
|
6
|
+
# call tree.
|
7
|
+
def root_methods
|
4
8
|
self.methods.select do |method_info|
|
5
|
-
method_info.
|
9
|
+
method_info.root?
|
6
10
|
end
|
7
11
|
end
|
8
12
|
|
9
|
-
|
10
|
-
top_methods.map(&:call_infos).flatten.select(&:root?)
|
11
|
-
end
|
12
|
-
|
13
|
+
# Returns the total time this thread was executed.
|
13
14
|
def total_time
|
14
|
-
self.
|
15
|
-
method_info.
|
16
|
-
|
17
|
-
sum += call_info.total_time
|
18
|
-
end
|
15
|
+
self.root_methods.inject(0) do |sum, method_info|
|
16
|
+
method_info.callers.each do |call_info|
|
17
|
+
sum += call_info.total_time
|
19
18
|
end
|
20
19
|
sum
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
23
|
+
# Returns the amount of time this thread waited while other thread executed.
|
24
24
|
def wait_time
|
25
25
|
# wait_time, like self:time, is always method local
|
26
26
|
# thus we need to sum over all methods and call infos
|
27
27
|
self.methods.inject(0) do |sum, method_info|
|
28
|
-
method_info.
|
28
|
+
method_info.callers.each do |call_info|
|
29
29
|
sum += call_info.wait_time
|
30
30
|
end
|
31
31
|
sum
|
data/lib/ruby-prof/version.rb
CHANGED
data/ruby-prof.gemspec
CHANGED
@@ -43,13 +43,13 @@ EOF
|
|
43
43
|
'lib/ruby-prof.rb',
|
44
44
|
'lib/unprof.rb',
|
45
45
|
'lib/ruby-prof/*.rb',
|
46
|
-
'lib/ruby-prof/assets
|
46
|
+
'lib/ruby-prof/assets/*',
|
47
47
|
'lib/ruby-prof/profile/*.rb',
|
48
48
|
'lib/ruby-prof/printers/*.rb',
|
49
49
|
'test/*.rb']
|
50
50
|
|
51
51
|
spec.test_files = Dir["test/test_*.rb"]
|
52
|
-
spec.required_ruby_version = '>=
|
52
|
+
spec.required_ruby_version = '>= 2.4.0'
|
53
53
|
spec.date = Time.now.strftime('%Y-%m-%d')
|
54
54
|
spec.homepage = 'https://github.com/ruby-prof/ruby-prof'
|
55
55
|
spec.add_development_dependency('minitest')
|
@@ -11,33 +11,6 @@ class AbstractPrinterTest < TestCase
|
|
11
11
|
@printer.setup_options(@options)
|
12
12
|
end
|
13
13
|
|
14
|
-
def test_editor_uri
|
15
|
-
env = {}
|
16
|
-
|
17
|
-
with_const_stubbed('ENV', env) do
|
18
|
-
@options[:editor_uri] = 'nvim'
|
19
|
-
|
20
|
-
env['RUBY_PROF_EDITOR_URI'] = 'atm'
|
21
|
-
assert_equal('atm', @printer.editor_uri)
|
22
|
-
|
23
|
-
env['RUBY_PROF_EDITOR_URI'] = nil
|
24
|
-
assert_equal(false, @printer.editor_uri)
|
25
|
-
|
26
|
-
env.delete('RUBY_PROF_EDITOR_URI')
|
27
|
-
assert_equal('nvim', @printer.editor_uri)
|
28
|
-
|
29
|
-
with_const_stubbed('RUBY_PLATFORM', 'x86_64-darwin18') do
|
30
|
-
assert_equal('nvim', @printer.editor_uri)
|
31
|
-
|
32
|
-
@options.delete(:editor_uri)
|
33
|
-
assert_equal('txmt', @printer.editor_uri)
|
34
|
-
end
|
35
|
-
with_const_stubbed('RUBY_PLATFORM', 'windows') do
|
36
|
-
assert_equal(false, @printer.editor_uri)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
14
|
private
|
42
15
|
|
43
16
|
def with_const_stubbed(name, value)
|
data/test/alias_test.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
require File.expand_path("../test_helper", __FILE__)
|
5
|
+
|
6
|
+
class AliasTest < TestCase
|
7
|
+
class TestMe
|
8
|
+
def some_method
|
9
|
+
sleep(0.1)
|
10
|
+
end
|
11
|
+
|
12
|
+
alias :some_method_original :some_method
|
13
|
+
def some_method
|
14
|
+
some_method_original
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def setup
|
19
|
+
# Need to use wall time for this test due to the sleep calls
|
20
|
+
RubyProf::measure_mode = RubyProf::WALL_TIME
|
21
|
+
end
|
22
|
+
|
23
|
+
# This test only correct works on Ruby 2.5 and higher because - see:
|
24
|
+
# https://bugs.ruby-lang.org/issues/12747
|
25
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.5.0')
|
26
|
+
def test_alias
|
27
|
+
result = RubyProf.profile do
|
28
|
+
TestMe.new.some_method
|
29
|
+
end
|
30
|
+
|
31
|
+
methods = result.threads.first.methods
|
32
|
+
assert_equal(6, methods.count)
|
33
|
+
|
34
|
+
# Method 0
|
35
|
+
method = methods[0]
|
36
|
+
assert_equal('AliasTest#test_alias', method.full_name)
|
37
|
+
assert_equal(28, method.line)
|
38
|
+
refute(method.recursive?)
|
39
|
+
|
40
|
+
assert_equal(1, method.callers.count)
|
41
|
+
call_info = method.callers[0]
|
42
|
+
assert_nil(call_info.parent)
|
43
|
+
assert_equal(28, call_info.line)
|
44
|
+
|
45
|
+
assert_equal(2, method.callees.count)
|
46
|
+
call_info = method.callees[0]
|
47
|
+
assert_equal('Class#new', call_info.target.full_name)
|
48
|
+
assert_equal(28, call_info.line)
|
49
|
+
|
50
|
+
call_info = method.callees[1]
|
51
|
+
assert_equal('AliasTest::TestMe#some_method', call_info.target.full_name)
|
52
|
+
assert_equal(28, call_info.line)
|
53
|
+
|
54
|
+
# Method 1
|
55
|
+
method = methods[1]
|
56
|
+
assert_equal('Class#new', method.full_name)
|
57
|
+
assert_equal(0, method.line)
|
58
|
+
refute(method.recursive?)
|
59
|
+
|
60
|
+
assert_equal(1, method.callers.count)
|
61
|
+
call_info = method.callers[0]
|
62
|
+
assert_equal('AliasTest#test_alias', call_info.parent.full_name)
|
63
|
+
assert_equal(28, call_info.line)
|
64
|
+
|
65
|
+
assert_equal(1, method.callees.count)
|
66
|
+
call_info = method.callees[0]
|
67
|
+
assert_equal('BasicObject#initialize', call_info.target.full_name)
|
68
|
+
assert_equal(0, call_info.line)
|
69
|
+
|
70
|
+
# Method 2
|
71
|
+
method = methods[2]
|
72
|
+
assert_equal('BasicObject#initialize', method.full_name)
|
73
|
+
assert_equal(0, method.line)
|
74
|
+
refute(method.recursive?)
|
75
|
+
|
76
|
+
assert_equal(1, method.callers.count)
|
77
|
+
call_info = method.callers[0]
|
78
|
+
assert_equal('Class#new', call_info.parent.full_name)
|
79
|
+
assert_equal(0, call_info.line)
|
80
|
+
|
81
|
+
assert_equal(0, method.callees.count)
|
82
|
+
|
83
|
+
# Method 3
|
84
|
+
method = methods[3]
|
85
|
+
assert_equal('AliasTest::TestMe#some_method', method.full_name)
|
86
|
+
assert_equal(13, method.line)
|
87
|
+
refute(method.recursive?)
|
88
|
+
|
89
|
+
assert_equal(1, method.callers.count)
|
90
|
+
call_info = method.callers[0]
|
91
|
+
assert_equal('AliasTest#test_alias', call_info.parent.full_name)
|
92
|
+
assert_equal(28, call_info.line)
|
93
|
+
|
94
|
+
assert_equal(1, method.callees.count)
|
95
|
+
call_info = method.callees[0]
|
96
|
+
assert_equal('AliasTest::TestMe#some_method_original', call_info.target.full_name)
|
97
|
+
assert_equal(14, call_info.line)
|
98
|
+
|
99
|
+
# Method 4
|
100
|
+
method = methods[4]
|
101
|
+
assert_equal('AliasTest::TestMe#some_method_original', method.full_name)
|
102
|
+
assert_equal(8, method.line)
|
103
|
+
refute(method.recursive?)
|
104
|
+
|
105
|
+
assert_equal(1, method.callers.count)
|
106
|
+
call_info = method.callers[0]
|
107
|
+
assert_equal('AliasTest::TestMe#some_method', call_info.parent.full_name)
|
108
|
+
assert_equal(14, call_info.line)
|
109
|
+
|
110
|
+
assert_equal(1, method.callees.count)
|
111
|
+
call_info = method.callees[0]
|
112
|
+
assert_equal('Kernel#sleep', call_info.target.full_name)
|
113
|
+
assert_equal(9, call_info.line)
|
114
|
+
|
115
|
+
# Method 5
|
116
|
+
method = methods[5]
|
117
|
+
assert_equal('Kernel#sleep', method.full_name)
|
118
|
+
assert_equal(0, method.line)
|
119
|
+
refute(method.recursive?)
|
120
|
+
|
121
|
+
assert_equal(1, method.callers.count)
|
122
|
+
call_info = method.callers[0]
|
123
|
+
assert_equal('AliasTest::TestMe#some_method_original', call_info.parent.full_name)
|
124
|
+
assert_equal(9, call_info.line)
|
125
|
+
|
126
|
+
assert_equal(0, method.callees.count)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
data/test/basic_test.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
# encoding: UTF-8
|
3
3
|
|
4
4
|
require File.expand_path('../test_helper', __FILE__)
|
5
|
+
require_relative './measure_times'
|
5
6
|
|
6
7
|
class BasicTest < TestCase
|
7
8
|
def setup
|
@@ -11,7 +12,7 @@ class BasicTest < TestCase
|
|
11
12
|
|
12
13
|
def start
|
13
14
|
RubyProf.start
|
14
|
-
RubyProf::C1.
|
15
|
+
RubyProf::C1.sleep_wait
|
15
16
|
end
|
16
17
|
|
17
18
|
def test_running
|
@@ -53,76 +54,76 @@ class BasicTest < TestCase
|
|
53
54
|
assert_equal(1, profile.threads.count)
|
54
55
|
|
55
56
|
thread = profile.threads.first
|
56
|
-
assert_in_delta(0.25, thread.total_time, 0.
|
57
|
+
assert_in_delta(0.25, thread.total_time, 0.05)
|
57
58
|
|
58
|
-
|
59
|
-
assert_equal(2,
|
60
|
-
assert_equal("BasicTest#start",
|
61
|
-
assert_equal("BasicTest#test_leave_method",
|
59
|
+
root_methods = thread.root_methods.sort
|
60
|
+
assert_equal(2, root_methods.count)
|
61
|
+
assert_equal("BasicTest#start", root_methods[0].full_name)
|
62
|
+
assert_equal("BasicTest#test_leave_method", root_methods[1].full_name)
|
62
63
|
|
63
64
|
assert_equal(4, thread.methods.length)
|
64
65
|
methods = profile.threads.first.methods.sort
|
65
66
|
|
66
67
|
# Check times
|
67
|
-
assert_equal("<Class::RubyProf::C1>#
|
68
|
-
assert_in_delta(0.1, methods[0].total_time, 0.
|
69
|
-
assert_in_delta(0.0, methods[0].wait_time, 0.
|
70
|
-
assert_in_delta(0.0, methods[0].self_time, 0.
|
68
|
+
assert_equal("<Class::RubyProf::C1>#sleep_wait", methods[0].full_name)
|
69
|
+
assert_in_delta(0.1, methods[0].total_time, 0.05)
|
70
|
+
assert_in_delta(0.0, methods[0].wait_time, 0.05)
|
71
|
+
assert_in_delta(0.0, methods[0].self_time, 0.05)
|
71
72
|
|
72
73
|
assert_equal("BasicTest#start", methods[1].full_name)
|
73
|
-
assert_in_delta(0.1, methods[1].total_time, 0.
|
74
|
-
assert_in_delta(0.0, methods[1].wait_time, 0.
|
75
|
-
assert_in_delta(0.0, methods[1].self_time, 0.
|
74
|
+
assert_in_delta(0.1, methods[1].total_time, 0.05)
|
75
|
+
assert_in_delta(0.0, methods[1].wait_time, 0.05)
|
76
|
+
assert_in_delta(0.0, methods[1].self_time, 0.05)
|
76
77
|
|
77
78
|
assert_equal("BasicTest#test_leave_method", methods[2].full_name)
|
78
|
-
assert_in_delta(0.15, methods[2].total_time, 0.
|
79
|
-
assert_in_delta(0.0, methods[2].wait_time, 0.
|
80
|
-
assert_in_delta(0.0, methods[2].self_time, 0.
|
79
|
+
assert_in_delta(0.15, methods[2].total_time, 0.05)
|
80
|
+
assert_in_delta(0.0, methods[2].wait_time, 0.05)
|
81
|
+
assert_in_delta(0.0, methods[2].self_time, 0.05)
|
81
82
|
|
82
83
|
assert_equal("Kernel#sleep", methods[3].full_name)
|
83
|
-
assert_in_delta(0.25, methods[3].total_time, 0.
|
84
|
-
assert_in_delta(0.0, methods[3].wait_time, 0.
|
85
|
-
assert_in_delta(0.25, methods[3].self_time, 0.
|
84
|
+
assert_in_delta(0.25, methods[3].total_time, 0.05)
|
85
|
+
assert_in_delta(0.0, methods[3].wait_time, 0.05)
|
86
|
+
assert_in_delta(0.25, methods[3].self_time, 0.05)
|
86
87
|
end
|
87
88
|
|
88
89
|
def test_leave_method_2
|
89
90
|
start
|
90
|
-
RubyProf::C1.
|
91
|
-
RubyProf::C1.
|
91
|
+
RubyProf::C1.sleep_wait
|
92
|
+
RubyProf::C1.sleep_wait
|
92
93
|
profile = RubyProf.stop
|
93
94
|
|
94
95
|
assert_equal(1, profile.threads.count)
|
95
96
|
|
96
97
|
thread = profile.threads.first
|
97
|
-
assert_in_delta(0.3, thread.total_time, 0.
|
98
|
+
assert_in_delta(0.3, thread.total_time, 0.05)
|
98
99
|
|
99
|
-
|
100
|
-
assert_equal(2,
|
101
|
-
assert_equal("BasicTest#start",
|
102
|
-
assert_equal("BasicTest#test_leave_method_2",
|
100
|
+
root_methods = thread.root_methods.sort
|
101
|
+
assert_equal(2, root_methods.count)
|
102
|
+
assert_equal("BasicTest#start", root_methods[0].full_name)
|
103
|
+
assert_equal("BasicTest#test_leave_method_2", root_methods[1].full_name)
|
103
104
|
|
104
105
|
assert_equal(4, thread.methods.length)
|
105
106
|
methods = profile.threads.first.methods.sort
|
106
107
|
|
107
108
|
# Check times
|
108
109
|
assert_equal("BasicTest#start", methods[0].full_name)
|
109
|
-
assert_in_delta(0.1, methods[0].total_time, 0.
|
110
|
-
assert_in_delta(0.0, methods[0].wait_time, 0.
|
111
|
-
assert_in_delta(0.0, methods[0].self_time, 0.
|
110
|
+
assert_in_delta(0.1, methods[0].total_time, 0.05)
|
111
|
+
assert_in_delta(0.0, methods[0].wait_time, 0.05)
|
112
|
+
assert_in_delta(0.0, methods[0].self_time, 0.05)
|
112
113
|
|
113
114
|
assert_equal("BasicTest#test_leave_method_2", methods[1].full_name)
|
114
|
-
assert_in_delta(0.2, methods[1].total_time, 0.
|
115
|
-
assert_in_delta(0.0, methods[1].wait_time, 0.
|
116
|
-
assert_in_delta(0.0, methods[1].self_time, 0.
|
115
|
+
assert_in_delta(0.2, methods[1].total_time, 0.05)
|
116
|
+
assert_in_delta(0.0, methods[1].wait_time, 0.05)
|
117
|
+
assert_in_delta(0.0, methods[1].self_time, 0.05)
|
117
118
|
|
118
119
|
assert_equal("Kernel#sleep", methods[2].full_name)
|
119
|
-
assert_in_delta(0.3, methods[2].total_time, 0.
|
120
|
-
assert_in_delta(0.0, methods[2].wait_time, 0.
|
121
|
-
assert_in_delta(0.3, methods[2].self_time, 0.
|
122
|
-
|
123
|
-
assert_equal("<Class::RubyProf::C1>#
|
124
|
-
assert_in_delta(0.3, methods[3].total_time, 0.
|
125
|
-
assert_in_delta(0.0, methods[3].wait_time, 0.
|
126
|
-
assert_in_delta(0.0, methods[3].self_time, 0.
|
120
|
+
assert_in_delta(0.3, methods[2].total_time, 0.05)
|
121
|
+
assert_in_delta(0.0, methods[2].wait_time, 0.05)
|
122
|
+
assert_in_delta(0.3, methods[2].self_time, 0.05)
|
123
|
+
|
124
|
+
assert_equal("<Class::RubyProf::C1>#sleep_wait", methods[3].full_name)
|
125
|
+
assert_in_delta(0.3, methods[3].total_time, 0.05)
|
126
|
+
assert_in_delta(0.0, methods[3].wait_time, 0.05)
|
127
|
+
assert_in_delta(0.0, methods[3].self_time, 0.05)
|
127
128
|
end
|
128
129
|
end
|