test-prof 1.4.0.rc.3 → 1.4.0.rc.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55eaa3ce2f79b5cae7992ea0e45a499c28ae1d301b2f7c9e34796d587c0e6090
4
- data.tar.gz: 2f5a07b3a9c78304c054e025d0e785a253d310c354005ca767a7ea0674033e0f
3
+ metadata.gz: 46c375967bb8f18cb7a27c0852c3bbc277ea6cae7c0d9ed51d8fe709b1ec67e9
4
+ data.tar.gz: 133939cf5cd497246b36642d3552ac0883a3a558d32775be960a9f308e3e67a5
5
5
  SHA512:
6
- metadata.gz: f26d5cdd70cd05d93fc0cc596302a72089c1718fd5b58084b5a219333ac6b0ba034d09c7a0e57840fa790f4198c7b8ba24f8dfdaa0d0b85a5f7404246b922b07
7
- data.tar.gz: 22e6d9304af0c182f4bd1bf7d4b34a9bc8d5435b505100bebe9519cdac2f3d29ba47db3fe7de48179cc88c191cac3da531de4d3b6f506c2275dc52f45b832444
6
+ metadata.gz: 830b4ed5c186ecec5a5396ad764f4d8c96700c8c0c3e55b2f0634b937906ec74d39e61ce1e270d9dd93a72b5618aaad87a6c0b316dc42874c3522631e1e8bbc6
7
+ data.tar.gz: 8e81d280c8f86adf1df271758d7bbf91499d86f2493ecbc6435f23cef73adfc23ed1404f475b10ef749a84dd19d0e87eff42aa61f1040738aef04cdb270a2689
@@ -7,7 +7,7 @@ module TestProf
7
7
  def create(name, overrides = {})
8
8
  variation = ""
9
9
 
10
- if FactoryProf.config.include_variations && !overrides.empty?
10
+ if FactoryProf.config.include_variations? && !overrides.empty?
11
11
  variation += overrides.keys.sort.to_s.gsub(/[\\":]/, "")
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ module TestProf
7
7
  def run(strategy = @strategy)
8
8
  variation = ""
9
9
 
10
- if FactoryProf.config.include_variations
10
+ if FactoryProf.config.include_variations?
11
11
  if @traits || @overrides
12
12
  unless @traits.empty?
13
13
  variation += @traits.sort.join(".").prepend(".")
@@ -40,6 +40,8 @@ module TestProf::FactoryProf
40
40
  (variation[:name] == "[...]") ? stat[:variations].size + 1 : i
41
41
  end
42
42
  sorted_variations.each do |variation_stat|
43
+ next if variation_stat[:total_count] < threshold
44
+
43
45
  msgs << format("%-5s%-18s %8d %11d %13.4fs %17.4fs %18.4fs", *format_args(variation_stat))
44
46
  end
45
47
  end
@@ -40,6 +40,10 @@ module TestProf
40
40
  def flamegraph?
41
41
  @mode == :flamegraph
42
42
  end
43
+
44
+ def include_variations?
45
+ @include_variations == true
46
+ end
43
47
  end
44
48
 
45
49
  class Result # :nodoc:
@@ -137,14 +141,14 @@ module TestProf
137
141
  @depth += 1
138
142
  @current_stack << factory if config.flamegraph?
139
143
  track_count(@stats[factory])
140
- track_count(@stats[factory][:variations][variation_name(variation)]) unless variation.empty?
144
+ track_count(@stats[factory][:variations][variation_name(variation)]) if config.include_variations?
141
145
  t1 = TestProf.now
142
146
  begin
143
147
  yield
144
148
  ensure
145
149
  t2 = TestProf.now
146
150
  track_time(@stats[factory], t1, t2)
147
- track_time(@stats[factory][:variations][variation_name(variation)], t1, t2) unless variation.empty?
151
+ track_time(@stats[factory][:variations][variation_name(variation)], t1, t2) if config.include_variations?
148
152
  @depth -= 1
149
153
  flush_stack if @depth.zero?
150
154
  end
@@ -153,6 +157,7 @@ module TestProf
153
157
  private
154
158
 
155
159
  def variation_name(variation)
160
+ return "-" if variation.empty?
156
161
  variations_count = variation.to_s.scan(/[\w]+/).size
157
162
  return "[...]" if variations_count > config.variations_limit
158
163
 
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.configure do |config|
4
+ report = nil
5
+
6
+ config.append_before(:suite) do
7
+ report = TestProf::RubyProf.profile(locked: true)
8
+
9
+ TestProf.log :info, "RubyProf enabled for examples"
10
+ end
11
+
12
+ config.after(:suite) do
13
+ report&.dump("examples")
14
+ end
15
+ end
@@ -48,12 +48,13 @@ module TestProf
48
48
  attr_accessor :printer, :mode, :min_percent,
49
49
  :include_threads, :exclude_common_methods,
50
50
  :test_prof_exclusions_enabled,
51
- :custom_exclusions
51
+ :custom_exclusions, :skip_boot
52
52
 
53
53
  def initialize
54
54
  @printer = ENV["TEST_RUBY_PROF"].to_sym if PRINTERS.key?(ENV["TEST_RUBY_PROF"])
55
55
  @printer ||= ENV.fetch("TEST_RUBY_PROF_PRINTER", :flat).to_sym
56
56
  @mode = ENV.fetch("TEST_RUBY_PROF_MODE", :wall).to_s
57
+ @skip_boot = %w[0 false f].include?(ENV["TEST_RUBY_PROF_BOOT"])
57
58
  @min_percent = 1
58
59
  @include_threads = false
59
60
  @exclude_common_methods = true
@@ -65,6 +66,10 @@ module TestProf
65
66
  include_threads == true
66
67
  end
67
68
 
69
+ def skip_boot?
70
+ skip_boot == true
71
+ end
72
+
68
73
  def exclude_common_methods?
69
74
  exclude_common_methods == true
70
75
  end
@@ -166,23 +171,21 @@ module TestProf
166
171
  #
167
172
  # Use this method to profile the whole run.
168
173
  def run
169
- report = profile
174
+ report = profile(locked: true)
170
175
 
171
176
  return unless report
172
177
 
173
- @locked = true
174
-
175
178
  log :info, "RubyProf enabled globally"
176
179
 
177
180
  at_exit { report.dump("total") }
178
181
  end
179
182
 
180
- def profile
183
+ def profile(locked: false)
181
184
  if locked?
182
185
  log :warn, <<~MSG
183
186
  RubyProf is activated globally, you cannot generate per-example report.
184
187
 
185
- Make sure you haven't set the TEST_RUBY_PROF environmental variable.
188
+ Make sure you haven not set the TEST_RUBY_PROF environmental variable.
186
189
  MSG
187
190
  return
188
191
  end
@@ -212,6 +215,8 @@ module TestProf
212
215
 
213
216
  profiler.start
214
217
 
218
+ @locked = true if locked
219
+
215
220
  Report.new(profiler)
216
221
  end
217
222
 
@@ -282,5 +287,13 @@ end
282
287
 
283
288
  # Hook to run RubyProf globally
284
289
  TestProf.activate("TEST_RUBY_PROF") do
285
- TestProf::RubyProf.run
290
+ if TestProf::RubyProf.config.skip_boot?
291
+ if TestProf.rspec?
292
+ require "test_prof/ruby_prof/rspec_no_boot"
293
+ else
294
+ TestProf.log :warn, "RubyProf tests profiling w/o test suite boot is only supported in RSpec"
295
+ end
296
+ else
297
+ TestProf::RubyProf.run
298
+ end
286
299
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TestProf
4
- VERSION = "1.4.0.rc.3"
4
+ VERSION = "1.4.0.rc.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-prof
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0.rc.3
4
+ version: 1.4.0.rc.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-25 00:00:00.000000000 Z
11
+ date: 2024-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -211,6 +211,7 @@ files:
211
211
  - lib/test_prof/ruby_prof.rb
212
212
  - lib/test_prof/ruby_prof/rspec.rb
213
213
  - lib/test_prof/ruby_prof/rspec_exclusions.rb
214
+ - lib/test_prof/ruby_prof/rspec_no_boot.rb
214
215
  - lib/test_prof/stack_prof.rb
215
216
  - lib/test_prof/stack_prof/rspec.rb
216
217
  - lib/test_prof/tag_prof.rb