Skip to content

Commit

Permalink
Update to use new ddprof File struct
Browse files Browse the repository at this point in the history
See DataDog/libddprof#33 for details.
  • Loading branch information
ivoanjo committed May 19, 2022
1 parent 3a467b6 commit 00a5238
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions ext/ddtrace_profiling_native_extension/http_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ static ddprof_ffi_Request *build_request(
Check_Type(code_provenance_file_name, T_STRING);

// Code provenance can be disabled and in that case will be set to nil
if (!NIL_P(code_provenance_data)) Check_Type(code_provenance_data, T_STRING);
bool have_code_provenance = !NIL_P(code_provenance_data);
if (have_code_provenance) Check_Type(code_provenance_data, T_STRING);

uint64_t timeout_milliseconds = NUM2ULONG(upload_timeout_milliseconds);

Expand All @@ -257,34 +258,24 @@ static ddprof_ffi_Request *build_request(
ddprof_ffi_Timespec finish =
{.seconds = NUM2LONG(finish_timespec_seconds), .nanoseconds = NUM2UINT(finish_timespec_nanoseconds)};

int files_to_report = 1 + (NIL_P(code_provenance_data) ? 0 : 1);

int files_to_report = 1 + (have_code_provenance ? 1 : 0);
ddprof_ffi_File files[files_to_report];
ddprof_ffi_Slice_file slice_files = {.ptr = files, .len = files_to_report};

ddprof_ffi_Buffer *pprof_buffer =
ddprof_ffi_Buffer_from_byte_slice((ddprof_ffi_ByteSlice) {
.ptr = (uint8_t *) StringValuePtr(pprof_data),
.len = RSTRING_LEN(pprof_data)
});

files[0] = (ddprof_ffi_File) {.name = byte_slice_from_ruby_string(pprof_file_name), .file = pprof_buffer};

if (!NIL_P(code_provenance_data)) {
ddprof_ffi_Buffer *code_provenance_buffer =
ddprof_ffi_Buffer_from_byte_slice((ddprof_ffi_ByteSlice) {
.ptr = (uint8_t *) StringValuePtr(code_provenance_data),
.len = RSTRING_LEN(code_provenance_data)
});

files[1] = (ddprof_ffi_File) {.name = byte_slice_from_ruby_string(code_provenance_file_name), .file = code_provenance_buffer};
files[0] = (ddprof_ffi_File) {
.name = byte_slice_from_ruby_string(pprof_file_name),
.file = byte_slice_from_ruby_string(pprof_data)
};
if (have_code_provenance) {
files[1] = (ddprof_ffi_File) {
.name = byte_slice_from_ruby_string(code_provenance_file_name),
.file = byte_slice_from_ruby_string(code_provenance_data)
};
}

ddprof_ffi_Request *request =
ddprof_ffi_ProfileExporterV3_build(exporter, start, finish, slice_files, timeout_milliseconds);

// We don't need to free pprof_buffer nor code_provenance_buffer because libddprof takes care of it.

return request;
}

Expand Down

0 comments on commit 00a5238

Please sign in to comment.