ruby-prof 0.6.0-x86-mswin32-60

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 (50) hide show
  1. data/CHANGES +116 -0
  2. data/LICENSE +23 -0
  3. data/README +307 -0
  4. data/Rakefile +141 -0
  5. data/bin/ruby-prof +192 -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/extconf.rb +21 -0
  10. data/ext/extconf.rb.rej +13 -0
  11. data/ext/measure_allocations.h +43 -0
  12. data/ext/measure_cpu_time.h +138 -0
  13. data/ext/measure_memory.h +42 -0
  14. data/ext/measure_process_time.h +41 -0
  15. data/ext/measure_wall_time.h +42 -0
  16. data/ext/ruby_prof.c +1628 -0
  17. data/lib/ruby-prof.rb +43 -0
  18. data/lib/ruby-prof/abstract_printer.rb +42 -0
  19. data/lib/ruby-prof/call_tree_printer.rb +76 -0
  20. data/lib/ruby-prof/call_tree_printer.rb.rej +27 -0
  21. data/lib/ruby-prof/flat_printer.rb +79 -0
  22. data/lib/ruby-prof/graph_html_printer.rb +255 -0
  23. data/lib/ruby-prof/graph_printer.rb +163 -0
  24. data/lib/ruby-prof/profile_test_case.rb +80 -0
  25. data/lib/ruby-prof/task.rb +147 -0
  26. data/lib/ruby_prof.so +0 -0
  27. data/lib/unprof.rb +8 -0
  28. data/rails_plugin/ruby-prof/init.rb +8 -0
  29. data/rails_plugin/ruby-prof/lib/profiling.rb +57 -0
  30. data/test/basic_test.rb +190 -0
  31. data/test/duplicate_names_test.rb +33 -0
  32. data/test/line_number_test.rb +69 -0
  33. data/test/measure_mode_test.rb +79 -0
  34. data/test/module_test.rb +57 -0
  35. data/test/no_method_class_test.rb +14 -0
  36. data/test/prime.rb +60 -0
  37. data/test/prime1.rb +17 -0
  38. data/test/prime2.rb +26 -0
  39. data/test/prime3.rb +17 -0
  40. data/test/prime_test.rb +24 -0
  41. data/test/printers_test.rb +74 -0
  42. data/test/profile_unit_test.rb +24 -0
  43. data/test/recursive_test.rb +144 -0
  44. data/test/singleton_test.rb +38 -0
  45. data/test/start_test.rb +24 -0
  46. data/test/test_helper.rb +55 -0
  47. data/test/test_suite.rb +19 -0
  48. data/test/thread_test.rb +135 -0
  49. data/test/timing_test.rb +133 -0
  50. metadata +116 -0
@@ -0,0 +1,190 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'ruby-prof'
5
+ require 'test_helper'
6
+
7
+ # Need to use wall time for this test due to the sleep calls
8
+ RubyProf::measure_mode = RubyProf::WALL_TIME
9
+
10
+ class C1
11
+ def C1.hello
12
+ sleep(0.1)
13
+ end
14
+
15
+ def hello
16
+ sleep(0.2)
17
+ end
18
+ end
19
+
20
+ module M1
21
+ def hello
22
+ sleep(0.3)
23
+ end
24
+ end
25
+
26
+ class C2
27
+ include M1
28
+ extend M1
29
+ end
30
+
31
+ class C3
32
+ def hello
33
+ sleep(0.4)
34
+ end
35
+ end
36
+
37
+ module M4
38
+ def hello
39
+ sleep(0.5)
40
+ end
41
+ end
42
+
43
+ module M5
44
+ include M4
45
+ def goodbye
46
+ hello
47
+ end
48
+ end
49
+
50
+ class C6
51
+ include M5
52
+ def test
53
+ goodbye
54
+ end
55
+ end
56
+
57
+ class BasicTest < Test::Unit::TestCase
58
+ def test_running
59
+ assert(!RubyProf.running?)
60
+ RubyProf.start
61
+ assert(RubyProf.running?)
62
+ RubyProf.stop
63
+ assert(!RubyProf.running?)
64
+ end
65
+
66
+ def test_double_profile
67
+ RubyProf.start
68
+ assert_raise(RuntimeError) do
69
+ RubyProf.start
70
+ end
71
+
72
+ assert_raise(RuntimeError) do
73
+ RubyProf.profile do
74
+ puts 1
75
+ end
76
+ end
77
+ RubyProf.stop
78
+ end
79
+
80
+ def test_no_block
81
+ assert_raise(ArgumentError) do
82
+ RubyProf.profile
83
+ end
84
+ end
85
+
86
+ def test_class_and_instance_methods
87
+ result = RubyProf.profile do
88
+ C1.hello
89
+ C1.new.hello
90
+ end
91
+
92
+ methods = result.threads.values.first
93
+
94
+ # Length should be 7:
95
+ # 1 test_class_and_instance_methods (this method)
96
+ # 1 Class.new
97
+ # 1 Class:Object allocate
98
+ # 1 for Object.initialize
99
+ # 1 for Class hello
100
+ # 1 for Object hello
101
+ # 1 sleep
102
+ assert_equal(7, methods.length)
103
+
104
+ # Check the names
105
+ methods = methods.sort.reverse
106
+
107
+ assert_equal('BasicTest#test_class_and_instance_methods', methods[0].full_name)
108
+ assert_equal('Kernel#sleep', methods[1].full_name)
109
+ assert_equal('C1#hello', methods[2].full_name)
110
+ assert_equal('<Class::C1>#hello', methods[3].full_name)
111
+
112
+ # The last three methods have total times of zero
113
+ assert_equal(0, methods[4].total_time)
114
+ assert_equal(0, methods[5].total_time)
115
+ assert_equal(0, methods[6].total_time)
116
+
117
+ #assert_equal('Class#new', methods[4].full_name)
118
+ #assert_equal('<Class::Object>#allocate', methods[5].full_name)
119
+ #assert_equal('Object#initialize', methods[6].full_name)
120
+ end
121
+
122
+ def test_module_methods
123
+ result = RubyProf.profile do
124
+ C2.hello
125
+ C2.new.hello
126
+ end
127
+
128
+ methods = result.threads.values.first
129
+
130
+ # Length should be 6:
131
+ # 1 BasicTest#test_module_methods (this method)
132
+ # 1 Class#new
133
+ # 1 <Class::Object>#allocate
134
+ # 1 Object#initialize
135
+ # 1 M1#hello
136
+ # 1 Kernel#sleep
137
+
138
+ assert_equal(6, methods.length)
139
+
140
+ # Check the names
141
+ methods = methods.sort.reverse
142
+
143
+ assert_equal('BasicTest#test_module_methods', methods[0].full_name)
144
+ assert_equal('Kernel#sleep', methods[1].full_name)
145
+ assert_equal('M1#hello', methods[2].full_name)
146
+
147
+ # The last three methods have times of zero
148
+ assert_equal(0, methods[3].total_time)
149
+ assert_equal(0, methods[4].total_time)
150
+ assert_equal(0, methods[5].total_time)
151
+
152
+ #assert_equal('<Class::Object>#allocate', methods[3].full_name)
153
+ #assert_equal('Class#new', methods[4].full_name)
154
+ #assert_equal('Object#initialize', methods[5].full_name)
155
+ end
156
+
157
+ def test_singleton
158
+ c3 = C3.new
159
+
160
+ class << c3
161
+ def hello
162
+ end
163
+ end
164
+
165
+ result = RubyProf.profile do
166
+ c3.hello
167
+ end
168
+
169
+ methods = result.threads.values.first
170
+
171
+ # Length should be 2 - one for top level
172
+ # and one for the singleton method.
173
+ assert_equal(2, methods.length)
174
+
175
+ # Check singleton method
176
+ methods = methods.sort.reverse
177
+
178
+ assert_equal('BasicTest#test_singleton', methods[0].full_name)
179
+ assert_equal('<Object::C3>#hello', methods[1].full_name)
180
+ end
181
+
182
+ def test_traceback
183
+ RubyProf.start
184
+ assert_raise(NoMethodError) do
185
+ RubyProf.xxx
186
+ end
187
+
188
+ RubyProf.stop
189
+ end
190
+ end
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'ruby-prof'
5
+ require 'test_helper'
6
+
7
+ class DuplicateNames < Test::Unit::TestCase
8
+ def test_names
9
+ result = RubyProf::profile do
10
+ str = %{module Foo; class Bar; def foo; end end end}
11
+
12
+ eval str
13
+ Foo::Bar.new.foo
14
+ DuplicateNames.class_eval {remove_const :Foo}
15
+
16
+ eval str
17
+ Foo::Bar.new.foo
18
+ DuplicateNames.class_eval {remove_const :Foo}
19
+
20
+ eval str
21
+ Foo::Bar.new.foo
22
+ end
23
+
24
+ # There should be 3 foo methods
25
+ methods = result.threads.values.first
26
+
27
+ methods = methods.select do |method|
28
+ method.full_name == 'DuplicateNames::Foo::Bar#foo'
29
+ end
30
+
31
+ assert_equal(3, methods.length)
32
+ end
33
+ end
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'ruby-prof'
5
+ require 'prime'
6
+ require 'test_helper'
7
+
8
+ class LineNumbers
9
+ def method1
10
+ a = 3
11
+ end
12
+
13
+ def method2
14
+ method1
15
+ end
16
+
17
+ def method3
18
+ sleep(1)
19
+ end
20
+ end
21
+
22
+ # -- Tests ----
23
+ class LineNumbersTest < Test::Unit::TestCase
24
+ def test_function_line_no
25
+ numbers = LineNumbers.new
26
+
27
+ result = RubyProf.profile do
28
+ numbers.method2
29
+ end
30
+
31
+ methods = result.threads.values.first.sort.reverse
32
+ assert_equal(3, methods.length)
33
+
34
+ method = methods[0]
35
+ assert_equal('LineNumbersTest#test_function_line_no', method.full_name)
36
+ assert_equal(28, method.line)
37
+
38
+ method = methods[1]
39
+ assert_equal('LineNumbers#method1', method.full_name)
40
+ assert_equal(9, method.line)
41
+
42
+ method = methods[2]
43
+ assert_equal('LineNumbers#method2', method.full_name)
44
+ assert_equal(13, method.line)
45
+ end
46
+
47
+ def test_c_function
48
+ numbers = LineNumbers.new
49
+
50
+ result = RubyProf.profile do
51
+ numbers.method3
52
+ end
53
+
54
+ methods = result.threads.values.first.sort.reverse
55
+ assert_equal(3, methods.length)
56
+
57
+ method = methods[0]
58
+ assert_equal('LineNumbersTest#test_c_function', method.full_name)
59
+ assert_equal(51, method.line)
60
+
61
+ method = methods[1]
62
+ assert_equal('LineNumbers#method3', method.full_name)
63
+ assert_equal(17, method.line)
64
+
65
+ method = methods[2]
66
+ assert_equal('Kernel#sleep', method.full_name)
67
+ assert_equal(0, method.line)
68
+ end
69
+ end
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'ruby-prof'
5
+ require 'test_helper'
6
+ require 'prime'
7
+
8
+
9
+ # -- Tests ----
10
+ class MeasureModeTest < Test::Unit::TestCase
11
+
12
+ def test_process_time
13
+ RubyProf::measure_mode = RubyProf::PROCESS_TIME
14
+ assert_equal(RubyProf::PROCESS_TIME, RubyProf::measure_mode)
15
+ result = RubyProf.profile do
16
+ run_primes
17
+ end
18
+
19
+ result.threads.each do |thread_id, methods|
20
+ methods.each do |method|
21
+ check_parent_times(method)
22
+ check_parent_calls(method)
23
+ check_child_times(method)
24
+ end
25
+ end
26
+ end
27
+
28
+ def test_wall_time
29
+ RubyProf::measure_mode = RubyProf::WALL_TIME
30
+ assert_equal(RubyProf::WALL_TIME, RubyProf::measure_mode)
31
+ result = RubyProf.profile do
32
+ run_primes
33
+ end
34
+
35
+ result.threads.values.each do |methods|
36
+ methods.each do |method|
37
+ check_parent_times(method)
38
+ check_parent_calls(method)
39
+ check_child_times(method)
40
+ end
41
+ end
42
+ end
43
+
44
+ def test_cpu
45
+ return unless RubyProf.constants.include?('CPU_TIME')
46
+
47
+ RubyProf::measure_mode = RubyProf::CPU_TIME
48
+ assert_equal(RubyProf::CPU_TIME, RubyProf::measure_mode)
49
+ result = RubyProf.profile do
50
+ run_primes
51
+ end
52
+
53
+ result.threads.values.each do |methods|
54
+ methods.each do |method|
55
+ check_parent_times(method)
56
+ check_parent_calls(method)
57
+ check_child_times(method)
58
+ end
59
+ end
60
+ end
61
+
62
+ def test_allocated_objects
63
+ return if RubyProf::ALLOCATIONS.nil?
64
+
65
+ RubyProf::measure_mode = RubyProf::ALLOCATIONS
66
+
67
+ assert_equal(RubyProf::ALLOCATIONS, RubyProf::measure_mode)
68
+
69
+ result = RubyProf.profile do
70
+ Array.new
71
+ end
72
+ end
73
+
74
+ def test_invalid
75
+ assert_raise(ArgumentError) do
76
+ RubyProf::measure_mode = 7777
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'ruby-prof'
5
+ require 'test_helper'
6
+
7
+ # Need to use wall time for this test due to the sleep calls
8
+ RubyProf::measure_mode = RubyProf::WALL_TIME
9
+
10
+ module Foo
11
+ def Foo::hello
12
+ sleep(0.5)
13
+ end
14
+ end
15
+
16
+ module Bar
17
+ def Bar::hello
18
+ sleep(0.5)
19
+ Foo::hello
20
+ end
21
+
22
+ def hello
23
+ sleep(0.5)
24
+ Bar::hello
25
+ end
26
+ end
27
+
28
+ include Bar
29
+
30
+ class ModuleTest < Test::Unit::TestCase
31
+ def test_nested_modules
32
+ result = RubyProf.profile do
33
+ hello
34
+ end
35
+
36
+ methods = result.threads.values.first
37
+ methods = methods.sort.reverse
38
+
39
+ # Length should be 4
40
+ assert_equal(5, methods.length)
41
+
42
+ method = methods[0]
43
+ assert_equal('ModuleTest#test_nested_modules', method.full_name)
44
+
45
+ method = methods[1]
46
+ assert_equal('Kernel#sleep', method.full_name)
47
+
48
+ method = methods[2]
49
+ assert_equal('Bar#hello', method.full_name)
50
+
51
+ method = methods[3]
52
+ assert_equal('<Module::Bar>#hello', method.full_name)
53
+
54
+ method = methods[4]
55
+ assert_equal('<Module::Foo>#hello', method.full_name)
56
+ end
57
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ruby-prof'
4
+
5
+ # Make sure this works with no class or method
6
+ result = RubyProf.profile do
7
+ sleep 1
8
+ end
9
+
10
+ method = result.threads.values.first.sort.last
11
+
12
+ if method.full_name != 'Global#[No method]'
13
+ raise(RuntimeError, "Wrong method name. Expected: Global#[No method]. Actual: #{method.full_name}")
14
+ end