Skip to content

Commit

Permalink
fix: enable patches only in autopilot context
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Nov 14, 2023
1 parent 7243655 commit 1ce73d5
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 7 deletions.
2 changes: 2 additions & 0 deletions examples/event_prof_most_time_consuming_plan.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

run :event_prof, event: "factory.create", top_count: 1000

total_run_time = report.raw_report["absolute_run_time"]
Expand Down
2 changes: 2 additions & 0 deletions examples/stack_prof_plan.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# First, profile the boot time
run :stack_prof, boot: true, sample: 10

Expand Down
1 change: 1 addition & 0 deletions lib/test-prof-autopilot.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true

require "test_prof/autopilot/version"
require "test_prof/autopilot"
13 changes: 9 additions & 4 deletions lib/test_prof/autopilot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

require "test-prof"
require "test_prof/autopilot/configuration"
require "test_prof/autopilot/patches/event_prof_patch"
require "test_prof/autopilot/patches/tag_prof_patch"
require "test_prof/autopilot/patches/factory_prof_patch"
require "test_prof/autopilot/patches/stack_prof_patch"

# We only load the patches when tests are executed by autopilot
# TODO: We should move the patches into TestProf itself as `--format=json`.
if ENV["TEST_PROF_AUTOPILOT_ENABLED"] == "true"
require "test_prof/autopilot/patches/event_prof_patch"
require "test_prof/autopilot/patches/tag_prof_patch"
require "test_prof/autopilot/patches/factory_prof_patch"
require "test_prof/autopilot/patches/stack_prof_patch"
end
2 changes: 2 additions & 0 deletions lib/test_prof/autopilot/command_executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module Autopilot
# Module is used for commands execution in child process.
module CommandExecutor
def execute(env, command)
env.merge!("TEST_PROF_AUTOPILOT_ENABLED" => "true")

Open3.popen2e(env, command) do |_stdin, stdout_and_stderr, _wait_thr|
while (line = stdout_and_stderr.gets)
Logging.log line
Expand Down
4 changes: 2 additions & 2 deletions lib/test_prof/autopilot/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class Configuration

def initialize
@output = $stdout
@tmp_dir = "tmp/test_prof_autopilot"
@artifacts_dir = "test_prof_autopilot"
@tmp_dir = ENV.fetch("TEST_PROF_AUTOPILOT_TMP_DIR", "tmp/test_prof_autopilot")
@artifacts_dir = ENV.fetch("TEST_PROF_AUTOPILOT_DIR", "test_prof_autopilot")
@merge_format = "info"
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/test_prof/autopilot/command_executor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

describe "#execute" do
it "executes command in child process" do
expect(Open3).to receive(:popen2e).with({"EVENT_PROF" => "factory.create"}, "rspec")
expect(Open3).to receive(:popen2e).with({"EVENT_PROF" => "factory.create", "TEST_PROF_AUTOPILOT_ENABLED" => "true"}, "rspec")

subject.execute({"EVENT_PROF" => "factory.create"}, "rspec")
end
Expand Down

0 comments on commit 1ce73d5

Please sign in to comment.