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-7307] Include 'ruby vm type' in profiler allocation samples #3074

Merged
merged 4 commits into from
Aug 25, 2023

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented Aug 24, 2023

What does this PR do?:

This PR builds extends the existing support for the ThreadContext collector to sample allocations to also record the "ruby vm type" of sampled objects.

This "ruby vm type" is what Ruby internally represents in its enum ruby_value_type, see
https://github.com/ruby/ruby/blob/84a12d657848dfb54f8cc556d344f017a793e95a/include/ruby/internal/value_type.h#L112

Motivation:

I'm working on tagging stacks of sampled objects with both the object class, as well as the ruby vm type.

I'm not yet sure how we may expose the ruby vm type in the UX, but having it is useful for development and debugging, and I can imagine it being useful in advanced use cases (e.g. a customer downloading a pprof to look at this data).

As libdatadog interns labels (DataDog/libdatadog#205), the cost of tracking this data is quite low.

Additional Notes:

Allocation profiling is still not something that can be enabled; e.g. right now we can only exercise it directly by calling the ThreadContext collector.

How to test the change?:

Change includes test coverage.

**What does this PR do?**:

This PR builds extends the existing support for the `ThreadContext`
collector to sample allocations to also record the "ruby vm type" of
sampled objects.

This "ruby vm type" is what Ruby internally represents in
its `enum ruby_value_type`, see
https://github.com/ruby/ruby/blob/84a12d657848dfb54f8cc556d344f017a793e95a/include/ruby/internal/value_type.h#L112

**Motivation**:

I'm working on tagging stacks of sampled objects with both the
object class, as well as the ruby vm type.

I'm not yet sure how we may expose the ruby vm type in the UX,
but having it is useful for development and debugging, and I
can imagine it being useful in advanced use cases
(e.g. a customer downloading a pprof to look at this data).

As libdatadog interns labels
(DataDog/libdatadog#205), the cost
of tracking this data is quite low.

**Additional Notes**:

Allocation profiling is still not something that can be enabled;
e.g. right now we can only exercise it directly by calling the
`ThreadContext` collector.

**How to test the change?**:

Change includes test coverage.
@ivoanjo ivoanjo requested a review from a team August 24, 2023 11:30
@github-actions github-actions bot added the profiling Involves Datadog profiling label Aug 24, 2023
@codecov-commenter
Copy link

Codecov Report

Merging #3074 (a653344) into master (afc4a02) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #3074   +/-   ##
=======================================
  Coverage   98.13%   98.13%           
=======================================
  Files        1328     1328           
  Lines       75128    75139   +11     
  Branches     3421     3421           
=======================================
+ Hits        73725    73736   +11     
  Misses       1403     1403           
Files Changed Coverage Δ
...atadog/profiling/collectors/thread_context_spec.rb 98.33% <100.00%> (+0.03%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

#ifdef RUBY_T_MOVED // Introduced in Ruby 2.7
case(RUBY_T_MOVED ): return "T_MOVED";
#endif
default: return "T_UNKNOWN_OR_MISSING_RUBY_VALUE_TYPE_ENTRY";
Copy link
Member

Choose a reason for hiding this comment

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

Is this a default created for this PR? I couldn't find it the ruby's source code.

If so, I'd say keep it different from the others, and I find it quite hard to parse such a long screaming case string.

I suggest something like "Unknown Ruby Value", or something that will unmistakably read as "Ha, this is not a valid Ruby VM type".

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed in d73a72f to BUG: Unknown value for ruby_value_type. As you suspected, the only objective here was to have an obvious wrong value that we could grep in the codebase and tie back to this function, so we can make it look even more as an obvious wrong value.

The previous `#ifdef RUBY_T_MOVED` was actually failing silently; and
because it's hard to test this helper, it was easy to miss since it
just meant a not-often-used element of the enum was omitted on all
Rubies.

By instead flipping the check to be not defined, we get a better
behavior: the default is to include the enum member, and if we get
the logic to disable incorrect, we get a compile error, not a silent
bug.
@ivoanjo
Copy link
Member Author

ivoanjo commented Aug 25, 2023

/merge

@dd-devflow
Copy link

dd-devflow bot commented Aug 25, 2023

🚂 MergeQueue

This merge request is not mergeable yet, because of pending checks/missing approvals. It will be added to the queue as soon as checks pass and/or get approvals. You can remove it from the waiting list with /remove command.

you can cancel this operation by commenting your pull request with /merge -c!

@ivoanjo
Copy link
Member Author

ivoanjo commented Aug 25, 2023

/remove

@dd-devflow
Copy link

dd-devflow bot commented Aug 25, 2023

⚠️ MergeQueue

This merge request was unqueued

If you need support, contact us on slack #ci-interfaces!

@ivoanjo
Copy link
Member Author

ivoanjo commented Aug 25, 2023

I was playing with the merge queue feature, please ignore! :)

@ivoanjo ivoanjo merged commit be628e2 into master Aug 25, 2023
162 of 163 checks passed
@ivoanjo ivoanjo deleted the ivoanjo/prof-7307-ruby-vm-type-samples branch August 25, 2023 10:29
@github-actions github-actions bot added this to the 1.15.0 milestone Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mergequeue-status: removed profiling Involves Datadog profiling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants