https://github.com/gresau/gresau.tracing
Easy performance tracing for .NET Core 3
https://github.com/gresau/gresau.tracing
csharp netcore3 performance
Last synced: 6 months ago
JSON representation
Easy performance tracing for .NET Core 3
- Host: GitHub
- URL: https://github.com/gresau/gresau.tracing
- Owner: GREsau
- License: mit
- Created: 2019-11-25T00:54:23.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-10T00:04:42.000Z (almost 6 years ago)
- Last Synced: 2025-03-19T19:45:05.179Z (7 months ago)
- Topics: csharp, netcore3, performance
- Language: C#
- Homepage: https://www.nuget.org/packages/GREsau.Tracing
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GREsau.Tracing
GREsau.Tracing is a library to perform performance tracing of .NET Core applications. Essentially, it is a simplified alternative to [dotnet-trace](https://github.com/dotnet/diagnostics/blob/master/documentation/dotnet-trace-instructions.md), consumable as a C# library rather than a CLI tool.GREsau.Tracing will only output `nettrace`-format files. These can be viewed on Windows using [PerfView](https://github.com/microsoft/perfview), or converted to `speedscope`-format using dotnet-trace's convert command, and then viewed at https://www.speedscope.app.
```sh
# Converts nettrace file to speedscope, writing to trace.speedscope.json
> dotnet-trace convert --format Speedscope trace.nettrace
```This library makes use of [Microsoft.Diagnostics.NETCore.Client](https://www.nuget.org/packages/Microsoft.Diagnostics.NETCore.Client). If you're looking for something more powerful/flexible and you're willing to accept the complexity that comes with that, consider using that library directly.
## Installing
Install via NuGet:
```sh
> dotnet add package GREsau.Tracing
```## Basic Usage
To trace the current process for a period of time, saving the output file as "trace.nettrace":
```csharp
var client = new TraceClient();
await client.CollectAsync("trace.nettrace", TimeSpan.FromMinutes(1));
```You can also trace a different process by passing in its ID:
```csharp
var client = new TraceClient(123);
await client.CollectAsync("trace.nettrace", TimeSpan.FromMinutes(1));
```By default, `TraceClient` will track CPU usage and general .NET runtime information, equivalent to running dotnet-trace with the cpu-sampling (default) profile. If you want to trace something different, you can pass in a collection of `Microsoft.Diagnostics.NETCore.Client.EventPipeProvider`s:
```csharp
var gcCollectProvider = new EventPipeProvider(
"Microsoft-Windows-DotNETRuntime",
EventLevel.Informational,
(long)(ClrTraceEventParser.Keywords.GC | ClrTraceEventParser.Keywords.Exception));
var client = new TraceClient(providers: new[] { gcCollectProvider });
await client.CollectAsync("trace.nettrace", TimeSpan.FromMinutes(1));
```