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

[Mono]: Make EventPipe MonoProfiler provider GC events async safe. #56714

Merged

Conversation

lateralusX
Copy link
Member

@lateralusX lateralusX commented Aug 2, 2021

EventPipe MonoProfiler provider includes most Mono profiler events, but events currently triggered during GC is not emitted since EventPipe is not async safe.

This PR add support to emit the MonoProfiler events triggered during GC (gc resize, gc moves, gc roots and heap dump object references) into a async safe temporary memory buffer that will be emitted into EventPipe once GC completes (and world has been restarted). This opens up the ability to do heapshots using EventPipe running on Mono into nettrace files.

Heapshots can be triggered in same way as on CoreCLR, creating an EventPipe session with GCHeapCollectKeyword keyword. Only one heapshot can be triggered at a time, so in order to trigger an additional heapshot, a new EventPipe session is setup (after the previous heapshot has completed). Heapshot events will be included in all session with configured keywords.

It is also possible to include all vtable/class references (including class name), into heap dump. This is enabled by a specific keyword and makes the dump self contained (no need to track type load etc). That way runtime can start up without any profiler support, and then it is possible to use custom tool or dotnet-trace to request a heap dump (including all referenced vtable/class references) and once that session is done, it is possible to do a new session and get a new separate heap dump into a new session. Having separate sessions in different files opens up the ability to diff between any heap dump over time.

Copy link
Member

@lambdageek lambdageek left a comment

Choose a reason for hiding this comment

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

lgtm. I'd like to see a bit more abstraction around the shared/exclusive lock (particularly the casting and bit manipulation could use some macros or helper functions).

Also consider making it automatic to take the shared fire event lock by making it part of the FireXYZ generated methods.

src/mono/mono/eventpipe/ep-rt-mono.c Outdated Show resolved Hide resolved
src/mono/mono/eventpipe/ep-rt-mono.c Outdated Show resolved Hide resolved
src/mono/mono/eventpipe/ep-rt-mono.c Outdated Show resolved Hide resolved
src/mono/mono/eventpipe/ep-rt-mono.c Outdated Show resolved Hide resolved
src/mono/mono/eventpipe/ep-rt-mono.c Show resolved Hide resolved
src/mono/mono/eventpipe/ep-rt-mono.c Show resolved Hide resolved
EventPipe MonoProfiler provider includes most Mono profiler events,
but events currently triggered during GC is not emitted since EventPipe
is not async safe.

This commit add support to emit the MonoProfiler events triggered during
GC (gc resize, gc moves, gc roots and heap dump object references) into
a async safe temporary memory buffer that will be emitted into EventPipe
once GC completes (and world has been restarted). This opens up the
ability to do heapshots using EventPipe running on Mono into nettrace
files.

Heapshots can be triggered in same way as on CoreCLR, creating an
EventPipe session with GCHeapCollectKeyword keyword. Only one heapshot
can be triggered at a time, so in order to trigger an additional
heapshot, a new EventPipe session is setup (after the previous heapshot
has completed). Heapshot events will be included in all session with
configured keywords.

It is also possible to include all vtable/class references
(including class name), into heap dump. This is enabled by a specific
keyword and makes the dump self contained (no need to track type load etc).
That way runtime can start up without any profiler support, and then it
is possible to use custom tool or dotnet-trace to request a heap dump
(including all referenced vtable/class references) and once that
session is done, it is possible to do a new session and get a new
separate heap dump into a new session. Having separate sessions in
different files opens up the ability to diff between any heap dump over
time.
@lateralusX lateralusX force-pushed the lateralusX/add-dump-heap-profiler-events branch from 0949e9b to 9a9b93c Compare August 4, 2021 14:20
@lateralusX
Copy link
Member Author

@lambdageek Rebase and address feedback doing all bit manipulation in defines.

@lateralusX lateralusX changed the title [WIP][Mono]: Make EventPipe MonoProfiler provider GC events async safe. [Mono]: Make EventPipe MonoProfiler provider GC events async safe. Aug 4, 2021
@steveisok steveisok self-requested a review August 5, 2021 12:12
@lateralusX
Copy link
Member Author

Failures in runtime-staging is unrelated and appears on several other PR's as well.

@lateralusX lateralusX merged commit 7fb406a into dotnet:main Aug 6, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Sep 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants