Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PROF-7192] Minor: Extend stack collector to be able to record the alloc-samples metric #2618

Merged
merged 1 commit into from
Feb 15, 2023
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
6 changes: 3 additions & 3 deletions ext/ddtrace_profiling_native_extension/collectors_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static VALUE _native_sample(
ENFORCE_TYPE(labels_array, T_ARRAY);
ENFORCE_TYPE(numeric_labels_array, T_ARRAY);

if (RHASH_SIZE(metric_values_hash) != ENABLED_VALUE_TYPES_COUNT) {
if (RHASH_SIZE(metric_values_hash) > ENABLED_VALUE_TYPES_COUNT || RHASH_SIZE(metric_values_hash) == 0) {
rb_raise(
rb_eArgError,
"Mismatched values for metrics; expected %lu values and got %lu instead",
Expand All @@ -92,8 +92,8 @@ static VALUE _native_sample(
);
}

int64_t metric_values[ENABLED_VALUE_TYPES_COUNT];
for (unsigned int i = 0; i < ENABLED_VALUE_TYPES_COUNT; i++) {
int64_t metric_values[ENABLED_VALUE_TYPES_COUNT] = {0};
for (unsigned int i = 0; i < RHASH_SIZE(metric_values_hash); i++) {
VALUE metric_value = rb_hash_fetch(metric_values_hash, rb_str_new_cstr(enabled_value_types[i].type_.ptr));
metric_values[i] = NUM2LONG(metric_value);
}
Expand Down
4 changes: 3 additions & 1 deletion ext/ddtrace_profiling_native_extension/stack_recorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ static const ddog_prof_ValueType enabled_value_types[] = {
#define CPU_SAMPLES_VALUE_POS 1
CPU_SAMPLES_VALUE,
#define WALL_TIME_VALUE_POS 2
WALL_TIME_VALUE
WALL_TIME_VALUE,
#define ALLOC_SAMPLES_VALUE_POS 3
ALLOC_SAMPLES_VALUE
};

#define ENABLED_VALUE_TYPES_COUNT (sizeof(enabled_value_types) / sizeof(ddog_prof_ValueType))
Expand Down
6 changes: 4 additions & 2 deletions spec/datadog/profiling/stack_recorder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def slot_two_mutex_locked?
'cpu-time' => 'nanoseconds',
'cpu-samples' => 'count',
'wall-time' => 'nanoseconds',
'alloc-samples' => 'count',
)
end

Expand All @@ -139,7 +140,7 @@ def sample_types_from(decoded_profile)
end

context 'when profile has a sample' do
let(:metric_values) { { 'cpu-time' => 123, 'cpu-samples' => 456, 'wall-time' => 789 } }
let(:metric_values) { { 'cpu-time' => 123, 'cpu-samples' => 456, 'wall-time' => 789, 'alloc-samples' => 4242 } }
let(:labels) { { 'label_a' => 'value_a', 'label_b' => 'value_b' }.to_a }

let(:samples) { samples_from_pprof(encoded_pprof) }
Expand All @@ -151,7 +152,8 @@ def sample_types_from(decoded_profile)
end

it 'encodes the sample with the metrics provided' do
expect(samples.first.values).to eq(:'cpu-time' => 123, :'cpu-samples' => 456, :'wall-time' => 789)
expect(samples.first.values)
.to eq(:'cpu-time' => 123, :'cpu-samples' => 456, :'wall-time' => 789, :'alloc-samples' => 4242)
end

it 'encodes the sample with the labels provided' do
Expand Down