Skip to content

Commit

Permalink
Start profiler in start_if_enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotc committed Jan 27, 2022
1 parent 8f6708a commit afc4868
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/datadog/profiling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,13 @@ def self.configuration
# @return [Boolean] `true` if the profiler has successfully started, otherwise `false`.
# @public_api
def self.start_if_enabled
# Getting the profiler instance triggers start as a side-effect;
# If the profiler was not previously touched, getting the profiler instance triggers start as a side-effect
# otherwise we get nil
!!Datadog.send(:components).profiler
profiler = Datadog.send(:components).profiler
# ...but we still try to start it BECAUSE if the process forks, the profiler will exist but may
# not yet have been started in the fork
profiler.start if profiler
!!profiler
end

private_class_method def self.ruby_engine_unsupported?
Expand Down
7 changes: 6 additions & 1 deletion spec/datadog/profiling_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@
end

context 'with the profiler instance available' do
let(:result) { double }
let(:result) { instance_double(Datadog::Profiling::Profiler) }
it { is_expected.to be(true) }

it 'starts the profiler instance' do
expect(result).to receive(:start)
subject
end
end

context 'with the profiler instance not available' do
Expand Down

0 comments on commit afc4868

Please sign in to comment.