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

[docs] how to get gc dumps w/ dotnet-trace #7875

Merged
merged 8 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions Documentation/guides/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,63 @@ And the output files should be found in the current directory. You can
use the `-o` switch if you would prefer to output them to a specific
directory.

## How to get GC memory dumps?

If running on desktop, you can simply do:
jonathanpeppers marked this conversation as resolved.
Show resolved Hide resolved

```
$ dotnet gcdump collect -p 29096
jonathanpeppers marked this conversation as resolved.
Show resolved Hide resolved
```
jonathanpeppers marked this conversation as resolved.
Show resolved Hide resolved

See the [`dotnet-gcdump` documentation][dotnet-gcdump] for details.

This will connect to a process and save a `*.gcdump` file. You can
open this file in Visual Studio on Windows, for example:

![Visual Studio GC Heap Dump](../images/VS-GC-Dump.png)

To get this data from an Android application, you need all the above
setup for `adb shell`, `dsrouter`, etc. except you need to change the
provider for `dotnet-trace`:

```
jonathanpeppers marked this conversation as resolved.
Show resolved Hide resolved
$ dotnet-trace collect --diagnostic-port /tmp/maui-app --providers Microsoft-DotNETRuntimeMonoProfiler:0xC900003:4
jonathanpeppers marked this conversation as resolved.
Show resolved Hide resolved
```

`0xC900003`, a bitmask, enables the following event types:

* `GCKeyword`
* `GCHandleKeyword`
* `GCHeapCollectKeyword`
* `GCRootKeyword`

See the [`Microsoft-DotNETRuntimeMonoProfiler` event types][mono-events] for more info.

`:4` enables "Informational" verbosity.

This saves a `.nettrace` file with GC events that are not available
with the default provider.

To actually view this data, you'll have to use one of:

* https://github.com/lateralusX/diagnostics-nettrace-samples
* https://github.com/filipnavara/mono-nettrace-gcdump

Using `mono-nettrace-gcdump`:
jonathanpeppers marked this conversation as resolved.
Show resolved Hide resolved

```
jonathanpeppers marked this conversation as resolved.
Show resolved Hide resolved
$ dotnet run --project mono-nettrace-gcdump.csproj -- foo.nettrace
jonathanpeppers marked this conversation as resolved.
Show resolved Hide resolved
```

This saves a `foo.gcdump` that you can open in Visual Studio.

See the [dotnet/runtime documentation][gc-dumps-on-mono] for
additional details.

[dotnet-gcdump]: https://learn.microsoft.com/dotnet/core/diagnostics/dotnet-gcdump
[mono-events]: https://github.com/dotnet/runtime/blob/c887c92d8af4ce65b19962b777f96ae8eb997a42/src/coreclr/vm/ClrEtwAll.man#L7425
[gc-dumps-on-mono]: https://github.com/dotnet/runtime/blob/728fd85bc7ad04f5a0ea2ad0d4d8afe371ff9b64/docs/design/mono/diagnostics-tracing.md#collect-gc-dumps-on-monovm

## How to `dotnet trace` our build?

Setting this up is easy, the main issue is there end up being
Expand Down
Binary file added Documentation/images/VS-GC-Dump.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.