ruby-prof 0.11.2 → 0.13.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.
Files changed (150) hide show
  1. data/CHANGES +31 -0
  2. data/README.rdoc +17 -17
  3. data/Rakefile +28 -5
  4. data/bin/ruby-prof +274 -265
  5. data/doc/LICENSE.html +155 -0
  6. data/doc/README_rdoc.html +640 -0
  7. data/doc/Rack/RubyProf.html +319 -0
  8. data/doc/Rack.html +167 -0
  9. data/doc/RubyProf/AbstractPrinter.html +580 -0
  10. data/doc/RubyProf/AggregateCallInfo.html +570 -0
  11. data/doc/RubyProf/CallInfo.html +512 -0
  12. data/doc/RubyProf/CallInfoPrinter.html +190 -0
  13. data/doc/RubyProf/CallInfoVisitor.html +332 -0
  14. data/doc/RubyProf/CallStackPrinter.html +1600 -0
  15. data/doc/RubyProf/CallTreePrinter.html +413 -0
  16. data/doc/RubyProf/Cmd.html +669 -0
  17. data/doc/RubyProf/DotPrinter.html +312 -0
  18. data/doc/RubyProf/FlatPrinter.html +229 -0
  19. data/doc/RubyProf/FlatPrinterWithLineNumbers.html +267 -0
  20. data/doc/RubyProf/GraphHtmlPrinter.html +631 -0
  21. data/doc/RubyProf/GraphPrinter.html +209 -0
  22. data/doc/RubyProf/MethodInfo.html +713 -0
  23. data/doc/RubyProf/MultiPrinter.html +407 -0
  24. data/doc/RubyProf/Profile.html +821 -0
  25. data/doc/RubyProf/ProfileTask.html +532 -0
  26. data/doc/RubyProf/Test.html +578 -0
  27. data/doc/RubyProf/Thread.html +262 -0
  28. data/doc/RubyProf.html +999 -0
  29. data/doc/created.rid +32 -0
  30. data/doc/examples/flat_txt.html +191 -0
  31. data/doc/examples/graph_txt.html +305 -0
  32. data/doc/images/add.png +0 -0
  33. data/doc/images/brick.png +0 -0
  34. data/doc/images/brick_link.png +0 -0
  35. data/doc/images/bug.png +0 -0
  36. data/doc/images/bullet_black.png +0 -0
  37. data/doc/images/bullet_toggle_minus.png +0 -0
  38. data/doc/images/bullet_toggle_plus.png +0 -0
  39. data/doc/images/date.png +0 -0
  40. data/doc/images/delete.png +0 -0
  41. data/doc/images/find.png +0 -0
  42. data/doc/images/loadingAnimation.gif +0 -0
  43. data/doc/images/macFFBgHack.png +0 -0
  44. data/doc/images/package.png +0 -0
  45. data/doc/images/page_green.png +0 -0
  46. data/doc/images/page_white_text.png +0 -0
  47. data/doc/images/page_white_width.png +0 -0
  48. data/doc/images/plugin.png +0 -0
  49. data/doc/images/ruby.png +0 -0
  50. data/doc/images/tag_blue.png +0 -0
  51. data/doc/images/tag_green.png +0 -0
  52. data/doc/images/transparent.png +0 -0
  53. data/doc/images/wrench.png +0 -0
  54. data/doc/images/wrench_orange.png +0 -0
  55. data/doc/images/zoom.png +0 -0
  56. data/doc/index.html +639 -0
  57. data/doc/js/darkfish.js +155 -0
  58. data/doc/js/jquery.js +18 -0
  59. data/doc/js/navigation.js +142 -0
  60. data/doc/js/search.js +94 -0
  61. data/doc/js/search_index.js +1 -0
  62. data/doc/js/searcher.js +228 -0
  63. data/doc/rdoc.css +543 -0
  64. data/doc/table_of_contents.html +462 -0
  65. data/examples/empty.png +0 -0
  66. data/examples/minus.png +0 -0
  67. data/examples/plus.png +0 -0
  68. data/ext/ruby_prof/extconf.rb +7 -1
  69. data/ext/ruby_prof/rp_call_info.c +33 -24
  70. data/ext/ruby_prof/rp_call_info.h +2 -1
  71. data/ext/ruby_prof/rp_measure.c +1 -1
  72. data/ext/ruby_prof/rp_measure.h +1 -1
  73. data/ext/ruby_prof/rp_measure_allocations.c +1 -1
  74. data/ext/ruby_prof/rp_measure_cpu_time.c +1 -1
  75. data/ext/ruby_prof/rp_measure_gc_runs.c +1 -1
  76. data/ext/ruby_prof/rp_measure_gc_time.c +7 -11
  77. data/ext/ruby_prof/rp_measure_memory.c +1 -2
  78. data/ext/ruby_prof/rp_measure_process_time.c +2 -2
  79. data/ext/ruby_prof/rp_measure_wall_time.c +2 -2
  80. data/ext/ruby_prof/rp_method.c +11 -24
  81. data/ext/ruby_prof/rp_method.h +2 -3
  82. data/ext/ruby_prof/rp_stack.c +50 -14
  83. data/ext/ruby_prof/rp_stack.h +10 -10
  84. data/ext/ruby_prof/rp_thread.c +54 -29
  85. data/ext/ruby_prof/rp_thread.h +8 -7
  86. data/ext/ruby_prof/ruby_prof.c +35 -98
  87. data/ext/ruby_prof/ruby_prof.h +1 -1
  88. data/ext/ruby_prof/vc/ruby_prof.sln +12 -6
  89. data/ext/ruby_prof/vc/{ruby_prof.vcxproj → ruby_prof_19.vcxproj} +1 -0
  90. data/ext/ruby_prof/vc/ruby_prof_20.vcxproj +110 -0
  91. data/ext/ruby_prof/version.h +4 -4
  92. data/lib/ruby-prof/call_info.rb +1 -1
  93. data/lib/ruby-prof/call_info_visitor.rb +4 -2
  94. data/lib/ruby-prof/compatibility.rb +21 -6
  95. data/lib/ruby-prof/images/empty.png +0 -0
  96. data/lib/ruby-prof/images/minus.png +0 -0
  97. data/lib/ruby-prof/images/plus.png +0 -0
  98. data/lib/ruby-prof/method_info.rb +1 -1
  99. data/lib/ruby-prof/printers/call_info_printer.rb +3 -2
  100. data/lib/ruby-prof/printers/call_stack_printer.rb +10 -7
  101. data/lib/ruby-prof/printers/dot_printer.rb +2 -2
  102. data/lib/ruby-prof/printers/flat_printer.rb +5 -4
  103. data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +2 -2
  104. data/lib/ruby-prof/printers/graph_html_printer.rb +16 -8
  105. data/lib/ruby-prof/printers/graph_printer.rb +17 -16
  106. data/lib/ruby-prof/profile.rb +1 -1
  107. data/lib/ruby-prof/rack.rb +1 -6
  108. data/lib/ruby-prof/task.rb +0 -0
  109. data/lib/ruby-prof/thread.rb +22 -0
  110. data/lib/ruby-prof.rb +1 -0
  111. data/ruby-prof.gemspec +5 -3
  112. data/test/aggregate_test.rb +0 -0
  113. data/test/basic_test.rb +77 -45
  114. data/test/call_info_test.rb +78 -0
  115. data/test/call_info_visitor_test.rb +1 -1
  116. data/test/duplicate_names_test.rb +0 -0
  117. data/test/dynamic_method_test.rb +21 -8
  118. data/test/enumerable_test.rb +0 -0
  119. data/test/exceptions_test.rb +0 -0
  120. data/test/exclude_threads_test.rb +0 -0
  121. data/test/exec_test.rb +0 -0
  122. data/test/fiber_test.rb +65 -0
  123. data/test/line_number_test.rb +0 -0
  124. data/test/measure_cpu_time_test.rb +23 -12
  125. data/test/measure_gc_runs_test.rb +4 -1
  126. data/test/measure_gc_time_test.rb +10 -3
  127. data/test/measure_memory_test.rb +3 -8
  128. data/test/measure_process_time_test.rb +27 -170
  129. data/test/measure_wall_time_test.rb +59 -13
  130. data/test/method_elimination_test.rb +31 -21
  131. data/test/module_test.rb +0 -0
  132. data/test/multi_printer_test.rb +9 -8
  133. data/test/no_method_class_test.rb +0 -0
  134. data/test/pause_resume_test.rb +125 -20
  135. data/test/prime.rb +1 -2
  136. data/test/printers_test.rb +10 -17
  137. data/test/recursive_test.rb +6 -50
  138. data/test/singleton_test.rb +0 -0
  139. data/test/stack_printer_test.rb +9 -6
  140. data/test/stack_test.rb +0 -0
  141. data/test/start_stop_test.rb +0 -0
  142. data/test/test_helper.rb +45 -11
  143. data/test/test_suite.rb +1 -2
  144. data/test/thread_test.rb +0 -0
  145. data/test/unique_call_path_test.rb +0 -0
  146. metadata +107 -12
  147. data/test/bug_test.rb +0 -6
  148. data/test/gc_test.rb +0 -35
  149. data/test/pause_test.rb +0 -57
  150. data/test/prime_test.rb +0 -13
@@ -40,7 +40,6 @@ module RubyProf
40
40
  def print(output = STDOUT, options = {})
41
41
  @output = output
42
42
  setup_options(options)
43
- _erbout = @output
44
43
  @output << @erb.result(binding)
45
44
  end
46
45
 
@@ -49,7 +48,7 @@ module RubyProf
49
48
  # specified by the user, since they will not be
50
49
  # printed out.
51
50
  def create_link(thread, method)
52
- overall_time = thread.top_method.total_time
51
+ overall_time = thread.total_time
53
52
  total_percent = (method.total_time/overall_time) * 100
54
53
  if total_percent < min_percent
55
54
  # Just return name
@@ -61,7 +60,7 @@ module RubyProf
61
60
  end
62
61
 
63
62
  def method_href(thread, method)
64
- h(method.full_name.gsub(/[><#\.\?=:]/,"_") + "_" + thread.id.to_s)
63
+ h(method.full_name.gsub(/[><#\.\?=:]/,"_") + "_" + thread.fiber_id.to_s)
65
64
  end
66
65
 
67
66
  def file_link(path, linenum)
@@ -140,12 +139,18 @@ module RubyProf
140
139
  <table>
141
140
  <tr>
142
141
  <th>Thread ID</th>
142
+ <% if RUBY_VERSION >= "1.9" %>
143
+ <th>Fiber ID</th>
144
+ <% end %>
143
145
  <th>Total Time</th>
144
146
  </tr>
145
147
  <% for thread in @result.threads %>
146
148
  <tr>
147
- <td><a href="#<%= thread.id %>"><%= thread.id %></a></td>
148
- <td><%= thread.top_method.total_time %></td>
149
+ <% if RUBY_VERSION >= "1.9" %>
150
+ <td><%= thread.id %></td>
151
+ <% end %>
152
+ <td><a href="#<%= thread.fiber_id %>"><%= thread.fiber_id %></a></td>
153
+ <td><%= thread.total_time %></td>
149
154
  </tr>
150
155
  <% end %>
151
156
  </table>
@@ -153,9 +158,12 @@ module RubyProf
153
158
  <!-- Methods Tables -->
154
159
  <% for thread in @result.threads
155
160
  methods = thread.methods
156
- total_time = thread.top_method.total_time %>
157
- <h2><a name="<%= thread.id %>">Thread <%= thread.id %></a></h2>
158
-
161
+ total_time = thread.total_time %>
162
+ <% if RUBY_VERSION >= "1.9" %>
163
+ <h2><a name="<%= thread.fiber_id %>">Thread <%= thread.id %>, Fiber: <%= thread.fiber_id %></a></h2>
164
+ <% else %>
165
+ <h2><a name="<%= thread.fiber_id %>">Thread <%= thread.fiber_id %></a></h2>
166
+ <% end %>
159
167
  <table>
160
168
  <thead>
161
169
  <tr>
@@ -15,14 +15,15 @@ module RubyProf
15
15
 
16
16
  class GraphPrinter < AbstractPrinter
17
17
  PERCENTAGE_WIDTH = 8
18
- TIME_WIDTH = 10
18
+ TIME_WIDTH = 11
19
19
  CALL_WIDTH = 17
20
20
 
21
21
  private
22
22
 
23
23
  def print_header(thread)
24
24
  @output << "Thread ID: #{thread.id}\n"
25
- @output << "Total Time: #{thread.top_method.total_time}\n"
25
+ @output << "Fiber ID: #{thread.fiber_id}\n" unless thread.id == thread.fiber_id
26
+ @output << "Total Time: #{thread.total_time}\n"
26
27
  @output << "Sort by: #{sort_method}\n"
27
28
  @output << "\n"
28
29
 
@@ -39,7 +40,7 @@ module RubyProf
39
40
  end
40
41
 
41
42
  def print_methods(thread)
42
- total_time = thread.top_method.total_time
43
+ total_time = thread.total_time
43
44
  # Sort methods from longest to shortest total time
44
45
  methods = thread.methods.sort_by(&sort_method)
45
46
 
@@ -57,10 +58,10 @@ module RubyProf
57
58
  # 1 is for % sign
58
59
  @output << sprintf("%#{PERCENTAGE_WIDTH-1}.2f\%", total_percentage)
59
60
  @output << sprintf("%#{PERCENTAGE_WIDTH-1}.2f\%", self_percentage)
60
- @output << sprintf("%#{TIME_WIDTH}.2f", method.total_time)
61
- @output << sprintf("%#{TIME_WIDTH}.2f", method.self_time)
62
- @output << sprintf("%#{TIME_WIDTH}.2f", method.wait_time)
63
- @output << sprintf("%#{TIME_WIDTH}.2f", method.children_time)
61
+ @output << sprintf("%#{TIME_WIDTH}.3f", method.total_time)
62
+ @output << sprintf("%#{TIME_WIDTH}.3f", method.self_time)
63
+ @output << sprintf("%#{TIME_WIDTH}.3f", method.wait_time)
64
+ @output << sprintf("%#{TIME_WIDTH}.3f", method.children_time)
64
65
  @output << sprintf("%#{CALL_WIDTH}i", method.called)
65
66
  @output << sprintf(" %s", method.recursive? ? "*" : " ")
66
67
  @output << sprintf("%s", method_name(method))
@@ -77,10 +78,10 @@ module RubyProf
77
78
  method.aggregate_parents.sort_by(&:total_time).each do |caller|
78
79
  next unless caller.parent
79
80
  @output << " " * 2 * PERCENTAGE_WIDTH
80
- @output << sprintf("%#{TIME_WIDTH}.2f", caller.total_time)
81
- @output << sprintf("%#{TIME_WIDTH}.2f", caller.self_time)
82
- @output << sprintf("%#{TIME_WIDTH}.2f", caller.wait_time)
83
- @output << sprintf("%#{TIME_WIDTH}.2f", caller.children_time)
81
+ @output << sprintf("%#{TIME_WIDTH}.3f", caller.total_time)
82
+ @output << sprintf("%#{TIME_WIDTH}.3f", caller.self_time)
83
+ @output << sprintf("%#{TIME_WIDTH}.3f", caller.wait_time)
84
+ @output << sprintf("%#{TIME_WIDTH}.3f", caller.children_time)
84
85
 
85
86
  call_called = "#{caller.called}/#{method.called}"
86
87
  @output << sprintf("%#{CALL_WIDTH}s", call_called)
@@ -95,10 +96,10 @@ module RubyProf
95
96
 
96
97
  @output << " " * 2 * PERCENTAGE_WIDTH
97
98
 
98
- @output << sprintf("%#{TIME_WIDTH}.2f", child.total_time)
99
- @output << sprintf("%#{TIME_WIDTH}.2f", child.self_time)
100
- @output << sprintf("%#{TIME_WIDTH}.2f", child.wait_time)
101
- @output << sprintf("%#{TIME_WIDTH}.2f", child.children_time)
99
+ @output << sprintf("%#{TIME_WIDTH}.3f", child.total_time)
100
+ @output << sprintf("%#{TIME_WIDTH}.3f", child.self_time)
101
+ @output << sprintf("%#{TIME_WIDTH}.3f", child.wait_time)
102
+ @output << sprintf("%#{TIME_WIDTH}.3f", child.children_time)
102
103
 
103
104
  call_called = "#{child.called}/#{child.target.called}"
104
105
  @output << sprintf("%#{CALL_WIDTH}s", call_called)
@@ -112,4 +113,4 @@ module RubyProf
112
113
  @output << "* indicates recursively called methods\n"
113
114
  end
114
115
  end
115
- end
116
+ end
@@ -49,7 +49,7 @@ module RubyProf
49
49
  # read regexps from file
50
50
  def read_regexps_from_file(file_name)
51
51
  matchers = []
52
- File.open(matchers).each_line do |l|
52
+ File.open(file_name).each_line do |l|
53
53
  next if (l =~ /^(#.*|\s*)$/) # emtpy lines and lines starting with #
54
54
  matchers << Regexp.new(l.strip)
55
55
  end
@@ -13,12 +13,7 @@ module Rack
13
13
  ::RubyProf::GraphHtmlPrinter => 'graph.html',
14
14
  ::RubyProf::CallStackPrinter => 'call_stack.html'}
15
15
 
16
- @printer_klasses = @options[:printers] || {::RubyProf::FlatPrinter => 'flat.txt',
17
- ::RubyProf::GraphPrinter => 'graph.txt',
18
- ::RubyProf::GraphHtmlPrinter => 'graph.html',
19
- ::RubyProf::CallStackPrinter => 'call_stack.html'}
20
-
21
- @skip_paths = options[:skip_paths] || [%r{^/assets}, %r{\.css$}, %r{\.js}, %r{\.png}, %r{\.jpeg}]
16
+ @skip_paths = options[:skip_paths] || [%r{^/assets}, %r{\.css$}, %r{\.js$}, %r{\.png$}, %r{\.jpeg$}, %r{\.jpg$}, %r{\.gif$}]
22
17
  end
23
18
 
24
19
  def call(env)
File without changes
@@ -0,0 +1,22 @@
1
+ module RubyProf
2
+ class Thread
3
+ def top_methods
4
+ self.methods.select do |method_info|
5
+ method_info.call_infos.detect do |call_info|
6
+ call_info.parent.nil?
7
+ end
8
+ end
9
+ end
10
+
11
+ def total_time
12
+ self.top_methods.inject(0) do |sum, method_info|
13
+ method_info.call_infos.each do |call_info|
14
+ if call_info.parent.nil?
15
+ sum += call_info.total_time
16
+ end
17
+ end
18
+ sum
19
+ end
20
+ end
21
+ end
22
+ end
data/lib/ruby-prof.rb CHANGED
@@ -15,6 +15,7 @@ require 'ruby-prof/compatibility'
15
15
  require 'ruby-prof/method_info'
16
16
  require 'ruby-prof/profile'
17
17
  require 'ruby-prof/rack'
18
+ require 'ruby-prof/thread'
18
19
 
19
20
  require 'ruby-prof/printers/abstract_printer'
20
21
  require 'ruby-prof/printers/call_info_printer'
data/ruby-prof.gemspec CHANGED
@@ -53,7 +53,9 @@ EOF
53
53
 
54
54
  spec.test_files = Dir["test/test_*.rb"]
55
55
  spec.required_ruby_version = '>= 1.8.7'
56
- spec.date = DateTime.now
56
+ spec.date = Time.now.strftime('%Y-%m-%d')
57
57
  spec.homepage = 'https://github.com/rdp/ruby-prof'
58
- spec.add_development_dependency 'rake-compiler'
59
- end
58
+ spec.add_development_dependency('minitest')
59
+ spec.add_development_dependency('rake-compiler')
60
+ spec.add_development_dependency('rdoc')
61
+ end
File without changes
data/test/basic_test.rb CHANGED
@@ -9,6 +9,11 @@ class BasicTest < Test::Unit::TestCase
9
9
  RubyProf::measure_mode = RubyProf::WALL_TIME
10
10
  end
11
11
 
12
+ def start
13
+ RubyProf.start
14
+ RubyProf::C1.hello
15
+ end
16
+
12
17
  def test_running
13
18
  assert(!RubyProf.running?)
14
19
  RubyProf.start
@@ -40,57 +45,84 @@ class BasicTest < Test::Unit::TestCase
40
45
  RubyProf.stop
41
46
  end
42
47
 
43
- def test_pause_seq
44
- p= RubyProf::Profile.new(RubyProf::WALL_TIME,[])
45
- p.start ; assert !p.paused?
46
- p.pause ; assert p.paused?
47
- p.resume; assert !p.paused?
48
- p.pause ; assert p.paused?
49
- p.pause ; assert p.paused?
50
- p.resume; assert !p.paused?
51
- p.resume; assert !p.paused?
52
- p.stop ; assert !p.paused?
53
- end
48
+ def test_leave_method
49
+ start
50
+ sleep 0.15
51
+ profile = RubyProf.stop
54
52
 
55
- def test_pause_block
56
- p= RubyProf::Profile.new(RubyProf::WALL_TIME,[])
57
- p.start
58
- p.pause
59
- assert p.paused?
53
+ assert_equal(1, profile.threads.count)
60
54
 
61
- times_block_invoked = 0
62
- retval= p.resume{
63
- times_block_invoked += 1
64
- 120 + times_block_invoked
65
- }
66
- assert_equal 1, times_block_invoked
67
- assert p.paused?
55
+ thread = profile.threads.first
56
+ assert_in_delta(0.25, thread.total_time, 0.01)
68
57
 
69
- assert_equal 121, retval, "resume() should return the result of the given block."
58
+ top_methods = thread.top_methods.sort
59
+ assert_equal(2, top_methods.count)
60
+ assert_equal("BasicTest#start", top_methods[0].full_name)
61
+ assert_equal("BasicTest#test_leave_method", top_methods[1].full_name)
70
62
 
71
- p.stop
72
- end
63
+ assert_equal(4, thread.methods.length)
64
+ methods = profile.threads.first.methods.sort
73
65
 
74
- def test_pause_block_with_error
75
- p= RubyProf::Profile.new(RubyProf::WALL_TIME,[])
76
- p.start
77
- p.pause
78
- assert p.paused?
79
-
80
- begin
81
- p.resume{ raise }
82
- flunk 'Exception expected.'
83
- rescue
84
- assert p.paused?
85
- end
66
+ # Check times
67
+ assert_equal("<Class::RubyProf::C1>#hello", methods[0].full_name)
68
+ assert_in_delta(0.1, methods[0].total_time, 0.01)
69
+ assert_in_delta(0.0, methods[0].wait_time, 0.01)
70
+ assert_in_delta(0.0, methods[0].self_time, 0.01)
71
+
72
+ assert_equal("BasicTest#start", methods[1].full_name)
73
+ assert_in_delta(0.1, methods[1].total_time, 0.01)
74
+ assert_in_delta(0.0, methods[1].wait_time, 0.01)
75
+ assert_in_delta(0.0, methods[1].self_time, 0.01)
76
+
77
+ assert_equal("BasicTest#test_leave_method", methods[2].full_name)
78
+ assert_in_delta(0.15, methods[2].total_time, 0.01)
79
+ assert_in_delta(0.0, methods[2].wait_time, 0.01)
80
+ assert_in_delta(0.0, methods[2].self_time, 0.01)
86
81
 
87
- p.stop
82
+ assert_equal("Kernel#sleep", methods[3].full_name)
83
+ assert_in_delta(0.25, methods[3].total_time, 0.01)
84
+ assert_in_delta(0.0, methods[3].wait_time, 0.01)
85
+ assert_in_delta(0.25, methods[3].self_time, 0.01)
88
86
  end
89
87
 
90
- def test_resume_when_not_paused
91
- p= RubyProf::Profile.new(RubyProf::WALL_TIME,[])
92
- p.start ; assert !p.paused?
93
- p.resume; assert !p.paused?
94
- p.stop ; assert !p.paused?
88
+ def test_leave_method_2
89
+ start
90
+ RubyProf::C1.hello
91
+ RubyProf::C1.hello
92
+ profile = RubyProf.stop
93
+
94
+ assert_equal(1, profile.threads.count)
95
+
96
+ thread = profile.threads.first
97
+ assert_in_delta(0.3, thread.total_time, 0.01)
98
+
99
+ top_methods = thread.top_methods.sort
100
+ assert_equal(2, top_methods.count)
101
+ assert_equal("BasicTest#start", top_methods[0].full_name)
102
+ assert_equal("BasicTest#test_leave_method_2", top_methods[1].full_name)
103
+
104
+ assert_equal(4, thread.methods.length)
105
+ methods = profile.threads.first.methods.sort
106
+
107
+ # Check times
108
+ assert_equal("BasicTest#start", methods[0].full_name)
109
+ assert_in_delta(0.1, methods[0].total_time, 0.01)
110
+ assert_in_delta(0.0, methods[0].wait_time, 0.01)
111
+ assert_in_delta(0.0, methods[0].self_time, 0.01)
112
+
113
+ assert_equal("BasicTest#test_leave_method_2", methods[1].full_name)
114
+ assert_in_delta(0.2, methods[1].total_time, 0.01)
115
+ assert_in_delta(0.0, methods[1].wait_time, 0.01)
116
+ assert_in_delta(0.0, methods[1].self_time, 0.01)
117
+
118
+ assert_equal("Kernel#sleep", methods[2].full_name)
119
+ assert_in_delta(0.3, methods[2].total_time, 0.01)
120
+ assert_in_delta(0.0, methods[2].wait_time, 0.01)
121
+ assert_in_delta(0.3, methods[2].self_time, 0.01)
122
+
123
+ assert_equal("<Class::RubyProf::C1>#hello", methods[3].full_name)
124
+ assert_in_delta(0.3, methods[3].total_time, 0.01)
125
+ assert_in_delta(0.0, methods[3].wait_time, 0.01)
126
+ assert_in_delta(0.0, methods[3].self_time, 0.01)
95
127
  end
96
- end
128
+ end
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+
6
+ class CallInfoTest < Test::Unit::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
+ result2 = 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
+
@@ -6,7 +6,7 @@ require File.expand_path('../test_helper', __FILE__)
6
6
  class CallInfoVisitorTest < Test::Unit::TestCase
7
7
  def setup
8
8
  # Need to use wall time for this test due to the sleep calls
9
- RubyProf::measure_mode = RubyProf::CPU_TIME
9
+ RubyProf::measure_mode = RubyProf::WALL_TIME
10
10
  end
11
11
 
12
12
  def test_visit
File without changes
@@ -3,8 +3,12 @@
3
3
 
4
4
  require File.expand_path("../test_helper", __FILE__)
5
5
 
6
-
7
6
  class DynamicMethodTest < Test::Unit::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
+
8
12
  def test_dynamic_method
9
13
  result = RubyProf.profile do
10
14
  1.times {RubyProf::C1.new.hello}
@@ -13,14 +17,14 @@ class DynamicMethodTest < Test::Unit::TestCase
13
17
  # Methods called
14
18
  # Kernel#sleep
15
19
  # <Class::BasicObject>#allocate
16
- # BasicObject#initialize
20
+ # #{RubyProf.parent_object}#inizialize
17
21
  # RubyProf::C1#hello
18
22
  # Class#new
19
23
  # Integer#times
20
24
  # DynamicMethodTest#test_dynamic_method
21
25
 
22
26
  methods = result.threads.first.methods.sort.reverse
23
- assert_equal(7, methods.length)
27
+ assert_equal(RubyProf.ruby_2? ? 6 : 7, methods.length)
24
28
 
25
29
  # Check times
26
30
  assert_equal("DynamicMethodTest#test_dynamic_method", methods[0].full_name)
@@ -48,14 +52,23 @@ class DynamicMethodTest < Test::Unit::TestCase
48
52
  assert_in_delta(0.0, methods[4].wait_time, 0.01)
49
53
  assert_in_delta(0.0, methods[4].self_time, 0.01)
50
54
 
51
- assert_equal("<Class::#{RubyProf::PARENT}>#allocate", methods[5].full_name)
52
- assert_in_delta(0.0, methods[5].total_time, 0.01)
53
- assert_in_delta(0.0, methods[5].wait_time, 0.01)
54
- assert_in_delta(0.0, methods[5].self_time, 0.01)
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
55
61
 
56
- assert_equal("#{RubyProf::PARENT}#initialize", methods[6].full_name)
62
+ assert_equal("#{RubyProf.parent_object}#initialize", methods[5].full_name)
57
63
  assert_in_delta(0.0, methods[5].total_time, 0.01)
58
64
  assert_in_delta(0.0, methods[5].wait_time, 0.01)
59
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
60
73
  end
61
74
  end
File without changes
File without changes
File without changes
data/test/exec_test.rb CHANGED
File without changes
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+ require 'timeout'
6
+ require 'set'
7
+ begin
8
+ require 'fiber'
9
+ rescue LoadError
10
+ end
11
+
12
+ # -- Tests ----
13
+ class FiberTest < Test::Unit::TestCase
14
+
15
+ def fiber_test
16
+ @fiber_ids << Fiber.current.object_id
17
+ enum = Enumerator.new do |yielder|
18
+ [1,2].each do |x|
19
+ @fiber_ids << Fiber.current.object_id
20
+ sleep 0.1
21
+ yielder.yield x
22
+ end
23
+ end
24
+ while true
25
+ begin
26
+ x = enum.next
27
+ rescue StopIteration
28
+ break
29
+ end
30
+ end
31
+ sleep 0.1
32
+ end
33
+
34
+ def setup
35
+ # Need to use wall time for this test due to the sleep calls
36
+ RubyProf::measure_mode = RubyProf::WALL_TIME
37
+ @fiber_ids = Set.new
38
+ @root_fiber = Fiber.current.object_id
39
+ @thread_id = Thread.current.object_id
40
+ @result = RubyProf.profile { fiber_test }
41
+ end
42
+
43
+ def test_fibers
44
+ profiled_fiber_ids = @result.threads.map(&:fiber_id)
45
+ assert_equal(2, @result.threads.length)
46
+ assert_equal([@thread_id], @result.threads.map(&:id).uniq)
47
+ assert_equal(@fiber_ids, Set.new(profiled_fiber_ids))
48
+
49
+ assert profiled_fiber_ids.include?(@root_fiber)
50
+ assert(root_fiber_profile = @result.threads.detect{|t| t.fiber_id == @root_fiber})
51
+ assert(enum_fiber_profile = @result.threads.detect{|t| t.fiber_id != @root_fiber})
52
+
53
+ assert_in_delta(0.3, root_fiber_profile.total_time, 0.01)
54
+ assert_in_delta(0.2, enum_fiber_profile.total_time, 0.01)
55
+
56
+ assert(method_next = root_fiber_profile.methods.detect{|m| m.full_name == "Enumerator#next"})
57
+ assert(method_each = enum_fiber_profile.methods.detect{|m| m.full_name == "Enumerator#each"})
58
+
59
+ assert_in_delta(0.2, method_next.total_time, 0.01)
60
+ assert_in_delta(0.2, method_each.total_time, 0.01)
61
+
62
+ # RubyProf::CallInfoPrinter.new(@result).print
63
+ end
64
+
65
+ end if RUBY_VERSION >= "1.9"
File without changes
@@ -64,15 +64,18 @@ class MeasureCpuTimeTest < Test::Unit::TestCase
64
64
  # Kernel#sleep
65
65
 
66
66
  methods = result.threads.first.methods.sort.reverse
67
- assert_equal(6, methods.length)
67
+ assert_equal(RubyProf.ruby_2? ? 5 : 6, methods.length)
68
68
  names = methods.map(&:full_name)
69
69
  assert_equal('MeasureCpuTimeTest#test_instance_methods', names[0])
70
70
  assert_equal('RubyProf::C1#hello', names[1])
71
71
  assert_equal('Kernel#sleep', names[2])
72
72
  assert_equal('Class#new', names[3])
73
+
73
74
  # order can differ
74
- assert(names.include?("<Class::#{RubyProf::PARENT}>#allocate"))
75
- assert(names.include?("#{RubyProf::PARENT}#initialize"))
75
+ assert(names.include?("#{RubyProf.parent_object}#initialize"))
76
+ unless RubyProf.ruby_2?
77
+ assert(names.include?("<Class::#{RubyProf.parent_object}>#allocate"))
78
+ end
76
79
 
77
80
  # Check times
78
81
  assert_in_delta(0.2, methods[0].total_time, 0.02)
@@ -95,9 +98,11 @@ class MeasureCpuTimeTest < Test::Unit::TestCase
95
98
  assert_in_delta(0, methods[4].wait_time, 0.01)
96
99
  assert_in_delta(0, methods[4].self_time, 0.01)
97
100
 
98
- assert_in_delta(0, methods[5].total_time, 0.01)
99
- assert_in_delta(0, methods[5].wait_time, 0.01)
100
- assert_in_delta(0, methods[5].self_time, 0.01)
101
+ unless RubyProf.ruby_2?
102
+ assert_in_delta(0, methods[5].total_time, 0.01)
103
+ assert_in_delta(0, methods[5].wait_time, 0.01)
104
+ assert_in_delta(0, methods[5].self_time, 0.01)
105
+ end
101
106
  end
102
107
 
103
108
  def test_module_methods
@@ -145,14 +150,18 @@ class MeasureCpuTimeTest < Test::Unit::TestCase
145
150
  # Kernel#sleep
146
151
 
147
152
  methods = result.threads.first.methods.sort.reverse
148
- assert_equal(6, methods.length)
153
+ assert_equal(RubyProf.ruby_2? ? 5 : 6, methods.length)
149
154
  names = methods.map(&:full_name)
150
155
  assert_equal('MeasureCpuTimeTest#test_module_instance_methods', names[0])
151
156
  assert_equal('RubyProf::M1#hello', names[1])
152
157
  assert_equal('Kernel#sleep', names[2])
153
158
  assert_equal('Class#new', names[3])
154
- assert(names.include?("<Class::#{RubyProf::PARENT}>#allocate"))
155
- assert(names.include?("#{RubyProf::PARENT}#initialize"))
159
+
160
+ # order can differ
161
+ assert(names.include?("#{RubyProf.parent_object}#initialize"))
162
+ unless RubyProf.ruby_2?
163
+ assert(names.include?("<Class::#{RubyProf.parent_object}>#allocate"))
164
+ end
156
165
 
157
166
  # Check times
158
167
  assert_in_delta(0.3, methods[0].total_time, 0.1)
@@ -175,9 +184,11 @@ class MeasureCpuTimeTest < Test::Unit::TestCase
175
184
  assert_in_delta(0, methods[4].wait_time, 0.01)
176
185
  assert_in_delta(0, methods[4].self_time, 0.01)
177
186
 
178
- assert_in_delta(0, methods[5].total_time, 0.01)
179
- assert_in_delta(0, methods[5].wait_time, 0.01)
180
- assert_in_delta(0, methods[5].self_time, 0.01)
187
+ unless RubyProf.ruby_2?
188
+ assert_in_delta(0, methods[5].total_time, 0.01)
189
+ assert_in_delta(0, methods[5].wait_time, 0.01)
190
+ assert_in_delta(0, methods[5].self_time, 0.01)
191
+ end
181
192
  end
182
193
 
183
194
  def test_singleton