Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 13 additions & 15 deletions datadog-profiling-replayer/src/replayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub struct Replayer<'pprof> {
pub start_time: SystemTime,
pub duration: Duration,
pub end_time: SystemTime, // start_time + duration
pub sample_types: Vec<api::ValueType<'pprof>>,
pub period: Option<api::Period<'pprof>>,
pub sample_types: Vec<api::SampleType>,
pub period: Option<api::Period>,
pub endpoints: Vec<(u64, &'pprof str)>,
pub samples: Vec<(Option<Timestamp>, api::Sample<'pprof>)>,
}
Expand Down Expand Up @@ -57,29 +57,27 @@ impl<'pprof> Replayer<'pprof> {

fn sample_types<'a>(
profile_index: &'a ProfileIndex<'pprof>,
) -> anyhow::Result<Vec<api::ValueType<'pprof>>> {
) -> anyhow::Result<Vec<api::SampleType>> {
let mut sample_types = Vec::with_capacity(profile_index.pprof.sample_types.len());
for sample_type in profile_index.pprof.sample_types.iter() {
sample_types.push(api::ValueType::new(
profile_index.get_string(sample_type.r#type)?,
profile_index.get_string(sample_type.unit)?,
))
let type_str = profile_index.get_string(sample_type.r#type)?;
let unit = profile_index.get_string(sample_type.unit)?;
let vt = api::ValueType::new(type_str, unit);
sample_types.push(vt.try_into()?);
}
Ok(sample_types)
}

fn period<'a>(
profile_index: &'a ProfileIndex<'pprof>,
) -> anyhow::Result<Option<api::Period<'pprof>>> {
fn period<'a>(profile_index: &'a ProfileIndex<'pprof>) -> anyhow::Result<Option<api::Period>> {
let value = profile_index.pprof.period;

match profile_index.pprof.period_type {
Some(period_type) => {
let r#type = api::ValueType::new(
profile_index.get_string(period_type.r#type)?,
profile_index.get_string(period_type.unit)?,
);
Ok(Some(api::Period { r#type, value }))
let type_str = profile_index.get_string(period_type.r#type)?;
let unit = profile_index.get_string(period_type.unit)?;
let vt = api::ValueType::new(type_str, unit);
let sample_type = vt.try_into()?;
Ok(Some(api::Period { sample_type, value }))
}
None => Ok(None),
}
Expand Down
12 changes: 5 additions & 7 deletions examples/cxx/profiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ int main() {
std::cout << "=== Datadog Profiling CXX Bindings Example ===" << std::endl;
std::cout << "\nCreating Profile..." << std::endl;

ValueType wall_time{
.type_ = "wall-time",
.unit = "nanoseconds"
};

Period period{
.value_type = wall_time,
.value_type = SampleType::WallTime,
.value = 60
};

auto profile = Profile::create({wall_time}, period);
// Create profile with predefined sample types
// Note: ExperimentalCount, ExperimentalNanoseconds, and ExperimentalBytes
// are available for custom profiling metrics
auto profile = Profile::create({SampleType::WallTime}, period);
std::cout << "✅ Profile created" << std::endl;

std::cout << "Adding upscaling rules..." << std::endl;
Expand Down
12 changes: 6 additions & 6 deletions examples/ffi/exporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ int main(int argc, char *argv[]) {

const auto service = argv[1];

const ddog_prof_ValueType wall_time = {
.type_ = DDOG_CHARSLICE_C_BARE("wall-time"),
.unit = DDOG_CHARSLICE_C_BARE("nanoseconds"),
// Use the SampleType enum instead of ValueType struct
const ddog_prof_SampleType wall_time = DDOG_PROF_SAMPLE_TYPE_WALL_TIME;
const ddog_prof_Slice_SampleType sample_types = {&wall_time, 1};
const ddog_prof_Period period = {
.sample_type = wall_time,
.value = 60,
};

const ddog_prof_Slice_ValueType sample_types = {&wall_time, 1};
const ddog_prof_Period period = {wall_time, 60};
ddog_prof_Profile_NewResult profile_new_result = ddog_prof_Profile_new(sample_types, &period);
if (profile_new_result.tag != DDOG_PROF_PROFILE_NEW_RESULT_OK) {
print_error("Failed to make new profile: ", profile_new_result.err);
Expand Down
40 changes: 22 additions & 18 deletions examples/ffi/exporter_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ void print_error(const char *s, const ddog_Error *err) {

// Helper function to create a simple profile with one sample
ddog_prof_Profile *create_profile_with_sample(void) {
const ddog_prof_ValueType wall_time = {
.type_ = DDOG_CHARSLICE_C_BARE("wall-time"),
.unit = DDOG_CHARSLICE_C_BARE("nanoseconds"),
// Use the SampleType enum instead of ValueType struct
const ddog_prof_SampleType wall_time = DDOG_PROF_SAMPLE_TYPE_WALL_TIME;
const ddog_prof_Slice_SampleType sample_types = {&wall_time, 1};
const ddog_prof_Period period = {
.sample_type = wall_time,
.value = 60,
};

const ddog_prof_Slice_ValueType sample_types = {&wall_time, 1};
const ddog_prof_Period period = {wall_time, 60};

ddog_prof_Profile_NewResult profile_result = ddog_prof_Profile_new(sample_types, &period);
if (profile_result.tag != DDOG_PROF_PROFILE_NEW_RESULT_OK) {
print_error("Failed to create profile", &profile_result.err);
Expand Down Expand Up @@ -121,16 +121,16 @@ int main(int argc, char *argv[]) {
}

// We need to heap-allocate the exporter to pass it to ExporterManager_new
ddog_prof_ProfileExporter *exporter = malloc(sizeof(ddog_prof_ProfileExporter));
*exporter = exporter_result.ok;
// The function takes ownership via a mutable pointer
ddog_prof_ProfileExporter exporter = exporter_result.ok;
ddog_prof_ProfileExporter *exporter_ptr = &exporter;

// Create the ExporterManager
printf("Creating ExporterManager...\n");
ddog_prof_Result_HandleExporterManager manager_result = ddog_prof_ExporterManager_new(exporter);
ddog_prof_Result_HandleExporterManager manager_result = ddog_prof_ExporterManager_new(exporter_ptr);
if (manager_result.tag != DDOG_PROF_RESULT_HANDLE_EXPORTER_MANAGER_OK_HANDLE_EXPORTER_MANAGER) {
print_error("Failed to create ExporterManager", &manager_result.err);
ddog_Error_drop(&manager_result.err);
free(exporter);
return 1;
}

Expand All @@ -156,15 +156,17 @@ int main(int argc, char *argv[]) {
return 1;
}

ddog_prof_EncodedProfile *encoded_profile = &serialize_result.ok;
// The queue function takes ownership of the encoded profile, so we need a mutable pointer
ddog_prof_EncodedProfile encoded_profile = serialize_result.ok;
ddog_prof_EncodedProfile *encoded_profile_ptr = &encoded_profile;

// Queue the profile (no additional files or tags for this simple example)
ddog_prof_Exporter_Slice_File empty_files = ddog_prof_Exporter_Slice_File_empty();
ddog_Vec_Tag empty_tags = ddog_Vec_Tag_new();

ddog_VoidResult queue_result = ddog_prof_ExporterManager_queue(
&manager,
encoded_profile,
encoded_profile_ptr,
empty_files,
&empty_tags,
NULL, // optional_process_tags
Expand All @@ -177,7 +179,7 @@ int main(int argc, char *argv[]) {
if (queue_result.tag != DDOG_VOID_RESULT_OK) {
print_error("Failed to queue profile", &queue_result.err);
ddog_Error_drop(&queue_result.err);
ddog_prof_EncodedProfile_drop(encoded_profile);
// encoded_profile was consumed by queue, so we don't drop it here
ddog_prof_Profile_drop(profile);
free(profile);
ddog_prof_ExporterManager_drop(&manager);
Expand All @@ -187,7 +189,7 @@ int main(int argc, char *argv[]) {
printf("Profile queued successfully!\n");

// Clean up profile after queueing
ddog_prof_EncodedProfile_drop(encoded_profile);
// Note: encoded_profile was consumed by queue, so we don't drop it
ddog_prof_Profile_drop(profile);
free(profile);

Expand Down Expand Up @@ -215,13 +217,15 @@ int main(int argc, char *argv[]) {
return 1;
}

encoded_profile = &serialize_result.ok;
// The queue function takes ownership of the encoded profile, so we need a mutable pointer
ddog_prof_EncodedProfile encoded_profile2 = serialize_result.ok;
ddog_prof_EncodedProfile *encoded_profile_ptr2 = &encoded_profile2;

// Queue another profile
empty_tags = ddog_Vec_Tag_new();
queue_result = ddog_prof_ExporterManager_queue(
&manager,
encoded_profile,
encoded_profile_ptr2,
empty_files,
&empty_tags,
NULL, // optional_process_tags
Expand All @@ -233,14 +237,14 @@ int main(int argc, char *argv[]) {
if (queue_result.tag != DDOG_VOID_RESULT_OK) {
print_error("Failed to queue profile for fork example", &queue_result.err);
ddog_Error_drop(&queue_result.err);
ddog_prof_EncodedProfile_drop(encoded_profile);
// encoded_profile was consumed by queue, so we don't drop it here
ddog_prof_Profile_drop(profile);
free(profile);
ddog_prof_ExporterManager_drop(&manager);
return 1;
}

ddog_prof_EncodedProfile_drop(encoded_profile);
// Note: encoded_profile was consumed by queue, so we don't drop it
ddog_prof_Profile_drop(profile);
free(profile);

Expand Down
11 changes: 6 additions & 5 deletions examples/ffi/profile_intern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ void wait_for_user(std::string s) {
}

int main(void) {
const ddog_prof_ValueType wall_time = {
.type_ = to_slice_c_char("wall-time"),
.unit = to_slice_c_char("nanoseconds"),
// Use the SampleType enum instead of ValueType struct
const ddog_prof_SampleType wall_time = DDOG_PROF_SAMPLE_TYPE_WALL_TIME;
const ddog_prof_Slice_SampleType sample_types = {&wall_time, 1};
const ddog_prof_Period period = {
.sample_type = wall_time,
.value = 60,
};
const ddog_prof_Slice_ValueType sample_types = {&wall_time, 1};
const ddog_prof_Period period = {wall_time, 60};

ddog_prof_Profile_NewResult new_result = ddog_prof_Profile_new(sample_types, &period);
if (new_result.tag != DDOG_PROF_PROFILE_NEW_RESULT_OK) {
Expand Down
11 changes: 6 additions & 5 deletions examples/ffi/profiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
#define NUM_SAMPLES 5000000

int main(void) {
const ddog_prof_ValueType wall_time = {
.type_ = DDOG_CHARSLICE_C("wall-time"),
.unit = DDOG_CHARSLICE_C("nanoseconds"),
// Use the SampleType enum instead of ValueType struct
const ddog_prof_SampleType wall_time = DDOG_PROF_SAMPLE_TYPE_WALL_TIME;
const ddog_prof_Slice_SampleType sample_types = {&wall_time, 1};
const ddog_prof_Period period = {
.sample_type = wall_time,
.value = 60,
};
const ddog_prof_Slice_ValueType sample_types = {&wall_time, 1};
const ddog_prof_Period period = {wall_time, 60};

// Create a ProfilesDictionary for the new API
ddog_prof_ProfilesDictionaryHandle dict = {0};
Expand Down
Loading
Loading