-
Notifications
You must be signed in to change notification settings - Fork 10
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
[profiling] Use the new FFI macros and types #797
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -14,15 +14,15 @@ int main(void) { | ||||||||||||||||||||||
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, NULL); | |||||||||||||||||||||||
if (new_result.tag != DDOG_PROF_PROFILE_NEW_RESULT_OK) { | |||||||||||||||||||||||
ddog_prof_Result_HandleProfile new_result = ddog_prof_Profile_new(sample_types, &period, NULL); | |||||||||||||||||||||||
if (new_result.tag != DDOG_PROF_RESULT_HANDLE_PROFILE_OK_HANDLE_PROFILE) { | |||||||||||||||||||||||
Comment on lines
+17
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't write C API these days, but this looks worse. Can we use renames and/or aliases to improve this? Examples:
Not sure what to do about the enum. Maybe @ivoanjo has thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm yeah I think Levi has a good point here, the "handle" change does look a bit like libdatadog internal implementation details being leaked across the FFI. E.g. looking at it from the pure API client side, I'm not sure it's relevant for client to care what a I also know that (at least in the past) some of our types were a bit less what we wanted because of cbindgen limitations, and I think it's still a reasonable trade-off to have the types uglier if the rust code becomes less error-prone/etc. But ideally having both (clear naming for ffi and better rust types) would be great.
TL;DR: 👍 on this one :) On the We've been using the convention of calling One advantage of this new convention is that it may result (no pun intended) in fewer I still think I slightly favor more the current convention, but I think both seem quite reasonable. Here's a few examples for a comparison:
(There's also a few more results in ddcommon-ffi) Not wanting to discourage changes (I think one of the key ingredients of libdatadog's massive success so far has been having "no sacred cows", and instead always striving to leave things better, even if in the very short term it causes a bit of migration pain) I'll suggest that if we plan to introduce the new convention, I don't think we should mix both -- I think we should rip-off the band-aid and convert everything to the new convention. |
|||||||||||||||||||||||
ddog_CharSlice message = ddog_Error_message(&new_result.err); | |||||||||||||||||||||||
fprintf(stderr, "%.*s", (int)message.len, message.ptr); | |||||||||||||||||||||||
ddog_Error_drop(&new_result.err); | |||||||||||||||||||||||
exit(EXIT_FAILURE); | |||||||||||||||||||||||
} | |||||||||||||||||||||||
|
|||||||||||||||||||||||
ddog_prof_Profile *profile = &new_result.ok; | |||||||||||||||||||||||
ddog_prof_Handle_Profile *profile = &new_result.ok; | |||||||||||||||||||||||
|
|||||||||||||||||||||||
ddog_prof_Location root_location = { | |||||||||||||||||||||||
// yes, a zero-initialized mapping is valid | |||||||||||||||||||||||
|
@@ -47,8 +47,8 @@ int main(void) { | ||||||||||||||||||||||
for (int i = 0; i < 10000000; i++) { | |||||||||||||||||||||||
label.num = i; | |||||||||||||||||||||||
|
|||||||||||||||||||||||
ddog_prof_Profile_Result add_result = ddog_prof_Profile_add(profile, sample, 0); | |||||||||||||||||||||||
if (add_result.tag != DDOG_PROF_PROFILE_RESULT_OK) { | |||||||||||||||||||||||
ddog_VoidResult add_result = ddog_prof_Profile_add(profile, sample, 0); | |||||||||||||||||||||||
if (add_result.tag == DDOG_VOID_RESULT_ERR) { | |||||||||||||||||||||||
ddog_CharSlice message = ddog_Error_message(&add_result.err); | |||||||||||||||||||||||
fprintf(stderr, "%.*s", (int)message.len, message.ptr); | |||||||||||||||||||||||
ddog_Error_drop(&add_result.err); | |||||||||||||||||||||||
|
@@ -58,8 +58,8 @@ int main(void) { | ||||||||||||||||||||||
// printf("Press any key to reset and drop..."); | |||||||||||||||||||||||
// getchar(); | |||||||||||||||||||||||
|
|||||||||||||||||||||||
ddog_prof_Profile_Result reset_result = ddog_prof_Profile_reset(profile, NULL); | |||||||||||||||||||||||
if (reset_result.tag != DDOG_PROF_PROFILE_RESULT_OK) { | |||||||||||||||||||||||
ddog_VoidResult reset_result = ddog_prof_Profile_reset(profile, NULL); | |||||||||||||||||||||||
if (reset_result.tag == DDOG_VOID_RESULT_ERR) { | |||||||||||||||||||||||
ddog_CharSlice message = ddog_Error_message(&reset_result.err); | |||||||||||||||||||||||
fprintf(stderr, "%.*s", (int)message.len, message.ptr); | |||||||||||||||||||||||
ddog_Error_drop(&reset_result.err); | |||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't care about the C++ changes, if someone thinks it's better, it's fine to me.