Skip to content

GVL Instrumentation: pass thread->self as part of event data #8885

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

Merged
merged 1 commit into from
Nov 13, 2023

Conversation

casperisfine
Copy link
Contributor

Replaces: #6189
Context: ivoanjo/gvl-tracing#4

Some hooks may want to collect data on a per thread basis. Right now the only way to identify the concerned thread is to use rb_nativethread_self() or similar, but even then because of the thread cache or MaNy, two distinct Ruby threads may report the same native thread id.

By passing thread->self, hooks can use it as a key to store the metadata.

NB: Most hooks are executed outside the GVL, so such data collection need to use a thread-safe data-structure, and shouldn't use the reference in other ways from inside the hook.

They must also either pin that value or handle compaction.

cc @ko1 @tenderlove @ivoanjo

Context: ivoanjo/gvl-tracing#4

Some hooks may want to collect data on a per thread basis.
Right now the only way to identify the concerned thread is to
use `rb_nativethread_self()` or similar, but even then because
of the thread cache or MaNy, two distinct Ruby threads may report
the same native thread id.

By passing `thread->self`, hooks can use it as a key to store
the metadata.

NB: Most hooks are executed outside the GVL, so such data collection
need to use a thread-safe data-structure, and shouldn't use the
reference in other ways from inside the hook.

They must also either pin that value or handle compaction.
@jpcamara
Copy link
Contributor

This is great. This also should make it much simpler to use rb_profile_thread_frames when instrumenting 👌🏼

@ivoanjo
Copy link
Contributor

ivoanjo commented Nov 16, 2023

+1 This is great, thanks as always :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants