diff --git a/ext/datadog_profiling_native_extension/collectors_stack.c b/ext/datadog_profiling_native_extension/collectors_stack.c index bf60dbc78b8..94ca42cbdca 100644 --- a/ext/datadog_profiling_native_extension/collectors_stack.c +++ b/ext/datadog_profiling_native_extension/collectors_stack.c @@ -354,6 +354,10 @@ void sample_thread( state_label->str = DDOG_CHARSLICE_C("blocked"); } else if (CHARSLICE_EQUALS("wait_readable", name_slice)) { // Expected to be IO#wait_readable state_label->str = DDOG_CHARSLICE_C("network"); + } else if (CHARSLICE_EQUALS("_native_idle_sampling_loop", name_slice)) { // Expected to be Datadog::Profiler::Collectors::IdleSamplingHelper#_native_idle_sampling_loop + state_label->str = DDOG_CHARSLICE_C("waiting"); + } else if (CHARSLICE_EQUALS("_native_sampling_loop", name_slice)) { // Expected to be Datadog::Profiler::Collectors::CpuAndWallTimeWorker#_native_sampling_loop + state_label->str = DDOG_CHARSLICE_C("sleeping"); } #ifdef NO_PRIMITIVE_POP // Ruby < 3.2 else if (CHARSLICE_EQUALS("pop", name_slice)) { // Expected to be Queue/SizedQueue#pop diff --git a/spec/datadog/profiling/collectors/stack_spec.rb b/spec/datadog/profiling/collectors/stack_spec.rb index 8896eac7c47..7a9ecf8997a 100644 --- a/spec/datadog/profiling/collectors/stack_spec.rb +++ b/spec/datadog/profiling/collectors/stack_spec.rb @@ -578,6 +578,22 @@ def save_rounding_mode # rubocop:disable Lint/UselessMethodDefinition expect(sample_and_decode(background_thread, :labels)).to include(state: "unknown") end end + + context "when sampling the idle sampling helper thread" do + let(:expected_method_name) { "_native_idle_sampling_loop" } + let(:idle_sampling_helper) { Datadog::Profiling::Collectors::IdleSamplingHelper.new } + let(:do_in_background_thread) do + proc do |ready_queue| + ready_queue << true + Datadog::Profiling::Collectors::IdleSamplingHelper._native_idle_sampling_loop(idle_sampling_helper) + end + end + let(:metric_values) { {"cpu-time" => 0, "cpu-samples" => 1, "wall-time" => 1} } + + it do + expect(sample_and_decode(background_thread, :labels)).to include(state: "waiting") + end + end end context "when sampling a stack with a dynamically-generated template method name" do