ruby-prof 0.18.0-x64-mingw32 → 1.1.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +32 -0
  3. data/LICENSE +2 -2
  4. data/README.rdoc +1 -483
  5. data/Rakefile +3 -6
  6. data/bin/ruby-prof +65 -30
  7. data/ext/ruby_prof/extconf.rb +6 -38
  8. data/ext/ruby_prof/rp_allocation.c +279 -0
  9. data/ext/ruby_prof/rp_allocation.h +31 -0
  10. data/ext/ruby_prof/rp_call_info.c +129 -283
  11. data/ext/ruby_prof/rp_call_info.h +16 -34
  12. data/ext/ruby_prof/rp_measure_allocations.c +25 -49
  13. data/ext/ruby_prof/rp_measure_memory.c +21 -56
  14. data/ext/ruby_prof/rp_measure_process_time.c +35 -39
  15. data/ext/ruby_prof/rp_measure_wall_time.c +36 -19
  16. data/ext/ruby_prof/rp_measurement.c +230 -0
  17. data/ext/ruby_prof/rp_measurement.h +50 -0
  18. data/ext/ruby_prof/rp_method.c +389 -389
  19. data/ext/ruby_prof/rp_method.h +34 -39
  20. data/ext/ruby_prof/rp_profile.c +895 -0
  21. data/ext/ruby_prof/rp_profile.h +37 -0
  22. data/ext/ruby_prof/rp_stack.c +103 -80
  23. data/ext/ruby_prof/rp_stack.h +5 -12
  24. data/ext/ruby_prof/rp_thread.c +143 -83
  25. data/ext/ruby_prof/rp_thread.h +15 -6
  26. data/ext/ruby_prof/ruby_prof.c +11 -757
  27. data/ext/ruby_prof/ruby_prof.h +4 -47
  28. data/ext/ruby_prof/vc/ruby_prof.vcxproj +10 -8
  29. data/lib/{2.6.3 → 2.6.5}/ruby_prof.so +0 -0
  30. data/lib/ruby-prof.rb +2 -18
  31. data/lib/ruby-prof/assets/call_stack_printer.html.erb +713 -0
  32. data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
  33. data/lib/ruby-prof/assets/graph_printer.html.erb +356 -0
  34. data/lib/ruby-prof/call_info.rb +35 -93
  35. data/lib/ruby-prof/call_info_visitor.rb +19 -21
  36. data/lib/ruby-prof/compatibility.rb +37 -107
  37. data/lib/ruby-prof/exclude_common_methods.rb +198 -0
  38. data/lib/ruby-prof/measurement.rb +14 -0
  39. data/lib/ruby-prof/method_info.rb +52 -83
  40. data/lib/ruby-prof/printers/abstract_printer.rb +73 -50
  41. data/lib/ruby-prof/printers/call_info_printer.rb +13 -3
  42. data/lib/ruby-prof/printers/call_stack_printer.rb +62 -145
  43. data/lib/ruby-prof/printers/call_tree_printer.rb +20 -12
  44. data/lib/ruby-prof/printers/dot_printer.rb +5 -5
  45. data/lib/ruby-prof/printers/flat_printer.rb +6 -24
  46. data/lib/ruby-prof/printers/graph_html_printer.rb +6 -192
  47. data/lib/ruby-prof/printers/graph_printer.rb +13 -15
  48. data/lib/ruby-prof/printers/multi_printer.rb +66 -23
  49. data/lib/ruby-prof/profile.rb +10 -3
  50. data/lib/ruby-prof/rack.rb +0 -3
  51. data/lib/ruby-prof/thread.rb +12 -12
  52. data/lib/ruby-prof/version.rb +1 -1
  53. data/ruby-prof.gemspec +2 -2
  54. data/test/abstract_printer_test.rb +0 -27
  55. data/test/alias_test.rb +129 -0
  56. data/test/basic_test.rb +41 -40
  57. data/test/call_info_visitor_test.rb +3 -3
  58. data/test/dynamic_method_test.rb +0 -2
  59. data/test/fiber_test.rb +11 -17
  60. data/test/gc_test.rb +96 -0
  61. data/test/line_number_test.rb +120 -39
  62. data/test/marshal_test.rb +119 -0
  63. data/test/measure_allocations.rb +30 -0
  64. data/test/measure_allocations_test.rb +371 -12
  65. data/test/measure_allocations_trace_test.rb +385 -0
  66. data/test/measure_memory_trace_test.rb +756 -0
  67. data/test/measure_process_time_test.rb +821 -33
  68. data/test/measure_times.rb +54 -0
  69. data/test/measure_wall_time_test.rb +349 -145
  70. data/test/multi_printer_test.rb +1 -34
  71. data/test/parser_timings.rb +24 -0
  72. data/test/pause_resume_test.rb +5 -5
  73. data/test/prime.rb +2 -0
  74. data/test/printer_call_stack_test.rb +28 -0
  75. data/test/printer_call_tree_test.rb +31 -0
  76. data/test/printer_flat_test.rb +68 -0
  77. data/test/printer_graph_html_test.rb +60 -0
  78. data/test/printer_graph_test.rb +41 -0
  79. data/test/printers_test.rb +32 -166
  80. data/test/printing_recursive_graph_test.rb +26 -72
  81. data/test/recursive_test.rb +72 -77
  82. data/test/stack_printer_test.rb +2 -15
  83. data/test/start_stop_test.rb +22 -25
  84. data/test/test_helper.rb +5 -248
  85. data/test/thread_test.rb +11 -54
  86. data/test/unique_call_path_test.rb +16 -28
  87. data/test/yarv_test.rb +1 -0
  88. metadata +28 -36
  89. data/examples/flat.txt +0 -50
  90. data/examples/graph.dot +0 -84
  91. data/examples/graph.html +0 -823
  92. data/examples/graph.txt +0 -139
  93. data/examples/multi.flat.txt +0 -23
  94. data/examples/multi.graph.html +0 -760
  95. data/examples/multi.grind.dat +0 -114
  96. data/examples/multi.stack.html +0 -547
  97. data/examples/stack.html +0 -547
  98. data/ext/ruby_prof/rp_measure.c +0 -40
  99. data/ext/ruby_prof/rp_measure.h +0 -45
  100. data/ext/ruby_prof/rp_measure_cpu_time.c +0 -136
  101. data/ext/ruby_prof/rp_measure_gc_runs.c +0 -73
  102. data/ext/ruby_prof/rp_measure_gc_time.c +0 -60
  103. data/lib/ruby-prof/aggregate_call_info.rb +0 -76
  104. data/lib/ruby-prof/assets/call_stack_printer.css.html +0 -117
  105. data/lib/ruby-prof/assets/call_stack_printer.js.html +0 -385
  106. data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +0 -83
  107. data/lib/ruby-prof/profile/exclude_common_methods.rb +0 -207
  108. data/lib/ruby-prof/profile/legacy_method_elimination.rb +0 -50
  109. data/test/aggregate_test.rb +0 -136
  110. data/test/block_test.rb +0 -74
  111. data/test/call_info_test.rb +0 -78
  112. data/test/issue137_test.rb +0 -63
  113. data/test/measure_cpu_time_test.rb +0 -212
  114. data/test/measure_gc_runs_test.rb +0 -32
  115. data/test/measure_gc_time_test.rb +0 -36
  116. data/test/measure_memory_test.rb +0 -33
  117. data/test/method_elimination_test.rb +0 -84
  118. data/test/module_test.rb +0 -45
  119. data/test/stack_test.rb +0 -138
@@ -54,40 +54,11 @@ class MultiPrinterTest < TestCase
54
54
  end
55
55
  end
56
56
 
57
- def test_all_profiles_can_be_created
58
- start_time = Time.now
59
- RubyProf.start
60
- 5.times{MSTPT.new.a}
61
- result = RubyProf.stop
62
- end_time = Time.now
63
- expected_time = end_time - start_time
64
- graph = print(result)[1]
65
- re = Regexp.new('
66
- \s*<table>
67
- \s*<tr>
68
- \s*<th>Thread ID</th>
69
- \s*(<th>Fiber ID</th>)?
70
- \s*<th>Total Time</th>
71
- \s*</tr>
72
- \s*
73
- \s*<tr>
74
- \s*(<td>([\.0-9]+)</td>)?
75
- \s*<td><a href="#-?\d+">-?\d+</a></td>
76
- \s*<td>([\.0-9e]+)</td>
77
- \s*</tr>
78
- \s*
79
- \s*</table>')
80
- assert_match(re, graph)
81
- graph =~ re
82
- display_time = $4.to_f
83
- assert_in_delta expected_time, display_time, 0.001
84
- end
85
-
86
57
  private
87
58
 
88
59
  def print(result)
89
60
  test = caller.first =~ /in `(.*)'/ ? $1 : "test"
90
- path = RubyProf.tmpdir
61
+ path = Dir.tmpdir
91
62
  profile = "ruby_prof_#{test}"
92
63
  printer = RubyProf::MultiPrinter.new(result)
93
64
  printer.print(:path => path, :profile => profile,
@@ -95,10 +66,6 @@ class MultiPrinterTest < TestCase
95
66
  if RUBY_PLATFORM =~ /darwin/ && ENV['SHOW_RUBY_PROF_PRINTER_OUTPUT']=="1"
96
67
  system("open '#{printer.stack_profile}'")
97
68
  end
98
- # if GC.respond_to?(:dump_file_and_line_info)
99
- # GC.start
100
- # GC.dump_file_and_line_info("heap.dump")
101
- # end
102
69
  [File.read(printer.stack_profile), File.read(printer.graph_profile)]
103
70
  end
104
71
  end
@@ -0,0 +1,24 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ require 'ruby-prof'
4
+
5
+ require 'parser/current'
6
+ Parser::Builders::Default.emit_lambda = true
7
+ Parser::Builders::Default.emit_procarg0 = true
8
+ Parser::Builders::Default.emit_encoding = true
9
+ Parser::Builders::Default.emit_index = true
10
+
11
+ start = Time.now
12
+ result = RubyProf.profile(:measure_mode => RubyProf::ALLOCATIONS, :track_allocations => true) do
13
+ code = File.read('C:/msys64/usr/local/src/ruby-2.6.3/lib/rdoc/markdown.rb')
14
+ parse = Parser::CurrentRuby.parse(code)
15
+ end
16
+
17
+ finish = Time.now
18
+
19
+ puts "#{finish - start} seconds"
20
+
21
+ printer = RubyProf::GraphHtmlPrinter.new(result)
22
+ File.open('c:/temp/graph.html', 'wb') do |file|
23
+ printer.print(file)
24
+ end
@@ -12,22 +12,22 @@ class PauseResumeTest < TestCase
12
12
  def test_pause_resume
13
13
  # Measured
14
14
  RubyProf.start
15
- RubyProf::C1.hello
15
+ RubyProf::C1.sleep_wait
16
16
 
17
17
  # Not measured
18
18
  RubyProf.pause
19
19
  sleep 1
20
- RubyProf::C1.hello
20
+ RubyProf::C1.sleep_wait
21
21
 
22
22
  # Measured
23
23
  RubyProf.resume
24
- RubyProf::C1.hello
24
+ RubyProf::C1.sleep_wait
25
25
 
26
26
  result = RubyProf.stop
27
27
 
28
28
  # Length should be 3:
29
29
  # PauseResumeTest#test_pause_resume
30
- # <Class::RubyProf::C1>#hello
30
+ # <Class::RubyProf::C1>#sleep_wait
31
31
  # Kernel#sleep
32
32
 
33
33
  methods = result.threads.first.methods.sort_by {|method_info| method_info.full_name}
@@ -38,7 +38,7 @@ class PauseResumeTest < TestCase
38
38
  assert_equal(3, methods.length)
39
39
 
40
40
  # Check the names
41
- assert_equal('<Class::RubyProf::C1>#hello', methods[0].full_name)
41
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', methods[0].full_name)
42
42
  assert_equal('Kernel#sleep', methods[1].full_name)
43
43
  assert_equal('PauseResumeTest#test_pause_resume', methods[2].full_name)
44
44
 
data/test/prime.rb CHANGED
@@ -4,6 +4,8 @@
4
4
  #
5
5
  # Source from http://people.cs.uchicago.edu/~bomb154/154/maclabs/profilers-lab/
6
6
 
7
+ require File.expand_path('../test_helper', __FILE__)
8
+
7
9
  def make_random_array(length, maxnum)
8
10
  result = Array.new(length)
9
11
  result.each_index do |i|
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+ require 'stringio'
6
+ require 'fileutils'
7
+ require 'tmpdir'
8
+ require_relative 'prime'
9
+
10
+ # -- Tests ----
11
+ class PrinterCallStackTest < TestCase
12
+ def setup
13
+ # WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
14
+ RubyProf::measure_mode = RubyProf::WALL_TIME
15
+ @result = RubyProf.profile do
16
+ run_primes(1000, 5000)
17
+ end
18
+ end
19
+
20
+ def test_graph_html_string
21
+ output = ''
22
+ printer = RubyProf::CallStackPrinter.new(@result)
23
+ printer.print(output)
24
+
25
+ assert_match(/<!DOCTYPE html>/i, output)
26
+ assert_match(/Object#run_primes/i, output)
27
+ end
28
+ end
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+ require 'stringio'
6
+ require 'fileutils'
7
+ require 'tmpdir'
8
+ require_relative 'prime'
9
+
10
+ # -- Tests ----
11
+ class PrinterCallTreeTest < TestCase
12
+ def setup
13
+ # WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
14
+ RubyProf::measure_mode = RubyProf::WALL_TIME
15
+ @result = RubyProf.profile do
16
+ run_primes(1000, 5000)
17
+ end
18
+ end
19
+
20
+ def test_call_tree_string
21
+ printer = RubyProf::CallTreePrinter.new(@result)
22
+
23
+ printer.print(:profile => "lolcat", :path => Dir.tmpdir)
24
+ main_output_file_name = File.join(Dir.tmpdir, "lolcat.callgrind.out.#{$$}")
25
+ assert(File.exist?(main_output_file_name))
26
+ output = File.read(main_output_file_name)
27
+ assert_match(/fn=Object::find_primes/i, output)
28
+ assert_match(/events: wall_time/i, output)
29
+ refute_match(/d\d\d\d\d\d/, output) # old bug looked [in error] like Object::run_primes(d5833116)
30
+ end
31
+ end
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+ require 'stringio'
6
+ require 'fileutils'
7
+ require 'tmpdir'
8
+ require_relative 'prime'
9
+
10
+ # -- Tests ----
11
+ class PrinterFlatTest < TestCase
12
+ def setup
13
+ # WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
14
+ RubyProf::measure_mode = RubyProf::WALL_TIME
15
+ @result = RubyProf.profile do
16
+ run_primes(1000, 5000)
17
+ end
18
+ end
19
+
20
+ def flat_output_nth_column_values(output, n)
21
+ only_method_calls = output.split("\n").select { |line| line =~ /^ +\d+/ }
22
+ only_method_calls.collect { |line| line.split(/ +/)[n] }
23
+ end
24
+
25
+ def assert_sorted array
26
+ array = array.map{|n| n.to_f} # allow for > 10s times to sort right, since lexographically 4.0 > 10.0
27
+ assert_equal array, array.sort.reverse, "Array #{array.inspect} is not sorted"
28
+ end
29
+
30
+ def test_flat_string
31
+ output = helper_test_flat_string(RubyProf::FlatPrinter)
32
+ assert_match(/prime.rb/, output)
33
+ end
34
+
35
+ def helper_test_flat_string(klass)
36
+ output = ''
37
+
38
+ printer = klass.new(@result)
39
+ printer.print(output)
40
+
41
+ assert_match(/Thread ID: -?\d+/i, output)
42
+ assert_match(/Fiber ID: -?\d+/i, output)
43
+ assert_match(/Total: \d+\.\d+/i, output)
44
+ assert_match(/Object#run_primes/i, output)
45
+ output
46
+ end
47
+
48
+ def test_flat_result_sorting_by_self_time_is_default
49
+ printer = RubyProf::FlatPrinter.new(@result)
50
+
51
+ printer.print(output = '')
52
+ self_times = flat_output_nth_column_values(output, 3)
53
+
54
+ assert_sorted self_times
55
+ end
56
+
57
+ def test_flat_result_sorting
58
+ printer = RubyProf::FlatPrinter.new(@result)
59
+
60
+ sort_method_with_column_number = {:total_time => 2, :self_time => 3, :wait_time => 4, :children_time => 5}
61
+
62
+ sort_method_with_column_number.each_pair do |sort_method, n|
63
+ printer.print(output = '', :sort_method => sort_method)
64
+ times = flat_output_nth_column_values(output, n)
65
+ assert_sorted times
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+ require 'stringio'
6
+ require 'fileutils'
7
+ require 'tmpdir'
8
+ require_relative 'prime'
9
+
10
+ # -- Tests ----
11
+ class PrinterGraphHtmlTest < TestCase
12
+ def setup
13
+ # WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
14
+ RubyProf::measure_mode = RubyProf::WALL_TIME
15
+ @result = RubyProf.profile do
16
+ run_primes(1000, 5000)
17
+ end
18
+ end
19
+
20
+ def graph_html_output_nth_column_values(output, n)
21
+ only_root_calls = output.split('<tr class="method">')
22
+ only_root_calls.delete_at(0)
23
+ only_root_calls.collect {|line| line.scan(/[\d\.]+/)[n - 1] }
24
+ end
25
+
26
+ def assert_sorted array
27
+ array = array.map{|n| n.to_f} # allow for > 10s times to sort right, since lexographically 4.0 > 10.0
28
+ assert_equal array, array.sort.reverse, "Array #{array.inspect} is not sorted"
29
+ end
30
+
31
+ def test_graph_html_string
32
+ output = ''
33
+ printer = RubyProf::GraphHtmlPrinter.new(@result)
34
+ printer.print(output)
35
+
36
+ assert_match(/<!DOCTYPE html>/i, output)
37
+ assert_match( %r{<th>Total</th>}i, output)
38
+ assert_match(/Object#run_primes/i, output)
39
+ end
40
+
41
+ def test_graph_html_result_sorting_by_total_time_is_default
42
+ printer = RubyProf::GraphHtmlPrinter.new(@result)
43
+ printer.print(output = '')
44
+ total_times = graph_html_output_nth_column_values(output, 3)
45
+
46
+ assert_sorted total_times
47
+ end
48
+
49
+ def test_graph_html_result_sorting
50
+ printer = RubyProf::GraphHtmlPrinter.new(@result)
51
+
52
+ sort_method_with_column_number = {:total_time => 3, :self_time => 4, :wait_time => 5, :children_time => 6}
53
+
54
+ sort_method_with_column_number.each_pair do |sort_method, n|
55
+ printer.print(output = '', :sort_method => sort_method)
56
+ times = graph_html_output_nth_column_values(output, n)
57
+ assert_sorted times
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+ require 'stringio'
6
+ require 'fileutils'
7
+ require 'tmpdir'
8
+ require_relative 'prime'
9
+
10
+ # -- Tests ----
11
+ class PrinterGraphTest < TestCase
12
+ def setup
13
+ # WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
14
+ RubyProf::measure_mode = RubyProf::WALL_TIME
15
+ @result = RubyProf.profile do
16
+ run_primes(1000, 5000)
17
+ end
18
+ end
19
+
20
+ def graph_output_nth_column_values(output, n)
21
+ only_root_calls = output.split("\n").select { |line| line =~ /^ +[\d\.]+%/ }
22
+ only_root_calls.collect { |line| line.split(/ +/)[n] }
23
+ end
24
+
25
+ def assert_sorted array
26
+ array = array.map{|n| n.to_f} # allow for > 10s times to sort right, since lexographically 4.0 > 10.0
27
+ assert_equal array, array.sort.reverse, "Array #{array.inspect} is not sorted"
28
+ end
29
+
30
+ def test_graph_results_sorting
31
+ printer = RubyProf::GraphPrinter.new(@result)
32
+
33
+ sort_method_with_column_number = {:total_time => 3, :self_time => 4, :wait_time => 5, :children_time => 6}
34
+
35
+ sort_method_with_column_number.each_pair do |sort_method, n|
36
+ printer.print(output = '', :sort_method => sort_method)
37
+ times = graph_output_nth_column_values(output, n)
38
+ assert_sorted times
39
+ end
40
+ end
41
+ end
@@ -4,6 +4,8 @@
4
4
  require File.expand_path('../test_helper', __FILE__)
5
5
  require 'stringio'
6
6
  require 'fileutils'
7
+ require 'tmpdir'
8
+ require_relative 'prime'
7
9
 
8
10
  # -- Tests ----
9
11
  class PrintersTest < TestCase
@@ -16,51 +18,44 @@ class PrintersTest < TestCase
16
18
  end
17
19
 
18
20
  def test_printers
19
- assert_nothing_raised do
20
- output = ENV['SHOW_RUBY_PROF_PRINTER_OUTPUT'] == "1" ? STDOUT : StringIO.new('')
21
+ output = ENV['SHOW_RUBY_PROF_PRINTER_OUTPUT'] == "1" ? STDOUT : StringIO.new('')
21
22
 
22
- printer = RubyProf::CallInfoPrinter.new(@result)
23
- printer.print(output)
24
-
25
- printer = RubyProf::CallTreePrinter.new(@result)
26
- printer.print()
23
+ printer = RubyProf::CallInfoPrinter.new(@result)
24
+ printer.print(output)
27
25
 
28
- printer = RubyProf::FlatPrinter.new(@result)
29
- printer.print(output)
26
+ printer = RubyProf::CallTreePrinter.new(@result)
27
+ printer.print()
30
28
 
31
- printer = RubyProf::FlatPrinterWithLineNumbers.new(@result)
32
- printer.print(output)
29
+ printer = RubyProf::FlatPrinter.new(@result)
30
+ printer.print(output)
33
31
 
34
- printer = RubyProf::GraphHtmlPrinter.new(@result)
35
- printer.print(output)
32
+ printer = RubyProf::GraphHtmlPrinter.new(@result)
33
+ printer.print(output)
36
34
 
37
- printer = RubyProf::GraphPrinter.new(@result)
38
- printer.print(output)
39
- end
35
+ printer = RubyProf::GraphPrinter.new(@result)
36
+ printer.print(output)
40
37
  end
41
38
 
42
39
  def test_print_to_files
43
- assert_nothing_raised do
44
- output_dir = 'examples2'
40
+ output_dir = 'examples2'
45
41
 
46
- if ENV['SAVE_NEW_PRINTER_EXAMPLES']
47
- output_dir = 'examples'
48
- end
49
- FileUtils.mkdir_p output_dir
42
+ if ENV['SAVE_NEW_PRINTER_EXAMPLES']
43
+ output_dir = 'examples'
44
+ end
45
+ FileUtils.mkdir_p output_dir
50
46
 
51
- printer = RubyProf::DotPrinter.new(@result)
52
- File.open("#{output_dir}/graph.dot", "w") {|f| printer.print(f)}
47
+ printer = RubyProf::DotPrinter.new(@result)
48
+ File.open("#{output_dir}/graph.dot", "w") {|f| printer.print(f)}
53
49
 
54
- printer = RubyProf::CallStackPrinter.new(@result)
55
- File.open("#{output_dir}/stack.html", "w") {|f| printer.print(f, :application => "primes")}
50
+ printer = RubyProf::CallStackPrinter.new(@result)
51
+ File.open("#{output_dir}/stack.html", "w") {|f| printer.print(f, :application => "primes")}
56
52
 
57
- printer = RubyProf::MultiPrinter.new(@result)
58
- printer.print(:path => "#{output_dir}", :profile => "multi", :application => "primes")
59
- for file in ['graph.dot', 'multi.flat.txt', 'multi.graph.html', "multi.callgrind.out.#{$$}", 'multi.stack.html', 'stack.html']
60
- existant_file = output_dir + '/' + file
61
- assert File.size(existant_file) > 0
62
- end
63
- end
53
+ # printer = RubyProf::MultiPrinter.new(@result)
54
+ # printer.print(:path => "#{output_dir}", :profile => "multi", :application => "primes")
55
+ # for file in ['graph.dot', 'multi.flat.txt', 'multi.graph.html', "multi.callgrind.out.#{$$}", 'multi.stack.html', 'stack.html']
56
+ # existant_file = output_dir + '/' + file
57
+ # assert File.size(existant_file) > 0
58
+ # end
64
59
  end
65
60
 
66
61
  def test_refuses_io_objects
@@ -85,7 +80,7 @@ class PrintersTest < TestCase
85
80
 
86
81
  def test_flat_string
87
82
  output = helper_test_flat_string(RubyProf::FlatPrinter)
88
- refute_match(/prime.rb/, output)
83
+ assert_match(/prime.rb/, output)
89
84
  end
90
85
 
91
86
  def helper_test_flat_string(klass)
@@ -101,25 +96,13 @@ class PrintersTest < TestCase
101
96
  output
102
97
  end
103
98
 
104
- def test_flat_string_with_numbers
105
- output = helper_test_flat_string RubyProf::FlatPrinterWithLineNumbers
106
- assert_match(/prime.rb/, output)
107
- refute_match(/ruby_runtime:0/, output)
108
- assert_match(/called from/, output)
109
-
110
- # should combine common parents
111
- # 1.9 inlines it's Fixnum#- so we don't see as many
112
- assert_equal(2, output.scan(/Object#is_prime/).length)
113
- refute_match(/\.\/test\/prime.rb/, output) # don't use relative paths
114
- end
115
-
116
99
  def test_graph_html_string
117
100
  output = ''
118
101
  printer = RubyProf::GraphHtmlPrinter.new(@result)
119
102
  printer.print(output)
120
103
 
121
- assert_match(/DTD HTML 4\.01/i, output)
122
- assert_match( %r{<th>Total Time</th>}i, output)
104
+ assert_match(/<!DOCTYPE html>/i, output)
105
+ assert_match( %r{<th>Total</th>}i, output)
123
106
  assert_match(/Object#run_primes/i, output)
124
107
  end
125
108
 
@@ -134,17 +117,6 @@ class PrintersTest < TestCase
134
117
  assert_match(/Object#run_primes/i, output)
135
118
  end
136
119
 
137
- def test_call_tree_string
138
- printer = RubyProf::CallTreePrinter.new(@result)
139
- printer.print(:profile => "lolcat", :path => RubyProf.tmpdir)
140
- main_output_file_name = File.join(RubyProf.tmpdir, "lolcat.callgrind.out.#{$$}")
141
- assert(File.exist?(main_output_file_name))
142
- output = File.read(main_output_file_name)
143
- assert_match(/fn=Object::find_primes/i, output)
144
- assert_match(/events: wall_time/i, output)
145
- refute_match(/d\d\d\d\d\d/, output) # old bug looked [in error] like Object::run_primes(d5833116)
146
- end
147
-
148
120
  def do_nothing
149
121
  start = Time.now
150
122
  while(Time.now == start)
@@ -159,117 +131,11 @@ class PrintersTest < TestCase
159
131
 
160
132
  # RubyProf::CallTreePrinter doesn't "do" a min_percent
161
133
  # RubyProf::FlatPrinter only outputs if self time > percent...
162
- # RubyProf::FlatPrinterWithLineNumbers same
163
- for klass in [ RubyProf::GraphPrinter, RubyProf::GraphHtmlPrinter]
134
+ for klass in [RubyProf::GraphPrinter, RubyProf::GraphHtmlPrinter]
164
135
  printer = klass.new(result)
165
136
  out = ''
166
137
  printer.print(out, :min_percent => 0.00000001)
167
138
  assert_match(/do_nothing/, out)
168
139
  end
169
-
170
- end
171
-
172
- def test_flat_result_sorting_by_self_time_is_default
173
- printer = RubyProf::FlatPrinter.new(@result)
174
-
175
- printer.print(output = '')
176
- self_times = flat_output_nth_column_values(output, 3)
177
-
178
- assert_sorted self_times
179
- end
180
-
181
- def test_flat_result_sorting
182
- printer = RubyProf::FlatPrinter.new(@result)
183
-
184
- sort_method_with_column_number = {:total_time => 2, :self_time => 3, :wait_time => 4, :children_time => 5}
185
-
186
- sort_method_with_column_number.each_pair do |sort_method, n|
187
- printer.print(output = '', :sort_method => sort_method)
188
- times = flat_output_nth_column_values(output, n)
189
- assert_sorted times
190
- end
191
- end
192
-
193
- def test_flat_result_with_line_numbers_sorting_by_self_time_is_default
194
- printer = RubyProf::FlatPrinterWithLineNumbers.new(@result)
195
-
196
- printer.print(output = '')
197
- self_times = flat_output_nth_column_values(output, 3)
198
-
199
- assert_sorted self_times
200
- end
201
-
202
- def test_flat_with_line_numbers_result_sorting
203
- printer = RubyProf::FlatPrinterWithLineNumbers.new(@result)
204
-
205
- sort_method_with_column_number = {:total_time => 2, :self_time => 3, :wait_time => 4, :children_time => 5}
206
-
207
- sort_method_with_column_number.each_pair do |sort_method, n|
208
- printer.print(output = '', :sort_method => sort_method)
209
- times = flat_output_nth_column_values(output, n)
210
- assert_sorted times
211
- end
212
- end
213
-
214
- def test_graph_result_sorting_by_total_time_is_default
215
- printer = RubyProf::GraphPrinter.new(@result)
216
- printer.print(output = '')
217
- total_times = graph_output_nth_column_values(output, 3)
218
-
219
- assert_sorted total_times
220
- end
221
-
222
- def test_graph_results_sorting
223
- printer = RubyProf::GraphPrinter.new(@result)
224
-
225
- sort_method_with_column_number = {:total_time => 3, :self_time => 4, :wait_time => 5, :children_time => 6}
226
-
227
- sort_method_with_column_number.each_pair do |sort_method, n|
228
- printer.print(output = '', :sort_method => sort_method)
229
- times = graph_output_nth_column_values(output, n)
230
- assert_sorted times
231
- end
232
- end
233
-
234
- def test_graph_html_result_sorting_by_total_time_is_default
235
- printer = RubyProf::GraphHtmlPrinter.new(@result)
236
- printer.print(output = '')
237
- total_times = graph_html_output_nth_column_values(output, 3)
238
-
239
- assert_sorted total_times
240
- end
241
-
242
- def test_graph_html_result_sorting
243
- printer = RubyProf::GraphHtmlPrinter.new(@result)
244
-
245
- sort_method_with_column_number = {:total_time => 3, :self_time => 4, :wait_time => 5, :children_time => 6}
246
-
247
- sort_method_with_column_number.each_pair do |sort_method, n|
248
- printer.print(output = '', :sort_method => sort_method)
249
- times = graph_html_output_nth_column_values(output, n)
250
- assert_sorted times
251
- end
252
- end
253
-
254
- private
255
- def flat_output_nth_column_values(output, n)
256
- only_method_calls = output.split("\n").select { |line| line =~ /^ +\d+/ }
257
- only_method_calls.collect { |line| line.split(/ +/)[n] }
258
- end
259
-
260
- def graph_output_nth_column_values(output, n)
261
- only_root_calls = output.split("\n").select { |line| line =~ /^ +[\d\.]+%/ }
262
- only_root_calls.collect { |line| line.split(/ +/)[n] }
263
- end
264
-
265
- def graph_html_output_nth_column_values(output, n)
266
- only_root_calls = output.split('<tr class="method">')
267
- only_root_calls.delete_at(0)
268
- only_root_calls.collect {|line| line.scan(/[\d\.]+/)[n - 1] }
269
- end
270
-
271
- def assert_sorted array
272
- array = array.map{|n| n.to_f} # allow for > 10s times to sort right, since lexographically 4.0 > 10.0
273
- assert_equal array, array.sort.reverse, "Array #{array.inspect} is not sorted"
274
140
  end
275
141
  end