ruby-prof 1.3.0 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +29 -0
- data/Rakefile +2 -14
- data/ext/ruby_prof/extconf.rb +8 -28
- data/ext/ruby_prof/rp_call_trees.c +2 -2
- data/ext/ruby_prof/rp_measure_allocations.c +1 -1
- data/ext/ruby_prof/rp_measure_process_time.c +1 -1
- data/ext/ruby_prof/rp_measure_wall_time.c +1 -1
- data/ext/ruby_prof/rp_profile.c +6 -23
- data/ext/ruby_prof/rp_profile.h +0 -1
- data/ext/ruby_prof/rp_stack.c +11 -3
- data/ext/ruby_prof/vc/ruby_prof.sln +8 -0
- data/ext/ruby_prof/vc/ruby_prof.vcxproj +14 -3
- data/lib/ruby-prof.rb +3 -2
- data/lib/ruby-prof/compatibility.rb +0 -10
- data/lib/ruby-prof/printers/abstract_printer.rb +12 -2
- data/lib/ruby-prof/printers/call_stack_printer.rb +1 -0
- data/lib/ruby-prof/printers/flat_printer.rb +3 -2
- data/lib/ruby-prof/printers/graph_printer.rb +1 -1
- data/lib/ruby-prof/profile.rb +8 -4
- data/lib/ruby-prof/rack.rb +51 -130
- data/lib/ruby-prof/version.rb +1 -1
- data/test/fiber_test.rb +55 -187
- data/test/marshal_test.rb +0 -2
- data/test/printer_call_stack_test.rb +0 -1
- data/test/printer_call_tree_test.rb +0 -1
- data/test/printer_flat_test.rb +61 -30
- data/test/printer_graph_html_test.rb +0 -1
- data/test/printer_graph_test.rb +3 -4
- data/test/printers_test.rb +1 -1
- data/test/printing_recursive_graph_test.rb +1 -1
- data/test/profile_test.rb +16 -0
- data/test/rack_test.rb +0 -64
- data/test/test_helper.rb +3 -2
- metadata +5 -4
data/test/marshal_test.rb
CHANGED
data/test/printer_flat_test.rb
CHANGED
@@ -2,67 +2,98 @@
|
|
2
2
|
# encoding: UTF-8
|
3
3
|
|
4
4
|
require File.expand_path('../test_helper', __FILE__)
|
5
|
-
require 'stringio'
|
6
5
|
require 'fileutils'
|
6
|
+
require 'stringio'
|
7
7
|
require 'tmpdir'
|
8
8
|
require_relative 'prime'
|
9
9
|
|
10
10
|
# -- Tests ----
|
11
11
|
class PrinterFlatTest < TestCase
|
12
|
-
def
|
13
|
-
|
14
|
-
RubyProf::measure_mode = RubyProf::WALL_TIME
|
15
|
-
@result = RubyProf.profile do
|
12
|
+
def run_profile
|
13
|
+
RubyProf.profile(:measure_mode => RubyProf::WALL_TIME) do
|
16
14
|
run_primes(1000, 5000)
|
17
15
|
end
|
18
16
|
end
|
19
17
|
|
20
18
|
def flat_output_nth_column_values(output, n)
|
21
|
-
only_method_calls = output.split("\n").select { |line| line =~
|
22
|
-
only_method_calls.collect { |line| line.split(
|
19
|
+
only_method_calls = output.split("\n").select { |line| line =~ /^\s+\d+/ }
|
20
|
+
only_method_calls.collect { |line| line.split(/\s+/)[n] }
|
23
21
|
end
|
24
22
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
23
|
+
def helper_test_flat_string(klass)
|
24
|
+
output = StringIO.new
|
25
|
+
|
26
|
+
printer = klass.new(self.run_profile)
|
27
|
+
printer.print(output)
|
28
|
+
|
29
|
+
assert_match(/Thread ID: -?\d+/i, output.string)
|
30
|
+
assert_match(/Fiber ID: -?\d+/i, output.string)
|
31
|
+
assert_match(/Total: \d+\.\d+/i, output.string)
|
32
|
+
assert_match(/Object#run_primes/i, output.string)
|
33
|
+
output.string
|
28
34
|
end
|
29
35
|
|
36
|
+
def assert_sorted(array)
|
37
|
+
array = array.map(&:to_f) # allow for > 10s times to sort right, since lexographically 4.0 > 10.0
|
38
|
+
assert_equal(array, array.sort.reverse)
|
39
|
+
end
|
40
|
+
|
30
41
|
def test_flat_string
|
31
42
|
output = helper_test_flat_string(RubyProf::FlatPrinter)
|
32
43
|
assert_match(/prime.rb/, output)
|
33
44
|
end
|
34
45
|
|
35
|
-
def helper_test_flat_string(klass)
|
36
|
-
output = ''
|
37
|
-
|
38
|
-
printer = klass.new(@result)
|
39
|
-
printer.print(output)
|
40
|
-
|
41
|
-
assert_match(/Thread ID: -?\d+/i, output)
|
42
|
-
assert_match(/Fiber ID: -?\d+/i, output)
|
43
|
-
assert_match(/Total: \d+\.\d+/i, output)
|
44
|
-
assert_match(/Object#run_primes/i, output)
|
45
|
-
output
|
46
|
-
end
|
47
|
-
|
48
46
|
def test_flat_result_sorting_by_self_time_is_default
|
49
|
-
printer = RubyProf::FlatPrinter.new(
|
47
|
+
printer = RubyProf::FlatPrinter.new(self.run_profile)
|
50
48
|
|
51
|
-
|
52
|
-
|
49
|
+
output = StringIO.new
|
50
|
+
printer.print(output)
|
51
|
+
self_times = flat_output_nth_column_values(output.string, 3)
|
53
52
|
|
54
53
|
assert_sorted self_times
|
55
54
|
end
|
56
55
|
|
57
56
|
def test_flat_result_sorting
|
58
|
-
printer = RubyProf::FlatPrinter.new(
|
57
|
+
printer = RubyProf::FlatPrinter.new(self.run_profile)
|
59
58
|
|
60
59
|
sort_method_with_column_number = {:total_time => 2, :self_time => 3, :wait_time => 4, :children_time => 5}
|
61
60
|
|
62
61
|
sort_method_with_column_number.each_pair do |sort_method, n|
|
63
|
-
|
64
|
-
|
65
|
-
|
62
|
+
output = StringIO.new
|
63
|
+
printer.print(output, :sort_method => sort_method)
|
64
|
+
|
65
|
+
times = flat_output_nth_column_values(output.string, n)
|
66
|
+
assert_sorted(times)
|
66
67
|
end
|
67
68
|
end
|
69
|
+
|
70
|
+
def test_flat_result_max_percent
|
71
|
+
printer = RubyProf::FlatPrinter.new(self.run_profile)
|
72
|
+
|
73
|
+
output = StringIO.new
|
74
|
+
printer.print(output, max_percent: 1)
|
75
|
+
self_percents = flat_output_nth_column_values(output.string, 1).map(&:to_f)
|
76
|
+
|
77
|
+
assert self_percents.max < 1
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_flat_result_filter_by_total_time
|
81
|
+
printer = RubyProf::FlatPrinter.new(self.run_profile)
|
82
|
+
|
83
|
+
output = StringIO.new
|
84
|
+
printer.print(output, filter_by: :total_time, min_percent: 50)
|
85
|
+
total_times = flat_output_nth_column_values(output.string, 2).map(&:to_f)
|
86
|
+
|
87
|
+
assert (total_times.min / total_times.max) >= 0.5
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_flat_result_filter_by_self_time
|
91
|
+
printer = RubyProf::FlatPrinter.new(self.run_profile)
|
92
|
+
|
93
|
+
output = StringIO.new
|
94
|
+
printer.print(output, filter_by: :self_time, min_percent: 0.1)
|
95
|
+
self_percents = flat_output_nth_column_values(output.string, 1).map(&:to_f)
|
96
|
+
|
97
|
+
assert self_percents.min >= 0.1
|
98
|
+
end
|
68
99
|
end
|
data/test/printer_graph_test.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
# encoding: UTF-8
|
3
3
|
|
4
4
|
require File.expand_path('../test_helper', __FILE__)
|
5
|
-
require 'stringio'
|
6
5
|
require 'fileutils'
|
7
6
|
require 'tmpdir'
|
8
7
|
require_relative 'prime'
|
@@ -22,9 +21,9 @@ class PrinterGraphTest < TestCase
|
|
22
21
|
only_root_calls.collect { |line| line.split(/ +/)[n] }
|
23
22
|
end
|
24
23
|
|
25
|
-
def assert_sorted
|
26
|
-
array = array.map{|n| n.to_f} # allow for > 10s times to sort right, since lexographically 4.0 > 10.0
|
27
|
-
assert_equal
|
24
|
+
def assert_sorted(array)
|
25
|
+
array = array.map {|n| n.to_f} # allow for > 10s times to sort right, since lexographically 4.0 > 10.0
|
26
|
+
assert_equal(array, array.sort.reverse, "Array #{array.inspect} is not sorted")
|
28
27
|
end
|
29
28
|
|
30
29
|
def test_graph_results_sorting
|
data/test/printers_test.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
require File.expand_path('../test_helper', __FILE__)
|
5
|
+
|
6
|
+
class ProfileTest < TestCase
|
7
|
+
def test_measure_mode
|
8
|
+
profile = RubyProf::Profile.new(:measure_mode => RubyProf::PROCESS_TIME)
|
9
|
+
assert_equal(RubyProf::PROCESS_TIME, profile.measure_mode)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_measure_mode_string
|
13
|
+
profile = RubyProf::Profile.new(:measure_mode => RubyProf::PROCESS_TIME)
|
14
|
+
assert_equal("process_time", profile.measure_mode_string)
|
15
|
+
end
|
16
|
+
end
|
data/test/rack_test.rb
CHANGED
@@ -24,16 +24,6 @@ module Rack
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
module Rack
|
28
|
-
class RubyProf
|
29
|
-
attr_reader :_profiler
|
30
|
-
|
31
|
-
def public_delete_profiler!
|
32
|
-
delete_profiler!
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
27
|
class RackTest < TestCase
|
38
28
|
def test_create_print_path
|
39
29
|
path = Dir.mktmpdir
|
@@ -100,58 +90,4 @@ class RackTest < TestCase
|
|
100
90
|
file_path = ::File.join(path, 'path-to-resource.json-dynamic.txt')
|
101
91
|
assert(File.exist?(file_path))
|
102
92
|
end
|
103
|
-
|
104
|
-
def test_works_for_multiple_requests
|
105
|
-
path = Dir.mktmpdir
|
106
|
-
|
107
|
-
adapter = Rack::RubyProf.new(FakeRackApp.new, :path => path, :max_requests => 2)
|
108
|
-
|
109
|
-
# make a 1st request, and check that this didn't create any files
|
110
|
-
adapter.call(:fake_env)
|
111
|
-
assert(Dir["#{path}/*"].empty?)
|
112
|
-
|
113
|
-
# now a second request should create all the expected files
|
114
|
-
adapter.call(:fake_env)
|
115
|
-
%w(flat.txt graph.txt graph.html call_stack.html).each do |base_name|
|
116
|
-
file_path = ::File.join(path, "multi-requests-2-#{base_name}")
|
117
|
-
assert(File.exist?(file_path))
|
118
|
-
end
|
119
|
-
|
120
|
-
# let's clean up
|
121
|
-
FileUtils.rm_rf(Dir["#{path}/*"])
|
122
|
-
|
123
|
-
# and do the same again for the next 2 requests
|
124
|
-
adapter.call(:fake_env)
|
125
|
-
assert(Dir["#{path}/*"].empty?)
|
126
|
-
|
127
|
-
adapter.call(:fake_env)
|
128
|
-
%w(flat.txt graph.txt graph.html call_stack.html).each do |base_name|
|
129
|
-
file_path = ::File.join(path, "multi-requests-2-#{base_name}")
|
130
|
-
assert(File.exist?(file_path))
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def test_tries_to_print_results_if_shut_down_before_max_requests_reached
|
135
|
-
path = Dir.mktmpdir
|
136
|
-
|
137
|
-
adapter = Rack::RubyProf.new(FakeRackApp.new, :path => path, :max_requests => 100)
|
138
|
-
|
139
|
-
# make a 1st request, and check that this didn't create any files
|
140
|
-
adapter.call(:fake_env)
|
141
|
-
assert(Dir["#{path}/*"].empty?)
|
142
|
-
|
143
|
-
adapter.public_delete_profiler!
|
144
|
-
|
145
|
-
%w(flat.txt graph.txt graph.html call_stack.html).each do |base_name|
|
146
|
-
file_path = ::File.join(path, "multi-requests-1-#{base_name}")
|
147
|
-
assert(File.exist?(file_path))
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_it_uses_separate_profilers_if_not_aggregating_multiple_requests
|
152
|
-
adapter1 = Rack::RubyProf.new(FakeRackApp.new)
|
153
|
-
adapter2 = Rack::RubyProf.new(FakeRackApp.new)
|
154
|
-
|
155
|
-
assert(adapter1.object_id != adapter2.object_id)
|
156
|
-
end
|
157
93
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
# Disable minitest parallel tests. The problem is the thread switching will
|
3
|
+
# Disable minitest parallel tests. The problem is the thread switching will change test results
|
4
4
|
# (self vs wait time)
|
5
|
-
ENV["N"] = "0"
|
5
|
+
ENV["N"] = "0" # Older versions of minitest
|
6
|
+
ENV["MT_CPU"] = "0" # Newer versions minitest
|
6
7
|
|
7
8
|
require 'bundler/setup'
|
8
9
|
require 'minitest/autorun'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-prof
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shugo Maeda, Charlie Savage, Roger Pack, Stefan Kaes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -161,6 +161,7 @@ files:
|
|
161
161
|
- test/printer_graph_test.rb
|
162
162
|
- test/printers_test.rb
|
163
163
|
- test/printing_recursive_graph_test.rb
|
164
|
+
- test/profile_test.rb
|
164
165
|
- test/rack_test.rb
|
165
166
|
- test/recursive_test.rb
|
166
167
|
- test/singleton_test.rb
|
@@ -177,7 +178,7 @@ metadata:
|
|
177
178
|
bug_tracker_uri: https://github.com/ruby-prof/ruby-prof/issues
|
178
179
|
changelog_uri: https://github.com/ruby-prof/ruby-prof/blob/master/CHANGES
|
179
180
|
documentation_uri: https://ruby-prof.github.io/
|
180
|
-
source_code_uri: https://github.com/ruby-prof/ruby-prof/tree/v1.
|
181
|
+
source_code_uri: https://github.com/ruby-prof/ruby-prof/tree/v1.4.2
|
181
182
|
post_install_message:
|
182
183
|
rdoc_options: []
|
183
184
|
require_paths:
|
@@ -193,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
194
|
- !ruby/object:Gem::Version
|
194
195
|
version: '0'
|
195
196
|
requirements: []
|
196
|
-
rubygems_version: 3.
|
197
|
+
rubygems_version: 3.1.4
|
197
198
|
signing_key:
|
198
199
|
specification_version: 4
|
199
200
|
summary: Fast Ruby profiler
|