Skip to content

Commit df4f87a

Browse files
authoredFeb 19, 2025··
Merge pull request #4406 from DataDog/ivoanjo/prof-11385-gvl-profiling-ga
[PROF-11385] Enable GVL profiling by default on Ruby 3.2+
2 parents aad61dd + 09eed91 commit df4f87a

File tree

5 files changed

+83
-40
lines changed

5 files changed

+83
-40
lines changed
 

‎.gitlab/benchmarks.yml

-8
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,6 @@ only-profiling-heap:
104104
DD_PROFILING_EXPERIMENTAL_HEAP_ENABLED: "true"
105105
ADD_TO_GEMFILE: "gem 'datadog', github: 'datadog/dd-trace-rb', ref: '$CI_COMMIT_SHA'"
106106

107-
only-profiling-gvl:
108-
extends: .benchmarks
109-
variables:
110-
DD_BENCHMARKS_CONFIGURATION: only-profiling
111-
DD_PROFILING_ENABLED: "true"
112-
DD_PROFILING_PREVIEW_GVL_ENABLED: "true"
113-
ADD_TO_GEMFILE: "gem 'datadog', github: 'datadog/dd-trace-rb', ref: '$CI_COMMIT_SHA'"
114-
115107
profiling-and-tracing:
116108
extends: .benchmarks
117109
variables:

‎lib/datadog/core/configuration/settings.rb

+22-6
Original file line numberDiff line numberDiff line change
@@ -463,15 +463,31 @@ def initialize(*_)
463463
end
464464
end
465465

466-
# Enables GVL profiling. This will show when threads are waiting for GVL in the timeline view.
467-
#
468-
# This is a preview feature and disabled by default. It requires Ruby 3.2+.
469-
#
470-
# @default `DD_PROFILING_PREVIEW_GVL_ENABLED` environment variable as a boolean, otherwise `false`
466+
# @deprecated Use {:gvl_enabled} instead.
471467
option :preview_gvl_enabled do |o|
472468
o.type :bool
473-
o.env 'DD_PROFILING_PREVIEW_GVL_ENABLED'
474469
o.default false
470+
o.after_set do |_, _, precedence|
471+
unless precedence == Datadog::Core::Configuration::Option::Precedence::DEFAULT
472+
Datadog.logger.warn(
473+
'The profiling.advanced.preview_gvl_enabled setting has been deprecated for removal and ' \
474+
'no longer does anything. Please remove it from your Datadog.configure block. ' \
475+
'GVL profiling is now controlled by the profiling.advanced.gvl_enabled setting instead.'
476+
)
477+
end
478+
end
479+
end
480+
481+
# Controls GVL profiling. This will show when threads are waiting for GVL in the timeline view.
482+
#
483+
# This feature requires Ruby 3.2+.
484+
#
485+
# @default `DD_PROFILING_GVL_ENABLED` environment variable as a boolean, otherwise `true`
486+
option :gvl_enabled do |o|
487+
o.type :bool
488+
o.deprecated_env 'DD_PROFILING_PREVIEW_GVL_ENABLED'
489+
o.env 'DD_PROFILING_GVL_ENABLED'
490+
o.default true
475491
end
476492

477493
# Controls the smallest time period the profiler will report a thread waiting for the GVL.

‎lib/datadog/profiling/component.rb

+2-8
Original file line numberDiff line numberDiff line change
@@ -432,17 +432,11 @@ def self.build_profiler_component(settings:, agent_settings:, optional_tracer:,
432432
end
433433

434434
private_class_method def self.enable_gvl_profiling?(settings, logger)
435-
if RUBY_VERSION < "3.2"
436-
if settings.profiling.advanced.preview_gvl_enabled
437-
logger.warn("GVL profiling is currently not supported in Ruby < 3.2 and will not be enabled.")
438-
end
439-
440-
return false
441-
end
435+
return false if RUBY_VERSION < "3.2"
442436

443437
# GVL profiling only makes sense in the context of timeline. We could emit a warning here, but not sure how
444438
# useful it is -- if a customer disables timeline, there's nowhere to look for GVL profiling anyway!
445-
settings.profiling.advanced.timeline_enabled && settings.profiling.advanced.preview_gvl_enabled
439+
settings.profiling.advanced.timeline_enabled && settings.profiling.advanced.gvl_enabled
446440
end
447441
end
448442
end

‎spec/datadog/core/configuration/settings_spec.rb

+41-9
Original file line numberDiff line numberDiff line change
@@ -688,18 +688,50 @@
688688
end
689689
end
690690

691-
describe '#preview_gvl_enabled' do
692-
subject(:preview_gvl_enabled) { settings.profiling.advanced.preview_gvl_enabled }
691+
describe '#preview_gvl_enabled=' do
692+
it 'logs a warning informing customers this no longer does anything' do
693+
expect(Datadog.logger).to receive(:warn).with(/no longer does anything/)
693694

694-
it_behaves_like 'a binary setting with', env_variable: 'DD_PROFILING_PREVIEW_GVL_ENABLED', default: false
695+
settings.profiling.advanced.preview_gvl_enabled = true
696+
end
695697
end
696698

697-
describe '#preview_gvl_enabled=' do
698-
it 'updates the #preview_gvl_enabled setting' do
699-
expect { settings.profiling.advanced.preview_gvl_enabled = true }
700-
.to change { settings.profiling.advanced.preview_gvl_enabled }
701-
.from(false)
702-
.to(true)
699+
describe '#gvl_enabled' do
700+
subject(:gvl_enabled) { settings.profiling.advanced.gvl_enabled }
701+
702+
it_behaves_like 'a binary setting with', env_variable: 'DD_PROFILING_GVL_ENABLED', default: true
703+
704+
context 'when DD_PROFILING_PREVIEW_GVL_ENABLED' do
705+
around do |example|
706+
ClimateControl.modify('DD_PROFILING_PREVIEW_GVL_ENABLED' => environment) do
707+
example.run
708+
end
709+
end
710+
711+
context 'is not defined' do
712+
let(:environment) { nil }
713+
714+
it { is_expected.to be true }
715+
end
716+
717+
[true, false].each do |value|
718+
context "is defined as #{value}" do
719+
let(:environment) { value.to_s }
720+
721+
before { expect(Datadog::Core).to receive(:log_deprecation) }
722+
723+
it { is_expected.to be value }
724+
end
725+
end
726+
end
727+
end
728+
729+
describe '#gvl_enabled=' do
730+
it 'updates the #gvl_enabled setting' do
731+
expect { settings.profiling.advanced.gvl_enabled = false }
732+
.to change { settings.profiling.advanced.gvl_enabled }
733+
.from(true)
734+
.to(false)
703735
end
704736
end
705737

‎spec/datadog/profiling/component_spec.rb

+18-9
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@
636636

637637
context "when GVL profiling is requested" do
638638
before do
639-
settings.profiling.advanced.preview_gvl_enabled = true
639+
settings.profiling.advanced.gvl_enabled = true
640640
# This triggers a warning in some Rubies so it's easier for testing to disable it
641641
settings.profiling.advanced.gc_enabled = false
642642
end
@@ -645,19 +645,11 @@
645645
before { skip "Behavior does not apply to current Ruby version" if RUBY_VERSION >= "3.2." }
646646

647647
it "does not enable GVL profiling" do
648-
allow(logger).to receive(:warn)
649-
650648
expect(Datadog::Profiling::Collectors::CpuAndWallTimeWorker)
651649
.to receive(:new).with(hash_including(gvl_profiling_enabled: false))
652650

653651
build_profiler_component
654652
end
655-
656-
it "logs a warning" do
657-
expect(logger).to receive(:warn).with(/GVL profiling is currently not supported/)
658-
659-
build_profiler_component
660-
end
661653
end
662654

663655
context "on Ruby >= 3.2" do
@@ -686,6 +678,23 @@
686678
end
687679
end
688680
end
681+
682+
context "when GVL profiling is disabled" do
683+
before do
684+
settings.profiling.advanced.gvl_enabled = false
685+
end
686+
687+
context "on Ruby >= 3.2" do
688+
before { skip "On Ruby < 3.2 you can't enable the feature, it's always disabled" if RUBY_VERSION < "3.2." }
689+
690+
it "disables GVL profiling" do
691+
expect(Datadog::Profiling::Collectors::CpuAndWallTimeWorker)
692+
.to receive(:new).with(hash_including(gvl_profiling_enabled: false))
693+
694+
build_profiler_component
695+
end
696+
end
697+
end
689698
end
690699
end
691700

0 commit comments

Comments
 (0)
Please sign in to comment.