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

Upgrade to libdatadog 0.9.0.1.0 #2302

Merged
merged 12 commits into from
Oct 10, 2022
Merged
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gem 'builder'
gem 'climate_control', '~> 0.2.0'
# Leave it open as we also have it as an integration and want Appraisal to control the version under test.
gem 'concurrent-ruby'
gem 'extlz4', '~> 0.3', '>= 0.3.3' if RUBY_PLATFORM != 'java' # Used to test lz4 compression done by libdatadog
gem 'json-schema', '< 3' # V3 only works with 2.5+
gem 'memory_profiler', '~> 0.9'
gem 'os', '~> 1.1'
Expand Down
1 change: 1 addition & 0 deletions benchmarks/profiler_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

require 'benchmark/ips'
require 'ddtrace'
require 'datadog/core/utils/compression'
require 'pry'
require 'digest'
require_relative 'dogstatsd_reporter'
Expand Down
2 changes: 1 addition & 1 deletion ddtrace.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'libddwaf', '~> 1.3.0.2.0'

# Used by profiling (and possibly others in the future)
spec.add_dependency 'libdatadog', '~> 0.7.0.1.1'
spec.add_dependency 'libdatadog', '~> 0.9.0.1.0'

spec.extensions = ['ext/ddtrace_profiling_native_extension/extconf.rb', 'ext/ddtrace_profiling_loader/extconf.rb']
end
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct cpu_and_wall_time_collector_state {
// Tracks per-thread state
struct per_thread_context {
char thread_id[THREAD_ID_LIMIT_CHARS];
ddprof_ffi_CharSlice thread_id_char_slice;
ddog_CharSlice thread_id_char_slice;
thread_cpu_time_id thread_cpu_time_id;
long cpu_time_at_previous_sample_ns; // Can be INVALID_TIME until initialized or if getting it fails for another reason
long wall_time_at_previous_sample_ns; // Can be INVALID_TIME until initialized
Expand Down Expand Up @@ -209,12 +209,12 @@ VALUE cpu_and_wall_time_collector_sample(VALUE self_instance) {
bool have_thread_name = thread_name != Qnil;

int label_count = 1 + (have_thread_name ? 1 : 0);
ddprof_ffi_Label labels[label_count];
ddog_Label labels[label_count];

labels[0] = (ddprof_ffi_Label) {.key = DDPROF_FFI_CHARSLICE_C("thread id"), .str = thread_context->thread_id_char_slice};
labels[0] = (ddog_Label) {.key = DDOG_CHARSLICE_C("thread id"), .str = thread_context->thread_id_char_slice};
if (have_thread_name) {
labels[1] = (ddprof_ffi_Label) {
.key = DDPROF_FFI_CHARSLICE_C("thread name"),
labels[1] = (ddog_Label) {
.key = DDOG_CHARSLICE_C("thread name"),
.str = char_slice_from_ruby_string(thread_name)
};
}
Expand All @@ -223,8 +223,8 @@ VALUE cpu_and_wall_time_collector_sample(VALUE self_instance) {
thread,
state->sampling_buffer,
state->recorder_instance,
(ddprof_ffi_Slice_i64) {.ptr = metric_values, .len = ENABLED_VALUE_TYPES_COUNT},
(ddprof_ffi_Slice_label) {.ptr = labels, .len = label_count}
(ddog_Slice_i64) {.ptr = metric_values, .len = ENABLED_VALUE_TYPES_COUNT},
(ddog_Slice_label) {.ptr = labels, .len = label_count}
);
}

Expand Down Expand Up @@ -261,7 +261,7 @@ static struct per_thread_context *get_or_create_context_for(VALUE thread, struct

static void initialize_context(VALUE thread, struct per_thread_context *thread_context) {
snprintf(thread_context->thread_id, THREAD_ID_LIMIT_CHARS, "%ld", thread_id_for(thread));
thread_context->thread_id_char_slice = (ddprof_ffi_CharSlice) {.ptr = thread_context->thread_id, .len = strlen(thread_context->thread_id)};
thread_context->thread_id_char_slice = (ddog_CharSlice) {.ptr = thread_context->thread_id, .len = strlen(thread_context->thread_id)};

thread_context->thread_cpu_time_id = thread_cpu_time_id_for(thread);

Expand Down
56 changes: 28 additions & 28 deletions ext/ddtrace_profiling_native_extension/collectors_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ struct sampling_buffer {
VALUE *stack_buffer;
int *lines_buffer;
bool *is_ruby_frame;
ddprof_ffi_Location *locations;
ddprof_ffi_Line *lines;
ddog_Location *locations;
ddog_Line *lines;
}; // Note: typedef'd in the header to sampling_buffer

static VALUE _native_sample(VALUE self, VALUE thread, VALUE recorder_instance, VALUE metric_values_hash, VALUE labels_array, VALUE max_frames);
static void maybe_add_placeholder_frames_omitted(VALUE thread, sampling_buffer* buffer, char *frames_omitted_message, int frames_omitted_message_size);
static void record_placeholder_stack_in_native_code(VALUE recorder_instance, ddprof_ffi_Slice_i64 metric_values, ddprof_ffi_Slice_label labels);
static void record_placeholder_stack_in_native_code(VALUE recorder_instance, ddog_Slice_i64 metric_values, ddog_Slice_label labels);

void collectors_stack_init(VALUE profiling_module) {
VALUE collectors_module = rb_define_module_under(profiling_module, "Collectors");
Expand Down Expand Up @@ -64,12 +64,12 @@ static VALUE _native_sample(DDTRACE_UNUSED VALUE _self, VALUE thread, VALUE reco
}

long labels_count = RARRAY_LEN(labels_array);
ddprof_ffi_Label labels[labels_count];
ddog_Label labels[labels_count];

for (int i = 0; i < labels_count; i++) {
VALUE key_str_pair = rb_ary_entry(labels_array, i);

labels[i] = (ddprof_ffi_Label) {
labels[i] = (ddog_Label) {
.key = char_slice_from_ruby_string(rb_ary_entry(key_str_pair, 0)),
.str = char_slice_from_ruby_string(rb_ary_entry(key_str_pair, 1))
};
Expand All @@ -84,16 +84,16 @@ static VALUE _native_sample(DDTRACE_UNUSED VALUE _self, VALUE thread, VALUE reco
thread,
buffer,
recorder_instance,
(ddprof_ffi_Slice_i64) {.ptr = metric_values, .len = ENABLED_VALUE_TYPES_COUNT},
(ddprof_ffi_Slice_label) {.ptr = labels, .len = labels_count}
(ddog_Slice_i64) {.ptr = metric_values, .len = ENABLED_VALUE_TYPES_COUNT},
(ddog_Slice_label) {.ptr = labels, .len = labels_count}
);

sampling_buffer_free(buffer);

return Qtrue;
}

void sample_thread(VALUE thread, sampling_buffer* buffer, VALUE recorder_instance, ddprof_ffi_Slice_i64 metric_values, ddprof_ffi_Slice_label labels) {
void sample_thread(VALUE thread, sampling_buffer* buffer, VALUE recorder_instance, ddog_Slice_i64 metric_values, ddog_Slice_label labels) {
int captured_frames = ddtrace_rb_profile_frames(
thread,
0 /* stack starting depth */,
Expand Down Expand Up @@ -157,15 +157,15 @@ void sample_thread(VALUE thread, sampling_buffer* buffer, VALUE recorder_instanc
name = NIL_P(name) ? missing_string : name;
filename = NIL_P(filename) ? missing_string : filename;

buffer->lines[i] = (ddprof_ffi_Line) {
.function = (ddprof_ffi_Function) {
buffer->lines[i] = (ddog_Line) {
.function = (ddog_Function) {
.name = char_slice_from_ruby_string(name),
.filename = char_slice_from_ruby_string(filename)
},
.line = line,
};

buffer->locations[i] = (ddprof_ffi_Location) {.lines = (ddprof_ffi_Slice_line) {.ptr = &buffer->lines[i], .len = 1}};
buffer->locations[i] = (ddog_Location) {.lines = (ddog_Slice_line) {.ptr = &buffer->lines[i], .len = 1}};
}

// Used below; since we want to stack-allocate this, we must do it here rather than in maybe_add_placeholder_frames_omitted
Expand All @@ -180,8 +180,8 @@ void sample_thread(VALUE thread, sampling_buffer* buffer, VALUE recorder_instanc

record_sample(
recorder_instance,
(ddprof_ffi_Sample) {
.locations = (ddprof_ffi_Slice_location) {.ptr = buffer->locations, .len = captured_frames},
(ddog_Sample) {
.locations = (ddog_Slice_location) {.ptr = buffer->locations, .len = captured_frames},
.values = metric_values,
.labels = labels,
}
Expand All @@ -201,10 +201,10 @@ static void maybe_add_placeholder_frames_omitted(VALUE thread, sampling_buffer*

// Important note: `frames_omitted_message` MUST have a lifetime that is at least as long as the call to
// `record_sample`. So be careful where it gets allocated. (We do have tests for this, at least!)
buffer->lines[buffer->max_frames - 1] = (ddprof_ffi_Line) {
.function = (ddprof_ffi_Function) {
.name = DDPROF_FFI_CHARSLICE_C(""),
.filename = ((ddprof_ffi_CharSlice) {.ptr = frames_omitted_message, .len = strlen(frames_omitted_message)})
buffer->lines[buffer->max_frames - 1] = (ddog_Line) {
.function = (ddog_Function) {
.name = DDOG_CHARSLICE_C(""),
.filename = ((ddog_CharSlice) {.ptr = frames_omitted_message, .len = strlen(frames_omitted_message)})
},
.line = 0,
};
Expand All @@ -230,21 +230,21 @@ static void maybe_add_placeholder_frames_omitted(VALUE thread, sampling_buffer*
//
// To give customers visibility into these threads, rather than reporting an empty stack, we replace the empty stack
// with one containing a placeholder frame, so that these threads are properly represented in the UX.
static void record_placeholder_stack_in_native_code(VALUE recorder_instance, ddprof_ffi_Slice_i64 metric_values, ddprof_ffi_Slice_label labels) {
ddprof_ffi_Line placeholder_stack_in_native_code_line = {
.function = (ddprof_ffi_Function) {
.name = DDPROF_FFI_CHARSLICE_C(""),
.filename = DDPROF_FFI_CHARSLICE_C("In native code")
static void record_placeholder_stack_in_native_code(VALUE recorder_instance, ddog_Slice_i64 metric_values, ddog_Slice_label labels) {
ddog_Line placeholder_stack_in_native_code_line = {
.function = (ddog_Function) {
.name = DDOG_CHARSLICE_C(""),
.filename = DDOG_CHARSLICE_C("In native code")
},
.line = 0
};
ddprof_ffi_Location placeholder_stack_in_native_code_location =
{.lines = (ddprof_ffi_Slice_line) {.ptr = &placeholder_stack_in_native_code_line, .len = 1}};
ddog_Location placeholder_stack_in_native_code_location =
{.lines = (ddog_Slice_line) {.ptr = &placeholder_stack_in_native_code_line, .len = 1}};

record_sample(
recorder_instance,
(ddprof_ffi_Sample) {
.locations = (ddprof_ffi_Slice_location) {.ptr = &placeholder_stack_in_native_code_location, .len = 1},
(ddog_Sample) {
.locations = (ddog_Slice_location) {.ptr = &placeholder_stack_in_native_code_location, .len = 1},
.values = metric_values,
.labels = labels,
}
Expand All @@ -263,8 +263,8 @@ sampling_buffer *sampling_buffer_new(unsigned int max_frames) {
buffer->stack_buffer = ruby_xcalloc(max_frames, sizeof(VALUE));
buffer->lines_buffer = ruby_xcalloc(max_frames, sizeof(int));
buffer->is_ruby_frame = ruby_xcalloc(max_frames, sizeof(bool));
buffer->locations = ruby_xcalloc(max_frames, sizeof(ddprof_ffi_Location));
buffer->lines = ruby_xcalloc(max_frames, sizeof(ddprof_ffi_Line));
buffer->locations = ruby_xcalloc(max_frames, sizeof(ddog_Location));
buffer->lines = ruby_xcalloc(max_frames, sizeof(ddog_Line));

return buffer;
}
Expand Down
4 changes: 2 additions & 2 deletions ext/ddtrace_profiling_native_extension/collectors_stack.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include <ddprof/ffi.h>
#include <datadog/profiling.h>

typedef struct sampling_buffer sampling_buffer;

void sample_thread(VALUE thread, sampling_buffer* buffer, VALUE recorder_instance, ddprof_ffi_Slice_i64 metric_values, ddprof_ffi_Slice_label labels);
void sample_thread(VALUE thread, sampling_buffer* buffer, VALUE recorder_instance, ddog_Slice_i64 metric_values, ddog_Slice_label labels);
sampling_buffer *sampling_buffer_new(unsigned int max_frames);
void sampling_buffer_free(sampling_buffer *buffer);
2 changes: 1 addition & 1 deletion ext/ddtrace_profiling_native_extension/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def add_compiler_flag(flag)
ENV['PKG_CONFIG_PATH'] = "#{ENV['PKG_CONFIG_PATH']}:#{Libdatadog.pkgconfig_folder}"
Logging.message(" [ddtrace] PKG_CONFIG_PATH set to #{ENV['PKG_CONFIG_PATH'].inspect}\n")

unless pkg_config('ddprof_ffi_with_rpath')
unless pkg_config('datadog_profiling_with_rpath')
skip_building_extension!(
if Datadog::Profiling::NativeExtensionHelpers::Supported.pkg_config_missing?
Datadog::Profiling::NativeExtensionHelpers::Supported::PKG_CONFIG_IS_MISSING
Expand Down
Loading