Sample: EventPipeProfiler
The EventPipeProfiler can be enabled using the [EventPipeProfiler(...)] attribute. This attribute takes the following profiles:
CpuSampling- Useful for tracking CPU usage and general .NET runtime information. This is the default option.GcVerbose- Tracks GC collections and samples object allocations.GcCollect- Tracks GC collections only at very low overhead.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)
Source code
using System.Threading;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Diagnosers;
namespace BenchmarkDotNet.Samples
{
[ShortRunJob]
[EventPipeProfiler(EventPipeProfile.CpuSampling)]
public class IntroEventPipeProfiler
{
[Benchmark]
public void Sleep() => Thread.Sleep(2000);
}
}
Output
The output should contain information about the exported trace file which can be analyzed using SpeedScope.
// * Diagnostic Output - EventPipeProfiler *
Exported 1 trace file(s). Example:
C:\Work\BenchmarkDotNet\samples\BenchmarkDotNet.Samples\BenchmarkDotNet.Artifacts\BenchmarkDotNet.Samples.IntroEventPipeProfiler.Sleep-20200406-090113.speedscope.json