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,147 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'rake'
5
+ require 'rake/testtask'
6
+ require 'fileutils'
7
+
8
+ module RubyProf
9
+
10
+ # Define a task library for profiling unit tests with ruby-prof.
11
+ #
12
+ # All of the options provided by
13
+ # the Rake:TestTask are supported except the loader
14
+ # which is set to ruby-prof. For detailed information
15
+ # please refer to the Rake:TestTask documentation.
16
+ #
17
+ # ruby-prof specific options include:
18
+ #
19
+ # output_dir - For each file specified an output
20
+ # file with profile information will be
21
+ # written to the output directory.
22
+ # By default, the output directory is
23
+ # called "profile" and is created underneath
24
+ # the current working directory.
25
+ #
26
+ # printer - Specifies the output printer. Valid values include
27
+ # :flat, :graph, :graph_html and :call_tree.
28
+ #
29
+ # min_percent - Methods that take less than the specified percent
30
+ # will not be written out.
31
+ #
32
+ # Example:
33
+ #
34
+ # require 'ruby-prof/task'
35
+ #
36
+ # RubyProf::ProfileTask.new do |t|
37
+ # t.test_files = FileList['test/test*.rb']
38
+ # t.output_dir = "c:/temp"
39
+ # t.printer = :graph
40
+ # t.min_percent = 10
41
+ # end
42
+ #
43
+ # If rake is invoked with a "TEST=filename" command line option,
44
+ # then the list of test files will be overridden to include only the
45
+ # filename specified on the command line. This provides an easy way
46
+ # to run just one test.
47
+ #
48
+ # If rake is invoked with a "TESTOPTS=options" command line option,
49
+ # then the given options are passed to the test process after a
50
+ # '--'. This allows Test::Unit options to be passed to the test
51
+ # suite.
52
+ #
53
+ # Examples:
54
+ #
55
+ # rake profile # run tests normally
56
+ # rake profile TEST=just_one_file.rb # run just one test file.
57
+ # rake profile TESTOPTS="-v" # run in verbose mode
58
+ # rake profile TESTOPTS="--runner=fox" # use the fox test runner
59
+
60
+ class ProfileTask < Rake::TestTask
61
+ attr_accessor :output_dir
62
+ attr_accessor :min_percent
63
+ attr_accessor :printer
64
+
65
+ def initialize(name = :profile)
66
+ super(name)
67
+ end
68
+
69
+ # Create the tasks defined by this task lib.
70
+ def define
71
+ lib_path = @libs.join(File::PATH_SEPARATOR)
72
+ desc "Profile" + (@name==:profile ? "" : " for #{@name}")
73
+
74
+ task @name do
75
+ create_output_directory
76
+
77
+ @ruby_opts.unshift( "-I#{lib_path}" )
78
+ @ruby_opts.unshift( "-w" ) if @warning
79
+ @ruby_opts.push("-S ruby-prof")
80
+ @ruby_opts.push("--printer #{@printer}")
81
+ @ruby_opts.push("--min_percent #{@min_percent}")
82
+
83
+ file_list.each do |file_path|
84
+ run_script(file_path)
85
+ end
86
+ end
87
+ self
88
+ end
89
+
90
+ # Run script
91
+ def run_script(script_path)
92
+ run_code = ''
93
+ RakeFileUtils.verbose(@verbose) do
94
+ file_name = File.basename(script_path, File.extname(script_path))
95
+ case @printer
96
+ when :flat, :graph, :call_tree
97
+ file_name += ".txt"
98
+ when :graph_html
99
+ file_name += ".html"
100
+ else
101
+ file_name += ".txt"
102
+ end
103
+
104
+ output_file_path = File.join(output_directory, file_name)
105
+
106
+ command_line = @ruby_opts.join(" ") +
107
+ " --file=" + output_file_path +
108
+ " " + script_path
109
+
110
+ puts "ruby " + command_line
111
+ # We have to catch the exeption to continue on. However,
112
+ # the error message will have been output to STDERR
113
+ # already by the time we get here so we don't have to
114
+ # do that again
115
+ begin
116
+ ruby command_line
117
+ rescue => e
118
+ STDOUT << e << "\n"
119
+ STDOUT.flush
120
+ end
121
+ puts ""
122
+ puts ""
123
+ end
124
+ end
125
+
126
+ def output_directory
127
+ File.expand_path(@output_dir)
128
+ end
129
+
130
+ def create_output_directory
131
+ if not File.exist?(output_directory)
132
+ Dir.mkdir(output_directory)
133
+ end
134
+ end
135
+
136
+ def clean_output_directory
137
+ if File.exist?(output_directory)
138
+ files = Dir.glob(output_directory + '/*')
139
+ FileUtils.rm(files)
140
+ end
141
+ end
142
+
143
+ def option_list # :nodoc:
144
+ ENV['OPTIONS'] || @options.join(" ") || ""
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,35 @@
1
+ module RubyProf
2
+ class Thread
3
+ def top_methods
4
+ self.methods.select do |method_info|
5
+ method_info.call_infos.detect(&:root?)
6
+ end
7
+ end
8
+
9
+ def top_call_infos
10
+ top_methods.map(&:call_infos).flatten.select(&:root?)
11
+ end
12
+
13
+ def total_time
14
+ self.top_methods.inject(0) do |sum, method_info|
15
+ method_info.call_infos.each do |call_info|
16
+ if call_info.parent.nil?
17
+ sum += call_info.total_time
18
+ end
19
+ end
20
+ sum
21
+ end
22
+ end
23
+
24
+ def wait_time
25
+ # wait_time, like self:time, is always method local
26
+ # thus we need to sum over all methods and call infos
27
+ self.methods.inject(0) do |sum, method_info|
28
+ method_info.call_infos.each do |call_info|
29
+ sum += call_info.wait_time
30
+ end
31
+ sum
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module RubyProf
2
+ VERSION = "0.18.0"
3
+ end
data/lib/unprof.rb ADDED
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ require "ruby-prof"
4
+
5
+ at_exit {
6
+ result = RubyProf.stop
7
+ printer = RubyProf::FlatPrinter.new(result)
8
+ printer.print(STDOUT)
9
+ }
10
+ RubyProf.start
data/ruby-prof.gemspec ADDED
@@ -0,0 +1,58 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+ require "ruby-prof/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruby-prof"
8
+
9
+ spec.homepage = "https://github.com/ruby-prof/ruby-prof/"
10
+ spec.summary = "Fast Ruby profiler"
11
+ spec.description = <<-EOF
12
+ ruby-prof is a fast code profiler for Ruby. It is a C extension and
13
+ therefore is many times faster than the standard Ruby profiler. It
14
+ supports both flat and graph profiles. For each method, graph profiles
15
+ show how long the method ran, which methods called it and which
16
+ methods it called. RubyProf generate both text and html and can output
17
+ it to standard out or to a file.
18
+ EOF
19
+ spec.license = 'BSD-2-Clause'
20
+ spec.version = RubyProf::VERSION
21
+
22
+ spec.author = "Shugo Maeda, Charlie Savage, Roger Pack, Stefan Kaes"
23
+ spec.email = "shugo@ruby-lang.org, cfis@savagexi.com, rogerdpack@gmail.com, skaes@railsexpress.de"
24
+ spec.platform = Gem::Platform::RUBY
25
+ spec.require_path = "lib"
26
+ spec.bindir = "bin"
27
+ spec.executables = ["ruby-prof", "ruby-prof-check-trace"]
28
+ spec.extensions = ["ext/ruby_prof/extconf.rb"]
29
+ spec.files = Dir['CHANGES',
30
+ 'LICENSE',
31
+ 'Rakefile',
32
+ 'README.rdoc',
33
+ 'ruby-prof.gemspec',
34
+ 'bin/ruby-prof',
35
+ 'bin/ruby-prof-check-trace',
36
+ 'doc/**/*',
37
+ 'examples/*',
38
+ 'ext/ruby_prof/extconf.rb',
39
+ 'ext/ruby_prof/*.c',
40
+ 'ext/ruby_prof/*.h',
41
+ 'ext/ruby_prof/vc/*.sln',
42
+ 'ext/ruby_prof/vc/*.vcxproj',
43
+ 'lib/ruby-prof.rb',
44
+ 'lib/unprof.rb',
45
+ 'lib/ruby-prof/*.rb',
46
+ 'lib/ruby-prof/assets/*.{html,png}',
47
+ 'lib/ruby-prof/profile/*.rb',
48
+ 'lib/ruby-prof/printers/*.rb',
49
+ 'test/*.rb']
50
+
51
+ spec.test_files = Dir["test/test_*.rb"]
52
+ spec.required_ruby_version = '>= 1.9.3'
53
+ spec.date = Time.now.strftime('%Y-%m-%d')
54
+ spec.homepage = 'https://github.com/ruby-prof/ruby-prof'
55
+ spec.add_development_dependency('minitest')
56
+ spec.add_development_dependency('rake-compiler')
57
+ spec.add_development_dependency('rdoc')
58
+ 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
+ class AbstractPrinterTest < TestCase
7
+ def setup
8
+ @result = {}
9
+ @printer = RubyProf::AbstractPrinter.new(@result)
10
+ @options = {}
11
+ @printer.setup_options(@options)
12
+ end
13
+
14
+ def test_editor_uri
15
+ env = {}
16
+
17
+ with_const_stubbed('ENV', env) do
18
+ @options[:editor_uri] = 'nvim'
19
+
20
+ env['RUBY_PROF_EDITOR_URI'] = 'atm'
21
+ assert_equal('atm', @printer.editor_uri)
22
+
23
+ env['RUBY_PROF_EDITOR_URI'] = nil
24
+ assert_equal(false, @printer.editor_uri)
25
+
26
+ env.delete('RUBY_PROF_EDITOR_URI')
27
+ assert_equal('nvim', @printer.editor_uri)
28
+
29
+ with_const_stubbed('RUBY_PLATFORM', 'x86_64-darwin18') do
30
+ assert_equal('nvim', @printer.editor_uri)
31
+
32
+ @options.delete(:editor_uri)
33
+ assert_equal('txmt', @printer.editor_uri)
34
+ end
35
+ with_const_stubbed('RUBY_PLATFORM', 'windows') do
36
+ assert_equal(false, @printer.editor_uri)
37
+ end
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def with_const_stubbed(name, value)
44
+ old_verbose, $VERBOSE = $VERBOSE, nil
45
+ old_value = Object.const_get(name)
46
+
47
+ Object.const_set(name, value)
48
+ yield
49
+ Object.const_set(name, old_value)
50
+
51
+ $VERBOSE = old_verbose
52
+ end
53
+ end
@@ -0,0 +1,136 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+
6
+ # Test data
7
+ # A B C
8
+ # | | |
9
+ # Z A A
10
+ # | |
11
+ # Z Z
12
+
13
+ class AggClass
14
+ def z
15
+ sleep 1
16
+ end
17
+
18
+ def a
19
+ z
20
+ end
21
+
22
+ def b
23
+ a
24
+ end
25
+
26
+ def c
27
+ a
28
+ end
29
+ end
30
+
31
+ class AggregateTest < TestCase
32
+ def setup
33
+ # Need to use wall time for this test due to the sleep calls
34
+ RubyProf::measure_mode = RubyProf::WALL_TIME
35
+ end
36
+
37
+ def test_all_call_infos_are_not_recursive
38
+ c1 = AggClass.new
39
+ result = RubyProf.profile do
40
+ c1.a
41
+ c1.b
42
+ c1.c
43
+ end
44
+ methods = result.threads.first.methods.sort.reverse
45
+ methods.each do |m|
46
+ m.call_infos.each do |ci|
47
+ assert(!ci.recursive?)
48
+ end
49
+ end
50
+ end
51
+
52
+ def test_call_infos
53
+ c1 = AggClass.new
54
+ result = RubyProf.profile do
55
+ c1.a
56
+ c1.b
57
+ c1.c
58
+ end
59
+
60
+ methods = result.threads.first.methods.sort.reverse
61
+ method = methods.find {|meth| meth.full_name == 'AggClass#z'}
62
+
63
+ # Check AggClass#z
64
+ assert_equal('AggClass#z', method.full_name)
65
+ assert_equal(3, method.called)
66
+ assert_in_delta(3, method.total_time, 0.05)
67
+ assert_in_delta(0, method.wait_time, 0.05)
68
+ assert_in_delta(0, method.self_time, 0.05)
69
+ assert_in_delta(3, method.children_time, 0.05)
70
+ assert_equal(3, method.call_infos.length)
71
+
72
+ call_info = method.call_infos[0]
73
+ assert_equal('AggregateTest#test_call_infos->AggClass#a->AggClass#z', call_info.call_sequence)
74
+ assert_equal(1, call_info.children.length)
75
+
76
+ call_info = method.call_infos[1]
77
+ assert_equal('AggregateTest#test_call_infos->AggClass#b->AggClass#a->AggClass#z', call_info.call_sequence)
78
+ assert_equal(1, call_info.children.length)
79
+
80
+ call_info = method.call_infos[2]
81
+ assert_equal('AggregateTest#test_call_infos->AggClass#c->AggClass#a->AggClass#z', call_info.call_sequence)
82
+ assert_equal(1, call_info.children.length)
83
+ end
84
+
85
+ def test_aggregates_parents
86
+ c1 = AggClass.new
87
+ result = RubyProf.profile do
88
+ c1.a
89
+ c1.b
90
+ c1.c
91
+ end
92
+
93
+ methods = result.threads.first.methods.sort.reverse
94
+ method = methods.find {|meth| meth.full_name == 'AggClass#z'}
95
+
96
+ # Check AggClass#z
97
+ assert_equal('AggClass#z', method.full_name)
98
+
99
+ call_infos = method.aggregate_parents
100
+ assert_equal(1, call_infos.length)
101
+
102
+ call_info = call_infos.first
103
+ assert_equal('AggClass#a', call_info.parent.target.full_name)
104
+ assert_in_delta(3, call_info.total_time, 0.05)
105
+ assert_in_delta(0, call_info.wait_time, 0.05)
106
+ assert_in_delta(0, call_info.self_time, 0.05)
107
+ assert_in_delta(3, call_info.children_time, 0.05)
108
+ assert_equal(3, call_info.called)
109
+ end
110
+
111
+ def test_aggregates_children
112
+ c1 = AggClass.new
113
+ result = RubyProf.profile do
114
+ c1.a
115
+ c1.b
116
+ c1.c
117
+ end
118
+
119
+ methods = result.threads.first.methods.sort.reverse
120
+ method = methods.find {|meth| meth.full_name == 'AggClass#a'}
121
+
122
+ # Check AggClass#a
123
+ assert_equal('AggClass#a', method.full_name)
124
+
125
+ call_infos = method.aggregate_children
126
+ assert_equal(1, call_infos.length)
127
+
128
+ call_info = call_infos.first
129
+ assert_equal('AggClass#z', call_info.target.full_name)
130
+ assert_in_delta(3, call_info.total_time, 0.05)
131
+ assert_in_delta(0, call_info.wait_time, 0.05)
132
+ assert_in_delta(0, call_info.self_time, 0.05)
133
+ assert_in_delta(3, call_info.children_time, 0.05)
134
+ assert_equal(3, call_info.called)
135
+ end
136
+ end