ruby-prof 1.8.0-x64-mswin64-140

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 +665 -0
  3. data/LICENSE +25 -0
  4. data/README.md +5 -0
  5. data/Rakefile +98 -0
  6. data/bin/ruby-prof +341 -0
  7. data/bin/ruby-prof-check-trace +45 -0
  8. data/ext/ruby_prof/extconf.rb +23 -0
  9. data/ext/ruby_prof/rp_allocation.c +327 -0
  10. data/ext/ruby_prof/rp_allocation.h +32 -0
  11. data/ext/ruby_prof/rp_call_tree.c +502 -0
  12. data/ext/ruby_prof/rp_call_tree.h +47 -0
  13. data/ext/ruby_prof/rp_call_trees.c +296 -0
  14. data/ext/ruby_prof/rp_call_trees.h +28 -0
  15. data/ext/ruby_prof/rp_measure_allocations.c +47 -0
  16. data/ext/ruby_prof/rp_measure_memory.c +46 -0
  17. data/ext/ruby_prof/rp_measure_process_time.c +64 -0
  18. data/ext/ruby_prof/rp_measure_wall_time.c +52 -0
  19. data/ext/ruby_prof/rp_measurement.c +359 -0
  20. data/ext/ruby_prof/rp_measurement.h +52 -0
  21. data/ext/ruby_prof/rp_method.c +551 -0
  22. data/ext/ruby_prof/rp_method.h +66 -0
  23. data/ext/ruby_prof/rp_profile.c +933 -0
  24. data/ext/ruby_prof/rp_profile.h +36 -0
  25. data/ext/ruby_prof/rp_stack.c +212 -0
  26. data/ext/ruby_prof/rp_stack.h +53 -0
  27. data/ext/ruby_prof/rp_thread.c +433 -0
  28. data/ext/ruby_prof/rp_thread.h +39 -0
  29. data/ext/ruby_prof/ruby_prof.c +50 -0
  30. data/ext/ruby_prof/ruby_prof.h +35 -0
  31. data/ext/ruby_prof/vc/ruby_prof.sln +39 -0
  32. data/ext/ruby_prof/vc/ruby_prof.vcxproj +158 -0
  33. data/lib/ruby-prof/assets/call_stack_printer.html.erb +711 -0
  34. data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
  35. data/lib/ruby-prof/assets/graph_printer.html.erb +355 -0
  36. data/lib/ruby-prof/call_tree.rb +57 -0
  37. data/lib/ruby-prof/call_tree_visitor.rb +36 -0
  38. data/lib/ruby-prof/compatibility.rb +113 -0
  39. data/lib/ruby-prof/exclude_common_methods.rb +204 -0
  40. data/lib/ruby-prof/measurement.rb +17 -0
  41. data/lib/ruby-prof/method_info.rb +87 -0
  42. data/lib/ruby-prof/printers/abstract_printer.rb +156 -0
  43. data/lib/ruby-prof/printers/call_info_printer.rb +53 -0
  44. data/lib/ruby-prof/printers/call_stack_printer.rb +180 -0
  45. data/lib/ruby-prof/printers/call_tree_printer.rb +145 -0
  46. data/lib/ruby-prof/printers/dot_printer.rb +132 -0
  47. data/lib/ruby-prof/printers/flat_printer.rb +53 -0
  48. data/lib/ruby-prof/printers/graph_html_printer.rb +63 -0
  49. data/lib/ruby-prof/printers/graph_printer.rb +113 -0
  50. data/lib/ruby-prof/printers/multi_printer.rb +127 -0
  51. data/lib/ruby-prof/profile.rb +70 -0
  52. data/lib/ruby-prof/rack.rb +105 -0
  53. data/lib/ruby-prof/task.rb +147 -0
  54. data/lib/ruby-prof/thread.rb +20 -0
  55. data/lib/ruby-prof/version.rb +3 -0
  56. data/lib/ruby-prof.rb +52 -0
  57. data/lib/unprof.rb +10 -0
  58. data/ruby-prof.gemspec +67 -0
  59. data/test/abstract_printer_test.rb +27 -0
  60. data/test/alias_test.rb +117 -0
  61. data/test/call_tree_builder.rb +126 -0
  62. data/test/call_tree_test.rb +94 -0
  63. data/test/call_tree_visitor_test.rb +27 -0
  64. data/test/call_trees_test.rb +66 -0
  65. data/test/compatibility_test.rb +49 -0
  66. data/test/duplicate_names_test.rb +32 -0
  67. data/test/dynamic_method_test.rb +50 -0
  68. data/test/enumerable_test.rb +23 -0
  69. data/test/exceptions_test.rb +24 -0
  70. data/test/exclude_methods_test.rb +363 -0
  71. data/test/exclude_threads_test.rb +48 -0
  72. data/test/fiber_test.rb +195 -0
  73. data/test/gc_test.rb +104 -0
  74. data/test/inverse_call_tree_test.rb +174 -0
  75. data/test/line_number_test.rb +426 -0
  76. data/test/marshal_test.rb +145 -0
  77. data/test/measure_allocations.rb +26 -0
  78. data/test/measure_allocations_test.rb +1172 -0
  79. data/test/measure_process_time_test.rb +3330 -0
  80. data/test/measure_times.rb +56 -0
  81. data/test/measure_wall_time_test.rb +635 -0
  82. data/test/measurement_test.rb +82 -0
  83. data/test/merge_test.rb +146 -0
  84. data/test/method_info_test.rb +100 -0
  85. data/test/multi_printer_test.rb +66 -0
  86. data/test/no_method_class_test.rb +15 -0
  87. data/test/pause_resume_test.rb +171 -0
  88. data/test/prime.rb +54 -0
  89. data/test/prime_script.rb +6 -0
  90. data/test/printer_call_stack_test.rb +27 -0
  91. data/test/printer_call_tree_test.rb +30 -0
  92. data/test/printer_flat_test.rb +99 -0
  93. data/test/printer_graph_html_test.rb +59 -0
  94. data/test/printer_graph_test.rb +40 -0
  95. data/test/printers_test.rb +178 -0
  96. data/test/printing_recursive_graph_test.rb +81 -0
  97. data/test/profile_test.rb +101 -0
  98. data/test/rack_test.rb +93 -0
  99. data/test/recursive_test.rb +796 -0
  100. data/test/scheduler.rb +363 -0
  101. data/test/singleton_test.rb +38 -0
  102. data/test/stack_printer_test.rb +61 -0
  103. data/test/start_stop_test.rb +106 -0
  104. data/test/test_helper.rb +21 -0
  105. data/test/thread_test.rb +229 -0
  106. data/test/unique_call_path_test.rb +123 -0
  107. data/test/yarv_test.rb +56 -0
  108. metadata +228 -0
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('../test_helper', __FILE__)
4
+ require_relative './call_tree_builder'
5
+ require 'base64'
6
+
7
+ class CallTreeTest < Minitest::Test
8
+ def test_initialize
9
+ method_info = RubyProf::MethodInfo.new(Base64, :encode64)
10
+ call_tree = RubyProf::CallTree.new(method_info)
11
+ assert_equal(method_info, call_tree.target)
12
+ end
13
+
14
+ def test_measurement
15
+ method_info = RubyProf::MethodInfo.new(Base64, :encode64)
16
+ call_tree = RubyProf::CallTree.new(method_info)
17
+
18
+ assert_equal(0, call_tree.total_time)
19
+ assert_equal(0, call_tree.self_time)
20
+ assert_equal(0, call_tree.wait_time)
21
+ assert_equal(0, call_tree.children_time)
22
+ assert_equal(0, call_tree.called)
23
+ end
24
+
25
+ def test_compare
26
+ method_info_1 = RubyProf::MethodInfo.new(Base64, :encode64)
27
+ call_tree_1 = RubyProf::CallTree.new(method_info_1)
28
+ method_info_2 = RubyProf::MethodInfo.new(Base64, :encode64)
29
+ call_tree_2 = RubyProf::CallTree.new(method_info_2)
30
+ assert_equal(0, call_tree_1 <=> call_tree_2)
31
+
32
+ method_info_1 = RubyProf::MethodInfo.new(Base64, :decode64)
33
+ call_tree_1 = RubyProf::CallTree.new(method_info_1)
34
+ call_tree_1.measurement.total_time = 1
35
+ method_info_2 = RubyProf::MethodInfo.new(Base64, :encode64)
36
+ call_tree_2 = RubyProf::CallTree.new(method_info_2)
37
+ assert_equal(1, call_tree_1 <=> call_tree_2)
38
+
39
+ method_info_1 = RubyProf::MethodInfo.new(Base64, :decode64)
40
+ call_tree_1 = RubyProf::CallTree.new(method_info_1)
41
+ method_info_2 = RubyProf::MethodInfo.new(Base64, :encode64)
42
+ call_tree_2 = RubyProf::CallTree.new(method_info_2)
43
+ call_tree_2.measurement.total_time = 1
44
+ assert_equal(-1, call_tree_1 <=> call_tree_2)
45
+ end
46
+
47
+ def test_to_s
48
+ method_info = RubyProf::MethodInfo.new(Base64, :encode64)
49
+ call_tree = RubyProf::CallTree.new(method_info)
50
+ assert_equal("<RubyProf::CallTree - Base64#encode64>", call_tree.to_s)
51
+ end
52
+
53
+ def test_add_child
54
+ method_info_parent = RubyProf::MethodInfo.new(Base64, :encode64)
55
+ call_tree_parent = RubyProf::CallTree.new(method_info_parent)
56
+
57
+ method_info_child = RubyProf::MethodInfo.new(Array, :pack)
58
+ call_tree_child = RubyProf::CallTree.new(method_info_child)
59
+
60
+ assert_equal(0, call_tree_parent.children.size)
61
+ assert_nil(call_tree_child.parent)
62
+
63
+ result = call_tree_parent.add_child(call_tree_child)
64
+ assert_equal(1, call_tree_parent.children.size)
65
+ assert_equal(call_tree_child, call_tree_parent.children.first)
66
+ assert_equal(call_tree_child, result)
67
+ assert_equal(call_tree_parent, call_tree_child.parent)
68
+ end
69
+
70
+ def test_add_child_gc
71
+ GC.stress = true
72
+
73
+ begin
74
+ method_info_parent = RubyProf::MethodInfo.new(Base64, :encode64)
75
+ call_tree_parent = RubyProf::CallTree.new(method_info_parent)
76
+
77
+ method_info_child = RubyProf::MethodInfo.new(Array, :pack)
78
+ call_tree_child = RubyProf::CallTree.new(method_info_child)
79
+ call_tree_parent.add_child(call_tree_child)
80
+
81
+ # Free the child first
82
+ call_tree_child = nil
83
+ GC.start
84
+
85
+ # Now free the parent and make sure it doesn't free the child a second time
86
+ call_tree_parent = nil
87
+ GC.start
88
+
89
+ assert(true)
90
+ ensure
91
+ GC.stress = false
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+ require_relative './measure_times'
6
+
7
+ class CallTreeVisitorTest < TestCase
8
+ def test_visit
9
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
10
+ RubyProf::C1.sleep_wait
11
+ end
12
+
13
+ visitor = RubyProf::CallTreeVisitor.new(result.threads.first.call_tree)
14
+
15
+ method_names = Array.new
16
+
17
+ visitor.visit do |call_tree, event|
18
+ method_names << call_tree.target.full_name if event == :enter
19
+ end
20
+
21
+ assert_equal(3, method_names.length)
22
+ assert_equal("CallTreeVisitorTest#test_visit", method_names[0])
23
+ assert_equal("<Class::RubyProf::C1>#sleep_wait", method_names[1])
24
+ assert_equal("Kernel#sleep", method_names[2])
25
+ end
26
+ end
27
+
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+
6
+ # -- Tests ----
7
+ class CallTreesTest < TestCase
8
+ def some_method_1
9
+ some_method_2
10
+ end
11
+
12
+ def some_method_2
13
+ end
14
+
15
+ def test_call_infos
16
+ result = RubyProf::Profile.profile do
17
+ some_method_1
18
+ end
19
+
20
+ thread = result.threads.first
21
+ assert_equal(3, thread.methods.length)
22
+
23
+ method = thread.methods[0]
24
+ assert_equal('CallTreesTest#test_call_infos', method.full_name)
25
+
26
+ call_trees = method.call_trees
27
+ assert_empty(call_trees.callers)
28
+ assert_equal(1, call_trees.callees.length)
29
+ assert_kind_of(RubyProf::CallTree, call_trees.callees[0])
30
+ assert_equal('CallTreesTest#some_method_1', call_trees.callees[0].target.full_name)
31
+
32
+ method = thread.methods[1]
33
+ assert_equal('CallTreesTest#some_method_1', method.full_name)
34
+
35
+ call_trees = method.call_trees
36
+ assert_equal(1, call_trees.callers.length)
37
+ assert_kind_of(RubyProf::CallTree, call_trees.callers[0])
38
+ assert_equal('CallTreesTest#test_call_infos', call_trees.callers[0].parent.target.full_name)
39
+ assert_equal(1, call_trees.callees.length)
40
+ assert_kind_of(RubyProf::CallTree, call_trees.callees[0])
41
+ assert_equal('CallTreesTest#some_method_2', call_trees.callees[0].target.full_name)
42
+
43
+ method = thread.methods[2]
44
+ assert_equal('CallTreesTest#some_method_2', method.full_name)
45
+
46
+ call_trees = method.call_trees
47
+ assert_equal(1, call_trees.callers.length)
48
+ assert_kind_of(RubyProf::CallTree, call_trees.callers[0])
49
+ assert_equal('CallTreesTest#some_method_1', call_trees.callers[0].parent.target.full_name)
50
+ assert_empty(call_trees.callees)
51
+ end
52
+
53
+ def test_gc
54
+ result = RubyProf::Profile.profile do
55
+ some_method_1
56
+ end
57
+
58
+ method = result.threads.first.methods[1]
59
+
60
+ 100.times do |i|
61
+ method.call_trees.callers
62
+ GC.start
63
+ end
64
+ assert(true)
65
+ end
66
+ end
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+ require_relative './measure_times'
6
+
7
+ class CompatibilityTest < TestCase
8
+ def setup
9
+ super
10
+ Gem::Deprecate.skip = true
11
+ RubyProf::measure_mode = RubyProf::WALL_TIME
12
+ end
13
+
14
+ def teardown
15
+ super
16
+ Gem::Deprecate.skip = false
17
+ end
18
+
19
+ def test_running
20
+ assert(!RubyProf.running?)
21
+ RubyProf.start
22
+ assert(RubyProf.running?)
23
+ RubyProf.stop
24
+ assert(!RubyProf.running?)
25
+ end
26
+
27
+ def test_double_profile
28
+ RubyProf.start
29
+ assert_raises(RuntimeError) do
30
+ RubyProf.start
31
+ end
32
+ RubyProf.stop
33
+ end
34
+
35
+ def test_no_block
36
+ assert_raises(ArgumentError) do
37
+ RubyProf.profile
38
+ end
39
+ end
40
+
41
+ def test_traceback
42
+ RubyProf.start
43
+ assert_raises(NoMethodError) do
44
+ RubyProf.xxx
45
+ end
46
+
47
+ RubyProf.stop
48
+ end
49
+ end
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+
6
+ class DuplicateNamesTest < TestCase
7
+ def test_names
8
+ result = RubyProf::Profile.profile do
9
+ str = %{module Foo; class Bar; def foo; end end end}
10
+
11
+ eval str
12
+ Foo::Bar.new.foo
13
+ DuplicateNamesTest.class_eval {remove_const :Foo}
14
+
15
+ eval str
16
+ Foo::Bar.new.foo
17
+ DuplicateNamesTest.class_eval {remove_const :Foo}
18
+
19
+ eval str
20
+ Foo::Bar.new.foo
21
+ end
22
+
23
+ # There should be 3 foo methods
24
+ methods = result.threads.first.methods.sort.reverse
25
+
26
+ methods = methods.select do |method|
27
+ method.full_name == 'DuplicateNamesTest::Foo::Bar#foo'
28
+ end
29
+
30
+ assert_equal(3, methods.length)
31
+ end
32
+ end
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path("../test_helper", __FILE__)
5
+
6
+ class DynamicMethodTest < TestCase
7
+
8
+ class FruitMedley
9
+ define_method(:apple) do
10
+ sleep(0.1)
11
+ "I'm a peach"
12
+ end
13
+
14
+ define_method(:orange) do
15
+ sleep(0.2)
16
+ "I'm an orange"
17
+ end
18
+
19
+ [:banana, :peach].each_with_index do |fruit,i|
20
+ define_method(fruit) do
21
+ sleep(i == 0 ? 0.3 : 0.4)
22
+ "I'm a #{fruit}"
23
+ end
24
+ end
25
+ end
26
+
27
+ def test_dynamic_method
28
+ medley = FruitMedley.new
29
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
30
+ medley.apple
31
+ medley.orange
32
+ medley.banana
33
+ medley.peach
34
+ end
35
+
36
+ methods = result.threads.first.methods.sort.reverse
37
+
38
+ expected_method_names = %w(
39
+ DynamicMethodTest#test_dynamic_method
40
+ Kernel#sleep
41
+ DynamicMethodTest::FruitMedley#peach
42
+ DynamicMethodTest::FruitMedley#banana
43
+ DynamicMethodTest::FruitMedley#orange
44
+ DynamicMethodTest::FruitMedley#apple
45
+ Integer#==
46
+ )
47
+
48
+ assert_equal expected_method_names.join("\n"), methods.map(&:full_name).join("\n")
49
+ end
50
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+
6
+ # -- Test for bug
7
+ # http://github.com/rdp/ruby-prof/issues#issue/12
8
+
9
+ class EnumerableTest < TestCase
10
+ def test_enumerable
11
+ result = RubyProf::Profile.profile do
12
+ 3.times { [1,2,3].any? {|n| n} }
13
+ end
14
+ methods = if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.3')
15
+ %w(EnumerableTest#test_enumerable Integer#times Array#any?)
16
+ elsif Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.4')
17
+ %w(EnumerableTest#test_enumerable Integer#times Kernel#block_given? Integer#< Array#any? Integer#succ)
18
+ else
19
+ %w(EnumerableTest#test_enumerable Integer#times Integer#< Array#any? Integer#succ)
20
+ end
21
+ assert_equal(methods, result.threads.first.methods.map(&:full_name))
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+
6
+ class ExceptionsTest < TestCase
7
+ def test_profile
8
+ result = begin
9
+ RubyProf::Profile.profile do
10
+ raise(RuntimeError, 'Test error')
11
+ end
12
+ rescue
13
+ end
14
+ assert_kind_of(RubyProf::Profile, result)
15
+ end
16
+
17
+ def test_profile_allows_exceptions
18
+ assert_raises(RuntimeError) do
19
+ RubyProf::Profile.profile(:allow_exceptions => true) do
20
+ raise(RuntimeError, 'Test error')
21
+ end
22
+ end
23
+ end
24
+ end