ruby-prof 0.18.0 → 1.2.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.
- checksums.yaml +4 -4
- data/CHANGES +44 -1
- data/LICENSE +2 -2
- data/README.rdoc +1 -483
- data/Rakefile +3 -6
- data/bin/ruby-prof +111 -128
- data/ext/ruby_prof/extconf.rb +6 -38
- data/ext/ruby_prof/rp_aggregate_call_tree.c +41 -0
- data/ext/ruby_prof/rp_aggregate_call_tree.h +13 -0
- data/ext/ruby_prof/rp_allocation.c +259 -0
- data/ext/ruby_prof/rp_allocation.h +31 -0
- data/ext/ruby_prof/rp_call_tree.c +353 -0
- data/ext/ruby_prof/rp_call_tree.h +43 -0
- data/ext/ruby_prof/rp_call_trees.c +266 -0
- data/ext/ruby_prof/rp_call_trees.h +29 -0
- data/ext/ruby_prof/rp_measure_allocations.c +25 -51
- data/ext/ruby_prof/rp_measure_memory.c +21 -56
- data/ext/ruby_prof/rp_measure_process_time.c +37 -43
- data/ext/ruby_prof/rp_measure_wall_time.c +40 -21
- data/ext/ruby_prof/rp_measurement.c +221 -0
- data/ext/ruby_prof/rp_measurement.h +50 -0
- data/ext/ruby_prof/rp_method.c +279 -439
- data/ext/ruby_prof/rp_method.h +33 -45
- data/ext/ruby_prof/rp_profile.c +902 -0
- data/ext/ruby_prof/rp_profile.h +36 -0
- data/ext/ruby_prof/rp_stack.c +163 -132
- data/ext/ruby_prof/rp_stack.h +18 -28
- data/ext/ruby_prof/rp_thread.c +192 -124
- data/ext/ruby_prof/rp_thread.h +18 -8
- data/ext/ruby_prof/ruby_prof.c +36 -778
- data/ext/ruby_prof/ruby_prof.h +11 -45
- data/ext/ruby_prof/vc/ruby_prof.vcxproj +18 -12
- data/lib/ruby-prof.rb +4 -21
- data/lib/ruby-prof/assets/call_stack_printer.html.erb +710 -0
- data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
- data/lib/ruby-prof/assets/graph_printer.html.erb +355 -0
- data/lib/ruby-prof/call_tree.rb +57 -0
- data/lib/ruby-prof/call_tree_visitor.rb +36 -0
- data/lib/ruby-prof/compatibility.rb +37 -107
- data/lib/ruby-prof/exclude_common_methods.rb +198 -0
- data/lib/ruby-prof/measurement.rb +17 -0
- data/lib/ruby-prof/method_info.rb +47 -90
- data/lib/ruby-prof/printers/abstract_printer.rb +73 -50
- data/lib/ruby-prof/printers/call_info_printer.rb +24 -12
- data/lib/ruby-prof/printers/call_stack_printer.rb +66 -152
- 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 +11 -14
- data/lib/ruby-prof/printers/multi_printer.rb +66 -23
- data/lib/ruby-prof/profile.rb +10 -3
- data/lib/ruby-prof/thread.rb +5 -20
- data/lib/ruby-prof/version.rb +1 -1
- data/ruby-prof.gemspec +9 -2
- data/test/abstract_printer_test.rb +0 -27
- data/test/alias_test.rb +126 -0
- data/test/basic_test.rb +1 -86
- data/test/call_tree_visitor_test.rb +32 -0
- data/test/call_trees_test.rb +66 -0
- data/test/dynamic_method_test.rb +0 -2
- data/test/exclude_methods_test.rb +17 -12
- data/test/fiber_test.rb +214 -23
- data/test/gc_test.rb +105 -0
- data/test/inverse_call_tree_test.rb +175 -0
- data/test/line_number_test.rb +118 -40
- data/test/marshal_test.rb +115 -0
- data/test/measure_allocations.rb +30 -0
- data/test/measure_allocations_test.rb +361 -12
- data/test/measure_allocations_trace_test.rb +375 -0
- data/test/measure_memory_trace_test.rb +1101 -0
- data/test/measure_process_time_test.rb +757 -33
- data/test/measure_times.rb +56 -0
- data/test/measure_wall_time_test.rb +329 -149
- data/test/multi_printer_test.rb +1 -34
- data/test/pause_resume_test.rb +24 -15
- data/test/prime.rb +1 -1
- data/test/prime_script.rb +6 -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 +68 -77
- data/test/stack_printer_test.rb +2 -15
- data/test/start_stop_test.rb +22 -25
- data/test/test_helper.rb +6 -261
- data/test/thread_test.rb +11 -54
- data/test/unique_call_path_test.rb +25 -107
- data/test/yarv_test.rb +1 -0
- metadata +43 -41
- 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_call_info.c +0 -425
- data/ext/ruby_prof/rp_call_info.h +0 -53
- 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/call_info.rb +0 -115
- data/lib/ruby-prof/call_info_visitor.rb +0 -40
- 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/call_info_visitor_test.rb +0 -31
- 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
data/test/block_test.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
require File.expand_path("../test_helper", __FILE__)
|
5
|
-
|
6
|
-
class BlockMethodTest < 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_block
|
13
|
-
result = RubyProf.profile do
|
14
|
-
1.times { RubyProf::C1.new.hello }
|
15
|
-
end
|
16
|
-
|
17
|
-
# Methods called
|
18
|
-
# Kernel#sleep
|
19
|
-
# <Class::BasicObject>#allocate
|
20
|
-
# #{RubyProf.parent_object}#inizialize
|
21
|
-
# RubyProf::C1#hello
|
22
|
-
# Class#new
|
23
|
-
# Integer#times
|
24
|
-
# BlockMethodTest#test_block
|
25
|
-
|
26
|
-
methods = result.threads.first.methods.sort.reverse
|
27
|
-
assert_equal(RubyProf.ruby_2? ? 6 : 7, methods.length)
|
28
|
-
|
29
|
-
# Check times
|
30
|
-
assert_equal("BlockMethodTest#test_block", methods[0].full_name)
|
31
|
-
assert_in_delta(0.2, methods[0].total_time, 0.02)
|
32
|
-
assert_in_delta(0.0, methods[0].wait_time, 0.02)
|
33
|
-
assert_in_delta(0.0, methods[0].self_time, 0.02)
|
34
|
-
|
35
|
-
assert_equal("Integer#times", methods[1].full_name)
|
36
|
-
assert_in_delta(0.2, methods[1].total_time, 0.02)
|
37
|
-
assert_in_delta(0.0, methods[1].wait_time, 0.02)
|
38
|
-
assert_in_delta(0.0, methods[1].self_time, 0.02)
|
39
|
-
|
40
|
-
assert_equal("RubyProf::C1#hello", methods[2].full_name)
|
41
|
-
assert_in_delta(0.2, methods[2].total_time, 0.02)
|
42
|
-
assert_in_delta(0.0, methods[2].wait_time, 0.02)
|
43
|
-
assert_in_delta(0.0, methods[2].self_time, 0.02)
|
44
|
-
|
45
|
-
assert_equal("Kernel#sleep", methods[3].full_name)
|
46
|
-
assert_in_delta(0.2, methods[3].total_time, 0.01)
|
47
|
-
assert_in_delta(0.0, methods[3].wait_time, 0.01)
|
48
|
-
assert_in_delta(0.2, methods[3].self_time, 0.01)
|
49
|
-
|
50
|
-
assert_equal("Class#new", methods[4].full_name)
|
51
|
-
assert_in_delta(0.0, methods[4].total_time, 0.01)
|
52
|
-
assert_in_delta(0.0, methods[4].wait_time, 0.01)
|
53
|
-
assert_in_delta(0.0, methods[4].self_time, 0.01)
|
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
|
61
|
-
|
62
|
-
assert_equal("#{RubyProf.parent_object}#initialize", methods[5].full_name)
|
63
|
-
assert_in_delta(0.0, methods[5].total_time, 0.01)
|
64
|
-
assert_in_delta(0.0, methods[5].wait_time, 0.01)
|
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
|
73
|
-
end
|
74
|
-
end
|
data/test/call_info_test.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
require File.expand_path('../test_helper', __FILE__)
|
5
|
-
|
6
|
-
class CallInfoTest < 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
|
-
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
|
-
|
@@ -1,31 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
require File.expand_path('../test_helper', __FILE__)
|
5
|
-
|
6
|
-
class CallInfoVisitorTest < 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_visit
|
13
|
-
result = RubyProf.profile do
|
14
|
-
RubyProf::C1.hello
|
15
|
-
end
|
16
|
-
|
17
|
-
visitor = RubyProf::CallInfoVisitor.new(result.threads.first.top_call_infos)
|
18
|
-
|
19
|
-
method_names = Array.new
|
20
|
-
|
21
|
-
visitor.visit do |call_info, event|
|
22
|
-
method_names << call_info.target.full_name if event == :enter
|
23
|
-
end
|
24
|
-
|
25
|
-
assert_equal(3, method_names.length)
|
26
|
-
assert_equal("CallInfoVisitorTest#test_visit", method_names[0])
|
27
|
-
assert_equal("<Class::RubyProf::C1>#hello", method_names[1])
|
28
|
-
assert_equal("Kernel#sleep", method_names[2])
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
data/test/issue137_test.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
require File.expand_path('../test_helper', __FILE__)
|
5
|
-
|
6
|
-
# issue 137 is about correctly attributing time of recursive children
|
7
|
-
|
8
|
-
class RecursiveChildrenTest < TestCase
|
9
|
-
class SlowClass
|
10
|
-
def time_sink
|
11
|
-
1234567890 ** 100 == 0
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class SlowSearcher
|
16
|
-
def do_find(slow_objects)
|
17
|
-
slow_objects.find(&:time_sink)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
class MainClass
|
22
|
-
def self.main_method
|
23
|
-
slow_objects = [SlowClass.new] * 100_000
|
24
|
-
slow_searcher = SlowSearcher.new
|
25
|
-
slow_searcher.do_find(slow_objects)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
include PrinterTestHelper
|
30
|
-
|
31
|
-
def setup
|
32
|
-
# Need to use wall time for this test due to the sleep calls
|
33
|
-
RubyProf::measure_mode = RubyProf::WALL_TIME
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_simple
|
37
|
-
result = RubyProf.profile do
|
38
|
-
# make array each recursive
|
39
|
-
[1].each do
|
40
|
-
MainClass.main_method
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# methods = result.threads.first.methods.sort.reverse
|
45
|
-
|
46
|
-
printer = RubyProf::GraphPrinter.new(result)
|
47
|
-
|
48
|
-
buffer = ''
|
49
|
-
printer.print(StringIO.new(buffer))
|
50
|
-
|
51
|
-
puts buffer if ENV['SHOW_RUBY_PROF_PRINTER_OUTPUT'] == "1"
|
52
|
-
|
53
|
-
parsed_output = MetricsArray.parse(buffer)
|
54
|
-
|
55
|
-
assert( enum_find = parsed_output.metrics_for("Enumerable#find") )
|
56
|
-
assert( array_each = enum_find.child("Array#each") )
|
57
|
-
|
58
|
-
assert_operator enum_find.metrics.total, :>=, array_each.total
|
59
|
-
assert_operator enum_find.metrics.total, :>, 0
|
60
|
-
assert_in_delta enum_find.metrics.total, array_each.total, 0.02
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
@@ -1,212 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
require File.expand_path('../test_helper', __FILE__)
|
5
|
-
|
6
|
-
class MeasureCpuTimeTest < TestCase
|
7
|
-
def setup
|
8
|
-
RubyProf::measure_mode = RubyProf::CPU_TIME
|
9
|
-
end
|
10
|
-
|
11
|
-
def teardown
|
12
|
-
RubyProf::measure_mode = RubyProf::WALL_TIME
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_mode
|
16
|
-
assert_equal(RubyProf::CPU_TIME, RubyProf::measure_mode)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_cpu_time_enabled_defined
|
20
|
-
assert(defined?(RubyProf::CPU_TIME_ENABLED))
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_class_methods
|
24
|
-
result = RubyProf.profile do
|
25
|
-
RubyProf::C7.busy_wait
|
26
|
-
end
|
27
|
-
|
28
|
-
# Length should be greater 2:
|
29
|
-
# MeasureCpuTimeTest#test_class_methods
|
30
|
-
# <Class::RubyProf::C1>#busy_wait
|
31
|
-
# ....
|
32
|
-
|
33
|
-
methods = result.threads.first.methods.sort.reverse[0..1]
|
34
|
-
assert_equal(2, methods.length)
|
35
|
-
|
36
|
-
# Check the names
|
37
|
-
assert_equal('MeasureCpuTimeTest#test_class_methods', methods[0].full_name)
|
38
|
-
assert_equal('<Class::RubyProf::C7>#busy_wait', methods[1].full_name)
|
39
|
-
|
40
|
-
# Check times
|
41
|
-
assert_in_delta(0.1, methods[0].total_time, 0.05)
|
42
|
-
assert_in_delta(0, methods[0].wait_time, 0.05)
|
43
|
-
assert_in_delta(0, methods[0].self_time, 0.05)
|
44
|
-
|
45
|
-
assert_in_delta(0.1, methods[1].total_time, 0.05)
|
46
|
-
assert_in_delta(0, methods[1].wait_time, 0.05)
|
47
|
-
assert_in_delta(0, methods[1].self_time, 0.05)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_instance_methods
|
51
|
-
result = RubyProf.profile do
|
52
|
-
RubyProf::C7.new.busy_wait
|
53
|
-
end
|
54
|
-
|
55
|
-
methods = result.threads.first.methods.sort.reverse[0..1]
|
56
|
-
assert_equal(2, methods.length)
|
57
|
-
|
58
|
-
# Methods at this point:
|
59
|
-
# MeasureCpuTimeTest#test_instance_methods
|
60
|
-
# C7#busy_wait
|
61
|
-
# ...
|
62
|
-
|
63
|
-
names = methods.map(&:full_name)
|
64
|
-
assert_equal('MeasureCpuTimeTest#test_instance_methods', names[0])
|
65
|
-
assert_equal('RubyProf::C7#busy_wait', names[1])
|
66
|
-
|
67
|
-
|
68
|
-
# Check times
|
69
|
-
assert_in_delta(0.2, methods[0].total_time, 0.03)
|
70
|
-
assert_in_delta(0, methods[0].wait_time, 0.03)
|
71
|
-
assert_in_delta(0, methods[0].self_time, 0.03)
|
72
|
-
|
73
|
-
assert_in_delta(0.2, methods[1].total_time, 0.03)
|
74
|
-
assert_in_delta(0, methods[1].wait_time, 0.03)
|
75
|
-
assert_in_delta(0, methods[1].self_time, 0.2)
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_module_methods
|
79
|
-
result = RubyProf.profile do
|
80
|
-
RubyProf::C8.busy_wait
|
81
|
-
end
|
82
|
-
|
83
|
-
# Methods:
|
84
|
-
# MeasureCpuTimeTest#test_module_methods
|
85
|
-
# M1#busy_wait
|
86
|
-
# ...
|
87
|
-
|
88
|
-
methods = result.threads.first.methods.sort.reverse[0..1]
|
89
|
-
assert_equal(2, methods.length)
|
90
|
-
|
91
|
-
assert_equal('MeasureCpuTimeTest#test_module_methods', methods[0].full_name)
|
92
|
-
assert_equal('RubyProf::M7#busy_wait', methods[1].full_name)
|
93
|
-
|
94
|
-
# Check times
|
95
|
-
assert_in_delta(0.3, methods[0].total_time, 0.1)
|
96
|
-
assert_in_delta(0, methods[0].wait_time, 0.02)
|
97
|
-
assert_in_delta(0, methods[0].self_time, 0.02)
|
98
|
-
|
99
|
-
assert_in_delta(0.3, methods[1].total_time, 0.1)
|
100
|
-
assert_in_delta(0, methods[1].wait_time, 0.02)
|
101
|
-
assert_in_delta(0, methods[1].self_time, 0.1)
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_module_instance_methods
|
105
|
-
result = RubyProf.profile do
|
106
|
-
RubyProf::C8.new.busy_wait
|
107
|
-
end
|
108
|
-
|
109
|
-
# Methods:
|
110
|
-
# MeasureCpuTimeTest#test_module_instance_methods
|
111
|
-
# M7#busy_wait
|
112
|
-
# ...
|
113
|
-
|
114
|
-
methods = result.threads.first.methods.sort.reverse[0..1]
|
115
|
-
assert_equal(2, methods.length)
|
116
|
-
names = methods.map(&:full_name)
|
117
|
-
assert_equal('MeasureCpuTimeTest#test_module_instance_methods', names[0])
|
118
|
-
assert_equal('RubyProf::M7#busy_wait', names[1])
|
119
|
-
|
120
|
-
# Check times
|
121
|
-
assert_in_delta(0.3, methods[0].total_time, 0.1)
|
122
|
-
assert_in_delta(0, methods[0].wait_time, 0.1)
|
123
|
-
assert_in_delta(0, methods[0].self_time, 0.1)
|
124
|
-
|
125
|
-
assert_in_delta(0.3, methods[1].total_time, 0.1)
|
126
|
-
assert_in_delta(0, methods[1].wait_time, 0.01)
|
127
|
-
assert_in_delta(0, methods[1].self_time, 0.1)
|
128
|
-
end
|
129
|
-
|
130
|
-
def test_singleton
|
131
|
-
c3 = RubyProf::C3.new
|
132
|
-
|
133
|
-
class << c3
|
134
|
-
def busy_wait
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
result = RubyProf.profile do
|
139
|
-
c3.busy_wait
|
140
|
-
end
|
141
|
-
|
142
|
-
methods = result.threads.first.methods.sort.reverse
|
143
|
-
assert_equal(2, methods.length)
|
144
|
-
|
145
|
-
assert_equal('MeasureCpuTimeTest#test_singleton', methods[0].full_name)
|
146
|
-
assert_equal('<Object::RubyProf::C3>#busy_wait', methods[1].full_name)
|
147
|
-
|
148
|
-
assert_in_delta(0, methods[0].total_time, 0.01)
|
149
|
-
assert_in_delta(0, methods[0].wait_time, 0.01)
|
150
|
-
assert_in_delta(0, methods[0].self_time, 0.01)
|
151
|
-
|
152
|
-
assert_in_delta(0, methods[1].total_time, 0.01)
|
153
|
-
assert_in_delta(0, methods[1].wait_time, 0.01)
|
154
|
-
assert_in_delta(0, methods[1].self_time, 0.01)
|
155
|
-
end
|
156
|
-
|
157
|
-
|
158
|
-
def test_sleeping_does_accumulate_wall_time
|
159
|
-
RubyProf::measure_mode = RubyProf::WALL_TIME
|
160
|
-
result = RubyProf.profile do
|
161
|
-
sleep 0.1
|
162
|
-
end
|
163
|
-
methods = result.threads.first.methods.sort.reverse
|
164
|
-
assert_equal(["MeasureCpuTimeTest#test_sleeping_does_accumulate_wall_time", "Kernel#sleep"], methods.map(&:full_name))
|
165
|
-
assert_in_delta(0.1, methods[1].total_time, 0.01)
|
166
|
-
assert_equal(0, methods[1].wait_time)
|
167
|
-
assert_in_delta(0.1, methods[1].self_time, 0.01)
|
168
|
-
end
|
169
|
-
|
170
|
-
def test_sleeping_does_not_accumulate_significant_cpu_time
|
171
|
-
result = RubyProf.profile do
|
172
|
-
sleep 0.1
|
173
|
-
end
|
174
|
-
methods = result.threads.first.methods.sort.reverse
|
175
|
-
assert_equal(["MeasureCpuTimeTest#test_sleeping_does_not_accumulate_significant_cpu_time", "Kernel#sleep"], methods.map(&:full_name))
|
176
|
-
assert_in_delta(0, methods[1].total_time, 0.01)
|
177
|
-
assert_equal(0, methods[1].wait_time)
|
178
|
-
assert_in_delta(0, methods[1].self_time, 0.01)
|
179
|
-
end
|
180
|
-
|
181
|
-
def test_waiting_for_threads_does_not_accumulate_cpu_time
|
182
|
-
background_thread = nil
|
183
|
-
result = RubyProf.profile do
|
184
|
-
background_thread = Thread.new{ sleep 0.1 }
|
185
|
-
background_thread.join
|
186
|
-
end
|
187
|
-
# check number of threads
|
188
|
-
assert_equal(2, result.threads.length)
|
189
|
-
fg, bg = result.threads
|
190
|
-
assert(fg.methods.map(&:full_name).include?("Thread#join"))
|
191
|
-
assert(bg.methods.map(&:full_name).include?("Kernel#sleep"))
|
192
|
-
assert_in_delta(0, fg.total_time, 0.01)
|
193
|
-
assert_in_delta(0, bg.total_time, 0.01)
|
194
|
-
end
|
195
|
-
|
196
|
-
def test_waiting_for_threads_does_accumulate_wall_time
|
197
|
-
RubyProf::measure_mode = RubyProf::WALL_TIME
|
198
|
-
background_thread = nil
|
199
|
-
result = RubyProf.profile do
|
200
|
-
background_thread = Thread.new{ sleep 0.1 }
|
201
|
-
background_thread.join
|
202
|
-
end
|
203
|
-
# check number of threads
|
204
|
-
assert_equal(2, result.threads.length)
|
205
|
-
fg, bg = result.threads
|
206
|
-
assert(fg.methods.map(&:full_name).include?("Thread#join"))
|
207
|
-
assert(bg.methods.map(&:full_name).include?("Kernel#sleep"))
|
208
|
-
assert_in_delta(0.1, fg.total_time, 0.01)
|
209
|
-
assert_in_delta(0.1, fg.wait_time, 0.01)
|
210
|
-
assert_in_delta(0.1, bg.total_time, 0.01)
|
211
|
-
end
|
212
|
-
end
|