From 807a5194b44eaf0b525b7a3cd3b553d8d29baa23 Mon Sep 17 00:00:00 2001 From: Ivo Anjo Date: Mon, 11 Dec 2023 13:11:41 +0000 Subject: [PATCH] Avoid duplicate boilerplate when calling `record_placeholder_stack` --- .../collectors_stack.c | 11 +++++------ .../collectors_stack.h | 2 +- .../collectors_thread_context.c | 3 +-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/ext/ddtrace_profiling_native_extension/collectors_stack.c b/ext/ddtrace_profiling_native_extension/collectors_stack.c index 404a4cabcb6..9bc0d11e0cb 100644 --- a/ext/ddtrace_profiling_native_extension/collectors_stack.c +++ b/ext/ddtrace_profiling_native_extension/collectors_stack.c @@ -115,13 +115,12 @@ static VALUE _native_sample( ddog_prof_Slice_Label slice_labels = {.ptr = labels, .len = labels_count}; if (in_gc == Qtrue) { - ddog_CharSlice gc_placeholder = DDOG_CHARSLICE_C("Garbage Collection"); record_placeholder_stack( buffer, recorder_instance, values, (sample_labels) {.labels = slice_labels, .state_label = state_label}, - (ddog_prof_Function) {.name = DDOG_CHARSLICE_C(""), .filename = gc_placeholder} + DDOG_CHARSLICE_C("Garbage Collection") ); } else { sample_thread( @@ -327,13 +326,12 @@ static void record_placeholder_stack_in_native_code( sample_values values, sample_labels labels ) { - ddog_CharSlice in_native_code_placeholder = DDOG_CHARSLICE_C("In native code"); record_placeholder_stack( buffer, recorder_instance, values, labels, - (ddog_prof_Function) {.name = DDOG_CHARSLICE_C(""), .filename = in_native_code_placeholder} + DDOG_CHARSLICE_C("In native code") ); } @@ -342,9 +340,10 @@ void record_placeholder_stack( VALUE recorder_instance, sample_values values, sample_labels labels, - ddog_prof_Function placeholder_stack + ddog_CharSlice placeholder_stack ) { - buffer->locations[0] = (ddog_prof_Location) {.function = placeholder_stack, .line = 0}; + ddog_prof_Function placeholder = {.name = DDOG_CHARSLICE_C(""), .filename = placeholder_stack}; + buffer->locations[0] = (ddog_prof_Location) {.function = placeholder, .line = 0}; record_sample( recorder_instance, diff --git a/ext/ddtrace_profiling_native_extension/collectors_stack.h b/ext/ddtrace_profiling_native_extension/collectors_stack.h index 3c9ae15db91..b026bbbdeb8 100644 --- a/ext/ddtrace_profiling_native_extension/collectors_stack.h +++ b/ext/ddtrace_profiling_native_extension/collectors_stack.h @@ -18,7 +18,7 @@ void record_placeholder_stack( VALUE recorder_instance, sample_values values, sample_labels labels, - ddog_prof_Function placeholder_stack + ddog_CharSlice placeholder_stack ); sampling_buffer *sampling_buffer_new(unsigned int max_frames); void sampling_buffer_free(sampling_buffer *buffer); diff --git a/ext/ddtrace_profiling_native_extension/collectors_thread_context.c b/ext/ddtrace_profiling_native_extension/collectors_thread_context.c index 7360982d47b..a86ce1dba9d 100644 --- a/ext/ddtrace_profiling_native_extension/collectors_thread_context.c +++ b/ext/ddtrace_profiling_native_extension/collectors_thread_context.c @@ -639,7 +639,6 @@ VALUE thread_context_collector_sample_after_gc(VALUE self_instance) { end_timestamp_ns = monotonic_to_system_epoch_ns(&state->time_converter_state, state->gc_tracking.wall_time_at_previous_gc_ns); } - ddog_CharSlice gc_placeholder = DDOG_CHARSLICE_C("Garbage Collection"); record_placeholder_stack( state->sampling_buffer, state->recorder_instance, @@ -655,7 +654,7 @@ VALUE thread_context_collector_sample_after_gc(VALUE self_instance) { .timeline_wall_time_ns = state->gc_tracking.accumulated_wall_time_ns, }, (sample_labels) {.labels = slice_labels, .state_label = NULL, .end_timestamp_ns = end_timestamp_ns}, - (ddog_prof_Function) {.name = DDOG_CHARSLICE_C(""), .filename = gc_placeholder} + DDOG_CHARSLICE_C("Garbage Collection") ); state->gc_tracking.wall_time_at_last_flushed_gc_event_ns = state->gc_tracking.wall_time_at_previous_gc_ns;