Skip to content

Commit

Permalink
Discussion from runtime/issues/12506
Browse files Browse the repository at this point in the history
dotnet/runtime#12506 (comment)

This article currently covers the verbose and (arguably, less common) way of using dotnet-trace to debug assembly loading issues, as most assembly loading issues likely occur when the generic IHostBuilder is initially called.

I debated rewriting the whole article to emphasize this use case, but I tempered that to simply get this documented with what I feel is the natural way to trace assembly loading events.

For the content, I elected to mostly use the docs @vitek-karas team has already written, here: https://github.com/dotnet/diagnostics/blob/main/documentation/dotnet-trace-instructions.md#using-dotnet-trace-to-launch-a-child-process-and-trace-it-from-startup

I realize copy-paste is not great, but I felt it was important to capture in this article the full flow of calling a new process.  I also fixed some minor stuff like kbd escape tags.
  • Loading branch information
jzabroski committed Aug 9, 2021
1 parent bd1b6a7 commit 474847c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/core/dependency-loading/collect-details.md
Expand Up @@ -16,6 +16,7 @@ Starting with .NET 5.0, the runtime can emit events through `EventPipe` with det

## Collect a trace with assembly loading events

### Tracing an existing process
To enable assembly loading events in the runtime and collect a trace of them, use `dotnet-trace` with the following command:

```console
Expand All @@ -24,6 +25,21 @@ dotnet-trace collect --providers Microsoft-Windows-DotNETRuntime:4 --process-id

This will collect a trace of the specified `<pid>`, enabling the `AssemblyLoader` events in the `Microsoft-Windows-DotNETRuntime` provider. The result is a `.nettrace` file.

### Using dotnet-trace to launch a child process and trace it from startup
Sometimes it may be useful to collect a trace of a process from its startup. For apps running .NET 5.0 or later, it is possible to do this by using dotnet-trace.

This will launch hello.exe with arg1 and arg2 as its command line arguments and collect a trace from its runtime startup:
```console
dotnet-trace collect --providers Microsoft-Windows-DotNETRuntime:4 -- hello.exe arg1 arg2
```

You can stop collecting the trace by pressing <kbd>Enter</kbd> or <kbd>Ctrl</kbd> + <kbd>C</kbd> key. Doing this will also exit hello.exe.

> [!NOTE]
> * Launching hello.exe via dotnet-trace will redirect its input/output and you will not be able to interact with it on the console by default. Use the `--show-child-io` switch to interact with its stdin/stdout.
> * Exiting the tool via CTRL+C or SIGTERM will safely end both the tool and the child process.
> * If the child process exits before the tool, the tool will exit as well and the trace should be safely viewable.
## View a trace

The collected trace file can be viewed on Windows using the Events view in [PerfView](https://github.com/microsoft/perfview). All the assembly loading events will be prefixed with `Microsoft-Windows-DotNETRuntime/AssemblyLoader`.
Expand Down

0 comments on commit 474847c

Please sign in to comment.