Skip to content

Commit 76a0704

Browse files
EventPipeProfiler documentation (#1418)
* EventPipeProfiler documentation * Update url to blog post. * Fix review
1 parent 2de040d commit 76a0704

File tree

6 files changed

+78
-1
lines changed

6 files changed

+78
-1
lines changed

docs/articles/configs/diagnosers.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ The current Diagnosers are:
3333
- Native Memory Profiler (`NativeMemoryProfiler`)
3434
It uses `EtwProfiler` to profile the code using ETW and adds the extra columns `Allocated native memory` and `Native memory leak`.
3535
Please see Wojciech Nagórski's [blog post](https://wojciechnagorski.com/2019/08/analyzing-native-memory-allocation-with-benchmarkdotnet/) for all the details.
36+
- Event Pipe Profiler (`EventPipeProfiler`).
37+
It is a cross-platform profiler that allows profile .NET code on every platform - Windows, Linux, macOS.
38+
Please see Wojciech Nagórski's [blog post](https://wojciechnagorski.com/2020/04/cross-platform-profiling-.net-code-with-benchmarkdotnet/) for all the details.
3639
- Threading Diagnoser (`ThreadingDiagnoser`) - .NET Core 3.0+ diagnoser that reports some Threading statistics.
3740

3841
## Usage
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
uid: docs.event-pipe-profiler
3+
name: EventPipeProfiler
4+
---
5+
6+
# EventPipeProfiler
7+
8+
`EventPipeProfiler` is a cross-platform profiler that allows profile .NET code on every platform - Windows, Linux, macOS. Collected data are exported to trace files (`.speedscope.json` and `.nettrace`) which can be analyzed using [SpeedScope](https://www.speedscope.app/), [PerfView](https://github.com/Microsoft/perfview), and [Windows Performance Analyzer](https://docs.microsoft.com/en-us/windows-hardware/test/wpt/windows-performance-analyzer). This new profiler is available from the 0.12.1 version.
9+
10+
![](https://wojciechnagorski.com/images/EventPipeProfiler/SpeedScopeAdvance.png)
11+
12+
# Configuration
13+
14+
`EventPipeProfiler` can be enabled in three ways:
15+
16+
1. Using parameter `-p EP` or `--profiler EP` from the console line.
17+
2. Marking the benchmarked class with `[EventPipeProfiler(...)]` attribute. You can find an example below.
18+
3. Using a custom configuration. You can find an example below.
19+
20+
[!include[IntroEventPipeProfiler](../samples/IntroEventPipeProfiler.md)]
21+
[!include[IntroEventPipeProfilerAdvanced](../samples/IntroEventPipeProfilerAdvanced.md)]

docs/articles/features/toc.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@
99
- name: Disassembler
1010
href: disassembler.md
1111
- name: EtwProfiler
12-
href: etwprofiler.md
12+
href: etwprofiler.md
13+
- name: EventPipeProfiler
14+
href: event-pipe-profiler.md
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
uid: BenchmarkDotNet.Samples.IntroEventPipeProfiler
3+
---
4+
5+
## Sample: EventPipeProfiler
6+
7+
The `EventPipeProfiler` can be enabled using the `[EventPipeProfiler(...)]` attribute. This attribute takes the following profiles:
8+
- `CpuSampling` - Useful for tracking CPU usage and general .NET runtime information. This is the default option.
9+
- `GcVerbose` - Tracks GC collections and samples object allocations.
10+
- `GcCollect` - Tracks GC collections only at very low overhead.
11+
- `Jit` - Logging when Just in time (JIT) compilation occurs. Logging of the internal workings of the Just In Time compiler. This is fairly verbose. It details decisions about interesting optimization (like inlining and tail call)
12+
13+
### Source code
14+
15+
[!code-csharp[EventPipeProfiler.cs](../../../samples/BenchmarkDotNet.Samples/IntroEventPipeProfiler.cs)]
16+
17+
### Output
18+
19+
The output should contain information about the exported trace file which can be analyzed using [SpeedScope](https://www.speedscope.app/).
20+
21+
```markdown
22+
// * Diagnostic Output - EventPipeProfiler *
23+
Exported 1 trace file(s). Example:
24+
C:\Work\BenchmarkDotNet\samples\BenchmarkDotNet.Samples\BenchmarkDotNet.Artifacts\BenchmarkDotNet.Samples.IntroEventPipeProfiler.Sleep-20200406-090113.speedscope.json
25+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
uid: BenchmarkDotNet.Samples.IntroEventPipeProfilerAdvanced
3+
---
4+
5+
## Sample: EventPipeProfilerAdvanced
6+
7+
The most advanced and powerful way to use `EventPipeProfiler` is a custom configuration. As you can see the below configuration adds `EventPipeProfiler` that constructor can take the profile and/or a list of providers.
8+
Both `EventPipeProfiler` and `dotnet trace` use the `Microsoft.Diagnostics.NETCore.Client` package internally. So before you start using the custom configuration of this profiler, it is worth reading the documentation [here](https://github.com/dotnet/diagnostics/blob/master/documentation/dotnet-trace-instructions.md) and [here](https://docs.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-trace#dotnet-trace-collect) where you can fine more information about how to configure provider list.
9+
10+
### Source code
11+
12+
[!code-csharp[EventPipeProfilerAdvanced.cs](../../../samples/BenchmarkDotNet.Samples/IntroEventPipeProfilerAdvanced.cs)]
13+
14+
### Output
15+
16+
The output should contain information about the exported trace file which can be analyzed using [SpeedScope](https://www.speedscope.app/).
17+
18+
```markdown
19+
// * Diagnostic Output - EventPipeProfiler *
20+
Exported 1 trace file(s). Example:
21+
C:\Work\BenchmarkDotNet\samples\BenchmarkDotNet.Samples\BenchmarkDotNet.Artifacts\BenchmarkDotNet.Samples.IntroEventPipeProfilerAdvanced.RentAndReturn_Shared-20200406-090136.speedscope.json
22+
```

docs/articles/samples/toc.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
href: IntroDisassemblyRyuJit.md
3535
- name: IntroEnvVars
3636
href: IntroEnvVars.md
37+
- name: IntroEventPipeProfiler
38+
href: IntroEventPipeProfiler.md
39+
- name: IntroEventPipeProfilerAdvanced
40+
href: IntroEventPipeProfilerAdvanced.md
3741
- name: IntroExport
3842
href: IntroExport.md
3943
- name: IntroExportJson

0 commit comments

Comments
 (0)