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

[PROF-8648] Add labels to heap samples #3263

Conversation

AlexJF
Copy link
Contributor

@AlexJF AlexJF commented Nov 17, 2023

What does this PR do?

Builds on top of #3261 by tagging heap samples with alloc class and gc gen age labels that describe, respectively, what class a sample corresponds to and how many GCs has this sample survived for. The latter is especially useful to track memory leaks since anything that has a very recent age is susceptible to be cleared in a near-future GC whereas real leaks will tend to have very big ages.

image

Motivation:

Add more context to heap profiling data.

Additional Notes:

How to test the change?

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

Unsure? Have a question? Request a review!

@github-actions github-actions bot added the profiling Involves Datadog profiling label Nov 17, 2023
@AlexJF AlexJF force-pushed the alexjf/prof-8648-heap-profile-labels branch from b3f2aba to 39dc8cf Compare November 17, 2023 18:04
@AlexJF AlexJF changed the title [PROF-8632] Add labels to heap samples [PROF-8648] Add labels to heap samples Nov 17, 2023
Copy link
Member

@ivoanjo ivoanjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few notes, really nice progress! :D

Comment on lines +12 to +18
inline static ddog_CharSlice char_slice_from_c_string(char *string) {
return (ddog_CharSlice) {
.ptr = string,
.len = strlen(string),
};
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: I've been somewhat hesitating about adding this specific helper, because it "hides" the strlen; there's a few places in the codebase that could've used it and actually explicitly do the construction to expose that detail.

But... maybe it's premature optimization? Any thoughts?

(I guess a third solution would be to name this something like char_slice_from_char_plus_strlen or something like that, although this may just me striking back again with long function names haha)

@@ -184,10 +191,20 @@ static int st_object_records_iterate(st_data_t key, st_data_t value, st_data_t e
object_record *record = (object_record*) value;
internal_iteration_data *iteration_data = (internal_iteration_data*) extra;

// FIXME: Uncomment the below block
/*
if (!rb_gc_is_ptr_to_obj(obj)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... this one... Would be nice to have it indeed. To be honest, I don't think we've tried asking for it to be exposed yet, so maybe we could get it for some future Ruby version? 🤔

Comment on lines +437 to +439
object_metadata object_metadata_init(ddog_CharSlice *alloc_class, size_t alloc_generation) {
object_metadata metadata;
metadata.alloc_class = ruby_strdup(alloc_class->ptr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Hmm... is it me or are we rountripping a ddog_CharSlice back to a char *, so we can later turn it back to a ddog_CharSlice? Maybe worth introducing a char_slice_dup helper or something like that?

Comment on lines +67 to +68
ddog_CharSlice *alloc_class;
size_t alloc_gen;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: I think this could be object_metadata as well?

@AlexJF
Copy link
Contributor Author

AlexJF commented Dec 13, 2023

Replaced with more production-ready versions starting from #3281

@AlexJF AlexJF closed this Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
profiling Involves Datadog profiling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants