ruby-prof 1.4.4-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +608 -0
  3. data/LICENSE +25 -0
  4. data/README.md +5 -0
  5. data/Rakefile +98 -0
  6. data/bin/ruby-prof +328 -0
  7. data/bin/ruby-prof-check-trace +45 -0
  8. data/ext/ruby_prof/extconf.rb +22 -0
  9. data/ext/ruby_prof/rp_aggregate_call_tree.c +59 -0
  10. data/ext/ruby_prof/rp_aggregate_call_tree.h +13 -0
  11. data/ext/ruby_prof/rp_allocation.c +287 -0
  12. data/ext/ruby_prof/rp_allocation.h +31 -0
  13. data/ext/ruby_prof/rp_call_tree.c +367 -0
  14. data/ext/ruby_prof/rp_call_tree.h +43 -0
  15. data/ext/ruby_prof/rp_call_trees.c +288 -0
  16. data/ext/ruby_prof/rp_call_trees.h +28 -0
  17. data/ext/ruby_prof/rp_measure_allocations.c +47 -0
  18. data/ext/ruby_prof/rp_measure_memory.c +46 -0
  19. data/ext/ruby_prof/rp_measure_process_time.c +66 -0
  20. data/ext/ruby_prof/rp_measure_wall_time.c +64 -0
  21. data/ext/ruby_prof/rp_measurement.c +237 -0
  22. data/ext/ruby_prof/rp_measurement.h +50 -0
  23. data/ext/ruby_prof/rp_method.c +491 -0
  24. data/ext/ruby_prof/rp_method.h +62 -0
  25. data/ext/ruby_prof/rp_profile.c +915 -0
  26. data/ext/ruby_prof/rp_profile.h +35 -0
  27. data/ext/ruby_prof/rp_stack.c +212 -0
  28. data/ext/ruby_prof/rp_stack.h +53 -0
  29. data/ext/ruby_prof/rp_thread.c +362 -0
  30. data/ext/ruby_prof/rp_thread.h +39 -0
  31. data/ext/ruby_prof/ruby_prof.c +52 -0
  32. data/ext/ruby_prof/ruby_prof.h +26 -0
  33. data/ext/ruby_prof/vc/ruby_prof.sln +39 -0
  34. data/ext/ruby_prof/vc/ruby_prof.vcxproj +160 -0
  35. data/lib/3.1/ruby_prof.so +0 -0
  36. data/lib/ruby-prof/assets/call_stack_printer.html.erb +711 -0
  37. data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
  38. data/lib/ruby-prof/assets/graph_printer.html.erb +355 -0
  39. data/lib/ruby-prof/call_tree.rb +57 -0
  40. data/lib/ruby-prof/call_tree_visitor.rb +36 -0
  41. data/lib/ruby-prof/compatibility.rb +99 -0
  42. data/lib/ruby-prof/exclude_common_methods.rb +198 -0
  43. data/lib/ruby-prof/measurement.rb +17 -0
  44. data/lib/ruby-prof/method_info.rb +78 -0
  45. data/lib/ruby-prof/printers/abstract_printer.rb +137 -0
  46. data/lib/ruby-prof/printers/call_info_printer.rb +53 -0
  47. data/lib/ruby-prof/printers/call_stack_printer.rb +180 -0
  48. data/lib/ruby-prof/printers/call_tree_printer.rb +147 -0
  49. data/lib/ruby-prof/printers/dot_printer.rb +132 -0
  50. data/lib/ruby-prof/printers/flat_printer.rb +53 -0
  51. data/lib/ruby-prof/printers/graph_html_printer.rb +63 -0
  52. data/lib/ruby-prof/printers/graph_printer.rb +113 -0
  53. data/lib/ruby-prof/printers/multi_printer.rb +127 -0
  54. data/lib/ruby-prof/profile.rb +37 -0
  55. data/lib/ruby-prof/rack.rb +95 -0
  56. data/lib/ruby-prof/task.rb +147 -0
  57. data/lib/ruby-prof/thread.rb +20 -0
  58. data/lib/ruby-prof/version.rb +3 -0
  59. data/lib/ruby-prof.rb +52 -0
  60. data/lib/unprof.rb +10 -0
  61. data/ruby-prof.gemspec +64 -0
  62. data/test/abstract_printer_test.rb +26 -0
  63. data/test/alias_test.rb +122 -0
  64. data/test/basic_test.rb +43 -0
  65. data/test/call_tree_visitor_test.rb +32 -0
  66. data/test/call_trees_test.rb +66 -0
  67. data/test/duplicate_names_test.rb +32 -0
  68. data/test/dynamic_method_test.rb +67 -0
  69. data/test/enumerable_test.rb +21 -0
  70. data/test/exceptions_test.rb +24 -0
  71. data/test/exclude_methods_test.rb +151 -0
  72. data/test/exclude_threads_test.rb +53 -0
  73. data/test/fiber_test.rb +129 -0
  74. data/test/gc_test.rb +100 -0
  75. data/test/inverse_call_tree_test.rb +175 -0
  76. data/test/line_number_test.rb +158 -0
  77. data/test/marshal_test.rb +145 -0
  78. data/test/measure_allocations.rb +26 -0
  79. data/test/measure_allocations_test.rb +333 -0
  80. data/test/measure_memory_test.rb +688 -0
  81. data/test/measure_process_time_test.rb +1614 -0
  82. data/test/measure_times.rb +56 -0
  83. data/test/measure_wall_time_test.rb +426 -0
  84. data/test/multi_printer_test.rb +71 -0
  85. data/test/no_method_class_test.rb +15 -0
  86. data/test/pause_resume_test.rb +175 -0
  87. data/test/prime.rb +54 -0
  88. data/test/prime_script.rb +6 -0
  89. data/test/printer_call_stack_test.rb +27 -0
  90. data/test/printer_call_tree_test.rb +30 -0
  91. data/test/printer_flat_test.rb +99 -0
  92. data/test/printer_graph_html_test.rb +59 -0
  93. data/test/printer_graph_test.rb +40 -0
  94. data/test/printers_test.rb +141 -0
  95. data/test/printing_recursive_graph_test.rb +81 -0
  96. data/test/profile_test.rb +16 -0
  97. data/test/rack_test.rb +93 -0
  98. data/test/recursive_test.rb +430 -0
  99. data/test/singleton_test.rb +38 -0
  100. data/test/stack_printer_test.rb +64 -0
  101. data/test/start_stop_test.rb +109 -0
  102. data/test/test_helper.rb +13 -0
  103. data/test/thread_test.rb +144 -0
  104. data/test/unique_call_path_test.rb +136 -0
  105. data/test/yarv_test.rb +60 -0
  106. metadata +187 -0
@@ -0,0 +1,95 @@
1
+ # encoding: utf-8
2
+ require 'tmpdir'
3
+
4
+ module Rack
5
+ class RubyProf
6
+ def initialize(app, options = {})
7
+ @app = app
8
+ @options = options
9
+ @options[:min_percent] ||= 1
10
+
11
+ @tmpdir = options[:path] || Dir.tmpdir
12
+ FileUtils.mkdir_p(@tmpdir)
13
+
14
+ @printer_klasses = @options[:printers] || {::RubyProf::FlatPrinter => 'flat.txt',
15
+ ::RubyProf::GraphPrinter => 'graph.txt',
16
+ ::RubyProf::GraphHtmlPrinter => 'graph.html',
17
+ ::RubyProf::CallStackPrinter => 'call_stack.html'}
18
+
19
+ @skip_paths = options[:skip_paths] || [%r{^/assets}, %r{\.(css|js|png|jpeg|jpg|gif)$}]
20
+ @only_paths = options[:only_paths]
21
+ end
22
+
23
+ def call(env)
24
+ request = Rack::Request.new(env)
25
+
26
+ if should_profile?(request.path)
27
+ begin
28
+ result = nil
29
+ data = ::RubyProf::Profile.profile(profiling_options) do
30
+ result = @app.call(env)
31
+ end
32
+
33
+ path = request.path.gsub('/', '-')
34
+ path.slice!(0)
35
+
36
+ print(data, path)
37
+ result
38
+ end
39
+ else
40
+ @app.call(env)
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def should_profile?(path)
47
+ return false if paths_match?(path, @skip_paths)
48
+
49
+ @only_paths ? paths_match?(path, @only_paths) : true
50
+ end
51
+
52
+ def paths_match?(path, paths)
53
+ paths.any? { |skip_path| skip_path =~ path }
54
+ end
55
+
56
+ def profiling_options
57
+ options = {}
58
+ options[:measure_mode] = ::RubyProf.measure_mode
59
+ options[:exclude_threads] =
60
+ if @options[:ignore_existing_threads]
61
+ Thread.list.select{|t| t != Thread.current}
62
+ else
63
+ ::RubyProf.exclude_threads
64
+ end
65
+ if @options[:request_thread_only]
66
+ options[:include_threads] = [Thread.current]
67
+ end
68
+ if @options[:merge_fibers]
69
+ options[:merge_fibers] = true
70
+ end
71
+ options
72
+ end
73
+
74
+ def print(data, path)
75
+ @printer_klasses.each do |printer_klass, base_name|
76
+ printer = printer_klass.new(data)
77
+
78
+ if base_name.respond_to?(:call)
79
+ base_name = base_name.call
80
+ end
81
+
82
+ if printer_klass == ::RubyProf::MultiPrinter
83
+ printer.print(@options.merge(:profile => "#{path}-#{base_name}"))
84
+ elsif printer_klass == ::RubyProf::CallTreePrinter
85
+ printer.print(@options.merge(:profile => "#{path}-#{base_name}"))
86
+ else
87
+ file_name = ::File.join(@tmpdir, "#{path}-#{base_name}")
88
+ ::File.open(file_name, 'wb') do |file|
89
+ printer.print(file, @options)
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -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,20 @@
1
+ module RubyProf
2
+ class Thread
3
+ # Returns the total time this thread was executed.
4
+ def total_time
5
+ self.call_tree.total_time
6
+ end
7
+
8
+ # Returns the amount of time this thread waited while other thread executed.
9
+ def wait_time
10
+ # wait_time, like self:time, is always method local
11
+ # thus we need to sum over all methods and call infos
12
+ self.methods.inject(0) do |sum, method_info|
13
+ method_info.callers.each do |call_tree|
14
+ sum += call_tree.wait_time
15
+ end
16
+ sum
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module RubyProf
2
+ VERSION = "1.4.4"
3
+ end
data/lib/ruby-prof.rb ADDED
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+ require 'rubygems/version'
3
+
4
+ # Load the C-based binding.
5
+ begin
6
+ version = Gem::Version.new(RUBY_VERSION)
7
+ require "#{version.segments[0..1].join('.')}/ruby_prof.so"
8
+ rescue LoadError
9
+ require_relative "../ext/ruby_prof/ruby_prof.so"
10
+ end
11
+
12
+ require 'ruby-prof/version'
13
+ require 'ruby-prof/call_tree'
14
+ require 'ruby-prof/compatibility'
15
+ require 'ruby-prof/measurement'
16
+ require 'ruby-prof/method_info'
17
+ require 'ruby-prof/profile'
18
+ require 'ruby-prof/rack'
19
+ require 'ruby-prof/thread'
20
+
21
+ module RubyProf
22
+ autoload :CallTreeVisitor, 'ruby-prof/call_tree_visitor'
23
+ autoload :AbstractPrinter, 'ruby-prof/printers/abstract_printer'
24
+ autoload :CallInfoPrinter, 'ruby-prof/printers/call_info_printer'
25
+ autoload :CallStackPrinter, 'ruby-prof/printers/call_stack_printer'
26
+ autoload :CallTreePrinter, 'ruby-prof/printers/call_tree_printer'
27
+ autoload :DotPrinter, 'ruby-prof/printers/dot_printer'
28
+ autoload :FlatPrinter, 'ruby-prof/printers/flat_printer'
29
+ autoload :GraphHtmlPrinter, 'ruby-prof/printers/graph_html_printer'
30
+ autoload :GraphPrinter, 'ruby-prof/printers/graph_printer'
31
+ autoload :MultiPrinter, 'ruby-prof/printers/multi_printer'
32
+
33
+ # :nodoc:
34
+ # Checks if the user specified the clock mode via
35
+ # the RUBY_PROF_MEASURE_MODE environment variable
36
+ def self.figure_measure_mode
37
+ case ENV["RUBY_PROF_MEASURE_MODE"]
38
+ when "wall", "wall_time"
39
+ RubyProf.measure_mode = RubyProf::WALL_TIME
40
+ when "allocations"
41
+ RubyProf.measure_mode = RubyProf::ALLOCATIONS
42
+ when "memory"
43
+ RubyProf.measure_mode = RubyProf::MEMORY
44
+ when "process", "process_time"
45
+ RubyProf.measure_mode = RubyProf::PROCESS_TIME
46
+ else
47
+ # the default is defined in the measure_mode reader
48
+ end
49
+ end
50
+ end
51
+
52
+ RubyProf::figure_measure_mode
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,64 @@
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.metadata = {
23
+ "bug_tracker_uri" => "https://github.com/ruby-prof/ruby-prof/issues",
24
+ "changelog_uri" => "https://github.com/ruby-prof/ruby-prof/blob/master/CHANGES",
25
+ "documentation_uri" => "https://ruby-prof.github.io/",
26
+ "source_code_uri" => "https://github.com/ruby-prof/ruby-prof/tree/v#{spec.version}",
27
+ }
28
+
29
+ spec.author = "Shugo Maeda, Charlie Savage, Roger Pack, Stefan Kaes"
30
+ spec.email = "shugo@ruby-lang.org, cfis@savagexi.com, rogerdpack@gmail.com, skaes@railsexpress.de"
31
+ spec.platform = Gem::Platform::RUBY
32
+ spec.require_path = "lib"
33
+ spec.bindir = "bin"
34
+ spec.executables = ["ruby-prof", "ruby-prof-check-trace"]
35
+ spec.extensions = ["ext/ruby_prof/extconf.rb"]
36
+ spec.files = Dir['CHANGES',
37
+ 'LICENSE',
38
+ 'Rakefile',
39
+ 'README.md',
40
+ 'ruby-prof.gemspec',
41
+ 'bin/ruby-prof',
42
+ 'bin/ruby-prof-check-trace',
43
+ 'doc/**/*',
44
+ 'examples/*',
45
+ 'ext/ruby_prof/extconf.rb',
46
+ 'ext/ruby_prof/*.c',
47
+ 'ext/ruby_prof/*.h',
48
+ 'ext/ruby_prof/vc/*.sln',
49
+ 'ext/ruby_prof/vc/*.vcxproj',
50
+ 'lib/ruby-prof.rb',
51
+ 'lib/unprof.rb',
52
+ 'lib/ruby-prof/*.rb',
53
+ 'lib/ruby-prof/assets/*',
54
+ 'lib/ruby-prof/profile/*.rb',
55
+ 'lib/ruby-prof/printers/*.rb',
56
+ 'test/*.rb']
57
+
58
+ spec.test_files = Dir["test/test_*.rb"]
59
+ spec.required_ruby_version = '>= 2.7.0'
60
+ spec.date = Time.now.strftime('%Y-%m-%d')
61
+ spec.homepage = 'https://github.com/ruby-prof/ruby-prof'
62
+ spec.add_development_dependency('minitest')
63
+ spec.add_development_dependency('rake-compiler')
64
+ 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 AbstractPrinterTest < TestCase
7
+ def setup
8
+ @result = {}
9
+ @printer = RubyProf::AbstractPrinter.new(@result)
10
+ @options = {}
11
+ @printer.setup_options(@options)
12
+ end
13
+
14
+ private
15
+
16
+ def with_const_stubbed(name, value)
17
+ old_verbose, $VERBOSE = $VERBOSE, nil
18
+ old_value = Object.const_get(name)
19
+
20
+ Object.const_set(name, value)
21
+ yield
22
+ Object.const_set(name, old_value)
23
+
24
+ $VERBOSE = old_verbose
25
+ end
26
+ end
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path("../test_helper", __FILE__)
5
+
6
+ class AliasTest < TestCase
7
+ class TestMe
8
+ def some_method
9
+ sleep(0.1)
10
+ end
11
+
12
+ alias :some_method_original :some_method
13
+ def some_method
14
+ some_method_original
15
+ end
16
+ end
17
+
18
+ def setup
19
+ # Need to use wall time for this test due to the sleep calls
20
+ RubyProf::measure_mode = RubyProf::WALL_TIME
21
+ end
22
+
23
+ def test_alias
24
+ result = RubyProf.profile do
25
+ TestMe.new.some_method
26
+ end
27
+
28
+ methods = result.threads.first.methods
29
+ assert_equal(6, methods.count)
30
+
31
+ # Method 0
32
+ method = methods[0]
33
+ assert_equal('AliasTest#test_alias', method.full_name)
34
+ assert_equal(25, method.line)
35
+ refute(method.recursive?)
36
+
37
+ assert_equal(0, method.call_trees.callers.count)
38
+
39
+ assert_equal(2, method.call_trees.callees.count)
40
+ call_tree = method.call_trees.callees[0]
41
+ assert_equal('Class#new', call_tree.target.full_name)
42
+ assert_equal(25, call_tree.line)
43
+
44
+ call_tree = method.call_trees.callees[1]
45
+ assert_equal('AliasTest::TestMe#some_method', call_tree.target.full_name)
46
+ assert_equal(25, call_tree.line)
47
+
48
+ # Method 1
49
+ method = methods[1]
50
+ assert_equal('Class#new', method.full_name)
51
+ assert_equal(0, method.line)
52
+ refute(method.recursive?)
53
+
54
+ assert_equal(1, method.call_trees.callers.count)
55
+ call_tree = method.call_trees.callers[0]
56
+ assert_equal('AliasTest#test_alias', call_tree.parent.target.full_name)
57
+ assert_equal(25, call_tree.line)
58
+
59
+ assert_equal(1, method.call_trees.callees.count)
60
+ call_tree = method.call_trees.callees[0]
61
+ assert_equal('BasicObject#initialize', call_tree.target.full_name)
62
+ assert_equal(0, call_tree.line)
63
+
64
+ # Method 2
65
+ method = methods[2]
66
+ assert_equal('BasicObject#initialize', method.full_name)
67
+ assert_equal(0, method.line)
68
+ refute(method.recursive?)
69
+
70
+ assert_equal(1, method.call_trees.callers.count)
71
+ call_tree = method.call_trees.callers[0]
72
+ assert_equal('Class#new', call_tree.parent.target.full_name)
73
+ assert_equal(0, call_tree.line)
74
+
75
+ assert_equal(0, method.call_trees.callees.count)
76
+
77
+ # Method 3
78
+ method = methods[3]
79
+ assert_equal('AliasTest::TestMe#some_method', method.full_name)
80
+ assert_equal(13, method.line)
81
+ refute(method.recursive?)
82
+
83
+ assert_equal(1, method.call_trees.callers.count)
84
+ call_tree = method.call_trees.callers[0]
85
+ assert_equal('AliasTest#test_alias', call_tree.parent.target.full_name)
86
+ assert_equal(25, call_tree.line)
87
+
88
+ assert_equal(1, method.call_trees.callees.count)
89
+ call_tree = method.call_trees.callees[0]
90
+ assert_equal('AliasTest::TestMe#some_method_original', call_tree.target.full_name)
91
+ assert_equal(14, call_tree.line)
92
+
93
+ # Method 4
94
+ method = methods[4]
95
+ assert_equal('AliasTest::TestMe#some_method_original', method.full_name)
96
+ assert_equal(8, method.line)
97
+ refute(method.recursive?)
98
+
99
+ assert_equal(1, method.call_trees.callers.count)
100
+ call_tree = method.call_trees.callers[0]
101
+ assert_equal('AliasTest::TestMe#some_method', call_tree.parent.target.full_name)
102
+ assert_equal(14, call_tree.line)
103
+
104
+ assert_equal(1, method.call_trees.callees.count)
105
+ call_tree = method.call_trees.callees[0]
106
+ assert_equal('Kernel#sleep', call_tree.target.full_name)
107
+ assert_equal(9, call_tree.line)
108
+
109
+ # Method 5
110
+ method = methods[5]
111
+ assert_equal('Kernel#sleep', method.full_name)
112
+ assert_equal(0, method.line)
113
+ refute(method.recursive?)
114
+
115
+ assert_equal(1, method.call_trees.callers.count)
116
+ call_tree = method.call_trees.callers[0]
117
+ assert_equal('AliasTest::TestMe#some_method_original', call_tree.parent.target.full_name)
118
+ assert_equal(9, call_tree.line)
119
+
120
+ assert_equal(0, method.call_trees.callees.count)
121
+ end
122
+ end
@@ -0,0 +1,43 @@
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 BasicTest < TestCase
8
+ def setup
9
+ # Need to use wall time for this test due to the sleep calls
10
+ RubyProf::measure_mode = RubyProf::WALL_TIME
11
+ end
12
+
13
+ def test_running
14
+ assert(!RubyProf.running?)
15
+ RubyProf.start
16
+ assert(RubyProf.running?)
17
+ RubyProf.stop
18
+ assert(!RubyProf.running?)
19
+ end
20
+
21
+ def test_double_profile
22
+ RubyProf.start
23
+ assert_raises(RuntimeError) do
24
+ RubyProf.start
25
+ end
26
+ RubyProf.stop
27
+ end
28
+
29
+ def test_no_block
30
+ assert_raises(ArgumentError) do
31
+ RubyProf.profile
32
+ end
33
+ end
34
+
35
+ def test_traceback
36
+ RubyProf.start
37
+ assert_raises(NoMethodError) do
38
+ RubyProf.xxx
39
+ end
40
+
41
+ RubyProf.stop
42
+ end
43
+ end
@@ -0,0 +1,32 @@
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 setup
9
+ # Need to use wall time for this test due to the sleep calls
10
+ RubyProf::measure_mode = RubyProf::WALL_TIME
11
+ end
12
+
13
+ def test_visit
14
+ result = RubyProf.profile do
15
+ RubyProf::C1.sleep_wait
16
+ end
17
+
18
+ visitor = RubyProf::CallTreeVisitor.new(result.threads.first.call_tree)
19
+
20
+ method_names = Array.new
21
+
22
+ visitor.visit do |call_tree, event|
23
+ method_names << call_tree.target.full_name if event == :enter
24
+ end
25
+
26
+ assert_equal(3, method_names.length)
27
+ assert_equal("CallTreeVisitorTest#test_visit", method_names[0])
28
+ assert_equal("<Class::RubyProf::C1>#sleep_wait", method_names[1])
29
+ assert_equal("Kernel#sleep", method_names[2])
30
+ end
31
+ end
32
+
@@ -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 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::AggregateCallTree, 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::AggregateCallTree, 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::AggregateCallTree, 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::AggregateCallTree, 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 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