Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ext/datadog_profiling_native_extension/collectors_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions spec/datadog/profiling/collectors/stack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down