Skip to content

Commit 37bf1a2

Browse files
committed
Re-apply "Merge pull request #4401 from DataDog/ivoanjo/prof-11394-heap-profiler-preview"
This reverts commit 32ded2e, thus re-applying the changes from #4401.
1 parent 2428c34 commit 37bf1a2

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

lib/datadog/core/configuration/settings.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def initialize(*_)
313313

314314
# Can be used to enable/disable the collection of heap profiles.
315315
#
316-
# This feature is alpha and disabled by default
316+
# This feature is in preview and disabled by default. Requires Ruby 3.1+.
317317
#
318318
# @warn To enable heap profiling you are required to also enable allocation profiling.
319319
#
@@ -326,12 +326,12 @@ def initialize(*_)
326326

327327
# Can be used to enable/disable the collection of heap size profiles.
328328
#
329-
# This feature is alpha and enabled by default when heap profiling is enabled.
329+
# This feature is in preview and by default is enabled whenever heap profiling is enabled.
330330
#
331-
# @warn To enable heap size profiling you are required to also enable allocation and heap profiling.
331+
# @warn Heap size profiling depends on allocation and heap profiling, so they must be enabled as well.
332332
#
333-
# @default `DD_PROFILING_EXPERIMENTAL_HEAP_SIZE_ENABLED` environment variable as a boolean, otherwise
334-
# whatever the value of DD_PROFILING_EXPERIMENTAL_HEAP_ENABLED is.
333+
# @default `DD_PROFILING_EXPERIMENTAL_HEAP_SIZE_ENABLED` environment variable as a boolean, otherwise it
334+
# follows the value of `experimental_heap_enabled`.
335335
option :experimental_heap_size_enabled do |o|
336336
o.type :bool
337337
o.env 'DD_PROFILING_EXPERIMENTAL_HEAP_SIZE_ENABLED'

lib/datadog/profiling/component.rb

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,14 @@ def self.build_profiler_component(settings:, agent_settings:, optional_tracer:,
221221
end
222222

223223
unless allocation_profiling_enabled
224-
raise ArgumentError, "Heap profiling requires allocation profiling to be enabled"
224+
logger.warn(
225+
"Heap profiling was requested but allocation profiling is not enabled. " \
226+
"Heap profiling has been disabled."
227+
)
228+
return false
225229
end
226230

227-
logger.warn(
228-
"Enabled experimental heap profiling: heap_sample_rate=#{heap_sample_rate}. This is experimental, not " \
229-
"recommended, and will increase overhead!"
230-
)
231+
logger.debug("Enabled heap profiling: heap_sample_rate=#{heap_sample_rate}")
231232

232233
true
233234
end
@@ -237,10 +238,6 @@ def self.build_profiler_component(settings:, agent_settings:, optional_tracer:,
237238

238239
return false unless heap_profiling_enabled && heap_size_profiling_enabled
239240

240-
logger.warn(
241-
"Enabled experimental heap size profiling. This is experimental, not recommended, and will increase overhead!"
242-
)
243-
244241
true
245242
end
246243

spec/datadog/profiling/component_spec.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,14 @@
331331
settings.profiling.allocation_enabled = false
332332
end
333333

334-
it "raises an ArgumentError during component initialization" do
335-
expect { build_profiler_component }.to raise_error(ArgumentError, /requires allocation profiling/)
334+
it "initializes StackRecorder without heap sampling support and warns" do
335+
expect(Datadog::Profiling::StackRecorder).to receive(:new)
336+
.with(hash_including(heap_samples_enabled: false, heap_size_enabled: false))
337+
.and_call_original
338+
339+
expect(logger).to receive(:warn).with(/allocation profiling is not enabled/)
340+
341+
build_profiler_component
336342
end
337343
end
338344

@@ -350,8 +356,7 @@
350356

351357
expect(logger).to receive(:info).with(/Ractors.+stopping/)
352358
expect(logger).to receive(:debug).with(/Enabled allocation profiling/)
353-
expect(logger).to receive(:warn).with(/experimental heap profiling/)
354-
expect(logger).to receive(:warn).with(/experimental heap size profiling/)
359+
expect(logger).to receive(:debug).with(/Enabled heap profiling/)
355360

356361
build_profiler_component
357362
end
@@ -368,8 +373,7 @@
368373

369374
expect(logger).to receive(:info).with(/Ractors.+stopping/)
370375
expect(logger).to receive(:debug).with(/Enabled allocation profiling/)
371-
expect(logger).to receive(:warn).with(/experimental heap profiling/)
372-
expect(logger).not_to receive(:warn).with(/experimental heap size profiling/)
376+
expect(logger).to receive(:debug).with(/Enabled heap profiling/)
373377

374378
build_profiler_component
375379
end

0 commit comments

Comments
 (0)