ruby-prof 0.8.1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/CHANGES +221 -0
  2. data/LICENSE +23 -0
  3. data/README +432 -0
  4. data/Rakefile +159 -0
  5. data/bin/ruby-prof +224 -0
  6. data/examples/flat.txt +55 -0
  7. data/examples/graph.html +823 -0
  8. data/examples/graph.txt +170 -0
  9. data/ext/ruby_prof/measure_allocations.h +58 -0
  10. data/ext/ruby_prof/measure_cpu_time.h +152 -0
  11. data/ext/ruby_prof/measure_gc_runs.h +76 -0
  12. data/ext/ruby_prof/measure_gc_time.h +57 -0
  13. data/ext/ruby_prof/measure_memory.h +101 -0
  14. data/ext/ruby_prof/measure_process_time.h +52 -0
  15. data/ext/ruby_prof/measure_wall_time.h +53 -0
  16. data/ext/ruby_prof/mingw/Rakefile +23 -0
  17. data/ext/ruby_prof/mingw/build.rake +38 -0
  18. data/ext/ruby_prof/ruby_prof.c +1747 -0
  19. data/ext/ruby_prof/ruby_prof.h +188 -0
  20. data/ext/ruby_prof/version.h +4 -0
  21. data/lib/1.8/ruby_prof.so +0 -0
  22. data/lib/1.9/ruby_prof.so +0 -0
  23. data/lib/ruby-prof.rb +56 -0
  24. data/lib/ruby-prof/abstract_printer.rb +41 -0
  25. data/lib/ruby-prof/aggregate_call_info.rb +62 -0
  26. data/lib/ruby-prof/call_info.rb +47 -0
  27. data/lib/ruby-prof/call_tree_printer.rb +84 -0
  28. data/lib/ruby-prof/flat_printer.rb +78 -0
  29. data/lib/ruby-prof/flat_printer_with_line_numbers.rb +72 -0
  30. data/lib/ruby-prof/graph_html_printer.rb +256 -0
  31. data/lib/ruby-prof/graph_printer.rb +157 -0
  32. data/lib/ruby-prof/method_info.rb +111 -0
  33. data/lib/ruby-prof/symbol_to_proc.rb +8 -0
  34. data/lib/ruby-prof/task.rb +146 -0
  35. data/lib/ruby-prof/test.rb +148 -0
  36. data/lib/unprof.rb +8 -0
  37. data/rails/environment/profile.rb +24 -0
  38. data/rails/example/example_test.rb +9 -0
  39. data/rails/profile_test_helper.rb +21 -0
  40. data/test/aggregate_test.rb +121 -0
  41. data/test/basic_test.rb +290 -0
  42. data/test/current_failures_windows +8 -0
  43. data/test/do_nothing.rb +0 -0
  44. data/test/duplicate_names_test.rb +32 -0
  45. data/test/enumerable_test.rb +16 -0
  46. data/test/exceptions_test.rb +15 -0
  47. data/test/exclude_threads_test.rb +54 -0
  48. data/test/exec_test.rb +14 -0
  49. data/test/line_number_test.rb +73 -0
  50. data/test/measurement_test.rb +121 -0
  51. data/test/module_test.rb +54 -0
  52. data/test/no_method_class_test.rb +13 -0
  53. data/test/prime.rb +58 -0
  54. data/test/prime_test.rb +13 -0
  55. data/test/printers_test.rb +130 -0
  56. data/test/recursive_test.rb +275 -0
  57. data/test/ruby-prof-bin +20 -0
  58. data/test/singleton_test.rb +37 -0
  59. data/test/stack_test.rb +138 -0
  60. data/test/start_stop_test.rb +95 -0
  61. data/test/test_suite.rb +23 -0
  62. data/test/thread_test.rb +173 -0
  63. data/test/unique_call_path_test.rb +225 -0
  64. metadata +143 -0
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+ require 'ruby-prof'
4
+ require 'prime'
5
+
6
+ # -- Tests ----
7
+ class PrimeTest< Test::Unit::TestCase
8
+ def test_consistency
9
+ result = RubyProf.profile do
10
+ run_primes
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+ require 'ruby-prof'
4
+ require File.dirname(__FILE__) + '/prime'
5
+
6
+ # -- Tests ----
7
+ class PrintersTest < Test::Unit::TestCase
8
+
9
+ def go
10
+ run_primes
11
+ end
12
+
13
+ def setup
14
+ RubyProf::measure_mode = RubyProf::WALL_TIME # WALL_TIME so we can use sleep in our test
15
+ @result = RubyProf.profile do
16
+ run_primes
17
+ go
18
+ end
19
+
20
+ end
21
+
22
+ def test_printers
23
+ printer = RubyProf::FlatPrinter.new(@result)
24
+ printer.print(STDOUT)
25
+
26
+ printer = RubyProf::FlatPrinterWithLineNumbers.new(@result)
27
+ printer.print(STDOUT)
28
+
29
+ printer = RubyProf::GraphHtmlPrinter.new(@result)
30
+ printer.print
31
+
32
+ printer = RubyProf::GraphPrinter.new(@result)
33
+ printer.print
34
+
35
+ printer = RubyProf::CallTreePrinter.new(@result)
36
+ printer.print(STDOUT)
37
+ # we should get here
38
+ end
39
+
40
+ def test_flat_string
41
+ output = helper_test_flat_string RubyProf::FlatPrinter
42
+ assert_no_match(/prime.rb/, output)
43
+ end
44
+
45
+ def helper_test_flat_string klass
46
+ output = ''
47
+
48
+ printer = klass.new(@result)
49
+ printer.print(output)
50
+
51
+ assert_match(/Thread ID: -?\d+/i, output)
52
+ assert_match(/Total: \d+\.\d+/i, output)
53
+ assert_match(/Object#run_primes/i, output)
54
+ output
55
+ end
56
+
57
+ def test_flat_string_with_numbers
58
+ output = helper_test_flat_string RubyProf::FlatPrinterWithLineNumbers
59
+ assert_match(/prime.rb/, output)
60
+ assert_no_match(/ruby_runtime:0/, output)
61
+ assert_match(/called from/, output)
62
+
63
+ # should combine common parents
64
+ if RUBY_VERSION < '1.9'
65
+ assert_equal(3, output.scan(/Object#is_prime/).length)
66
+ else
67
+ # 1.9
68
+ assert_equal(2, output.scan(/Object#is_prime/).length)
69
+ end
70
+ assert_no_match(/\.\/test\/prime.rb/, output) # don't use relative paths
71
+ end
72
+
73
+ def test_graph_html_string
74
+ output = ''
75
+ printer = RubyProf::GraphHtmlPrinter.new(@result)
76
+ printer.print(output)
77
+
78
+ assert_match( /DTD HTML 4\.01/i, output )
79
+ assert_match( %r{<th>Total Time</th>}i, output )
80
+ assert_match( /Object#run_primes/i, output )
81
+ end
82
+
83
+ def test_graph_string
84
+ output = ''
85
+ printer = RubyProf::GraphPrinter.new(@result)
86
+ printer.print(output)
87
+
88
+ assert_match( /Thread ID: -?\d+/i, output )
89
+ assert_match( /Total Time: \d+\.\d+/i, output )
90
+ assert_match( /Object#run_primes/i, output )
91
+ end
92
+
93
+ def test_call_tree_string
94
+ output = ''
95
+ printer = RubyProf::CallTreePrinter.new(@result)
96
+ printer.print(output)
97
+
98
+ assert_match(/fn=Object::find_primes/i, output)
99
+ assert_match(/events: wall_time/i, output)
100
+ end
101
+
102
+ def do_nothing
103
+ start = Time.now
104
+ while(Time.now == start)
105
+ end
106
+ end
107
+
108
+ def test_all_with_small_percentiles
109
+
110
+ result = RubyProf.profile do
111
+ sleep 2
112
+ do_nothing
113
+ end
114
+
115
+ # RubyProf::CallTreePrinter doesn't "do" a min_percent
116
+ # RubyProf::FlatPrinter only outputs if self time > percent...
117
+ # RubyProf::FlatPrinterWithLineNumbers same
118
+ for klass in [ RubyProf::GraphPrinter, RubyProf::GraphHtmlPrinter]
119
+ puts klass
120
+ printer = klass.new(result)
121
+ out = ''
122
+ output = printer.print(out, :min_percent => 0.00000001 )
123
+ assert_match(/do_nothing/, out)
124
+ end
125
+
126
+ end
127
+
128
+
129
+
130
+ end
@@ -0,0 +1,275 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+ require 'ruby-prof'
4
+
5
+ def simple(n)
6
+ sleep(1)
7
+ n -= 1
8
+ return if n == 0
9
+ simple(n)
10
+ end
11
+
12
+ def cycle(n)
13
+ sub_cycle(n)
14
+ end
15
+
16
+ def sub_cycle(n)
17
+ sleep(1)
18
+ n -= 1
19
+ return if n == 0
20
+ cycle(n)
21
+ end
22
+
23
+
24
+ # -- Tests ----
25
+ class RecursiveTest < Test::Unit::TestCase
26
+ def setup
27
+ # Need to use wall time for this test due to the sleep calls
28
+ RubyProf::measure_mode = RubyProf::WALL_TIME
29
+ end
30
+
31
+ def test_simple
32
+ result = RubyProf.profile do
33
+ simple(2)
34
+ end
35
+
36
+ methods = result.threads.values.first.sort.reverse
37
+
38
+ if RUBY_VERSION < '1.9'
39
+ assert_equal(6, methods.length) # includes Fixnum+, Fixnum==...
40
+ else
41
+ assert_equal(4, methods.length)
42
+ end
43
+
44
+ method = methods[0]
45
+ assert_equal('RecursiveTest#test_simple', method.full_name)
46
+ assert_equal(1, method.called)
47
+ assert_in_delta(2, method.total_time, 0.05)
48
+ assert_in_delta(0, method.self_time, 0.01)
49
+ assert_in_delta(0, method.wait_time, 0.01)
50
+ assert_in_delta(2, method.children_time, 0.05)
51
+
52
+ assert_equal(1, method.call_infos.length)
53
+ call_info = method.call_infos[0]
54
+ assert_equal('RecursiveTest#test_simple', call_info.call_sequence)
55
+ assert_equal(1, call_info.children.length)
56
+
57
+ method = methods[1]
58
+ assert_equal('Object#simple', method.full_name)
59
+ assert_equal(1, method.called)
60
+ assert_in_delta(2, method.total_time, 0.02)
61
+ assert_in_delta(0, method.self_time, 0.02)
62
+ assert_in_delta(0, method.wait_time, 0.02)
63
+ assert_in_delta(2, method.children_time, 0.02)
64
+
65
+ assert_equal(1, method.call_infos.length)
66
+ call_info = method.call_infos[0]
67
+ assert_equal('RecursiveTest#test_simple->Object#simple', call_info.call_sequence)
68
+ if RUBY_VERSION < '1.9'
69
+ assert_equal(4, call_info.children.length)
70
+ else
71
+ assert_equal(2, call_info.children.length)
72
+ end
73
+ method = methods[2]
74
+ assert_equal('Kernel#sleep', method.full_name)
75
+ assert_equal(2, method.called)
76
+ assert_in_delta(2, method.total_time, 0.01)
77
+ assert_in_delta(2, method.self_time, 0.01)
78
+ assert_in_delta(0, method.wait_time, 0.01)
79
+ assert_in_delta(0, method.children_time, 0.01)
80
+
81
+ assert_equal(2, method.call_infos.length)
82
+ call_info = method.call_infos[0]
83
+ assert_equal('RecursiveTest#test_simple->Object#simple->Kernel#sleep', call_info.call_sequence)
84
+ assert_equal(0, call_info.children.length)
85
+
86
+ call_info = method.call_infos[1]
87
+ assert_equal('RecursiveTest#test_simple->Object#simple->Object#simple(d1)->Kernel#sleep', call_info.call_sequence)
88
+ assert_equal(0, call_info.children.length)
89
+
90
+ method = methods[3]
91
+ assert_equal('Object#simple(d1)', method.full_name)
92
+ assert_equal(1, method.called)
93
+ assert_in_delta(1, method.total_time, 0.01)
94
+ assert_in_delta(0, method.self_time, 0.01)
95
+ assert_in_delta(0, method.wait_time, 0.01)
96
+ assert_in_delta(1, method.children_time, 0.01)
97
+
98
+ assert_equal(1, method.call_infos.length)
99
+ call_info = method.call_infos[0]
100
+ assert_equal('RecursiveTest#test_simple->Object#simple->Object#simple(d1)', call_info.call_sequence)
101
+ if RUBY_VERSION < '1.9'
102
+ assert_equal(3, call_info.children.length)
103
+
104
+ method = methods[4]
105
+ assert_equal('Fixnum#-', method.full_name)
106
+ assert_equal(2, method.called)
107
+ assert_in_delta(0, method.total_time, 0.01)
108
+ assert_in_delta(0, method.self_time, 0.01)
109
+ assert_in_delta(0, method.wait_time, 0.01)
110
+ assert_in_delta(0, method.children_time, 0.01)
111
+
112
+ assert_equal(2, method.call_infos.length)
113
+ call_info = method.call_infos[0]
114
+ assert_equal('RecursiveTest#test_simple->Object#simple->Fixnum#-', call_info.call_sequence)
115
+ assert_equal(0, call_info.children.length)
116
+
117
+ call_info = method.call_infos[1]
118
+ assert_equal('RecursiveTest#test_simple->Object#simple->Object#simple(d1)->Fixnum#-', call_info.call_sequence)
119
+ assert_equal(0, call_info.children.length)
120
+
121
+ method = methods[5]
122
+ assert_equal('Fixnum#==', method.full_name)
123
+ assert_equal(2, method.called)
124
+ assert_in_delta(0, method.total_time, 0.01)
125
+ assert_in_delta(0, method.self_time, 0.01)
126
+ assert_in_delta(0, method.wait_time, 0.01)
127
+ assert_in_delta(0, method.children_time, 0.01)
128
+
129
+ assert_equal(2, method.call_infos.length)
130
+ call_info = method.call_infos[0]
131
+ assert_equal('RecursiveTest#test_simple->Object#simple->Fixnum#==', call_info.call_sequence)
132
+ assert_equal(0, call_info.children.length)
133
+
134
+ call_info = method.call_infos[1]
135
+ assert_equal('RecursiveTest#test_simple->Object#simple->Object#simple(d1)->Fixnum#==', call_info.call_sequence)
136
+ assert_equal(0, call_info.children.length)
137
+
138
+ else
139
+ assert_equal(1, call_info.children.length)
140
+ end
141
+ end
142
+
143
+ def test_cycle
144
+ result = RubyProf.profile do
145
+ cycle(2)
146
+ end
147
+
148
+ methods = result.threads.values.first.sort.reverse
149
+ if RUBY_VERSION < '1.9'
150
+ assert_equal(8, methods.length) # includes Fixnum+ and Fixnum==, which aren't included in 1.9
151
+ else
152
+ assert_equal(6, methods.length)
153
+ end
154
+ method = methods[0]
155
+ assert_equal('RecursiveTest#test_cycle', method.full_name)
156
+ assert_equal(1, method.called)
157
+ assert_in_delta(2, method.total_time, 0.05)
158
+ assert_in_delta(0, method.self_time, 0.01)
159
+ assert_in_delta(0, method.wait_time, 0.01)
160
+ assert_in_delta(2, method.children_time, 0.05)
161
+
162
+ assert_equal(1, method.call_infos.length)
163
+ call_info = method.call_infos[0]
164
+ assert_equal('RecursiveTest#test_cycle', call_info.call_sequence)
165
+ assert_equal(1, call_info.children.length)
166
+
167
+ method = methods[1]
168
+ assert_equal('Object#cycle', method.full_name)
169
+ assert_equal(1, method.called)
170
+ assert_in_delta(2, method.total_time, 0.05)
171
+ assert_in_delta(0, method.self_time, 0.01)
172
+ assert_in_delta(0, method.wait_time, 0.01)
173
+ assert_in_delta(2, method.children_time, 0.05)
174
+
175
+ assert_equal(1, method.call_infos.length)
176
+ call_info = method.call_infos[0]
177
+ assert_equal('RecursiveTest#test_cycle->Object#cycle', call_info.call_sequence)
178
+ assert_equal(1, call_info.children.length)
179
+
180
+ method = methods[2]
181
+ assert_equal('Object#sub_cycle', method.full_name)
182
+ assert_equal(1, method.called)
183
+ assert_in_delta(2, method.total_time, 0.05)
184
+ assert_in_delta(0, method.self_time, 0.05)
185
+ assert_in_delta(0, method.wait_time, 0.05)
186
+ assert_in_delta(2, method.children_time, 0.05)
187
+
188
+ assert_equal(1, method.call_infos.length)
189
+ call_info = method.call_infos[0]
190
+ assert_equal('RecursiveTest#test_cycle->Object#cycle->Object#sub_cycle', call_info.call_sequence)
191
+ if RUBY_VERSION < '1.9'
192
+ assert_equal(4, call_info.children.length)
193
+ else
194
+ assert_equal(2, call_info.children.length)
195
+ end
196
+
197
+ method = methods[3]
198
+ assert_equal('Kernel#sleep', method.full_name)
199
+ assert_equal(2, method.called)
200
+ assert_in_delta(2, method.total_time, 0.05)
201
+ assert_in_delta(2, method.self_time, 0.05)
202
+ assert_in_delta(0, method.wait_time, 0.01)
203
+ assert_in_delta(0, method.children_time, 0.01)
204
+
205
+ assert_equal(2, method.call_infos.length)
206
+ call_info = method.call_infos[0]
207
+ assert_equal('RecursiveTest#test_cycle->Object#cycle->Object#sub_cycle->Kernel#sleep', call_info.call_sequence)
208
+ assert_equal(0, call_info.children.length)
209
+
210
+ call_info = method.call_infos[1]
211
+ assert_equal('RecursiveTest#test_cycle->Object#cycle->Object#sub_cycle->Object#cycle(d1)->Object#sub_cycle(d1)->Kernel#sleep', call_info.call_sequence)
212
+ assert_equal(0, call_info.children.length)
213
+
214
+ method = methods[4]
215
+ assert_equal('Object#cycle(d1)', method.full_name)
216
+ assert_equal(1, method.called)
217
+ assert_in_delta(1, method.total_time, 0.05)
218
+ assert_in_delta(0, method.self_time, 0.01)
219
+ assert_in_delta(0, method.wait_time, 0.01)
220
+ assert_in_delta(1, method.children_time, 0.05)
221
+
222
+ assert_equal(1, method.call_infos.length)
223
+ call_info = method.call_infos[0]
224
+ assert_equal('RecursiveTest#test_cycle->Object#cycle->Object#sub_cycle->Object#cycle(d1)', call_info.call_sequence)
225
+ assert_equal(1, call_info.children.length)
226
+
227
+ method = methods[5]
228
+ assert_equal('Object#sub_cycle(d1)', method.full_name)
229
+ assert_equal(1, method.called)
230
+ assert_in_delta(1, method.total_time, 0.01)
231
+ assert_in_delta(0, method.self_time, 0.01)
232
+ assert_in_delta(0, method.wait_time, 0.01)
233
+ call_info = method.call_infos[0]
234
+ assert_equal('RecursiveTest#test_cycle->Object#cycle->Object#sub_cycle->Object#cycle(d1)->Object#sub_cycle(d1)', call_info.call_sequence)
235
+ if RUBY_VERSION < '1.9'
236
+ assert_equal(3, call_info.children.length)
237
+ method = methods[6]
238
+ assert_equal('Fixnum#-', method.full_name)
239
+ assert_equal(2, method.called)
240
+ assert_in_delta(0, method.total_time, 0.01)
241
+ assert_in_delta(0, method.self_time, 0.01)
242
+ assert_in_delta(0, method.wait_time, 0.01)
243
+ assert_in_delta(0, method.children_time, 0.01)
244
+
245
+ assert_equal(2, method.call_infos.length)
246
+ call_info = method.call_infos[0]
247
+ assert_equal('RecursiveTest#test_cycle->Object#cycle->Object#sub_cycle->Fixnum#-', call_info.call_sequence)
248
+ assert_equal(0, call_info.children.length)
249
+
250
+ call_info = method.call_infos[1]
251
+ assert_equal('RecursiveTest#test_cycle->Object#cycle->Object#sub_cycle->Object#cycle(d1)->Object#sub_cycle(d1)->Fixnum#-', call_info.call_sequence)
252
+ assert_equal(0, call_info.children.length)
253
+
254
+ method = methods[7]
255
+ assert_equal('Fixnum#==', method.full_name)
256
+ assert_equal(2, method.called)
257
+ assert_in_delta(0, method.total_time, 0.01)
258
+ assert_in_delta(0, method.self_time, 0.01)
259
+ assert_in_delta(0, method.wait_time, 0.01)
260
+ assert_in_delta(0, method.children_time, 0.01)
261
+
262
+ assert_equal(2, method.call_infos.length)
263
+ call_info = method.call_infos[0]
264
+ assert_equal('RecursiveTest#test_cycle->Object#cycle->Object#sub_cycle->Fixnum#==', call_info.call_sequence)
265
+ assert_equal(0, call_info.children.length)
266
+
267
+ call_info = method.call_infos[1]
268
+ assert_equal('RecursiveTest#test_cycle->Object#cycle->Object#sub_cycle->Object#cycle(d1)->Object#sub_cycle(d1)->Fixnum#==', call_info.call_sequence)
269
+ assert_equal(0, call_info.children.length)
270
+ else
271
+ assert_equal(1, call_info.children.length)
272
+ end
273
+
274
+ end
275
+ end
@@ -0,0 +1,20 @@
1
+ #!E:/installs/ruby191p376/bin/ruby.exe
2
+ #
3
+ # This file was generated by RubyGems.
4
+ #
5
+ # The application 'ruby-prof' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'rubygems'
10
+
11
+ version = ">= 0"
12
+
13
+ if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
14
+ version = $1
15
+ ARGV.shift
16
+ end
17
+
18
+ #gem 'ruby-prof', version
19
+ $: << File.dirname(__FILE__) + '/../lib'
20
+ load File.dirname(__FILE__) + '/../bin/ruby-prof'
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'ruby-prof'
5
+ require 'timeout'
6
+
7
+ # -- Test for bug [#5657]
8
+ # http://rubyforge.org/tracker/index.php?func=detail&aid=5657&group_id=1814&atid=7060
9
+
10
+
11
+ class A
12
+ attr_accessor :as
13
+ def initialize
14
+ @as = []
15
+ class << @as
16
+ def <<(an_a)
17
+ super
18
+ end
19
+ end
20
+ end
21
+
22
+ def <<(an_a)
23
+ @as << an_a
24
+ end
25
+ end
26
+
27
+ class SingletonTest < Test::Unit::TestCase
28
+ def test_singleton
29
+ result = RubyProf.profile do
30
+ a = A.new
31
+ a << :first_thing
32
+ assert_equal(1, a.as.size)
33
+ end
34
+ printer = RubyProf::FlatPrinter.new(result)
35
+ printer.print(STDOUT)
36
+ end
37
+ end