ruby-prof 1.7.1 → 1.7.2

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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +8 -0
  3. data/ext/ruby_prof/extconf.rb +23 -22
  4. data/ext/ruby_prof/rp_call_trees.c +296 -296
  5. data/ext/ruby_prof/rp_call_trees.h +28 -28
  6. data/ext/ruby_prof/rp_measure_allocations.c +47 -47
  7. data/ext/ruby_prof/rp_measure_process_time.c +64 -66
  8. data/ext/ruby_prof/rp_measure_wall_time.c +52 -64
  9. data/ext/ruby_prof/rp_method.c +551 -551
  10. data/ext/ruby_prof/rp_stack.c +212 -212
  11. data/ext/ruby_prof/ruby_prof.c +50 -50
  12. data/ext/ruby_prof/ruby_prof.h +3 -2
  13. data/ext/ruby_prof/vc/ruby_prof.vcxproj +3 -3
  14. data/lib/ruby-prof/compatibility.rb +113 -113
  15. data/lib/ruby-prof/exclude_common_methods.rb +204 -204
  16. data/lib/ruby-prof/printers/abstract_printer.rb +156 -138
  17. data/lib/ruby-prof/version.rb +3 -3
  18. data/ruby-prof.gemspec +66 -65
  19. data/test/dynamic_method_test.rb +9 -21
  20. data/test/enumerable_test.rb +23 -21
  21. data/test/exclude_methods_test.rb +363 -257
  22. data/test/fiber_test.rb +195 -195
  23. data/test/gc_test.rb +104 -102
  24. data/test/line_number_test.rb +426 -289
  25. data/test/measure_allocations_test.rb +1172 -1081
  26. data/test/measure_memory_test.rb +1193 -1456
  27. data/test/measure_process_time_test.rb +3330 -2477
  28. data/test/measure_wall_time_test.rb +634 -568
  29. data/test/merge_test.rb +146 -146
  30. data/test/method_info_test.rb +100 -95
  31. data/test/printers_test.rb +178 -135
  32. data/test/recursive_test.rb +796 -622
  33. data/test/start_stop_test.rb +4 -4
  34. data/test/test_helper.rb +20 -20
  35. data/test/thread_test.rb +229 -231
  36. data/test/unique_call_path_test.rb +9 -22
  37. data/test/yarv_test.rb +1 -5
  38. metadata +19 -9
  39. data/test/crash2.rb +0 -144
@@ -1,135 +1,178 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- require File.expand_path('../test_helper', __FILE__)
5
- require 'fileutils'
6
- require 'stringio'
7
- require 'tmpdir'
8
- require_relative 'prime'
9
-
10
- # -- Tests ----
11
- class PrintersTest < TestCase
12
- def setup
13
- super
14
- # WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
15
- @result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
16
- run_primes(1000, 5000)
17
- end
18
- end
19
-
20
- def test_printers
21
- output = ENV['SHOW_RUBY_PROF_PRINTER_OUTPUT'] == "1" ? STDOUT : StringIO.new('')
22
-
23
- printer = RubyProf::CallStackPrinter.new(@result)
24
- printer.print(output)
25
-
26
- printer = RubyProf::CallTreePrinter.new(@result)
27
- printer.print(:path => Dir.tmpdir)
28
-
29
- printer = RubyProf::FlatPrinter.new(@result)
30
- printer.print(output)
31
-
32
- printer = RubyProf::GraphHtmlPrinter.new(@result)
33
- printer.print(output)
34
-
35
- printer = RubyProf::GraphPrinter.new(@result)
36
- printer.print(output)
37
- end
38
-
39
- def test_print_to_files
40
- printer = RubyProf::DotPrinter.new(@result)
41
- File.open("#{Dir.tmpdir}/graph.dot", "w") {|f| printer.print(f)}
42
-
43
- printer = RubyProf::CallStackPrinter.new(@result)
44
- File.open("#{Dir.tmpdir}/stack.html", "w") {|f| printer.print(f, :application => "primes")}
45
-
46
- printer = RubyProf::MultiPrinter.new(@result)
47
- printer.print(:path => Dir.tmpdir, :profile => "multi", :application => "primes")
48
-
49
- ['graph.dot', 'multi.flat.txt', 'multi.graph.html', "multi.callgrind.out.#{$$}", 'multi.stack.html', 'stack.html'].each do |file_name|
50
- file_path = File.join(Dir.tmpdir, file_name)
51
- refute(File.empty?(file_path))
52
- end
53
- end
54
-
55
- def test_refuses_io_objects
56
- p = RubyProf::MultiPrinter.new(@result)
57
- begin
58
- p.print(STDOUT)
59
- flunk "should have raised an ArgumentError"
60
- rescue ArgumentError => e
61
- assert_match(/IO/, e.to_s)
62
- end
63
- end
64
-
65
- def test_refuses_non_hashes
66
- p = RubyProf::MultiPrinter.new (@result)
67
- begin
68
- p.print([])
69
- flunk "should have raised an ArgumentError"
70
- rescue ArgumentError => e
71
- assert_match(/hash/, e.to_s)
72
- end
73
- end
74
-
75
- def test_flat_string
76
- output = helper_test_flat_string(RubyProf::FlatPrinter)
77
- assert_match(/prime.rb/, output)
78
- end
79
-
80
- def helper_test_flat_string(klass)
81
- output = ''
82
-
83
- printer = klass.new(@result)
84
- printer.print(output)
85
-
86
- assert_match(/Thread ID: -?\d+/i, output)
87
- assert_match(/Fiber ID: -?\d+/i, output)
88
- assert_match(/Total: \d+\.\d+/i, output)
89
- assert_match(/Object#run_primes/i, output)
90
- output
91
- end
92
-
93
- def test_graph_html_string
94
- output = ''
95
- printer = RubyProf::GraphHtmlPrinter.new(@result)
96
- printer.print(output)
97
-
98
- assert_match(/<!DOCTYPE html>/i, output)
99
- assert_match( %r{<th>Total</th>}i, output)
100
- assert_match(/Object#run_primes/i, output)
101
- end
102
-
103
- def test_graph_string
104
- output = ''
105
- printer = RubyProf::GraphPrinter.new(@result)
106
- printer.print(output)
107
-
108
- assert_match(/Thread ID: -?\d+/i, output)
109
- assert_match(/Fiber ID: -?\d+/i, output)
110
- assert_match(/Total Time: \d+\.\d+/i, output)
111
- assert_match(/Object#run_primes/i, output)
112
- end
113
-
114
- def do_nothing
115
- start = Time.now
116
- while(Time.now == start)
117
- end
118
- end
119
-
120
- def test_all_with_small_percentiles
121
- result = RubyProf::Profile.profile do
122
- sleep 2
123
- do_nothing
124
- end
125
-
126
- # RubyProf::CallTreePrinter doesn't "do" a min_percent
127
- # RubyProf::FlatPrinter only outputs if self time > percent...
128
- for klass in [RubyProf::GraphPrinter, RubyProf::GraphHtmlPrinter]
129
- printer = klass.new(result)
130
- out = ''
131
- printer.print(out, :min_percent => 0.00000001)
132
- assert_match(/do_nothing/, out)
133
- end
134
- end
135
- end
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+ require 'fileutils'
6
+ require 'stringio'
7
+ require 'tmpdir'
8
+ require_relative 'prime'
9
+
10
+ # -- Tests ----
11
+ class PrintersTest < TestCase
12
+ def setup
13
+ super
14
+ # WALL_TIME, PROCESS_TIME, ALLOCATIONS and MEMORY as types of measuremen
15
+ measure_modes = {wall_time: RubyProf::WALL_TIME, process_time: RubyProf::PROCESS_TIME, allocations: RubyProf::ALLOCATIONS, memory: RubyProf::MEMORY}
16
+
17
+ @results = {}
18
+
19
+ measure_modes.each do |key, value|
20
+ @results[key] = RubyProf::Profile.profile(measure_mode: value) do
21
+ run_primes(1000, 5000)
22
+ end
23
+ end
24
+ end
25
+
26
+ def test_printers
27
+ output = ENV['SHOW_RUBY_PROF_PRINTER_OUTPUT'] == "1" ? STDOUT : StringIO.new('')
28
+
29
+ printer = RubyProf::CallStackPrinter.new(@results[:wall_time])
30
+ printer.print(output)
31
+
32
+ printer = RubyProf::CallTreePrinter.new(@results[:wall_time])
33
+ printer.print(:path => Dir.tmpdir)
34
+
35
+ printer = RubyProf::FlatPrinter.new(@results[:wall_time])
36
+ printer.print(output)
37
+
38
+ printer = RubyProf::GraphHtmlPrinter.new(@results[:wall_time])
39
+ printer.print(output)
40
+
41
+ printer = RubyProf::GraphPrinter.new(@results[:wall_time])
42
+ printer.print(output)
43
+ end
44
+
45
+ def test_print_to_files
46
+ printer = RubyProf::DotPrinter.new(@results[:wall_time])
47
+ File.open("#{Dir.tmpdir}/graph.dot", "w") {|f| printer.print(f)}
48
+
49
+ printer = RubyProf::CallStackPrinter.new(@results[:wall_time])
50
+ File.open("#{Dir.tmpdir}/stack.html", "w") {|f| printer.print(f, :application => "primes")}
51
+
52
+ printer = RubyProf::MultiPrinter.new(@results[:wall_time])
53
+ printer.print(:path => Dir.tmpdir, :profile => "multi", :application => "primes")
54
+
55
+ ['graph.dot', 'multi.flat.txt', 'multi.graph.html', "multi.callgrind.out.#{$$}", 'multi.stack.html', 'stack.html'].each do |file_name|
56
+ file_path = File.join(Dir.tmpdir, file_name)
57
+ refute(File.empty?(file_path))
58
+ end
59
+ end
60
+
61
+ def test_refuses_io_objects
62
+ p = RubyProf::MultiPrinter.new(@results[:wall_time])
63
+ begin
64
+ p.print(STDOUT)
65
+ flunk "should have raised an ArgumentError"
66
+ rescue ArgumentError => e
67
+ assert_match(/IO/, e.to_s)
68
+ end
69
+ end
70
+
71
+ def test_refuses_non_hashes
72
+ p = RubyProf::MultiPrinter.new (@results[:wall_time])
73
+ begin
74
+ p.print([])
75
+ flunk "should have raised an ArgumentError"
76
+ rescue ArgumentError => e
77
+ assert_match(/hash/, e.to_s)
78
+ end
79
+ end
80
+
81
+ def test_flat_string
82
+ output = helper_test_flat_string(RubyProf::FlatPrinter)
83
+ assert_match(/prime.rb/, output)
84
+ end
85
+
86
+ def helper_test_flat_string(klass)
87
+ output = ''
88
+
89
+ printer = klass.new(@results[:wall_time])
90
+ printer.print(output)
91
+
92
+ assert_match(/Thread ID: -?\d+/i, output)
93
+ assert_match(/Fiber ID: -?\d+/i, output)
94
+ assert_match(/Total: \d+\.\d+/i, output)
95
+ assert_match(/Object#run_primes/i, output)
96
+ output
97
+ end
98
+
99
+ def test_graph_html_string
100
+ output = ''
101
+ printer = RubyProf::GraphHtmlPrinter.new(@results[:wall_time])
102
+ printer.print(output)
103
+
104
+ assert_match(/<!DOCTYPE html>/i, output)
105
+ assert_match( %r{<th>Total</th>}i, output)
106
+ assert_match(/Object#run_primes/i, output)
107
+ end
108
+
109
+ def test_graph_string
110
+ output = ''
111
+ printer = RubyProf::GraphPrinter.new(@results[:wall_time])
112
+ printer.print(output)
113
+
114
+ assert_match(/Thread ID: -?\d+/i, output)
115
+ assert_match(/Fiber ID: -?\d+/i, output)
116
+ assert_match(/Total Time: \d+\.\d+/i, output)
117
+ assert_match(/Object#run_primes/i, output)
118
+ end
119
+
120
+ def do_nothing
121
+ start = Time.now
122
+ while(Time.now == start)
123
+ end
124
+ end
125
+
126
+ def test_all_with_small_percentiles
127
+ result = RubyProf::Profile.profile do
128
+ sleep 2
129
+ do_nothing
130
+ end
131
+
132
+ # RubyProf::CallTreePrinter doesn't "do" a min_percent
133
+ # RubyProf::FlatPrinter only outputs if self time > percent...
134
+ for klass in [RubyProf::GraphPrinter, RubyProf::GraphHtmlPrinter]
135
+ printer = klass.new(result)
136
+ out = ''
137
+ printer.print(out, :min_percent => 0.00000001)
138
+ assert_match(/do_nothing/, out)
139
+ end
140
+ end
141
+
142
+ def test_print_footer
143
+ results_keys = [:wall_time, :process_time, :allocations, :memory]
144
+ expected_matches = [
145
+ "The percentage of time spent by this method relative to the total time in the entire program.",
146
+ "The total time spent by this method and its children.",
147
+ "The time spent by this method.",
148
+ "The time spent by this method's children.",
149
+ "The percentage of allocations made by this method relative to the total allocations in the entire program.",
150
+ "The total number of allocations made by this method and its children.",
151
+ "The number of allocations made by this method.",
152
+ "The number of allocations made by this method's children.",
153
+ "The percentage of memory used by this method relative to the total memory in the entire program.",
154
+ "The total memory used by this method and its children.",
155
+ "The memory used by this method.",
156
+ "The memory used by this method's children."
157
+ ]
158
+
159
+ results_keys.each do |key|
160
+ output = ''
161
+ printer = RubyProf::GraphPrinter.new(@results[key])
162
+ printer.print(output)
163
+
164
+ case key
165
+ when :wall_time, :process_time
166
+ matches = expected_matches[0..3]
167
+ when :allocations
168
+ matches = expected_matches[4..7]
169
+ when :memory
170
+ matches = expected_matches[8..11]
171
+ end
172
+
173
+ matches.each do |pattern|
174
+ assert_match(pattern, output)
175
+ end
176
+ end
177
+ end
178
+ end