Skip to content

Support GC detection for 3.1.0+#16

Closed
dalehamel wants to merge 3 commits into
mainfrom
ruby-gc-frames-rebased
Closed

Support GC detection for 3.1.0+#16
dalehamel wants to merge 3 commits into
mainfrom
ruby-gc-frames-rebased

Conversation

@dalehamel
Copy link
Copy Markdown
Member

What

When we are running GC, we insert dummy frames to indicate the GC state, and not unwind the ruby stack:

Image Screenshot 2025-11-06 at 10 46 54 AM

Why

When GC runs, we are no longer actually running the interpreter code. The current approach will erroneously attribute the GC native frames to whatever the state of the ruby VM is, even though that ruby stack had nothing to do with the triggering of GC.

This also allows us to keep track of GC overhead very easily, as the various GC modes (predominantly marking and sweeping) are grouped under a single "garbage collection" frame.

How

Taking inspiration from stackprof, we copy the same convention they use for dummy frames:

https://github.com/tmm1/stackprof/blob/8085169f071b2e25d5d798482bd1737e012af877/ext/stackprof/stackprof.c#L29-L33

This gives us a similar view to what stackprof request profiles:

Image Image

Only we get additional details, we can see the actual native code that the ruby VM is running.

To do this, we will check objspace for the flags that indicate if gc is running, and if so, in which mode. If GC is running, we push a special "GC" frame type indicating what GC mode we are in, and handle this accordingly on the userspace side.

@dalehamel dalehamel force-pushed the ruby-gc-frames-rebased branch from d8ef66f to dbe484f Compare January 20, 2026 19:20
@dalehamel dalehamel mentioned this pull request Jan 20, 2026
@dalehamel
Copy link
Copy Markdown
Member Author

Upstream PR opened open-telemetry#1101

@dalehamel
Copy link
Copy Markdown
Member Author

Merged upstream

@dalehamel dalehamel closed this Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant