ruby-prof 0.18.0-x64-mingw32

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 (108) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +500 -0
  3. data/LICENSE +25 -0
  4. data/README.rdoc +487 -0
  5. data/Rakefile +113 -0
  6. data/bin/ruby-prof +345 -0
  7. data/bin/ruby-prof-check-trace +45 -0
  8. data/examples/flat.txt +50 -0
  9. data/examples/graph.dot +84 -0
  10. data/examples/graph.html +823 -0
  11. data/examples/graph.txt +139 -0
  12. data/examples/multi.flat.txt +23 -0
  13. data/examples/multi.graph.html +760 -0
  14. data/examples/multi.grind.dat +114 -0
  15. data/examples/multi.stack.html +547 -0
  16. data/examples/stack.html +547 -0
  17. data/ext/ruby_prof/extconf.rb +68 -0
  18. data/ext/ruby_prof/rp_call_info.c +425 -0
  19. data/ext/ruby_prof/rp_call_info.h +53 -0
  20. data/ext/ruby_prof/rp_measure.c +40 -0
  21. data/ext/ruby_prof/rp_measure.h +45 -0
  22. data/ext/ruby_prof/rp_measure_allocations.c +76 -0
  23. data/ext/ruby_prof/rp_measure_cpu_time.c +136 -0
  24. data/ext/ruby_prof/rp_measure_gc_runs.c +73 -0
  25. data/ext/ruby_prof/rp_measure_gc_time.c +60 -0
  26. data/ext/ruby_prof/rp_measure_memory.c +77 -0
  27. data/ext/ruby_prof/rp_measure_process_time.c +71 -0
  28. data/ext/ruby_prof/rp_measure_wall_time.c +45 -0
  29. data/ext/ruby_prof/rp_method.c +630 -0
  30. data/ext/ruby_prof/rp_method.h +75 -0
  31. data/ext/ruby_prof/rp_stack.c +173 -0
  32. data/ext/ruby_prof/rp_stack.h +63 -0
  33. data/ext/ruby_prof/rp_thread.c +277 -0
  34. data/ext/ruby_prof/rp_thread.h +27 -0
  35. data/ext/ruby_prof/ruby_prof.c +794 -0
  36. data/ext/ruby_prof/ruby_prof.h +60 -0
  37. data/ext/ruby_prof/vc/ruby_prof.sln +31 -0
  38. data/ext/ruby_prof/vc/ruby_prof.vcxproj +141 -0
  39. data/lib/2.6.3/ruby_prof.so +0 -0
  40. data/lib/ruby-prof.rb +68 -0
  41. data/lib/ruby-prof/aggregate_call_info.rb +76 -0
  42. data/lib/ruby-prof/assets/call_stack_printer.css.html +117 -0
  43. data/lib/ruby-prof/assets/call_stack_printer.js.html +385 -0
  44. data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
  45. data/lib/ruby-prof/call_info.rb +115 -0
  46. data/lib/ruby-prof/call_info_visitor.rb +40 -0
  47. data/lib/ruby-prof/compatibility.rb +179 -0
  48. data/lib/ruby-prof/method_info.rb +121 -0
  49. data/lib/ruby-prof/printers/abstract_printer.rb +104 -0
  50. data/lib/ruby-prof/printers/call_info_printer.rb +41 -0
  51. data/lib/ruby-prof/printers/call_stack_printer.rb +265 -0
  52. data/lib/ruby-prof/printers/call_tree_printer.rb +143 -0
  53. data/lib/ruby-prof/printers/dot_printer.rb +132 -0
  54. data/lib/ruby-prof/printers/flat_printer.rb +70 -0
  55. data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +83 -0
  56. data/lib/ruby-prof/printers/graph_html_printer.rb +249 -0
  57. data/lib/ruby-prof/printers/graph_printer.rb +116 -0
  58. data/lib/ruby-prof/printers/multi_printer.rb +84 -0
  59. data/lib/ruby-prof/profile.rb +26 -0
  60. data/lib/ruby-prof/profile/exclude_common_methods.rb +207 -0
  61. data/lib/ruby-prof/profile/legacy_method_elimination.rb +50 -0
  62. data/lib/ruby-prof/rack.rb +174 -0
  63. data/lib/ruby-prof/task.rb +147 -0
  64. data/lib/ruby-prof/thread.rb +35 -0
  65. data/lib/ruby-prof/version.rb +3 -0
  66. data/lib/unprof.rb +10 -0
  67. data/ruby-prof.gemspec +58 -0
  68. data/test/abstract_printer_test.rb +53 -0
  69. data/test/aggregate_test.rb +136 -0
  70. data/test/basic_test.rb +128 -0
  71. data/test/block_test.rb +74 -0
  72. data/test/call_info_test.rb +78 -0
  73. data/test/call_info_visitor_test.rb +31 -0
  74. data/test/duplicate_names_test.rb +32 -0
  75. data/test/dynamic_method_test.rb +55 -0
  76. data/test/enumerable_test.rb +21 -0
  77. data/test/exceptions_test.rb +24 -0
  78. data/test/exclude_methods_test.rb +146 -0
  79. data/test/exclude_threads_test.rb +53 -0
  80. data/test/fiber_test.rb +79 -0
  81. data/test/issue137_test.rb +63 -0
  82. data/test/line_number_test.rb +80 -0
  83. data/test/measure_allocations_test.rb +26 -0
  84. data/test/measure_cpu_time_test.rb +212 -0
  85. data/test/measure_gc_runs_test.rb +32 -0
  86. data/test/measure_gc_time_test.rb +36 -0
  87. data/test/measure_memory_test.rb +33 -0
  88. data/test/measure_process_time_test.rb +61 -0
  89. data/test/measure_wall_time_test.rb +255 -0
  90. data/test/method_elimination_test.rb +84 -0
  91. data/test/module_test.rb +45 -0
  92. data/test/multi_printer_test.rb +104 -0
  93. data/test/no_method_class_test.rb +15 -0
  94. data/test/pause_resume_test.rb +166 -0
  95. data/test/prime.rb +54 -0
  96. data/test/printers_test.rb +275 -0
  97. data/test/printing_recursive_graph_test.rb +127 -0
  98. data/test/rack_test.rb +157 -0
  99. data/test/recursive_test.rb +215 -0
  100. data/test/singleton_test.rb +38 -0
  101. data/test/stack_printer_test.rb +77 -0
  102. data/test/stack_test.rb +138 -0
  103. data/test/start_stop_test.rb +112 -0
  104. data/test/test_helper.rb +267 -0
  105. data/test/thread_test.rb +187 -0
  106. data/test/unique_call_path_test.rb +202 -0
  107. data/test/yarv_test.rb +55 -0
  108. metadata +199 -0
@@ -0,0 +1,146 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+
6
+ module ExcludeMethodsModule
7
+ def c
8
+ 1.times { |i| ExcludeMethodsModule.d }
9
+ end
10
+
11
+ def self.d
12
+ 1.times { |i| ExcludeMethodsClass.e }
13
+ end
14
+ end
15
+
16
+ class ExcludeMethodsClass
17
+ include ExcludeMethodsModule
18
+
19
+ def a
20
+ 1.times { |i| b }
21
+ end
22
+
23
+ def b
24
+ 1.times { |i| c; self.class.e }
25
+ end
26
+
27
+ def self.e
28
+ 1.times { |i| f }
29
+ end
30
+
31
+ def self.f
32
+ sleep 0.1
33
+ end
34
+ end
35
+
36
+ class ExcludeMethodsTest < TestCase
37
+ def setup
38
+ # Need to use wall time for this test due to the sleep calls
39
+ RubyProf::measure_mode = RubyProf::WALL_TIME
40
+ end
41
+
42
+ def test_methods_can_be_profiled
43
+ obj = ExcludeMethodsClass.new
44
+ prf = RubyProf::Profile.new
45
+
46
+ result = prf.profile { 5.times {obj.a} }
47
+ methods = result.threads.first.methods.sort.reverse
48
+
49
+ assert_equal(10, methods.count)
50
+ assert_equal('ExcludeMethodsTest#test_methods_can_be_profiled', methods[0].full_name)
51
+ assert_equal('Integer#times', methods[1].full_name)
52
+ assert_equal('ExcludeMethodsClass#a', methods[2].full_name)
53
+ assert_equal('ExcludeMethodsClass#b', methods[3].full_name)
54
+ assert_equal('<Class::ExcludeMethodsClass>#e', methods[4].full_name)
55
+ assert_equal('<Class::ExcludeMethodsClass>#f', methods[5].full_name)
56
+ assert_equal('Kernel#sleep', methods[6].full_name)
57
+ assert_equal('ExcludeMethodsModule#c', methods[7].full_name)
58
+ assert_equal('<Module::ExcludeMethodsModule>#d', methods[8].full_name)
59
+ assert_equal('Kernel#class', methods[9].full_name)
60
+ end
61
+
62
+ def test_methods_can_be_hidden1
63
+ obj = ExcludeMethodsClass.new
64
+ prf = RubyProf::Profile.new
65
+
66
+ prf.exclude_methods!(Integer, :times)
67
+
68
+ result = prf.profile { 5.times {obj.a} }
69
+ methods = result.threads.first.methods.sort.reverse
70
+
71
+ assert_equal(9, methods.count)
72
+ assert_equal('ExcludeMethodsTest#test_methods_can_be_hidden1', methods[0].full_name)
73
+ assert_equal('ExcludeMethodsClass#a', methods[1].full_name)
74
+ assert_equal('ExcludeMethodsClass#b', methods[2].full_name)
75
+ assert_equal('<Class::ExcludeMethodsClass>#e', methods[3].full_name)
76
+ assert_equal('<Class::ExcludeMethodsClass>#f', methods[4].full_name)
77
+ assert_equal('Kernel#sleep', methods[5].full_name)
78
+ assert_equal('ExcludeMethodsModule#c', methods[6].full_name)
79
+ assert_equal('<Module::ExcludeMethodsModule>#d', methods[7].full_name)
80
+ assert_equal('Kernel#class', methods[8].full_name)
81
+ end
82
+
83
+ def test_methods_can_be_hidden2
84
+ obj = ExcludeMethodsClass.new
85
+ prf = RubyProf::Profile.new
86
+
87
+ prf.exclude_methods!(Integer, :times)
88
+ prf.exclude_methods!(ExcludeMethodsClass.singleton_class, :f)
89
+ prf.exclude_methods!(ExcludeMethodsModule.singleton_class, :d)
90
+
91
+ result = prf.profile { 5.times {obj.a} }
92
+ methods = result.threads.first.methods.sort.reverse
93
+
94
+ assert_equal(7, methods.count)
95
+ assert_equal('ExcludeMethodsTest#test_methods_can_be_hidden2', methods[0].full_name)
96
+ assert_equal('ExcludeMethodsClass#a', methods[1].full_name)
97
+ assert_equal('ExcludeMethodsClass#b', methods[2].full_name)
98
+ assert_equal('<Class::ExcludeMethodsClass>#e', methods[3].full_name)
99
+ assert_equal('Kernel#sleep', methods[4].full_name)
100
+ assert_equal('ExcludeMethodsModule#c', methods[5].full_name)
101
+ assert_equal('Kernel#class', methods[6].full_name)
102
+ end
103
+
104
+ def test_exclude_common_methods1
105
+ obj = ExcludeMethodsClass.new
106
+ prf = RubyProf::Profile.new
107
+
108
+ prf.exclude_common_methods!
109
+
110
+ result = prf.profile { 5.times {obj.a} }
111
+ methods = result.threads.first.methods.sort.reverse
112
+
113
+ assert_equal(9, methods.count)
114
+ assert_equal('ExcludeMethodsTest#test_exclude_common_methods1', methods[0].full_name)
115
+ assert_equal('ExcludeMethodsClass#a', methods[1].full_name)
116
+ assert_equal('ExcludeMethodsClass#b', methods[2].full_name)
117
+ end
118
+
119
+ def test_exclude_common_methods2
120
+ obj = ExcludeMethodsClass.new
121
+
122
+ result = RubyProf.profile(exclude_common: true) { 5.times {obj.a} }
123
+ methods = result.threads.first.methods.sort.reverse
124
+
125
+ assert_equal(9, methods.count)
126
+ assert_equal('ExcludeMethodsTest#test_exclude_common_methods2', methods[0].full_name)
127
+ assert_equal('ExcludeMethodsClass#a', methods[1].full_name)
128
+ assert_equal('ExcludeMethodsClass#b', methods[2].full_name)
129
+ end
130
+
131
+ private
132
+
133
+ def assert_method_has_been_eliminated(result, eliminated_method)
134
+ result.threads.each do |thread|
135
+ thread.methods.each do |method|
136
+ method.call_infos.each do |ci|
137
+ assert(ci.target != eliminated_method, "broken self")
138
+ assert(ci.parent.target != eliminated_method, "broken parent") if ci.parent
139
+ ci.children.each do |callee|
140
+ assert(callee.target != eliminated_method, "broken kid")
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+
6
+
7
+ # -- Tests ----
8
+ class ExcludeThreadsTest < TestCase
9
+ def test_exclude_threads
10
+
11
+ def thread1_proc
12
+ sleep(0.5)
13
+ sleep(2)
14
+ end
15
+
16
+ def thread2_proc
17
+ sleep(0.5)
18
+ sleep(2)
19
+ end
20
+
21
+ thread1 = Thread.new do
22
+ thread1_proc
23
+ end
24
+
25
+ thread2 = Thread.new do
26
+ thread2_proc
27
+ end
28
+
29
+ # exclude_threads already includes the minitest thread pool
30
+ RubyProf.exclude_threads += [ thread2 ]
31
+
32
+ RubyProf.start
33
+
34
+ thread1.join
35
+ thread2.join
36
+
37
+ result = RubyProf.stop
38
+
39
+ assert_equal(2, result.threads.length)
40
+
41
+ output = Array.new
42
+ result.threads.each do |thread|
43
+ thread.methods.each do | m |
44
+ if m.full_name.index("ExcludeThreadsTest#thread") == 0
45
+ output.push(m.full_name)
46
+ end
47
+ end
48
+ end
49
+
50
+ assert_equal(1, output.length)
51
+ assert_equal("ExcludeThreadsTest#thread1_proc", output[0])
52
+ end
53
+ end
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+ require 'timeout'
6
+ require 'set'
7
+ begin
8
+ require 'fiber'
9
+ rescue LoadError
10
+ end
11
+
12
+ # -- Tests ----
13
+ class FiberTest < TestCase
14
+
15
+ def fiber_test
16
+ @fiber_ids << Fiber.current.object_id
17
+ enum = Enumerator.new do |yielder|
18
+ [1,2].each do |x|
19
+ @fiber_ids << Fiber.current.object_id
20
+ sleep 0.1
21
+ yielder.yield x
22
+ end
23
+ end
24
+ while true
25
+ begin
26
+ enum.next
27
+ rescue StopIteration
28
+ break
29
+ end
30
+ end
31
+ sleep 0.1
32
+ end
33
+
34
+ def setup
35
+ # Need to use wall time for this test due to the sleep calls
36
+ RubyProf::measure_mode = RubyProf::WALL_TIME
37
+ @fiber_ids = Set.new
38
+ @root_fiber = Fiber.current.object_id
39
+ @thread_id = Thread.current.object_id
40
+ end
41
+
42
+ def test_fibers
43
+ result = RubyProf.profile { fiber_test }
44
+ profiled_fiber_ids = result.threads.map(&:fiber_id)
45
+ assert_equal(2, result.threads.length)
46
+ assert_equal([@thread_id], result.threads.map(&:id).uniq)
47
+ assert_equal(@fiber_ids, Set.new(profiled_fiber_ids))
48
+
49
+ assert profiled_fiber_ids.include?(@root_fiber)
50
+ assert(root_fiber_profile = result.threads.detect{|t| t.fiber_id == @root_fiber})
51
+ assert(enum_fiber_profile = result.threads.detect{|t| t.fiber_id != @root_fiber})
52
+
53
+ assert_in_delta(0.3, root_fiber_profile.total_time, 0.05)
54
+ assert_in_delta(0.2, enum_fiber_profile.total_time, 0.05)
55
+
56
+ assert(method_next = root_fiber_profile.methods.detect{|m| m.full_name == "Enumerator#next"})
57
+ assert(method_each = enum_fiber_profile.methods.detect{|m| m.full_name == "Enumerator#each"})
58
+
59
+ assert_in_delta(0.2, method_next.total_time, 0.05)
60
+ assert_in_delta(0.2, method_each.total_time, 0.05)
61
+ end
62
+
63
+ def test_merged_fibers
64
+ result = RubyProf.profile(merge_fibers: true) { fiber_test }
65
+ assert_equal(1, result.threads.length)
66
+
67
+ profile = result.threads.first
68
+ assert_equal 0, profile.fiber_id
69
+
70
+ assert_in_delta(0.3, profile.total_time, 0.05)
71
+
72
+ assert(method_next = profile.methods.detect{|m| m.full_name == "Enumerator#next"})
73
+ assert(method_each = profile.methods.detect{|m| m.full_name == "Enumerator#each"})
74
+
75
+ assert_in_delta(0.2, method_next.total_time, 0.05)
76
+ assert_in_delta(0.2, method_each.total_time, 0.05)
77
+ end
78
+
79
+ end
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+
6
+ # issue 137 is about correctly attributing time of recursive children
7
+
8
+ class RecursiveChildrenTest < TestCase
9
+ class SlowClass
10
+ def time_sink
11
+ 1234567890 ** 100 == 0
12
+ end
13
+ end
14
+
15
+ class SlowSearcher
16
+ def do_find(slow_objects)
17
+ slow_objects.find(&:time_sink)
18
+ end
19
+ end
20
+
21
+ class MainClass
22
+ def self.main_method
23
+ slow_objects = [SlowClass.new] * 100_000
24
+ slow_searcher = SlowSearcher.new
25
+ slow_searcher.do_find(slow_objects)
26
+ end
27
+ end
28
+
29
+ include PrinterTestHelper
30
+
31
+ def setup
32
+ # Need to use wall time for this test due to the sleep calls
33
+ RubyProf::measure_mode = RubyProf::WALL_TIME
34
+ end
35
+
36
+ def test_simple
37
+ result = RubyProf.profile do
38
+ # make array each recursive
39
+ [1].each do
40
+ MainClass.main_method
41
+ end
42
+ end
43
+
44
+ # methods = result.threads.first.methods.sort.reverse
45
+
46
+ printer = RubyProf::GraphPrinter.new(result)
47
+
48
+ buffer = ''
49
+ printer.print(StringIO.new(buffer))
50
+
51
+ puts buffer if ENV['SHOW_RUBY_PROF_PRINTER_OUTPUT'] == "1"
52
+
53
+ parsed_output = MetricsArray.parse(buffer)
54
+
55
+ assert( enum_find = parsed_output.metrics_for("Enumerable#find") )
56
+ assert( array_each = enum_find.child("Array#each") )
57
+
58
+ assert_operator enum_find.metrics.total, :>=, array_each.total
59
+ assert_operator enum_find.metrics.total, :>, 0
60
+ assert_in_delta enum_find.metrics.total, array_each.total, 0.02
61
+ end
62
+
63
+ end
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+
6
+ class LineNumbers
7
+ def method1
8
+ end
9
+
10
+ def method2
11
+ method1
12
+ end
13
+
14
+ def method3
15
+ sleep(1)
16
+ end
17
+ end
18
+
19
+ # -- Tests ----
20
+ class LineNumbersTest < TestCase
21
+ def test_function_line_no
22
+ numbers = LineNumbers.new
23
+
24
+ result = RubyProf.profile do
25
+ numbers.method2
26
+ end
27
+
28
+ methods = result.threads.first.methods.sort.reverse
29
+ assert_equal(3, methods.length)
30
+
31
+ method = methods[0]
32
+ assert_equal('LineNumbersTest#test_function_line_no', method.full_name)
33
+ assert_equal(25, method.line)
34
+
35
+ method = methods[1]
36
+ assert_equal('LineNumbers#method2', method.full_name)
37
+ if RUBY_VERSION < "2.5"
38
+ assert_equal(10, method.line)
39
+ else
40
+ assert_equal(11, method.line)
41
+ end
42
+
43
+ method = methods[2]
44
+ assert_equal('LineNumbers#method1', method.full_name)
45
+ assert_equal(7, method.line)
46
+ end
47
+
48
+ def test_c_function
49
+ numbers = LineNumbers.new
50
+
51
+ result = RubyProf.profile do
52
+ numbers.method3
53
+ end
54
+
55
+ methods = result.threads.first.methods.sort_by {|method| method.full_name}
56
+ assert_equal(3, methods.length)
57
+
58
+ # Methods:
59
+ # LineNumbers#method3
60
+ # LineNumbersTest#test_c_function
61
+ # Kernel#sleep
62
+
63
+ method = methods[0]
64
+ assert_equal('Kernel#sleep', method.full_name)
65
+ assert_equal(0, method.line)
66
+
67
+ method = methods[1]
68
+ assert_equal('LineNumbers#method3', method.full_name)
69
+ if RUBY_VERSION < "2.5"
70
+ assert_equal(14, method.line)
71
+ else
72
+ assert_equal(15, method.line)
73
+ end
74
+
75
+ method = methods[2]
76
+ assert_equal('LineNumbersTest#test_c_function', method.full_name)
77
+ assert_equal(52, method.line)
78
+ end
79
+
80
+ end
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+
6
+ class MeasureAllocationsTest < TestCase
7
+ def test_allocations_mode
8
+ RubyProf::measure_mode = RubyProf::ALLOCATIONS
9
+ assert_equal(RubyProf::ALLOCATIONS, RubyProf::measure_mode)
10
+ end
11
+
12
+ def test_allocations_enabled_defined
13
+ assert(defined?(RubyProf::ALLOCATIONS_ENABLED))
14
+ end
15
+
16
+ if RubyProf::ALLOCATIONS_ENABLED
17
+ def test_allocations
18
+ t = RubyProf.measure_allocations
19
+ refute_empty("a" + "b")
20
+ u = RubyProf.measure_allocations
21
+ assert_kind_of Integer, t
22
+ assert_kind_of Integer, u
23
+ assert_operator t, :<, u
24
+ end
25
+ end
26
+ end