Skip to content

Commit

Permalink
Avoid duplicate boilerplate when calling record_placeholder_stack
Browse files Browse the repository at this point in the history
  • Loading branch information
ivoanjo committed Dec 11, 2023
1 parent 391db52 commit 807a519
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
11 changes: 5 additions & 6 deletions ext/ddtrace_profiling_native_extension/collectors_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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")
);
}

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion ext/ddtrace_profiling_native_extension/collectors_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down

0 comments on commit 807a519

Please sign in to comment.