-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: factory_default profiler support + chore
- Loading branch information
Showing
41 changed files
with
306 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Release gems | ||
on: | ||
workflow_dispatch: | ||
push: | ||
tags: | ||
- v* | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
id-token: write | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # Fetch current tag as annotated. See https://github.com/actions/checkout/issues/290 | ||
- uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: 3.2 | ||
- name: Configure RubyGems Credentials | ||
uses: rubygems/configure-rubygems-credentials@main | ||
- name: Publish to RubyGems | ||
run: | | ||
gem install gem-release | ||
gem release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ source "https://rubygems.org" | |
|
||
gem "debug", platform: :mri | ||
gem "factory_bot" | ||
gem "test-prof" | ||
|
||
gemspec | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module TestProf | ||
module Autopilot | ||
module FactoryDefault | ||
# Module is used for printing :factory_prof report | ||
module Printer | ||
Registry.register(:factory_default_prof_printer, self) | ||
|
||
class PrinterError < StandardError; end | ||
|
||
def print_report(report) | ||
result = report.result | ||
|
||
require "test_prof/factory_default" | ||
profiler = TestProf::FactoryDefault::Profiler.new | ||
profiler.data.merge!(result) | ||
profiler.print_report | ||
end | ||
|
||
module_function :print_report | ||
end | ||
end | ||
end | ||
end |
28 changes: 28 additions & 0 deletions
28
lib/test_prof/autopilot/factory_default/profiling_executor.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_prof/autopilot/profiling_executor/base" | ||
|
||
module TestProf | ||
module Autopilot | ||
module FactoryDefault | ||
# Provides :factory_default_prof specific validations, env and command building. | ||
class ProfilingExecutor < ProfilingExecutor::Base | ||
Registry.register(:factory_default_prof_executor, self) | ||
|
||
def initialize(options) | ||
super | ||
@profiler = :factory_default_prof | ||
end | ||
|
||
private | ||
|
||
def build_env | ||
super.tap do |env| | ||
env["FACTORY_DEFAULT_ENABLED"] = "true" | ||
env["FACTORY_DEFAULT_PROF"] = "1" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
require "json" | ||
require "test_prof/autopilot/report_builder" | ||
|
||
module TestProf | ||
module Autopilot | ||
module FactoryDefault | ||
class Report | ||
Registry.register(:factory_default_prof_report, self) | ||
|
||
extend ReportBuilder | ||
|
||
ARTIFACT_FILE = "factory_default_prof_report.json" | ||
|
||
attr_reader :type, :raw_report | ||
|
||
def initialize(raw_report) | ||
@type = :factory_default_prof | ||
@raw_report = raw_report | ||
end | ||
|
||
def result | ||
@result ||= raw_report.tap { |r| r.transform_values! { |v| v.transform_keys!(&:to_sym) } } | ||
end | ||
|
||
def factories | ||
result.dup | ||
end | ||
|
||
def merge(other) | ||
report = result.dup | ||
|
||
other.result.each do |name, stats| | ||
if result.key?(name) | ||
report[name][:count] += stats[:count] | ||
report[name][:time] += stats[:time] | ||
else | ||
report[name] = stats | ||
end | ||
end | ||
|
||
Report.new(report) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module TestProf | ||
module Autopilot | ||
module FactoryDefault | ||
# Class is used for writing :factory_prof report in different formats | ||
class Writer < ReportWriter | ||
Registry.register(:factory_default_prof_writer, self) | ||
|
||
ARTIFACT_FILE = "factory_default_prof_report" | ||
|
||
def generate_json | ||
report.result.to_json | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
module TestProf | ||
module Autopilot | ||
module Patches | ||
module FactoryDefaultPatch | ||
ARTIFACT_FILE = "factory_default_prof_report.json" | ||
|
||
module ProfilerExt | ||
def print_report | ||
# TODO: extract it into a method in TestProf | ||
data = self.data.each_with_object({}) do |(name, stats), acc| | ||
name = name.gsub(/\$id\$.+\$di\$/, "<id>") | ||
if acc.key?(name) | ||
acc[name][:count] += stats[:count] | ||
acc[name][:time] += stats[:time] | ||
else | ||
acc[name] = stats | ||
end | ||
end | ||
|
||
dir_path = FileUtils.mkdir_p(Autopilot.config.tmp_dir)[0] | ||
file_path = File.join(dir_path, ARTIFACT_FILE) | ||
|
||
File.write(file_path, data.to_json) | ||
end | ||
end | ||
|
||
def patch | ||
::TestProf::FactoryDefault::Profiler.prepend(ProfilerExt) | ||
end | ||
|
||
module_function :patch | ||
end | ||
end | ||
end | ||
end | ||
|
||
if ENV["FACTORY_DEFAULT_ENABLED"] == "true" | ||
require "test_prof/factory_default" | ||
require "test_prof/recipes/rspec/factory_default" | ||
TestProf::Autopilot::Patches::FactoryDefaultPatch.patch | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
run :factory_default_prof | ||
|
||
info report | ||
|
||
report.factories.select { |_, v| v[:count] > 1 }.each do |name, stats| | ||
puts "#{name} - #{stats[:count]} times, #{stats[:time]}s" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.