1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
#!/usr/bin/env ruby
# encoding: UTF-8
require File.expand_path('../test_helper', __FILE__)
# Test data
# A B C
# | | |
# Z A A
# | |
# Z Z
class AggClass
def z
sleep 1
end
def a
z
end
def b
a
end
def c
a
end
end
class AggregateTest < TestCase
def setup
# Need to use wall time for this test due to the sleep calls
RubyProf::measure_mode = RubyProf::WALL_TIME
end
def test_all_call_infos_are_not_recursive
c1 = AggClass.new
result = RubyProf.profile do
c1.a
c1.b
c1.c
end
methods = result.threads.first.methods.sort.reverse
methods.each do |m|
m.call_infos.each do |ci|
assert(!ci.recursive?)
end
end
end
def test_call_infos
c1 = AggClass.new
result = RubyProf.profile do
c1.a
c1.b
c1.c
end
methods = result.threads.first.methods.sort.reverse
method = methods.find {|meth| meth.full_name == 'AggClass#z'}
# Check AggClass#z
assert_equal('AggClass#z', method.full_name)
assert_equal(3, method.called)
assert_in_delta(3, method.total_time, 0.05)
assert_in_delta(0, method.wait_time, 0.05)
assert_in_delta(0, method.self_time, 0.05)
assert_in_delta(3, method.children_time, 0.05)
assert_equal(3, method.call_infos.length)
call_info = method.call_infos[0]
assert_equal('AggregateTest#test_call_infos->AggClass#a->AggClass#z', call_info.call_sequence)
assert_equal(1, call_info.children.length)
call_info = method.call_infos[1]
assert_equal('AggregateTest#test_call_infos->AggClass#b->AggClass#a->AggClass#z', call_info.call_sequence)
assert_equal(1, call_info.children.length)
call_info = method.call_infos[2]
assert_equal('AggregateTest#test_call_infos->AggClass#c->AggClass#a->AggClass#z', call_info.call_sequence)
assert_equal(1, call_info.children.length)
end
def test_aggregates_parents
c1 = AggClass.new
result = RubyProf.profile do
c1.a
c1.b
c1.c
end
methods = result.threads.first.methods.sort.reverse
method = methods.find {|meth| meth.full_name == 'AggClass#z'}
# Check AggClass#z
assert_equal('AggClass#z', method.full_name)
call_infos = method.aggregate_parents
assert_equal(1, call_infos.length)
call_info = call_infos.first
assert_equal('AggClass#a', call_info.parent.target.full_name)
assert_in_delta(3, call_info.total_time, 0.05)
assert_in_delta(0, call_info.wait_time, 0.05)
assert_in_delta(0, call_info.self_time, 0.05)
assert_in_delta(3, call_info.children_time, 0.05)
assert_equal(3, call_info.called)
end
def test_aggregates_children
c1 = AggClass.new
result = RubyProf.profile do
c1.a
c1.b
c1.c
end
methods = result.threads.first.methods.sort.reverse
method = methods.find {|meth| meth.full_name == 'AggClass#a'}
# Check AggClass#a
assert_equal('AggClass#a', method.full_name)
call_infos = method.aggregate_children
assert_equal(1, call_infos.length)
call_info = call_infos.first
assert_equal('AggClass#z', call_info.target.full_name)
assert_in_delta(3, call_info.total_time, 0.05)
assert_in_delta(0, call_info.wait_time, 0.05)
assert_in_delta(0, call_info.self_time, 0.05)
assert_in_delta(3, call_info.children_time, 0.05)
assert_equal(3, call_info.called)
end
end
|