File: call_info_test.rb

package info (click to toggle)
ruby-prof 0.17.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,656 kB
  • sloc: ruby: 5,043; ansic: 2,175; makefile: 6
file content (78 lines) | stat: -rwxr-xr-x 2,542 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env ruby
# encoding: UTF-8

require File.expand_path('../test_helper', __FILE__)

class CallInfoTest < 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_clone
#    result = RubyProf.profile do
#      RubyProf::C1.hello
#    end
#
#    method = result.threads.first.top_methods.first
#    call_info = method.call_infos.first
#    call_info_clone = call_info.clone
#
##    assert_equal(call_info.target, call_info_clone.target)
#    assert_equal(call_info.total_time, call_info_clone.total_time)
#  end

  def test_merge
    result1 = RubyProf.profile do
      RubyProf::C1.hello
    end

    methods = result1.threads.first.methods.sort.reverse
    assert_equal(3, methods.length)

    assert_equal('CallInfoTest#test_merge', methods[0].full_name)
    assert_in_delta(0.1, methods[0].total_time, 0.01)
    assert_in_delta(0, methods[0].wait_time, 0.01)
    assert_in_delta(0, methods[0].self_time, 0.01)
    assert_equal(1, methods[0].called)

    assert_equal('<Class::RubyProf::C1>#hello', methods[1].full_name)
    assert_in_delta(0.1, methods[1].total_time, 0.01)
    assert_in_delta(0, methods[1].wait_time, 0.01)
    assert_in_delta(0, methods[1].self_time, 0.01)
    assert_equal(1, methods[1].called)

    assert_equal('Kernel#sleep', methods[2].full_name)
    assert_in_delta(0.1, methods[2].total_time, 0.01)
    assert_in_delta(0, methods[2].wait_time, 0.01)
    assert_in_delta(0.1, methods[2].self_time, 0.01)
    assert_equal(1, methods[2].called)

    RubyProf.profile do
      RubyProf::C1.hello
    end

    # Merge the trees
    methods = result1.threads.first.methods.sort.reverse
    assert_equal(3, methods.length)

    assert_equal('CallInfoTest#test_merge', methods[0].full_name)
    assert_in_delta(0.1, methods[0].total_time, 0.01)
    assert_in_delta(0, methods[0].wait_time, 0.01)
    assert_in_delta(0, methods[0].self_time, 0.01)
    assert_equal(1, methods[0].called)

    assert_equal('<Class::RubyProf::C1>#hello', methods[1].full_name)
    assert_in_delta(0.1, methods[1].total_time, 0.01)
    assert_in_delta(0, methods[1].wait_time, 0.01)
    assert_in_delta(0, methods[1].self_time, 0.01)
    assert_equal(1, methods[1].called)

    assert_equal('Kernel#sleep', methods[2].full_name)
    assert_in_delta(0.1, methods[2].total_time, 0.01)
    assert_in_delta(0, methods[2].wait_time, 0.01)
    assert_in_delta(0.1, methods[2].self_time, 0.01)
    assert_equal(1, methods[2].called)
  end
end