ruby-prof 0.10.8 → 0.11.0.rc1

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.
Files changed (105) hide show
  1. data/CHANGES +38 -18
  2. data/LICENSE +4 -3
  3. data/README.rdoc +30 -66
  4. data/Rakefile +47 -54
  5. data/bin/ruby-prof +24 -4
  6. data/ext/ruby_prof/extconf.rb +9 -16
  7. data/ext/ruby_prof/rp_call_info.c +369 -0
  8. data/ext/ruby_prof/rp_call_info.h +46 -0
  9. data/ext/ruby_prof/rp_measure.c +48 -0
  10. data/ext/ruby_prof/rp_measure.h +45 -0
  11. data/ext/ruby_prof/rp_measure_allocations.c +86 -0
  12. data/ext/ruby_prof/rp_measure_cpu_time.c +112 -0
  13. data/ext/ruby_prof/rp_measure_gc_runs.c +87 -0
  14. data/ext/ruby_prof/rp_measure_gc_time.c +73 -0
  15. data/ext/ruby_prof/rp_measure_memory.c +81 -0
  16. data/ext/ruby_prof/rp_measure_process_time.c +71 -0
  17. data/ext/ruby_prof/rp_measure_wall_time.c +42 -0
  18. data/ext/ruby_prof/rp_method.c +363 -0
  19. data/ext/ruby_prof/rp_method.h +55 -0
  20. data/ext/ruby_prof/rp_stack.c +61 -0
  21. data/ext/ruby_prof/rp_stack.h +40 -0
  22. data/ext/ruby_prof/rp_thread.c +113 -0
  23. data/ext/ruby_prof/rp_thread.h +20 -0
  24. data/ext/ruby_prof/ruby_prof.c +259 -1398
  25. data/ext/ruby_prof/ruby_prof.h +54 -190
  26. data/ext/ruby_prof/version.h +6 -3
  27. data/lib/1.8/ruby_prof.so +0 -0
  28. data/lib/1.9/ruby_prof.exp +0 -0
  29. data/lib/1.9/ruby_prof.ilk +0 -0
  30. data/lib/1.9/ruby_prof.lib +0 -0
  31. data/lib/1.9/ruby_prof.pdb +0 -0
  32. data/lib/1.9/ruby_prof.so +0 -0
  33. data/lib/ruby-prof.rb +14 -11
  34. data/lib/ruby-prof/abstract_printer.rb +10 -0
  35. data/lib/ruby-prof/aggregate_call_info.rb +2 -0
  36. data/lib/ruby-prof/call_info.rb +2 -0
  37. data/lib/ruby-prof/call_stack_printer.rb +2 -4
  38. data/lib/ruby-prof/call_tree_printer.rb +1 -0
  39. data/lib/ruby-prof/compatibility.rb +134 -0
  40. data/lib/ruby-prof/dot_printer.rb +7 -7
  41. data/lib/ruby-prof/flat_printer.rb +7 -7
  42. data/lib/ruby-prof/flat_printer_with_line_numbers.rb +2 -5
  43. data/lib/ruby-prof/graph_html_printer.rb +4 -2
  44. data/lib/ruby-prof/graph_printer.rb +4 -3
  45. data/lib/ruby-prof/method_info.rb +2 -0
  46. data/lib/ruby-prof/multi_printer.rb +2 -0
  47. data/lib/ruby-prof/{result.rb → profile.rb} +3 -1
  48. data/lib/ruby-prof/rack.rb +1 -0
  49. data/lib/ruby-prof/symbol_to_proc.rb +2 -0
  50. data/lib/ruby-prof/task.rb +1 -0
  51. data/lib/ruby-prof/test.rb +2 -0
  52. data/lib/ruby_prof.exp +0 -0
  53. data/lib/ruby_prof.ilk +0 -0
  54. data/lib/ruby_prof.lib +0 -0
  55. data/lib/ruby_prof.pdb +0 -0
  56. data/lib/ruby_prof.so +0 -0
  57. data/lib/unprof.rb +2 -0
  58. data/test/aggregate_test.rb +8 -8
  59. data/test/basic_test.rb +3 -251
  60. data/test/bug_test.rb +6 -0
  61. data/test/duplicate_names_test.rb +2 -2
  62. data/test/dynamic_method_test.rb +61 -0
  63. data/test/enumerable_test.rb +2 -2
  64. data/test/exceptions_test.rb +4 -3
  65. data/test/exclude_threads_test.rb +2 -2
  66. data/test/exec_test.rb +3 -3
  67. data/test/line_number_test.rb +5 -5
  68. data/test/measure_allocations_test.rb +25 -0
  69. data/test/measure_cpu_time_test.rb +212 -0
  70. data/test/measure_gc_runs_test.rb +29 -0
  71. data/test/measure_gc_time_test.rb +29 -0
  72. data/test/measure_memory_test.rb +36 -0
  73. data/test/measure_process_time_test.rb +205 -0
  74. data/test/measure_wall_time_test.rb +209 -0
  75. data/test/method_elimination_test.rb +2 -2
  76. data/test/module_test.rb +3 -2
  77. data/test/multi_printer_test.rb +2 -2
  78. data/test/no_method_class_test.rb +3 -1
  79. data/test/prime_test.rb +3 -3
  80. data/test/printers_test.rb +106 -8
  81. data/test/recursive_test.rb +7 -6
  82. data/test/singleton_test.rb +2 -2
  83. data/test/stack_printer_test.rb +2 -3
  84. data/test/stack_test.rb +2 -2
  85. data/test/start_stop_test.rb +2 -2
  86. data/test/test_helper.rb +81 -0
  87. data/test/test_suite.rb +34 -29
  88. data/test/thread_test.rb +24 -23
  89. data/test/unique_call_path_test.rb +2 -2
  90. metadata +101 -69
  91. data/ext/ruby_prof/measure_allocations.h +0 -83
  92. data/ext/ruby_prof/measure_cpu_time.h +0 -152
  93. data/ext/ruby_prof/measure_gc_runs.h +0 -76
  94. data/ext/ruby_prof/measure_gc_time.h +0 -57
  95. data/ext/ruby_prof/measure_memory.h +0 -101
  96. data/ext/ruby_prof/measure_process_time.h +0 -63
  97. data/ext/ruby_prof/measure_wall_time.h +0 -53
  98. data/ext/ruby_prof/mingw/Rakefile +0 -23
  99. data/ext/ruby_prof/mingw/build.rake +0 -38
  100. data/rails/environment/profile.rb +0 -24
  101. data/rails/example/example_test.rb +0 -9
  102. data/rails/profile_test_helper.rb +0 -21
  103. data/test/current_failures_windows +0 -8
  104. data/test/measurement_test.rb +0 -132
  105. data/test/ruby-prof-bin +0 -20
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'set'
2
4
 
3
5
  module RubyProf
@@ -32,7 +34,7 @@ module RubyProf
32
34
  # STDOUT.
33
35
  #
34
36
  # options - Hash of print options. See #setup_options
35
- # for more information.
37
+ # for more information.
36
38
  #
37
39
  # When profiling results that cover a large number of method calls it
38
40
  # helps to use the :min_percent option, for example:
@@ -59,7 +61,7 @@ module RubyProf
59
61
  # RubyProf.measure_mode so that we can display it. Otherwise it's easy to
60
62
  # forget what measurement was made.
61
63
  def mode_name
62
- mode = RubyProf.constants.find{|c| RubyProf.const_get(c) == RubyProf.measure_mode}
64
+ RubyProf.constants.find{|c| RubyProf.const_get(c) == RubyProf.measure_mode}
63
65
  end
64
66
 
65
67
  # Computes the total time per thread:
@@ -98,11 +100,9 @@ module RubyProf
98
100
 
99
101
  def print_methods(thread_id, methods)
100
102
  total_time = thread_times[thread_id]
101
- # Print each method in total time order
102
- methods.reverse_each do |method|
103
+ methods.sort_by(&sort_method).reverse_each do |method|
103
104
  total_percentage = (method.total_time/total_time) * 100
104
- self_percentage = (method.self_time/total_time) * 100
105
-
105
+
106
106
  next if total_percentage < min_percent
107
107
  name = method_name(method).split("#").last
108
108
  puts "#{dot_id(method)} [label=\"#{name}\\n(#{total_percentage.round}%)\"];"
@@ -149,4 +149,4 @@ module RubyProf
149
149
  end
150
150
 
151
151
  end
152
- end
152
+ end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
 
2
3
  module RubyProf
3
4
  # Generates flat[link:files/examples/flat_txt.html] profile reports as text.
@@ -13,14 +14,17 @@ module RubyProf
13
14
  class FlatPrinter < AbstractPrinter
14
15
  # Print a flat profile report to the provided output.
15
16
  #
16
- # output - Any IO oject, including STDOUT or a file.
17
+ # output - Any IO object, including STDOUT or a file.
17
18
  # The default value is STDOUT.
18
19
  #
19
20
  # options - Hash of print options. See #setup_options
20
- # for more information.
21
+ # for more information.
21
22
  #
22
23
  def print(output = STDOUT, options = {})
23
24
  @output = output
25
+ # Now sort methods by largest self time by default,
26
+ # not total time like in other printouts
27
+ options[:sort_method] ||= :self_time
24
28
  setup_options(options)
25
29
  print_threads
26
30
  end
@@ -42,11 +46,7 @@ module RubyProf
42
46
  total_time = 0.01
43
47
  end
44
48
 
45
- # Now sort methods by largest self time,
46
- # not total time like in other printouts
47
- methods = methods.sort do |m1, m2|
48
- m1.self_time <=> m2.self_time
49
- end.reverse
49
+ methods = methods.sort_by(&sort_method).reverse
50
50
 
51
51
  @output << "Thread ID: %d\n" % thread_id
52
52
  @output << "Total: %0.6f\n" % total_time
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
 
2
3
  module RubyProf
3
4
  # Generates flat[link:files/examples/flat_txt.html] profile reports as text.
@@ -20,11 +21,7 @@ module RubyProf
20
21
  total_time = 0.01
21
22
  end
22
23
 
23
- # Now sort methods by largest self time,
24
- # not total time like in other printouts
25
- methods = methods.sort do |m1, m2|
26
- m1.self_time <=> m2.self_time
27
- end.reverse
24
+ methods = methods.sort_by(&sort_method).reverse
28
25
 
29
26
  @output << "Thread ID: %d\n" % thread_id
30
27
  @output << "Total: %0.6f\n" % total_time
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'erb'
2
4
 
3
5
  module RubyProf
@@ -40,7 +42,7 @@ module RubyProf
40
42
  # The default value is STDOUT.
41
43
  #
42
44
  # options - Hash of print options. See #setup_options
43
- # for more information.
45
+ # for more information.
44
46
  #
45
47
  # unique options are:
46
48
  # :filename - specify a file to use that contains the ERB
@@ -219,7 +221,7 @@ module RubyProf
219
221
  </tr>
220
222
 
221
223
  <% min_time = @options[:min_time] || (@options[:nonzero] ? 0.005 : nil)
222
- methods.sort.reverse_each do |method|
224
+ methods.sort_by(&sort_method).reverse_each do |method|
223
225
  total_percentage = (method.total_time/total_time) * 100
224
226
  next if total_percentage < min_percent
225
227
  next if min_time && method.total_time < min_time
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
 
2
3
  module RubyProf
3
4
  # Generates graph[link:files/examples/graph_txt.html] profile reports as text.
@@ -7,7 +8,7 @@ module RubyProf
7
8
  # [code to profile]
8
9
  # end
9
10
  #
10
- # printer = RubyProf::GraphPrinter.new(result, 5)
11
+ # printer = RubyProf::GraphPrinter.new(result)
11
12
  # printer.print(STDOUT, {})
12
13
  #
13
14
  # The constructor takes two arguments. See the README
@@ -43,7 +44,7 @@ module RubyProf
43
44
  # The default value is STDOUT.
44
45
  #
45
46
  # options - Hash of print options. See #setup_options
46
- # for more information.
47
+ # for more information.
47
48
  #
48
49
  def print(output = STDOUT, options = {})
49
50
  @output = output
@@ -62,7 +63,7 @@ module RubyProf
62
63
 
63
64
  def print_methods(thread_id, methods)
64
65
  # Sort methods from longest to shortest total time
65
- methods = methods.sort
66
+ methods = methods.sort_by(&sort_method)
66
67
 
67
68
  toplevel = methods.last
68
69
  total_time = toplevel.total_time
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module RubyProf
2
4
  class MethodInfo
3
5
  include Comparable
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module RubyProf
2
4
  # Helper class to simplify printing profiles of several types from
3
5
  # one profiling run. Currently prints a flat profile, a callgrind
@@ -1,6 +1,8 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'set'
2
4
  module RubyProf
3
- class Result
5
+ class Profile
4
6
  # this method gets called internally when profiling is stopped.
5
7
  # it determines for each call_info whether it is minimal: a
6
8
  # call_info is minimal in a call tree if the call_info is not a
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
 
2
3
  module Rack
3
4
  class RubyProf
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  unless (:a.respond_to?(:to_proc))
2
4
  class Symbol
3
5
  def to_proc
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
2
3
 
3
4
  require 'rake'
4
5
  require 'rake/testtask'
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  # Now load ruby-prof and away we go
2
4
  require 'fileutils'
3
5
  require 'ruby-prof'
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require "ruby-prof"
2
4
 
3
5
  at_exit {
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: UTF-8
2
3
 
3
- require 'test/unit'
4
- require 'ruby-prof'
4
+ require File.expand_path('../test_helper', __FILE__)
5
5
 
6
6
  # Test data
7
7
  # A B C
@@ -63,10 +63,10 @@ class AggregateTest < Test::Unit::TestCase
63
63
  # Check AggClass#z
64
64
  assert_equal('AggClass#z', method.full_name)
65
65
  assert_equal(3, method.called)
66
- assert_in_delta(3, method.total_time, 0.01)
67
- assert_in_delta(0, method.wait_time, 0.01)
68
- assert_in_delta(0, method.self_time, 0.01)
69
- assert_in_delta(3, method.children_time, 0.01)
66
+ assert_in_delta(3, method.total_time, 0.05)
67
+ assert_in_delta(0, method.wait_time, 0.05)
68
+ assert_in_delta(0, method.self_time, 0.05)
69
+ assert_in_delta(3, method.children_time, 0.05)
70
70
  assert_equal(3, method.call_infos.length)
71
71
 
72
72
  call_info = method.call_infos[0]
@@ -102,7 +102,7 @@ class AggregateTest < Test::Unit::TestCase
102
102
  call_info = call_infos.first
103
103
  assert_equal('AggClass#a', call_info.parent.target.full_name)
104
104
  assert_in_delta(3, call_info.total_time, 0.05)
105
- assert_in_delta(0, call_info.wait_time, 0.01)
105
+ assert_in_delta(0, call_info.wait_time, 0.05)
106
106
  assert_in_delta(0, call_info.self_time, 0.05)
107
107
  assert_in_delta(3, call_info.children_time, 0.05)
108
108
  assert_equal(3, call_info.called)
@@ -128,7 +128,7 @@ class AggregateTest < Test::Unit::TestCase
128
128
  call_info = call_infos.first
129
129
  assert_equal('AggClass#z', call_info.target.full_name)
130
130
  assert_in_delta(3, call_info.total_time, 0.05)
131
- assert_in_delta(0, call_info.wait_time, 0.01)
131
+ assert_in_delta(0, call_info.wait_time, 0.05)
132
132
  assert_in_delta(0, call_info.self_time, 0.05)
133
133
  assert_in_delta(3, call_info.children_time, 0.05)
134
134
  assert_equal(3, call_info.called)
@@ -1,54 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: UTF-8
2
3
 
3
- require 'test/unit'
4
- require 'ruby-prof'
5
-
6
- class C1
7
- def C1.hello
8
- sleep(0.1)
9
- end
10
-
11
- def hello
12
- sleep(0.2)
13
- end
14
- end
15
-
16
- module M1
17
- def hello
18
- sleep(0.3)
19
- end
20
- end
21
-
22
- class C2
23
- include M1
24
- extend M1
25
- end
26
-
27
- class C3
28
- def hello
29
- sleep(0.4)
30
- end
31
- end
32
-
33
- module M4
34
- def hello
35
- sleep(0.5)
36
- end
37
- end
38
-
39
- module M5
40
- include M4
41
- def goodbye
42
- hello
43
- end
44
- end
45
-
46
- class C6
47
- include M5
48
- def test
49
- goodbye
50
- end
51
- end
4
+ require File.expand_path('../test_helper', __FILE__)
52
5
 
53
6
  class BasicTest < Test::Unit::TestCase
54
7
  def setup
@@ -69,12 +22,6 @@ class BasicTest < Test::Unit::TestCase
69
22
  assert_raise(RuntimeError) do
70
23
  RubyProf.start
71
24
  end
72
-
73
- assert_raise(RuntimeError) do
74
- RubyProf.profile do
75
- puts 1
76
- end
77
- end
78
25
  RubyProf.stop
79
26
  end
80
27
 
@@ -84,201 +31,6 @@ class BasicTest < Test::Unit::TestCase
84
31
  end
85
32
  end
86
33
 
87
- def test_class_methods
88
- result = RubyProf.profile do
89
- C1.hello
90
- end
91
-
92
- # Length should be 3:
93
- # BasicTest#test_class_methods
94
- # <Class::C1>#hello
95
- # Kernel#sleep
96
-
97
- methods = result.threads.values.first.sort.reverse
98
- assert_equal(3, methods.length)
99
-
100
- # Check the names
101
- assert_equal('BasicTest#test_class_methods', methods[0].full_name)
102
- assert_equal('<Class::C1>#hello', methods[1].full_name)
103
- assert_equal('Kernel#sleep', methods[2].full_name)
104
-
105
- # Check times
106
- assert_in_delta(0.1, methods[0].total_time, 0.01)
107
- assert_in_delta(0, methods[0].wait_time, 0.01)
108
- assert_in_delta(0, methods[0].self_time, 0.01)
109
-
110
- assert_in_delta(0.1, methods[1].total_time, 0.01)
111
- assert_in_delta(0, methods[1].wait_time, 0.01)
112
- assert_in_delta(0, methods[1].self_time, 0.01)
113
-
114
- assert_in_delta(0.1, methods[2].total_time, 0.01)
115
- assert_in_delta(0, methods[2].wait_time, 0.01)
116
- assert_in_delta(0.1, methods[2].self_time, 0.01)
117
- end
118
-
119
- if RUBY_VERSION < '1.9'
120
- PARENT = Object
121
- else
122
- PARENT = BasicObject
123
- end
124
-
125
- def test_instance_methods
126
- result = RubyProf.profile do
127
- C1.new.hello
128
- end
129
-
130
- # Methods called
131
- # BasicTest#test_instance_methods
132
- # Class.new
133
- # Class:Object#allocate
134
- # for Object#initialize
135
- # C1#hello
136
- # Kernel#sleep
137
-
138
- methods = result.threads.values.first.sort.reverse
139
- assert_equal(6, methods.length)
140
- names = methods.map(&:full_name)
141
- assert_equal('BasicTest#test_instance_methods', names[0])
142
- assert_equal('C1#hello', names[1])
143
- assert_equal('Kernel#sleep', names[2])
144
- assert_equal('Class#new', names[3])
145
- # order can differ
146
- assert(names.include?("<Class::#{PARENT}>#allocate"))
147
- assert(names.include?("#{PARENT}#initialize"))
148
-
149
- # Check times
150
- assert_in_delta(0.2, methods[0].total_time, 0.02)
151
- assert_in_delta(0, methods[0].wait_time, 0.02)
152
- assert_in_delta(0, methods[0].self_time, 0.02)
153
-
154
- assert_in_delta(0.2, methods[1].total_time, 0.02)
155
- assert_in_delta(0, methods[1].wait_time, 0.02)
156
- assert_in_delta(0, methods[1].self_time, 0.02)
157
-
158
- assert_in_delta(0.2, methods[2].total_time, 0.02)
159
- assert_in_delta(0, methods[2].wait_time, 0.02)
160
- assert_in_delta(0.2, methods[2].self_time, 0.02)
161
-
162
- assert_in_delta(0, methods[3].total_time, 0.01)
163
- assert_in_delta(0, methods[3].wait_time, 0.01)
164
- assert_in_delta(0, methods[3].self_time, 0.01)
165
-
166
- assert_in_delta(0, methods[4].total_time, 0.01)
167
- assert_in_delta(0, methods[4].wait_time, 0.01)
168
- assert_in_delta(0, methods[4].self_time, 0.01)
169
-
170
- assert_in_delta(0, methods[5].total_time, 0.01)
171
- assert_in_delta(0, methods[5].wait_time, 0.01)
172
- assert_in_delta(0, methods[5].self_time, 0.01)
173
- end
174
-
175
- def test_module_methods
176
- result = RubyProf.profile do
177
- C2.hello
178
- end
179
-
180
- # Methods:
181
- # BasicTest#test_module_methods
182
- # M1#hello
183
- # Kernel#sleep
184
-
185
- methods = result.threads.values.first.sort.reverse
186
- assert_equal(3, methods.length)
187
-
188
- assert_equal('BasicTest#test_module_methods', methods[0].full_name)
189
- assert_equal('M1#hello', methods[1].full_name)
190
- assert_equal('Kernel#sleep', methods[2].full_name)
191
-
192
- # Check times
193
- assert_in_delta(0.3, methods[0].total_time, 0.1)
194
- assert_in_delta(0, methods[0].wait_time, 0.02)
195
- assert_in_delta(0, methods[0].self_time, 0.02)
196
-
197
- assert_in_delta(0.3, methods[1].total_time, 0.1)
198
- assert_in_delta(0, methods[1].wait_time, 0.02)
199
- assert_in_delta(0, methods[1].self_time, 0.02)
200
-
201
- assert_in_delta(0.3, methods[2].total_time, 0.1)
202
- assert_in_delta(0, methods[2].wait_time, 0.02)
203
- assert_in_delta(0.3, methods[2].self_time, 0.1)
204
- end
205
-
206
- def test_module_instance_methods
207
- result = RubyProf.profile do
208
- C2.new.hello
209
- end
210
-
211
- # Methods:
212
- # BasicTest#test_module_instance_methods
213
- # Class#new
214
- # <Class::Object>#allocate
215
- # Object#initialize
216
- # M1#hello
217
- # Kernel#sleep
218
-
219
- methods = result.threads.values.first.sort.reverse
220
- assert_equal(6, methods.length)
221
- names = methods.map(&:full_name)
222
- assert_equal('BasicTest#test_module_instance_methods', names[0])
223
- assert_equal('M1#hello', names[1])
224
- assert_equal('Kernel#sleep', names[2])
225
- assert_equal('Class#new', names[3])
226
- assert(names.include?("<Class::#{PARENT}>#allocate"))
227
- assert(names.include?("#{PARENT}#initialize"))
228
-
229
- # Check times
230
- assert_in_delta(0.3, methods[0].total_time, 0.1)
231
- assert_in_delta(0, methods[0].wait_time, 0.1)
232
- assert_in_delta(0, methods[0].self_time, 0.1)
233
-
234
- assert_in_delta(0.3, methods[1].total_time, 0.02)
235
- assert_in_delta(0, methods[1].wait_time, 0.01)
236
- assert_in_delta(0, methods[1].self_time, 0.01)
237
-
238
- assert_in_delta(0.3, methods[2].total_time, 0.02)
239
- assert_in_delta(0, methods[2].wait_time, 0.01)
240
- assert_in_delta(0.3, methods[2].self_time, 0.02)
241
-
242
- assert_in_delta(0, methods[3].total_time, 0.01)
243
- assert_in_delta(0, methods[3].wait_time, 0.01)
244
- assert_in_delta(0, methods[3].self_time, 0.01)
245
-
246
- assert_in_delta(0, methods[4].total_time, 0.01)
247
- assert_in_delta(0, methods[4].wait_time, 0.01)
248
- assert_in_delta(0, methods[4].self_time, 0.01)
249
-
250
- assert_in_delta(0, methods[5].total_time, 0.01)
251
- assert_in_delta(0, methods[5].wait_time, 0.01)
252
- assert_in_delta(0, methods[5].self_time, 0.01)
253
- end
254
-
255
- def test_singleton
256
- c3 = C3.new
257
-
258
- class << c3
259
- def hello
260
- end
261
- end
262
-
263
- result = RubyProf.profile do
264
- c3.hello
265
- end
266
-
267
- methods = result.threads.values.first.sort.reverse
268
- assert_equal(2, methods.length)
269
-
270
- assert_equal('BasicTest#test_singleton', methods[0].full_name)
271
- assert_equal('<Object::C3>#hello', methods[1].full_name)
272
-
273
- assert_in_delta(0, methods[0].total_time, 0.01)
274
- assert_in_delta(0, methods[0].wait_time, 0.01)
275
- assert_in_delta(0, methods[0].self_time, 0.01)
276
-
277
- assert_in_delta(0, methods[1].total_time, 0.01)
278
- assert_in_delta(0, methods[1].wait_time, 0.01)
279
- assert_in_delta(0, methods[1].self_time, 0.01)
280
- end
281
-
282
34
  def test_traceback
283
35
  RubyProf.start
284
36
  assert_raise(NoMethodError) do
@@ -287,4 +39,4 @@ class BasicTest < Test::Unit::TestCase
287
39
 
288
40
  RubyProf.stop
289
41
  end
290
- end
42
+ end