ruby-prof 2.0.4 → 2.0.5

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 (85) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -2
  3. data/lib/ruby-prof/printers/flame_graph_printer.rb +80 -78
  4. data/lib/ruby-prof/version.rb +1 -1
  5. metadata +4 -85
  6. data/Rakefile +0 -98
  7. data/docs/advanced-usage.md +0 -132
  8. data/docs/alternatives.md +0 -98
  9. data/docs/architecture.md +0 -304
  10. data/docs/best-practices.md +0 -27
  11. data/docs/getting-started.md +0 -130
  12. data/docs/history.md +0 -11
  13. data/docs/index.md +0 -45
  14. data/docs/profiling-rails.md +0 -64
  15. data/docs/public/examples/example.rb +0 -33
  16. data/docs/public/examples/generate_reports.rb +0 -92
  17. data/docs/public/examples/reports/call_info.txt +0 -27
  18. data/docs/public/examples/reports/call_stack.html +0 -835
  19. data/docs/public/examples/reports/callgrind.out +0 -150
  20. data/docs/public/examples/reports/flame_graph.html +0 -408
  21. data/docs/public/examples/reports/flat.txt +0 -45
  22. data/docs/public/examples/reports/graph.dot +0 -129
  23. data/docs/public/examples/reports/graph.html +0 -1319
  24. data/docs/public/examples/reports/graph.txt +0 -100
  25. data/docs/public/examples/reports/graphviz_viewer.html +0 -1
  26. data/docs/public/images/call_stack.png +0 -0
  27. data/docs/public/images/class_diagram.png +0 -0
  28. data/docs/public/images/dot_printer.png +0 -0
  29. data/docs/public/images/flame_graph.png +0 -0
  30. data/docs/public/images/flat.png +0 -0
  31. data/docs/public/images/graph.png +0 -0
  32. data/docs/public/images/graph_html.png +0 -0
  33. data/docs/public/images/ruby-prof-logo.svg +0 -1
  34. data/docs/reports.md +0 -151
  35. data/docs/stylesheets/extra.css +0 -80
  36. data/ruby-prof.gemspec +0 -66
  37. data/test/abstract_printer_test.rb +0 -25
  38. data/test/alias_test.rb +0 -203
  39. data/test/call_tree_builder.rb +0 -126
  40. data/test/call_tree_test.rb +0 -94
  41. data/test/call_tree_visitor_test.rb +0 -27
  42. data/test/call_trees_test.rb +0 -66
  43. data/test/duplicate_names_test.rb +0 -32
  44. data/test/dynamic_method_test.rb +0 -50
  45. data/test/enumerable_test.rb +0 -23
  46. data/test/exceptions_test.rb +0 -24
  47. data/test/exclude_methods_test.rb +0 -363
  48. data/test/exclude_threads_test.rb +0 -48
  49. data/test/fiber_test.rb +0 -195
  50. data/test/gc_test.rb +0 -104
  51. data/test/inverse_call_tree_test.rb +0 -174
  52. data/test/line_number_test.rb +0 -563
  53. data/test/marshal_test.rb +0 -144
  54. data/test/measure_allocations.rb +0 -26
  55. data/test/measure_allocations_test.rb +0 -1511
  56. data/test/measure_process_time_test.rb +0 -3286
  57. data/test/measure_times.rb +0 -56
  58. data/test/measure_wall_time_test.rb +0 -774
  59. data/test/measurement_test.rb +0 -82
  60. data/test/merge_test.rb +0 -146
  61. data/test/method_info_test.rb +0 -100
  62. data/test/multi_printer_test.rb +0 -52
  63. data/test/no_method_class_test.rb +0 -15
  64. data/test/pause_resume_test.rb +0 -171
  65. data/test/prime.rb +0 -54
  66. data/test/prime_script.rb +0 -6
  67. data/test/printer_call_stack_test.rb +0 -28
  68. data/test/printer_call_tree_test.rb +0 -30
  69. data/test/printer_flame_graph_test.rb +0 -82
  70. data/test/printer_flat_test.rb +0 -110
  71. data/test/printer_graph_html_test.rb +0 -62
  72. data/test/printer_graph_test.rb +0 -42
  73. data/test/printers_test.rb +0 -162
  74. data/test/printing_recursive_graph_test.rb +0 -81
  75. data/test/profile_test.rb +0 -101
  76. data/test/rack_test.rb +0 -103
  77. data/test/recursive_test.rb +0 -796
  78. data/test/scheduler.rb +0 -367
  79. data/test/singleton_test.rb +0 -39
  80. data/test/stack_printer_test.rb +0 -61
  81. data/test/start_stop_test.rb +0 -106
  82. data/test/test_helper.rb +0 -24
  83. data/test/thread_test.rb +0 -229
  84. data/test/unique_call_path_test.rb +0 -123
  85. data/test/yarv_test.rb +0 -56
data/test/thread_test.rb DELETED
@@ -1,229 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- require File.expand_path('../test_helper', __FILE__)
5
- require_relative './call_tree_builder'
6
-
7
- # -- Tests ----
8
- class ThreadTest < TestCase
9
- def test_initialize
10
- method_info = RubyProf::MethodInfo.new(Array, :size)
11
- call_tree = RubyProf::CallTree.new(method_info)
12
- thread = RubyProf::Thread.new(call_tree, Thread.current, Fiber.current)
13
-
14
- assert_equal(call_tree, thread.call_tree)
15
- assert(thread)
16
- assert(thread.id)
17
- assert(thread.fiber_id)
18
-
19
- assert_equal(1, thread.methods.size)
20
- assert_same(method_info, thread.methods[0])
21
- end
22
-
23
- def test_merge
24
- call_tree_1 = create_call_tree_1
25
- thread_1 = RubyProf::Thread.new(call_tree_1, Thread.current, Fiber.current)
26
- assert_equal(6, thread_1.methods.size)
27
-
28
- call_tree_2 = create_call_tree_2
29
- thread_2 = RubyProf::Thread.new(call_tree_2, Thread.current, Fiber.current)
30
- assert_equal(6, thread_2.methods.size)
31
-
32
- thread_1.merge!(thread_2)
33
- assert_equal(7, thread_1.methods.size)
34
-
35
- # Method times
36
- assert_in_delta(11.6, thread_1.methods[0].total_time, 0.00001) # root
37
- assert_in_delta(4.1, thread_1.methods[1].total_time, 0.00001) # a
38
- assert_in_delta(1.5, thread_1.methods[2].total_time, 0.00001) # aa
39
- assert_in_delta(2.6, thread_1.methods[3].total_time, 0.00001) # ab
40
- assert_in_delta(7.5, thread_1.methods[4].total_time, 0.00001) # b
41
- assert_in_delta(6.6, thread_1.methods[5].total_time, 0.00001) # bb
42
- assert_in_delta(0.9, thread_1.methods[6].total_time, 0.00001) # ba
43
-
44
- # Root
45
- call_tree = call_tree_1
46
- assert_equal(:root, call_tree.target.method_name)
47
- assert_in_delta(11.6, call_tree.total_time, 0.00001)
48
- assert_in_delta(0, call_tree.self_time, 0.00001)
49
- assert_in_delta(0.0, call_tree.wait_time, 0.00001)
50
- assert_in_delta(11.6, call_tree.children_time, 0.00001)
51
-
52
- # a
53
- call_tree = call_tree_1.children[0]
54
- assert_equal(:a, call_tree.target.method_name)
55
- assert_in_delta(4.1, call_tree.total_time, 0.00001)
56
- assert_in_delta(0, call_tree.self_time, 0.00001)
57
- assert_in_delta(0.0, call_tree.wait_time, 0.00001)
58
- assert_in_delta(4.1, call_tree.children_time, 0.00001)
59
-
60
- # aa
61
- call_tree = call_tree_1.children[0].children[0]
62
- assert_equal(:aa, call_tree.target.method_name)
63
- assert_in_delta(1.5, call_tree.total_time, 0.00001)
64
- assert_in_delta(1.5, call_tree.self_time, 0.00001)
65
- assert_in_delta(0.0, call_tree.wait_time, 0.00001)
66
- assert_in_delta(0.0, call_tree.children_time, 0.00001)
67
-
68
- # ab
69
- call_tree = call_tree_1.children[0].children[1]
70
- assert_equal(:ab, call_tree.target.method_name)
71
- assert_in_delta(2.6, call_tree.total_time, 0.00001)
72
- assert_in_delta(2.6, call_tree.self_time, 0.00001)
73
- assert_in_delta(0.0, call_tree.wait_time, 0.00001)
74
- assert_in_delta(0.0, call_tree.children_time, 0.00001)
75
-
76
- # # b
77
- # call_tree = call_tree_1.children[1]
78
- # assert_equal(:b, call_tree.target.method_name)
79
- # assert_in_delta(7.5, call_tree.total_time, 0.00001)
80
- # assert_in_delta(0, call_tree.self_time, 0.00001)
81
- # assert_in_delta(0.0, call_tree.wait_time, 0.00001)
82
- # assert_in_delta(7.5, call_tree.children_time, 0.00001)
83
-
84
- # bb
85
- # call_tree = call_tree_1.children[1].children[0]
86
- # assert_equal(:bb, call_tree.target.method_name)
87
- # assert_in_delta(6.6, call_tree.total_time, 0.00001)
88
- # assert_in_delta(6.6, call_tree.self_time, 0.00001)
89
- # assert_in_delta(0.0, call_tree.wait_time, 0.00001)
90
- # assert_in_delta(0.0, call_tree.children_time, 0.00001)
91
-
92
- # ba
93
- call_tree = call_tree_1.children[1].children[1]
94
- assert_equal(:ba, call_tree.target.method_name)
95
- assert_in_delta(0.9, call_tree.total_time, 0.00001)
96
- assert_in_delta(0.7, call_tree.self_time, 0.00001)
97
- assert_in_delta(0.2, call_tree.wait_time, 0.00001)
98
- assert_in_delta(0.0, call_tree.children_time, 0.00001)
99
- end
100
-
101
- def test_thread_count
102
- result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
103
- thread = Thread.new do
104
- sleep(1)
105
- end
106
-
107
- thread.join
108
- end
109
- assert_equal(2, result.threads.length)
110
- end
111
-
112
- def test_thread_identity
113
- profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
114
- profile.start
115
-
116
- sleep_thread = Thread.new do
117
- sleep(1)
118
- end
119
- sleep_thread.join
120
- result = profile.stop
121
-
122
- thread_ids = result.threads.map {|thread| thread.id}.sort
123
- threads = [Thread.current, sleep_thread]
124
- assert_equal(2, result.threads.length)
125
-
126
- assert(thread_ids.include?(threads[0].object_id))
127
- assert(thread_ids.include?(threads[1].object_id))
128
-
129
- thread_ids.each do |id|
130
- thread = threads.find { |t| t.object_id == id }
131
- refute_nil(thread)
132
- assert_instance_of(Thread, thread)
133
- end
134
- end
135
-
136
- def test_thread_timings
137
- profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
138
- profile.start
139
-
140
- thread = Thread.new do
141
- sleep 0
142
- # force it to hit thread.join, below, first
143
- # thus forcing sleep(1), below, to be counted as (wall) self_time
144
- # since we currently count time "in some other thread" as self.wait_time
145
- sleep(1)
146
- end
147
- thread.join
148
- result = profile.stop
149
-
150
- # Check background thread
151
- assert_equal(2, result.threads.length)
152
-
153
- rp_thread = result.threads.detect {|t| t.id == thread.object_id}
154
- methods = rp_thread.methods.sort.reverse
155
-
156
- method = methods[0]
157
- assert_equal('ThreadTest#test_thread_timings', method.full_name)
158
- assert_equal(1, method.called)
159
- assert_in_delta(1, method.total_time, 0.1 * delta_multiplier)
160
- assert_in_delta(0, method.self_time, 0.05 * delta_multiplier)
161
- assert_in_delta(0, method.wait_time, 0.05 * delta_multiplier)
162
- assert_in_delta(1, method.children_time, 0.1 * delta_multiplier)
163
- assert_equal(0, method.call_trees.callers.length)
164
-
165
- method = methods[1]
166
- assert_equal('Kernel#sleep', method.full_name)
167
- assert_equal(2, method.called)
168
- assert_in_delta(1, method.total_time, 0.05 * delta_multiplier)
169
- assert_in_delta(1.0, method.self_time, 0.05 * delta_multiplier)
170
- assert_in_delta(0, method.wait_time, 0.05 * delta_multiplier)
171
- assert_in_delta(0, method.children_time, 0.05 * delta_multiplier)
172
-
173
- assert_equal(1, method.call_trees.callers.length)
174
- assert_equal(0, method.call_trees.callees.length)
175
-
176
- # Check foreground thread
177
- rp_thread = result.threads.detect {|athread| athread.id == Thread.current.object_id}
178
- methods = rp_thread.methods.sort.reverse
179
- assert_equal(4, methods.length)
180
- methods = methods.sort.reverse
181
-
182
- method = methods[0]
183
- assert_equal('ThreadTest#test_thread_timings', method.full_name)
184
- # the sub calls to Object#new, when popped,
185
- # cause the parent frame to be created for method #test_thread_timings, which means a +1 when it's popped in the end
186
- # xxxx a test that shows it the other way, too (never creates parent frame--if that's even possible)
187
- assert_equal(1, method.called)
188
- assert_in_delta(1, method.total_time, 0.05 * delta_multiplier)
189
- assert_in_delta(0, method.self_time, 0.05 * delta_multiplier)
190
- assert_in_delta(0, method.wait_time, 0.05 * delta_multiplier)
191
- assert_in_delta(1, method.children_time, 0.05 * delta_multiplier)
192
-
193
- assert_equal(0, method.call_trees.callers.length)
194
- assert_equal(2, method.call_trees.callees.length)
195
-
196
- method = methods[1]
197
- assert_equal('Thread#join', method.full_name)
198
- assert_equal(1, method.called)
199
- assert_in_delta(1, method.total_time, 0.05 * delta_multiplier)
200
- assert_in_delta(0, method.self_time, 0.05 * delta_multiplier)
201
- assert_in_delta(1.0, method.wait_time, 0.05 * delta_multiplier)
202
- assert_in_delta(0, method.children_time, 0.05 * delta_multiplier)
203
-
204
- assert_equal(1, method.call_trees.callers.length)
205
- assert_equal(0, method.call_trees.callees.length)
206
-
207
- method = methods[2]
208
- assert_equal('<Class::Thread>#new', method.full_name)
209
- assert_equal(1, method.called)
210
- assert_in_delta(0, method.total_time, 0.05 * delta_multiplier)
211
- assert_in_delta(0, method.self_time, 0.05 * delta_multiplier)
212
- assert_in_delta(0, method.wait_time, 0.05 * delta_multiplier)
213
- assert_in_delta(0, method.children_time, 0.05 * delta_multiplier)
214
-
215
- assert_equal(1, method.call_trees.callers.length)
216
- assert_equal(1, method.call_trees.callees.length)
217
-
218
- method = methods[3]
219
- assert_equal('Thread#initialize', method.full_name)
220
- assert_equal(1, method.called)
221
- assert_in_delta(0, method.total_time, 0.05 * delta_multiplier)
222
- assert_in_delta(0, method.self_time, 0.05 * delta_multiplier)
223
- assert_in_delta(0, method.wait_time, 0.05 * delta_multiplier)
224
- assert_in_delta(0, method.children_time, 0.05 * delta_multiplier)
225
-
226
- assert_equal(1, method.call_trees.callers.length)
227
- assert_equal(0, method.call_trees.callees.length)
228
- end
229
- end
@@ -1,123 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- require File.expand_path('../test_helper', __FILE__)
5
-
6
- class UniqueCallPath
7
- def method_a(i)
8
- if i==1
9
- method_b
10
- else
11
- method_c
12
- end
13
- end
14
-
15
- def method_b
16
- method_c
17
- end
18
-
19
- def method_c
20
- end
21
-
22
- def method_k(i)
23
- method_a(i)
24
- end
25
- end
26
-
27
-
28
- # -- Tests ----
29
- class UniqueCallPathTest < TestCase
30
- def test_root
31
- unique_call_path = UniqueCallPath.new
32
-
33
- result = RubyProf::Profile.profile do
34
- unique_call_path.method_a(1)
35
- end
36
-
37
- root_call_info = result.threads.first.call_tree
38
- assert_equal("UniqueCallPathTest#test_root", root_call_info.target.full_name)
39
- end
40
-
41
- def test_root_children
42
- unique_call_path = UniqueCallPath.new
43
-
44
- result = RubyProf::Profile.profile do
45
- unique_call_path.method_a(1)
46
- unique_call_path.method_k(2)
47
- end
48
-
49
- root_call_info = result.threads.first.call_tree
50
- children = root_call_info.children.sort do |c1, c2|
51
- c1.target.full_name <=> c2.target.full_name
52
- end
53
-
54
- assert_equal(2, children.length)
55
- assert_equal("UniqueCallPath#method_a", children[0].target.full_name)
56
- assert_equal("UniqueCallPath#method_k", children[1].target.full_name)
57
- end
58
-
59
- def test_children_of
60
- unique_call_path = UniqueCallPath.new
61
-
62
- result = RubyProf::Profile.profile do
63
- unique_call_path.method_a(1)
64
- unique_call_path.method_k(2)
65
- end
66
-
67
- root_call_info = result.threads.first.call_tree
68
- assert_equal("UniqueCallPathTest#test_children_of", root_call_info.target.full_name)
69
-
70
- call_info_a = root_call_info.children.detect do |call_tree|
71
- call_tree.target.full_name == "UniqueCallPath#method_a"
72
- end
73
- refute_nil(call_info_a)
74
-
75
- _children_of_a = call_info_a.children.inject(Array.new) do |array, c|
76
- if c.parent.eql?(call_info_a)
77
- array << c
78
- end
79
- array
80
- end
81
-
82
- assert_equal(2, call_info_a.children.length)
83
- assert_equal("Integer#==", call_info_a.children[0].target.full_name)
84
- assert_equal("UniqueCallPath#method_b", call_info_a.children[1].target.full_name)
85
- end
86
-
87
- def test_unique_path
88
- unique_call_path = UniqueCallPath.new
89
-
90
- result = RubyProf::Profile.profile do
91
- unique_call_path.method_a(1)
92
- unique_call_path.method_k(1)
93
- end
94
-
95
- root_call_info = result.threads.first.call_tree
96
- assert_equal("UniqueCallPathTest#test_unique_path", root_call_info.target.full_name)
97
-
98
- call_info_a = root_call_info.children.detect do |call_tree|
99
- call_tree.target.full_name == "UniqueCallPath#method_a"
100
- end
101
- refute_nil(call_info_a)
102
-
103
- children_of_a = call_info_a.children.reduce(Array.new) do |array, c|
104
- if c.parent.eql?(call_info_a)
105
- array << c
106
- end
107
- array
108
- end
109
-
110
- children_of_a = children_of_a.sort do |c1, c2|
111
- c1.target.full_name <=> c2.target.full_name
112
- end
113
-
114
- assert_equal(2, call_info_a.children.length)
115
- assert_equal(2, children_of_a.length)
116
-
117
- assert_equal(1, children_of_a[0].called)
118
- assert_equal("Integer#==", children_of_a[0].target.full_name)
119
-
120
- assert_equal(1, children_of_a[1].called)
121
- assert_equal("UniqueCallPath#method_b", children_of_a[1].target.full_name)
122
- end
123
- end
data/test/yarv_test.rb DELETED
@@ -1,56 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- require File.expand_path('../test_helper', __FILE__)
5
-
6
- # tests for bugs reported by users
7
- class YarvTest < TestCase
8
- def setup
9
- super
10
- define_methods
11
- end
12
-
13
- def test_array_push_unoptimized
14
- a = nil
15
- result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
16
- a = self.array_push_unoptimized
17
- end
18
- assert_equal 2, a.length
19
- assert_equal ["YarvTest#test_array_push_unoptimized", "YarvTest#array_push_unoptimized", 'Array#<<', "Array#push"], result.threads.first.methods.map(&:full_name)
20
- end
21
-
22
- def test_array_push_optimized
23
- a = nil
24
- result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
25
- a = self.array_push_optimized
26
- end
27
- assert_equal(2, a.length)
28
- assert_equal(["YarvTest#test_array_push_optimized", "YarvTest#array_push_optimized", "Array#<<", "Array#push"], result.threads.first.methods.map(&:full_name))
29
- end
30
-
31
- private
32
-
33
- def define_methods
34
- return if respond_to?(:array_push_optimized)
35
- old_compile_option = RubyVM::InstructionSequence.compile_option
36
- RubyVM::InstructionSequence.compile_option = {
37
- trace_instruction: true,
38
- specialized_instruction: false
39
- }
40
- self.class.class_eval <<-"EOM"
41
- def array_push_unoptimized
42
- a = []
43
- a << 1
44
- a.push 2
45
- end
46
- EOM
47
- RubyVM::InstructionSequence.compile_option = old_compile_option
48
- self.class.class_eval <<-"EOM"
49
- def array_push_optimized
50
- a = []
51
- a << 1
52
- a.push 2
53
- end
54
- EOM
55
- end
56
- end