test-prof 1.3.1 → 1.3.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: c81241143c4e7788e5fef3e5508534e878615a8e1b9e577a389d50da04cf445c
4
- data.tar.gz: cd4d3ff2cee2cc93c569d8d25fa574653c8c9b29a1e67d97673b6e784e341146
3
+ metadata.gz: ed617176a00461b30a96b07f086b52ea89d28fff7d1e4b085110e1b2333b6c60
4
+ data.tar.gz: c2e425a439407505f4ac1ecbfe25d84517343d7e9d7f1260ce675382f3ee6f1f
5
5
  SHA512:
6
- metadata.gz: 812d6f7fd0672cd5a08f3812aafb60b677be8ae8131620ca13495ae9f79b6b23bac3b3a9cec1c1f64bc6c7cba4cae156baa5fb2441756bf21dc41e2bfe2c4b70
7
- data.tar.gz: 6990de149f5824297ea8ff60ed07cc4ad8098fbb52a990d602418aaf37222a9a0583895ec2fa8c9a78fc6e54c8abadb344cdf53468e2f39daf900bbb54377352
6
+ metadata.gz: 3548abd19a6f283dd230e340a0651fc2196b7253bc4fcf4f5115d53a3e55b35e43ece87a875d4267a00edfa5105c303365bc1b7e9f787a0fcd5d3d8ffd86634b
7
+ data.tar.gz: 911ed9f79a48b4fd72b1ea7885f2eb5d3f75410421946cdd61966b9ffc50a245bb1f0c88b93b256ec5b06159267b16ccfcf129c06fde3d021605f1b15375c7cf
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 1.3.2 (2024-03-08) 🌷
6
+
7
+ - Add Minitest support for TagProf. ([@lioneldebauge][])
8
+
5
9
  ## 1.3.1 (2023-12-12)
6
10
 
7
11
  - Add support for dumping FactoryProf results in JSON format. ([@uzushino][])
@@ -381,3 +385,4 @@ See [changelog](https://github.com/test-prof/test-prof/blob/v0.8.0/CHANGELOG.md)
381
385
  [@bf4]: https://github.com/bf4
382
386
  [@Vankiru]: https://github.com/Vankiru
383
387
  [@uzushino]: https://github.com/uzushino
388
+ [@lioneldebauge]: https://github.com/lioneldebauge
@@ -3,6 +3,7 @@
3
3
  require "test_prof/event_prof/minitest"
4
4
  require "test_prof/factory_doctor/minitest"
5
5
  require "test_prof/memory_prof/minitest"
6
+ require "test_prof/tag_prof/minitest"
6
7
 
7
8
  module Minitest # :nodoc:
8
9
  module TestProf # :nodoc:
@@ -16,6 +17,7 @@ module Minitest # :nodoc:
16
17
  opts[:sample] = true if ENV["SAMPLE"] || ENV["SAMPLE_GROUPS"]
17
18
  opts[:mem_prof_mode] = ENV["TEST_MEM_PROF"] if ENV["TEST_MEM_PROF"]
18
19
  opts[:mem_prof_top_count] = ENV["TEST_MEM_PROF_COUNT"] if ENV["TEST_MEM_PROF_COUNT"]
20
+ opts[:tag_prof] = true if ENV["TAG_PROF"] == "type"
19
21
  end
20
22
  end
21
23
  end
@@ -50,6 +52,7 @@ module Minitest # :nodoc:
50
52
  reporter << TestProf::EventProfReporter.new(options[:io], options) if options[:event]
51
53
  reporter << TestProf::FactoryDoctorReporter.new(options[:io], options) if options[:fdoc]
52
54
  reporter << TestProf::MemoryProfReporter.new(options[:io], options) if options[:mem_prof_mode]
55
+ reporter << Minitest::TestProf::TagProfReporter.new(options[:io], options) if options[:tag_prof]
53
56
 
54
57
  ::TestProf::MinitestSample.call if options[:sample]
55
58
  end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Minitest
4
+ module TestProf
5
+ class TagProfReporter < BaseReporter # :nodoc:
6
+ attr_reader :results
7
+
8
+ def initialize(io = $stdout, _options = {})
9
+ super
10
+ @results = ::TestProf::TagProf::Result.new("type")
11
+
12
+ if event_prof_activated?
13
+ require "test_prof/event_prof"
14
+ @current_group_id = nil
15
+ @events_profiler = configure_profiler
16
+ @results = ::TestProf::TagProf::Result.new("type", @events_profiler.events)
17
+ end
18
+ end
19
+
20
+ def prerecord(group, example)
21
+ return unless event_prof_activated?
22
+
23
+ # enable event profiling
24
+ @events_profiler.group_started(true)
25
+ end
26
+
27
+ def record(result)
28
+ results.track(main_folder_path(result), time: result.time, events: fetch_events_data)
29
+ @events_profiler.group_started(nil) if event_prof_activated? # reset and disable event profilers
30
+ end
31
+
32
+ def report
33
+ printer = (ENV["TAG_PROF_FORMAT"] == "html") ? ::TestProf::TagProf::Printers::HTML : ::TestProf::TagProf::Printers::Simple
34
+ printer.dump(results)
35
+ end
36
+
37
+ private
38
+
39
+ def main_folder_path(result)
40
+ return :__unknown__ if absolute_path_from(result).nil?
41
+
42
+ absolute_path_from(result)
43
+ end
44
+
45
+ def absolute_path_from(result)
46
+ absolute_path = File.expand_path(result.source_location.first)
47
+ absolute_path.slice(/(?<=(?:spec|test)\/)\w*/)
48
+ end
49
+
50
+ def configure_profiler
51
+ ::TestProf::EventProf::CustomEvents.activate_all(tag_prof_event)
52
+ ::TestProf::EventProf.build(tag_prof_event)
53
+ end
54
+
55
+ def event_prof_activated?
56
+ return false if tag_prof_event.nil?
57
+
58
+ !tag_prof_event.empty?
59
+ end
60
+
61
+ def tag_prof_event
62
+ ENV["TAG_PROF_EVENT"]
63
+ end
64
+
65
+ def fetch_events_data
66
+ return {} unless @events_profiler
67
+
68
+ @events_profiler.profilers.map do |profiler|
69
+ [profiler.event, profiler.time || 0.0]
70
+ end.to_h
71
+ end
72
+ end
73
+ end
74
+ end
@@ -21,8 +21,8 @@ module TestProf
21
21
  def track(tag, time:, events: {})
22
22
  data[tag][:count] += 1
23
23
  data[tag][:time] += time
24
- events.each do |k, v|
25
- data[tag][k] += v
24
+ events.each do |event, time|
25
+ data[tag][event] += time
26
26
  end
27
27
  end
28
28
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TestProf
4
- VERSION = "1.3.1"
4
+ VERSION = "1.3.2"
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.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-12 00:00:00.000000000 Z
11
+ date: 2024-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -213,6 +213,7 @@ files:
213
213
  - lib/test_prof/stack_prof.rb
214
214
  - lib/test_prof/stack_prof/rspec.rb
215
215
  - lib/test_prof/tag_prof.rb
216
+ - lib/test_prof/tag_prof/minitest.rb
216
217
  - lib/test_prof/tag_prof/printers/html.rb
217
218
  - lib/test_prof/tag_prof/printers/simple.rb
218
219
  - lib/test_prof/tag_prof/result.rb