ruby-prof 2.0.0 → 2.0.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/bin/ruby-prof-check-trace +45 -45
- data/docs/advanced-usage.md +132 -132
- data/docs/best-practices.md +27 -27
- data/docs/getting-started.md +130 -130
- data/docs/index.md +45 -45
- data/docs/profiling-rails.md +64 -64
- data/docs/public/examples/generate_reports.rb +92 -92
- data/docs/public/examples/reports/call_stack.html +835 -835
- data/docs/public/examples/reports/graph.html +1319 -1319
- data/docs/reports.md +150 -150
- data/lib/ruby-prof/version.rb +1 -1
- data/ruby-prof.gemspec +66 -66
- data/test/call_tree_builder.rb +126 -126
- data/test/exceptions_test.rb +24 -24
- data/test/marshal_test.rb +144 -144
- data/test/printer_call_stack_test.rb +28 -28
- data/test/printer_flame_graph_test.rb +82 -82
- data/test/printer_flat_test.rb +99 -99
- data/test/printer_graph_html_test.rb +62 -62
- data/test/printer_graph_test.rb +42 -42
- data/test/printers_test.rb +162 -162
- data/test/printing_recursive_graph_test.rb +81 -81
- data/test/profile_test.rb +101 -101
- data/test/rack_test.rb +103 -103
- data/test/scheduler.rb +367 -367
- data/test/singleton_test.rb +39 -39
- data/test/thread_test.rb +229 -229
- data/test/yarv_test.rb +56 -56
- metadata +3 -3
data/test/profile_test.rb
CHANGED
|
@@ -1,101 +1,101 @@
|
|
|
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
|
-
class ProfileTest < TestCase
|
|
8
|
-
def test_measure_mode
|
|
9
|
-
profile = RubyProf::Profile.new(measure_mode: RubyProf::PROCESS_TIME)
|
|
10
|
-
assert_equal(RubyProf::PROCESS_TIME, profile.measure_mode)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def test_measure_mode_string
|
|
14
|
-
profile = RubyProf::Profile.new(measure_mode: RubyProf::PROCESS_TIME)
|
|
15
|
-
assert_equal("process_time", profile.measure_mode_string)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def test_add_thread
|
|
19
|
-
profile = RubyProf::Profile.new
|
|
20
|
-
assert_empty(profile.threads)
|
|
21
|
-
|
|
22
|
-
method_info = RubyProf::MethodInfo.new(Array, :size)
|
|
23
|
-
call_tree = RubyProf::CallTree.new(method_info)
|
|
24
|
-
thread = RubyProf::Thread.new(call_tree, Thread.current, Fiber.current)
|
|
25
|
-
|
|
26
|
-
profile.add_thread(thread)
|
|
27
|
-
assert_equal(1, profile.threads.size)
|
|
28
|
-
assert(thread.equal?(profile.threads.first))
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def test_add_threads
|
|
32
|
-
call_tree_1 = create_call_tree_1
|
|
33
|
-
ruby_thread_1 = Thread.new { }
|
|
34
|
-
thread_1 = RubyProf::Thread.new(call_tree_1, ruby_thread_1, Fiber.current)
|
|
35
|
-
|
|
36
|
-
call_tree_2 = create_call_tree_2
|
|
37
|
-
ruby_thread_2 = Thread.new { }
|
|
38
|
-
thread_2 = RubyProf::Thread.new(call_tree_2, ruby_thread_2, Fiber.current)
|
|
39
|
-
|
|
40
|
-
profile = RubyProf::Profile.new
|
|
41
|
-
profile.add_thread(thread_1)
|
|
42
|
-
profile.add_thread(thread_2)
|
|
43
|
-
assert_equal(1, profile.threads.count)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def test_add_fibers
|
|
47
|
-
call_tree_1 = create_call_tree_1
|
|
48
|
-
fiber_1 = Fiber.new { }
|
|
49
|
-
thread_1 = RubyProf::Thread.new(call_tree_1, Thread.current, fiber_1)
|
|
50
|
-
|
|
51
|
-
call_tree_2 = create_call_tree_2
|
|
52
|
-
fiber_2 = Fiber.new { }
|
|
53
|
-
thread_2 = RubyProf::Thread.new(call_tree_2, Thread.current, fiber_2)
|
|
54
|
-
|
|
55
|
-
profile = RubyProf::Profile.new
|
|
56
|
-
profile.add_thread(thread_1)
|
|
57
|
-
profile.add_thread(thread_2)
|
|
58
|
-
assert_equal(2, profile.threads.count)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def test_remove_thread
|
|
62
|
-
profile = RubyProf::Profile.new
|
|
63
|
-
assert_empty(profile.threads)
|
|
64
|
-
|
|
65
|
-
method_info = RubyProf::MethodInfo.new(Array, :size)
|
|
66
|
-
call_tree = RubyProf::CallTree.new(method_info)
|
|
67
|
-
thread = RubyProf::Thread.new(call_tree, Thread.current, Fiber.current)
|
|
68
|
-
|
|
69
|
-
profile.add_thread(thread)
|
|
70
|
-
assert_equal(1, profile.threads.size)
|
|
71
|
-
assert(thread.equal?(profile.threads.first))
|
|
72
|
-
|
|
73
|
-
removed = profile.remove_thread(thread)
|
|
74
|
-
assert_equal(0, profile.threads.size)
|
|
75
|
-
assert(removed.equal?(thread))
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def test_merge
|
|
79
|
-
call_tree_1 = create_call_tree_1
|
|
80
|
-
fiber_1 = Thread.new { }
|
|
81
|
-
thread_1 = RubyProf::Thread.new(call_tree_1, Thread.current, fiber_1)
|
|
82
|
-
|
|
83
|
-
call_tree_2 = create_call_tree_2
|
|
84
|
-
fiber_2 = Thread.new { }
|
|
85
|
-
thread_2 = RubyProf::Thread.new(call_tree_2, Thread.current, fiber_2)
|
|
86
|
-
|
|
87
|
-
profile = RubyProf::Profile.new
|
|
88
|
-
profile.add_thread(thread_1)
|
|
89
|
-
profile.add_thread(thread_2)
|
|
90
|
-
|
|
91
|
-
profile.merge!
|
|
92
|
-
assert_equal(1, profile.threads.count)
|
|
93
|
-
|
|
94
|
-
assert_equal(thread_1, profile.threads.first)
|
|
95
|
-
|
|
96
|
-
assert_in_delta(11.6, thread_1.call_tree.total_time, 0.00001)
|
|
97
|
-
assert_in_delta(0, thread_1.call_tree.self_time, 0.00001)
|
|
98
|
-
assert_in_delta(0.0, thread_1.call_tree.wait_time, 0.00001)
|
|
99
|
-
assert_in_delta(11.6, thread_1.call_tree.children_time, 0.00001)
|
|
100
|
-
end
|
|
101
|
-
end
|
|
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
|
+
class ProfileTest < TestCase
|
|
8
|
+
def test_measure_mode
|
|
9
|
+
profile = RubyProf::Profile.new(measure_mode: RubyProf::PROCESS_TIME)
|
|
10
|
+
assert_equal(RubyProf::PROCESS_TIME, profile.measure_mode)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_measure_mode_string
|
|
14
|
+
profile = RubyProf::Profile.new(measure_mode: RubyProf::PROCESS_TIME)
|
|
15
|
+
assert_equal("process_time", profile.measure_mode_string)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_add_thread
|
|
19
|
+
profile = RubyProf::Profile.new
|
|
20
|
+
assert_empty(profile.threads)
|
|
21
|
+
|
|
22
|
+
method_info = RubyProf::MethodInfo.new(Array, :size)
|
|
23
|
+
call_tree = RubyProf::CallTree.new(method_info)
|
|
24
|
+
thread = RubyProf::Thread.new(call_tree, Thread.current, Fiber.current)
|
|
25
|
+
|
|
26
|
+
profile.add_thread(thread)
|
|
27
|
+
assert_equal(1, profile.threads.size)
|
|
28
|
+
assert(thread.equal?(profile.threads.first))
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_add_threads
|
|
32
|
+
call_tree_1 = create_call_tree_1
|
|
33
|
+
ruby_thread_1 = Thread.new { }
|
|
34
|
+
thread_1 = RubyProf::Thread.new(call_tree_1, ruby_thread_1, Fiber.current)
|
|
35
|
+
|
|
36
|
+
call_tree_2 = create_call_tree_2
|
|
37
|
+
ruby_thread_2 = Thread.new { }
|
|
38
|
+
thread_2 = RubyProf::Thread.new(call_tree_2, ruby_thread_2, Fiber.current)
|
|
39
|
+
|
|
40
|
+
profile = RubyProf::Profile.new
|
|
41
|
+
profile.add_thread(thread_1)
|
|
42
|
+
profile.add_thread(thread_2)
|
|
43
|
+
assert_equal(1, profile.threads.count)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_add_fibers
|
|
47
|
+
call_tree_1 = create_call_tree_1
|
|
48
|
+
fiber_1 = Fiber.new { }
|
|
49
|
+
thread_1 = RubyProf::Thread.new(call_tree_1, Thread.current, fiber_1)
|
|
50
|
+
|
|
51
|
+
call_tree_2 = create_call_tree_2
|
|
52
|
+
fiber_2 = Fiber.new { }
|
|
53
|
+
thread_2 = RubyProf::Thread.new(call_tree_2, Thread.current, fiber_2)
|
|
54
|
+
|
|
55
|
+
profile = RubyProf::Profile.new
|
|
56
|
+
profile.add_thread(thread_1)
|
|
57
|
+
profile.add_thread(thread_2)
|
|
58
|
+
assert_equal(2, profile.threads.count)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def test_remove_thread
|
|
62
|
+
profile = RubyProf::Profile.new
|
|
63
|
+
assert_empty(profile.threads)
|
|
64
|
+
|
|
65
|
+
method_info = RubyProf::MethodInfo.new(Array, :size)
|
|
66
|
+
call_tree = RubyProf::CallTree.new(method_info)
|
|
67
|
+
thread = RubyProf::Thread.new(call_tree, Thread.current, Fiber.current)
|
|
68
|
+
|
|
69
|
+
profile.add_thread(thread)
|
|
70
|
+
assert_equal(1, profile.threads.size)
|
|
71
|
+
assert(thread.equal?(profile.threads.first))
|
|
72
|
+
|
|
73
|
+
removed = profile.remove_thread(thread)
|
|
74
|
+
assert_equal(0, profile.threads.size)
|
|
75
|
+
assert(removed.equal?(thread))
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def test_merge
|
|
79
|
+
call_tree_1 = create_call_tree_1
|
|
80
|
+
fiber_1 = Thread.new { }
|
|
81
|
+
thread_1 = RubyProf::Thread.new(call_tree_1, Thread.current, fiber_1)
|
|
82
|
+
|
|
83
|
+
call_tree_2 = create_call_tree_2
|
|
84
|
+
fiber_2 = Thread.new { }
|
|
85
|
+
thread_2 = RubyProf::Thread.new(call_tree_2, Thread.current, fiber_2)
|
|
86
|
+
|
|
87
|
+
profile = RubyProf::Profile.new
|
|
88
|
+
profile.add_thread(thread_1)
|
|
89
|
+
profile.add_thread(thread_2)
|
|
90
|
+
|
|
91
|
+
profile.merge!
|
|
92
|
+
assert_equal(1, profile.threads.count)
|
|
93
|
+
|
|
94
|
+
assert_equal(thread_1, profile.threads.first)
|
|
95
|
+
|
|
96
|
+
assert_in_delta(11.6, thread_1.call_tree.total_time, 0.00001)
|
|
97
|
+
assert_in_delta(0, thread_1.call_tree.self_time, 0.00001)
|
|
98
|
+
assert_in_delta(0.0, thread_1.call_tree.wait_time, 0.00001)
|
|
99
|
+
assert_in_delta(11.6, thread_1.call_tree.children_time, 0.00001)
|
|
100
|
+
end
|
|
101
|
+
end
|
data/test/rack_test.rb
CHANGED
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# encoding: UTF-8
|
|
3
|
-
|
|
4
|
-
require File.expand_path('../test_helper', __FILE__)
|
|
5
|
-
|
|
6
|
-
class FakeRackApp
|
|
7
|
-
def call(env)
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
module Rack
|
|
12
|
-
class Request
|
|
13
|
-
def initialize(env)
|
|
14
|
-
if env == :fake_env
|
|
15
|
-
@env = {}
|
|
16
|
-
else
|
|
17
|
-
@env = env
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def path
|
|
22
|
-
@env[:path] || '/path/to/resource.json'
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
class RackTest < TestCase
|
|
28
|
-
def test_pathname_path
|
|
29
|
-
path = Pathname.new(Dir.mktmpdir)
|
|
30
|
-
adapter = Rack::RubyProf.new(FakeRackApp.new, path: path)
|
|
31
|
-
|
|
32
|
-
adapter.call(:fake_env)
|
|
33
|
-
|
|
34
|
-
file_path = ::File.join(path.to_s, 'path-to-resource.json-flat.txt')
|
|
35
|
-
assert(File.exist?(file_path))
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def test_create_print_path
|
|
39
|
-
path = Dir.mktmpdir
|
|
40
|
-
Dir.delete(path)
|
|
41
|
-
|
|
42
|
-
Rack::RubyProf.new(FakeRackApp.new, path: path)
|
|
43
|
-
|
|
44
|
-
assert(Dir.exist?(path))
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def test_create_profile_reports
|
|
48
|
-
path = Dir.mktmpdir
|
|
49
|
-
|
|
50
|
-
adapter = Rack::RubyProf.new(FakeRackApp.new, path: path)
|
|
51
|
-
|
|
52
|
-
adapter.call(:fake_env)
|
|
53
|
-
|
|
54
|
-
%w(flat.txt graph.txt graph.html call_stack.html).each do |base_name|
|
|
55
|
-
file_path = ::File.join(path, "path-to-resource.json-#{base_name}")
|
|
56
|
-
assert(File.exist?(file_path))
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def test_skip_paths
|
|
61
|
-
path = Dir.mktmpdir
|
|
62
|
-
|
|
63
|
-
adapter = Rack::RubyProf.new(FakeRackApp.new, path: path, skip_paths: [%r{\.json$}])
|
|
64
|
-
|
|
65
|
-
adapter.call(:fake_env)
|
|
66
|
-
|
|
67
|
-
%w(flat.txt graph.txt graph.html call_stack.html).each do |base_name|
|
|
68
|
-
file_path = ::File.join(path, "path-to-resource.json-#{base_name}")
|
|
69
|
-
assert(!File.exist?(file_path))
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def test_only_paths
|
|
74
|
-
path = Dir.mktmpdir
|
|
75
|
-
|
|
76
|
-
adapter = Rack::RubyProf.new(FakeRackApp.new, path: path, only_paths: [%r{\.json$}])
|
|
77
|
-
|
|
78
|
-
adapter.call({path: '/path/to/resource.json'})
|
|
79
|
-
|
|
80
|
-
%w(flat.txt graph.txt graph.html call_stack.html).each do |base_name|
|
|
81
|
-
file_path = ::File.join(path, "path-to-resource.json-#{base_name}")
|
|
82
|
-
assert(File.exist?(file_path))
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
adapter.call({path: '/path/to/resource.html'})
|
|
86
|
-
%w(flat.txt graph.txt graph.html call_stack.html).each do |base_name|
|
|
87
|
-
file_path = ::File.join(path, "path-to-resource.html-#{base_name}")
|
|
88
|
-
assert(!File.exist?(file_path))
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def test_allows_lazy_filename_setting
|
|
93
|
-
path = Dir.mktmpdir
|
|
94
|
-
|
|
95
|
-
printer = {::RubyProf::FlatPrinter => lambda { 'dynamic.txt' }}
|
|
96
|
-
adapter = Rack::RubyProf.new(FakeRackApp.new, path: path, printers: printer)
|
|
97
|
-
|
|
98
|
-
adapter.call(:fake_env)
|
|
99
|
-
|
|
100
|
-
file_path = ::File.join(path, 'path-to-resource.json-dynamic.txt')
|
|
101
|
-
assert(File.exist?(file_path))
|
|
102
|
-
end
|
|
103
|
-
end
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# encoding: UTF-8
|
|
3
|
+
|
|
4
|
+
require File.expand_path('../test_helper', __FILE__)
|
|
5
|
+
|
|
6
|
+
class FakeRackApp
|
|
7
|
+
def call(env)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
module Rack
|
|
12
|
+
class Request
|
|
13
|
+
def initialize(env)
|
|
14
|
+
if env == :fake_env
|
|
15
|
+
@env = {}
|
|
16
|
+
else
|
|
17
|
+
@env = env
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def path
|
|
22
|
+
@env[:path] || '/path/to/resource.json'
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class RackTest < TestCase
|
|
28
|
+
def test_pathname_path
|
|
29
|
+
path = Pathname.new(Dir.mktmpdir)
|
|
30
|
+
adapter = Rack::RubyProf.new(FakeRackApp.new, path: path)
|
|
31
|
+
|
|
32
|
+
adapter.call(:fake_env)
|
|
33
|
+
|
|
34
|
+
file_path = ::File.join(path.to_s, 'path-to-resource.json-flat.txt')
|
|
35
|
+
assert(File.exist?(file_path))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_create_print_path
|
|
39
|
+
path = Dir.mktmpdir
|
|
40
|
+
Dir.delete(path)
|
|
41
|
+
|
|
42
|
+
Rack::RubyProf.new(FakeRackApp.new, path: path)
|
|
43
|
+
|
|
44
|
+
assert(Dir.exist?(path))
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_create_profile_reports
|
|
48
|
+
path = Dir.mktmpdir
|
|
49
|
+
|
|
50
|
+
adapter = Rack::RubyProf.new(FakeRackApp.new, path: path)
|
|
51
|
+
|
|
52
|
+
adapter.call(:fake_env)
|
|
53
|
+
|
|
54
|
+
%w(flat.txt graph.txt graph.html call_stack.html).each do |base_name|
|
|
55
|
+
file_path = ::File.join(path, "path-to-resource.json-#{base_name}")
|
|
56
|
+
assert(File.exist?(file_path))
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def test_skip_paths
|
|
61
|
+
path = Dir.mktmpdir
|
|
62
|
+
|
|
63
|
+
adapter = Rack::RubyProf.new(FakeRackApp.new, path: path, skip_paths: [%r{\.json$}])
|
|
64
|
+
|
|
65
|
+
adapter.call(:fake_env)
|
|
66
|
+
|
|
67
|
+
%w(flat.txt graph.txt graph.html call_stack.html).each do |base_name|
|
|
68
|
+
file_path = ::File.join(path, "path-to-resource.json-#{base_name}")
|
|
69
|
+
assert(!File.exist?(file_path))
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_only_paths
|
|
74
|
+
path = Dir.mktmpdir
|
|
75
|
+
|
|
76
|
+
adapter = Rack::RubyProf.new(FakeRackApp.new, path: path, only_paths: [%r{\.json$}])
|
|
77
|
+
|
|
78
|
+
adapter.call({path: '/path/to/resource.json'})
|
|
79
|
+
|
|
80
|
+
%w(flat.txt graph.txt graph.html call_stack.html).each do |base_name|
|
|
81
|
+
file_path = ::File.join(path, "path-to-resource.json-#{base_name}")
|
|
82
|
+
assert(File.exist?(file_path))
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
adapter.call({path: '/path/to/resource.html'})
|
|
86
|
+
%w(flat.txt graph.txt graph.html call_stack.html).each do |base_name|
|
|
87
|
+
file_path = ::File.join(path, "path-to-resource.html-#{base_name}")
|
|
88
|
+
assert(!File.exist?(file_path))
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def test_allows_lazy_filename_setting
|
|
93
|
+
path = Dir.mktmpdir
|
|
94
|
+
|
|
95
|
+
printer = {::RubyProf::FlatPrinter => lambda { 'dynamic.txt' }}
|
|
96
|
+
adapter = Rack::RubyProf.new(FakeRackApp.new, path: path, printers: printer)
|
|
97
|
+
|
|
98
|
+
adapter.call(:fake_env)
|
|
99
|
+
|
|
100
|
+
file_path = ::File.join(path, 'path-to-resource.json-dynamic.txt')
|
|
101
|
+
assert(File.exist?(file_path))
|
|
102
|
+
end
|
|
103
|
+
end
|