ruby-prof 1.3.0-x64-mingw32 → 1.4.3-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +42 -0
  3. data/README.rdoc +1 -1
  4. data/Rakefile +2 -14
  5. data/ext/ruby_prof/extconf.rb +13 -27
  6. data/ext/ruby_prof/rp_allocation.c +1 -1
  7. data/ext/ruby_prof/rp_call_trees.c +2 -2
  8. data/ext/ruby_prof/rp_measure_allocations.c +1 -1
  9. data/ext/ruby_prof/rp_measure_process_time.c +1 -1
  10. data/ext/ruby_prof/rp_measure_wall_time.c +1 -1
  11. data/ext/ruby_prof/rp_measurement.c +1 -1
  12. data/ext/ruby_prof/rp_method.c +2 -2
  13. data/ext/ruby_prof/rp_method.h +19 -19
  14. data/ext/ruby_prof/rp_profile.c +12 -37
  15. data/ext/ruby_prof/rp_profile.h +0 -1
  16. data/ext/ruby_prof/rp_stack.c +12 -4
  17. data/ext/ruby_prof/rp_thread.c +2 -2
  18. data/ext/ruby_prof/vc/ruby_prof.sln +8 -0
  19. data/ext/ruby_prof/vc/ruby_prof.vcxproj +15 -4
  20. data/lib/2.7/ruby_prof.so +0 -0
  21. data/lib/3.0/ruby_prof.so +0 -0
  22. data/lib/ruby-prof.rb +4 -3
  23. data/lib/ruby-prof/compatibility.rb +0 -10
  24. data/lib/ruby-prof/printers/abstract_printer.rb +13 -3
  25. data/lib/ruby-prof/printers/call_stack_printer.rb +1 -0
  26. data/lib/ruby-prof/printers/flat_printer.rb +3 -2
  27. data/lib/ruby-prof/printers/graph_printer.rb +1 -1
  28. data/lib/ruby-prof/profile.rb +8 -4
  29. data/lib/ruby-prof/rack.rb +51 -130
  30. data/lib/ruby-prof/version.rb +1 -1
  31. data/ruby-prof.gemspec +1 -1
  32. data/test/fiber_test.rb +55 -187
  33. data/test/gc_test.rb +12 -2
  34. data/test/marshal_test.rb +22 -5
  35. data/test/measure_memory_trace_test.rb +361 -2
  36. data/test/printer_call_stack_test.rb +0 -1
  37. data/test/printer_call_tree_test.rb +0 -1
  38. data/test/printer_flat_test.rb +61 -30
  39. data/test/printer_graph_html_test.rb +0 -1
  40. data/test/printer_graph_test.rb +3 -4
  41. data/test/printers_test.rb +3 -3
  42. data/test/printing_recursive_graph_test.rb +1 -1
  43. data/test/profile_test.rb +16 -0
  44. data/test/rack_test.rb +0 -64
  45. data/test/start_stop_test.rb +4 -4
  46. data/test/temp.rb +20 -0
  47. data/test/test_helper.rb +10 -5
  48. metadata +9 -5
@@ -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'
@@ -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'
@@ -2,29 +2,40 @@
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 setup
13
- # WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
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 =~ /^ +\d+/ }
22
- only_method_calls.collect { |line| line.split(/ +/)[n] }
19
+ only_method_calls = output.split("\n").select { |line| line =~ /^\s+\d+/ }
20
+ only_method_calls.collect { |line| line.split(/\s+/)[n] }
21
+ end
22
+
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
23
34
  end
24
35
 
25
- def assert_sorted array
26
- array = array.map{|n| n.to_f} # allow for > 10s times to sort right, since lexographically 4.0 > 10.0
27
- assert_equal array, array.sort.reverse, "Array #{array.inspect} is not sorted"
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)
28
39
  end
29
40
 
30
41
  def test_flat_string
@@ -32,37 +43,57 @@ class PrinterFlatTest < TestCase
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(@result)
47
+ printer = RubyProf::FlatPrinter.new(self.run_profile)
50
48
 
51
- printer.print(output = '')
52
- self_times = flat_output_nth_column_values(output, 3)
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(@result)
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
- printer.print(output = '', :sort_method => sort_method)
64
- times = flat_output_nth_column_values(output, n)
65
- assert_sorted times
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
@@ -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'
@@ -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 array
26
- array = array.map{|n| n.to_f} # allow for > 10s times to sort right, since lexographically 4.0 > 10.0
27
- assert_equal array, array.sort.reverse, "Array #{array.inspect} is not sorted"
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
@@ -2,8 +2,8 @@
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
 
@@ -37,10 +37,10 @@ class PrintersTest < TestCase
37
37
  end
38
38
 
39
39
  def test_print_to_files
40
- output_dir = 'examples2'
40
+ output_dir = 'tmp/examples2'
41
41
 
42
42
  if ENV['SAVE_NEW_PRINTER_EXAMPLES']
43
- output_dir = 'examples'
43
+ output_dir = 'tmp/examples'
44
44
  end
45
45
  FileUtils.mkdir_p output_dir
46
46
 
@@ -2,8 +2,8 @@
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
 
8
8
  # --- code to be tested ---
9
9
  module PRGT
@@ -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
@@ -22,23 +22,23 @@ class StartStopTest < TestCase
22
22
  sleep(2)
23
23
  @result = RubyProf.stop
24
24
  end
25
-
25
+
26
26
  def test_extra_stop_should_raise
27
27
  RubyProf.start
28
28
  assert_raises(RuntimeError) do
29
29
  RubyProf.start
30
30
  end
31
-
31
+
32
32
  assert_raises(RuntimeError) do
33
33
  RubyProf.profile {}
34
34
  end
35
-
35
+
36
36
  RubyProf.stop # ok
37
37
  assert_raises(RuntimeError) do
38
38
  RubyProf.stop
39
39
  end
40
40
  end
41
-
41
+
42
42
  def test_different_methods
43
43
  method1
44
44
 
data/test/temp.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'redis'
2
+
3
+ path = File.expand_path(File.join(__dir__, '..', 'lib'))
4
+ $LOAD_PATH << path
5
+ require 'ruby-prof'
6
+
7
+ Widget = Struct.new(:key) do
8
+ def set!
9
+ Redis.current.set(key, 1, ex: 10)
10
+ end
11
+ end
12
+
13
+ result = RubyProf.profile do
14
+ (1..20).each { |i| Widget.new(i).set! }
15
+ end
16
+
17
+ printer = RubyProf::CallStackPrinter.new(result)
18
+ File.open("framez.html", 'w:ASCII-8BIT') do |file|
19
+ printer.print(file, {})
20
+ end
data/test/test_helper.rb CHANGED
@@ -1,12 +1,17 @@
1
1
  # encoding: UTF-8
2
2
 
3
- # Disable minitest parallel tests. The problem is the thread switching will cahnge test results
4
- # (self vs wait time)
5
- ENV["N"] = "0"
6
-
7
3
  require 'bundler/setup'
8
4
  require 'minitest/autorun'
5
+
6
+ # Disable minitest parallel tests. The problem is the thread switching will change test results
7
+ # (self vs wait time)
8
+ if Gem::Version.new(Minitest::VERSION) > Gem::Version.new('5.11.3')
9
+ ENV["MT_CPU"] = "0" # Newer versions minitest
10
+ else
11
+ ENV["N"] = "0" # Older versions of minitest
12
+ end
13
+
9
14
  require 'ruby-prof'
10
15
 
11
16
  class TestCase < Minitest::Test
12
- end
17
+ end
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.3.0
4
+ version: 1.4.3
5
5
  platform: x64-mingw32
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-02-22 00:00:00.000000000 Z
11
+ date: 2021-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -99,6 +99,8 @@ files:
99
99
  - ext/ruby_prof/ruby_prof.h
100
100
  - ext/ruby_prof/vc/ruby_prof.sln
101
101
  - ext/ruby_prof/vc/ruby_prof.vcxproj
102
+ - lib/2.7/ruby_prof.so
103
+ - lib/3.0/ruby_prof.so
102
104
  - lib/ruby-prof.rb
103
105
  - lib/ruby-prof/assets/call_stack_printer.html.erb
104
106
  - lib/ruby-prof/assets/call_stack_printer.png
@@ -160,11 +162,13 @@ files:
160
162
  - test/printer_graph_test.rb
161
163
  - test/printers_test.rb
162
164
  - test/printing_recursive_graph_test.rb
165
+ - test/profile_test.rb
163
166
  - test/rack_test.rb
164
167
  - test/recursive_test.rb
165
168
  - test/singleton_test.rb
166
169
  - test/stack_printer_test.rb
167
170
  - test/start_stop_test.rb
171
+ - test/temp.rb
168
172
  - test/test_helper.rb
169
173
  - test/thread_test.rb
170
174
  - test/unique_call_path_test.rb
@@ -176,7 +180,7 @@ metadata:
176
180
  bug_tracker_uri: https://github.com/ruby-prof/ruby-prof/issues
177
181
  changelog_uri: https://github.com/ruby-prof/ruby-prof/blob/master/CHANGES
178
182
  documentation_uri: https://ruby-prof.github.io/
179
- source_code_uri: https://github.com/ruby-prof/ruby-prof/tree/v1.3.0
183
+ source_code_uri: https://github.com/ruby-prof/ruby-prof/tree/v1.4.3
180
184
  post_install_message:
181
185
  rdoc_options: []
182
186
  require_paths:
@@ -185,14 +189,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
189
  requirements:
186
190
  - - ">="
187
191
  - !ruby/object:Gem::Version
188
- version: 2.4.0
192
+ version: 2.5.0
189
193
  required_rubygems_version: !ruby/object:Gem::Requirement
190
194
  requirements:
191
195
  - - ">="
192
196
  - !ruby/object:Gem::Version
193
197
  version: '0'
194
198
  requirements: []
195
- rubygems_version: 3.0.6
199
+ rubygems_version: 3.1.4
196
200
  signing_key:
197
201
  specification_version: 4
198
202
  summary: Fast Ruby profiler