[Mono]: Make EventPipe MonoProfiler provider GC events async safe. (#56714)
authorJohan Lorensson <lateralusx.github@gmail.com>
Fri, 6 Aug 2021 18:35:56 +0000 (20:35 +0200)
committerGitHub <noreply@github.com>
Fri, 6 Aug 2021 18:35:56 +0000 (20:35 +0200)
commit7fb406a3cb11f0dd7bc9a177622d4e41206fb761
tree22a43b596bb7c2adc3d566845bae68362e75f2e4
parentb6647fce59c7de0f870dae4bd008c278c99e036f
[Mono]: Make EventPipe MonoProfiler provider GC events async safe. (#56714)

* Make EventPipe MonoProfiler provider GC events async safe.

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.
src/coreclr/vm/ClrEtwAll.man
src/coreclr/vm/ClrEtwAllMeta.lst
src/mono/mono/eventpipe/ep-rt-mono.c