Skip to content

Commit

Permalink
Add JitStatsDiagnoserAttribute (#2250)
Browse files Browse the repository at this point in the history
  • Loading branch information
KeterSCP committed Jan 20, 2023
1 parent a992b57 commit 512413c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/articles/configs/diagnosers.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ The current Diagnosers are:

- GC and Memory Allocation (`MemoryDiagnoser`) which is cross platform, built-in and **is not enabled by default anymore**.
Please see Adam Sitnik's [blog post](https://adamsitnik.com/the-new-Memory-Diagnoser/) for all the details.
- JIT Stats Diagnoser.
You can find this diagnoser in a separate package with diagnosers for Windows (`BenchmarkDotNet.Diagnostics.Windows`):
[![NuGet](https://img.shields.io/nuget/v/BenchmarkDotNet.svg)](https://www.nuget.org/packages/BenchmarkDotNet.Diagnostics.Windows/)
- JIT Inlining Events (`InliningDiagnoser`).
You can find this diagnoser in a separate package with diagnosers for Windows (`BenchmarkDotNet.Diagnostics.Windows`):
[![NuGet](https://img.shields.io/nuget/v/BenchmarkDotNet.svg)](https://www.nuget.org/packages/BenchmarkDotNet.Diagnostics.Windows/)
Expand Down Expand Up @@ -123,6 +126,8 @@ In BenchmarkDotNet, 1kB = 1024B, 1MB = 1024kB, and so on. The column Gen X means

[!include[IntroTailcall](../samples/IntroTailcall.md)]

[!include[IntroJitStatsDiagnoser](../samples/IntroJitStatsDiagnoser.md)]

[!include[IntroNativeMemory](../samples/IntroNativeMemory.md)]

[!include[IntroThreadingDiagnoser](../samples/IntroThreadingDiagnoser.md)]
Expand Down
31 changes: 31 additions & 0 deletions docs/articles/samples/IntroJitStatsDiagnoser.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
uid: BenchmarkDotNet.Samples.IntroJitStatsDiagnoser
---

## Sample: IntroJitStatsDiagnoser

This diagnoser shows various stats from the JIT compiler that were collected during entire benchmark run (warmup phase and BenchmarkDotNet-generated boilerplate code are included):
* Amount of JITted methods.
* Amount of [tiered methods](https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0#tiered-compilation).
* How much memory JIT allocated during the benchmark.

### Restrictions

* Windows only

### Source code

[!code-csharp[IntroJitStatsDiagnoser.cs](../../../samples/BenchmarkDotNet.Samples/IntroJitStatsDiagnoser.cs)]

### Output

| Method | Mean | Error | StdDev | Methods JITted | Methods Tiered | JIT allocated memory |
|------- |---------:|---------:|---------:|---------------:|---------------:|---------------------:|
| Sleep | 15.50 ms | 0.052 ms | 0.048 ms | 1,102 | 214 | 221,736 B |

### Links

* @docs.diagnosers
* The permanent link to this sample: @BenchmarkDotNet.Samples.IntroJitStatsDiagnoser

---
2 changes: 2 additions & 0 deletions docs/articles/samples/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
href: IntroInProcess.md
- name: IntroInProcessWrongEnv
href: IntroInProcessWrongEnv.md
- name: IntroJitStatsDiagnoser
href: IntroJitStatsDiagnoser.md
- name: IntroJobBaseline
href: IntroJobBaseline.md
- name: IntroJoin
Expand Down
12 changes: 12 additions & 0 deletions samples/BenchmarkDotNet.Samples/IntroJitStatsDiagnoser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Threading;
using BenchmarkDotNet.Attributes;

namespace BenchmarkDotNet.Samples
{
[Diagnostics.Windows.Configs.JitStatsDiagnoser]
public class IntroJitStatsDiagnoser
{
[Benchmark]
public void Sleep() => Thread.Sleep(10);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using BenchmarkDotNet.Configs;
using JetBrains.Annotations;

namespace BenchmarkDotNet.Diagnostics.Windows.Configs
{
[PublicAPI]
[AttributeUsage(AttributeTargets.Class)]
public class JitStatsDiagnoserAttribute : Attribute, IConfigSource
{
public JitStatsDiagnoserAttribute()
{
Config = ManualConfig.CreateEmpty().AddDiagnoser(new JitStatsDiagnoser());
}

public IConfig Config { get; }
}
}

0 comments on commit 512413c

Please sign in to comment.