ruby-prof 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46257897a9eb100edbd33483a4d9b025754eae985f6c4fd49a4b986f7dbac895
4
- data.tar.gz: 043ba8f3fcfec4322f4dde5b2489b4b44ee3fa12e383ba2b89853a47c489772d
3
+ metadata.gz: 6e62266e388c4742f279cccfd909bc167b83e2b2bc3438b52254855281ec3b56
4
+ data.tar.gz: 4becfdabd8c0453c433f36fcc767a32e5ac50f295c45deaa9b9ed7e09763b8e2
5
5
  SHA512:
6
- metadata.gz: c48297977b2cae9ec15a8a8a98f4a3b3ea58006bce7de933d55bea935be10fc03b7d99a93551acfe223d3aa0ad1dad72c53943cfc5a76b5f0f214a555c03518e
7
- data.tar.gz: 2fbcfa48dafa4f8d8ee0f53bd474656e360a9255051a60e3afb820aa8389102dbbd38fda2f078858c724fc624a23f21913174425ac807d3991165c382a619f9a
6
+ metadata.gz: ecdc60504e71f9adc7bcc5df7deb3864e0fad1544cfc57ad225053a205bdb75cad3953a415834761c964e069907e232786f977f667a7492bd7521839a4663bb4
7
+ data.tar.gz: d524f3cfa338fb190b362e42d29aaa1b60d1011e84945e73dd6bfc7f5979e0d3fe8702f6135f2c5a3f67ae4dddcd1915e7ddd1db7bab70ee00d22447cb02a398
data/CHANGES CHANGED
@@ -1,3 +1,11 @@
1
+ 1.4.2 (2020-11-3)
2
+ =====================
3
+ * Do NOT use Ruby 2.7.0 and 2.7.1 with ruby-prof. A bug in those versions of ruby causes ruby-prof to
4
+ not work. Version 2.7.2 works correctly.
5
+ * Fix crash caused be reallocating an internal stack that keeps tracks of frames *after* getting a reference to the
6
+ top frame in the stack (Charlie Savage).
7
+ * Fix bug where the flat printer did not correctly report the correct measurement mode.
8
+
1
9
  1.4.1 (2020-05-14)
2
10
  =====================
3
11
  * Fix compiling on older versions of gcc that do not default to c99 (Charlie Savage)
data/Rakefile CHANGED
@@ -6,13 +6,6 @@ require "rake/testtask"
6
6
  require "rdoc/task"
7
7
  require "date"
8
8
  require "rake/clean"
9
- begin
10
- require "bundler/setup"
11
- Bundler::GemHelper.install_tasks
12
- [:build, :install, :release].each {|t| Rake::Task[t].enhance [:rdoc] }
13
- rescue LoadError
14
- $stderr.puts "Install bundler to get support for simplified gem publishing"
15
- end
16
9
 
17
10
  # To release a version of ruby-prof:
18
11
  # * Update lib/ruby-prof/version.rb
@@ -23,10 +16,6 @@ end
23
16
  # * rake package to create the gems
24
17
  # * Tag the release (git tag 0.10.1)
25
18
  # * Push to ruybgems.org (gem push pkg/<gem files>)
26
- # For a ruby only release, just run
27
- # * rake release
28
- # it will push changes to github, tag the release, build the package and upload it to rubygems.org
29
- # and in case you forgot to increment the version number or have uncommitted changes, it will refuse to work
30
19
 
31
20
  GEM_NAME = 'ruby-prof'
32
21
  SO_NAME = 'ruby_prof'
@@ -4,9 +4,13 @@ require "mkmf"
4
4
  have_func('rb_tracearg_callee_id', ["ruby.h"])
5
5
 
6
6
  # We want to intermix declarations and code (ie, don't define all variables at the top of the method)
7
- $CFLAGS += ' -std=c99'
7
+ unless RUBY_PLATFORM =~ /mswin/
8
+ $CFLAGS += ' -std=c99'
9
+ end
8
10
 
9
11
  # And since we are using C99 we want to disable Ruby sending these warnings to gcc
10
- CONFIG['warnflags'].gsub!('-Wdeclaration-after-statement', '')
12
+ if CONFIG['warnflags']
13
+ CONFIG['warnflags'].gsub!('-Wdeclaration-after-statement', '')
14
+ end
11
15
 
12
16
  create_makefile("ruby_prof")
@@ -22,6 +22,14 @@ void prof_stack_free(prof_stack_t* stack)
22
22
  xfree(stack);
23
23
  }
24
24
 
25
+ prof_frame_t* prof_stack_parent(prof_stack_t* stack)
26
+ {
27
+ if (stack->ptr == stack->start || stack->ptr - 1 == stack->start)
28
+ return NULL;
29
+ else
30
+ return stack->ptr - 2;
31
+ }
32
+
25
33
  prof_frame_t* prof_stack_last(prof_stack_t* stack)
26
34
  {
27
35
  if (stack->ptr == stack->start)
@@ -86,8 +94,8 @@ prof_frame_t* prof_frame_current(prof_stack_t* stack)
86
94
 
87
95
  prof_frame_t* prof_frame_push(prof_stack_t* stack, prof_call_tree_t* call_tree, double measurement, bool paused)
88
96
  {
89
- prof_frame_t* parent_frame = prof_stack_last(stack);
90
97
  prof_frame_t* result = prof_stack_push(stack);
98
+ prof_frame_t* parent_frame = prof_stack_parent(stack);
91
99
 
92
100
  result->call_tree = call_tree;
93
101
 
@@ -102,13 +102,13 @@
102
102
  </ItemDefinitionGroup>
103
103
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
104
104
  <ClCompile>
105
- <AdditionalIncludeDirectories>C:\msys64\usr\local\ruby-2.7.1vc\include\ruby-2.7.0\x64-mswin64_140;C:\msys64\usr\local\ruby-2.7.1vc\include\ruby-2.7.0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
105
+ <AdditionalIncludeDirectories>C:\msys64\usr\local\ruby-2.7.2vc\include\ruby-2.7.0\x64-mswin64_140;C:\msys64\usr\local\ruby-2.7.2vc\include\ruby-2.7.0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
106
106
  <Optimization>Disabled</Optimization>
107
107
  <PreprocessorDefinitions>HAVE_RB_TRACEARG_CALLEE_ID;%(PreprocessorDefinitions)</PreprocessorDefinitions>
108
108
  <WarningLevel>Level3</WarningLevel>
109
109
  </ClCompile>
110
110
  <Link>
111
- <AdditionalLibraryDirectories>C:\msys64\usr\local\ruby-2.7.1vc\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
111
+ <AdditionalLibraryDirectories>C:\msys64\usr\local\ruby-2.7.2vc\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
112
112
  <AdditionalDependencies>x64-vcruntime140-ruby270.lib;%(AdditionalDependencies)</AdditionalDependencies>
113
113
  <ModuleDefinitionFile>ruby_prof.def</ModuleDefinitionFile>
114
114
  <SubSystem>Console</SubSystem>
@@ -81,16 +81,6 @@ module RubyProf
81
81
  Profile.profile(options, &block)
82
82
  end
83
83
 
84
- # :nodoc:
85
- def self.measure_mode_string
86
- case measure_mode
87
- when WALL_TIME then "wall_time"
88
- when PROCESS_TIME then "process_time"
89
- when ALLOCATIONS then "allocations"
90
- when MEMORY then "memory"
91
- end
92
- end
93
-
94
84
  # :nodoc:
95
85
  def self.start_script(script)
96
86
  start
@@ -99,7 +99,7 @@ module RubyProf
99
99
  end
100
100
 
101
101
  def print_header(thread)
102
- @output << "Measure Mode: %s\n" % RubyProf.measure_mode_string
102
+ @output << "Measure Mode: %s\n" % @result.measure_mode_string
103
103
  @output << "Thread ID: %d\n" % thread.id
104
104
  @output << "Fiber ID: %d\n" % thread.fiber_id unless thread.id == thread.fiber_id
105
105
  @output << "Total: %0.6f\n" % thread.total_time
@@ -4,6 +4,7 @@ require 'erb'
4
4
  require 'fileutils'
5
5
  require 'base64'
6
6
  require 'set'
7
+ require 'stringio'
7
8
 
8
9
  module RubyProf
9
10
  # Prints a HTML visualization of the call tree.
@@ -25,7 +25,7 @@ module RubyProf
25
25
  end
26
26
 
27
27
  def print_header(thread)
28
- @output << "Measure Mode: %s\n" % RubyProf.measure_mode_string
28
+ @output << "Measure Mode: %s\n" % @result.measure_mode_string
29
29
  @output << "Thread ID: #{thread.id}\n"
30
30
  @output << "Fiber ID: #{thread.fiber_id}\n"
31
31
  @output << "Total Time: #{thread.total_time}\n"
@@ -7,10 +7,14 @@ module RubyProf
7
7
  # :nodoc:
8
8
  def measure_mode_string
9
9
  case self.measure_mode
10
- when WALL_TIME then "wall_time"
11
- when PROCESS_TIME then "process_time"
12
- when ALLOCATIONS then "allocations"
13
- when MEMORY then "memory"
10
+ when WALL_TIME
11
+ "wall_time"
12
+ when PROCESS_TIME
13
+ "process_time"
14
+ when ALLOCATIONS
15
+ "allocations"
16
+ when MEMORY
17
+ "memory"
14
18
  end
15
19
  end
16
20
 
@@ -1,3 +1,3 @@
1
1
  module RubyProf
2
- VERSION = "1.4.1"
2
+ VERSION = "1.4.2"
3
3
  end
@@ -2,8 +2,6 @@
2
2
  # encoding: UTF-8
3
3
 
4
4
  require File.expand_path("../test_helper", __FILE__)
5
- require 'stringio'
6
-
7
5
  class MarshalTest < TestCase
8
6
  def verify_profile(profile_1, profile_2)
9
7
  verify_threads(profile_1.threads, profile_2.threads)
@@ -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,93 +2,97 @@
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] }
23
21
  end
24
22
 
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"
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(@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
68
69
 
69
70
  def test_flat_result_max_percent
70
- printer = RubyProf::FlatPrinter.new(@result)
71
+ printer = RubyProf::FlatPrinter.new(self.run_profile)
71
72
 
72
- printer.print(output = '', max_percent: 1)
73
- self_percents = flat_output_nth_column_values(output, 1).map(&:to_f)
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)
74
76
 
75
77
  assert self_percents.max < 1
76
78
  end
77
79
 
78
80
  def test_flat_result_filter_by_total_time
79
- printer = RubyProf::FlatPrinter.new(@result)
81
+ printer = RubyProf::FlatPrinter.new(self.run_profile)
80
82
 
81
- printer.print(output = '', filter_by: :total_time, min_percent: 50)
82
- total_times = flat_output_nth_column_values(output, 2).map(&:to_f)
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)
83
86
 
84
87
  assert (total_times.min / total_times.max) >= 0.5
85
88
  end
86
89
 
87
90
  def test_flat_result_filter_by_self_time
88
- printer = RubyProf::FlatPrinter.new(@result)
91
+ printer = RubyProf::FlatPrinter.new(self.run_profile)
89
92
 
90
- printer.print(output = '', filter_by: :self_time, min_percent: 0.1)
91
- self_percents = flat_output_nth_column_values(output, 1).map(&:to_f)
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)
92
96
 
93
97
  assert self_percents.min >= 0.1
94
98
  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
 
@@ -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
@@ -1,8 +1,9 @@
1
1
  # encoding: UTF-8
2
2
 
3
- # Disable minitest parallel tests. The problem is the thread switching will cahnge test results
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.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-05-14 00:00:00.000000000 Z
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.4.1
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.1.2
197
+ rubygems_version: 3.1.4
197
198
  signing_key:
198
199
  specification_version: 4
199
200
  summary: Fast Ruby profiler