Skip to content

Commit 512413c

Browse files
authored
Add JitStatsDiagnoserAttribute (#2250)
1 parent a992b57 commit 512413c

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed

docs/articles/configs/diagnosers.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ The current Diagnosers are:
1111

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

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

129+
[!include[IntroJitStatsDiagnoser](../samples/IntroJitStatsDiagnoser.md)]
130+
126131
[!include[IntroNativeMemory](../samples/IntroNativeMemory.md)]
127132

128133
[!include[IntroThreadingDiagnoser](../samples/IntroThreadingDiagnoser.md)]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
uid: BenchmarkDotNet.Samples.IntroJitStatsDiagnoser
3+
---
4+
5+
## Sample: IntroJitStatsDiagnoser
6+
7+
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):
8+
* Amount of JITted methods.
9+
* Amount of [tiered methods](https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0#tiered-compilation).
10+
* How much memory JIT allocated during the benchmark.
11+
12+
### Restrictions
13+
14+
* Windows only
15+
16+
### Source code
17+
18+
[!code-csharp[IntroJitStatsDiagnoser.cs](../../../samples/BenchmarkDotNet.Samples/IntroJitStatsDiagnoser.cs)]
19+
20+
### Output
21+
22+
| Method | Mean | Error | StdDev | Methods JITted | Methods Tiered | JIT allocated memory |
23+
|------- |---------:|---------:|---------:|---------------:|---------------:|---------------------:|
24+
| Sleep | 15.50 ms | 0.052 ms | 0.048 ms | 1,102 | 214 | 221,736 B |
25+
26+
### Links
27+
28+
* @docs.diagnosers
29+
* The permanent link to this sample: @BenchmarkDotNet.Samples.IntroJitStatsDiagnoser
30+
31+
---

docs/articles/samples/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
href: IntroInProcess.md
6161
- name: IntroInProcessWrongEnv
6262
href: IntroInProcessWrongEnv.md
63+
- name: IntroJitStatsDiagnoser
64+
href: IntroJitStatsDiagnoser.md
6365
- name: IntroJobBaseline
6466
href: IntroJobBaseline.md
6567
- name: IntroJoin
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Threading;
2+
using BenchmarkDotNet.Attributes;
3+
4+
namespace BenchmarkDotNet.Samples
5+
{
6+
[Diagnostics.Windows.Configs.JitStatsDiagnoser]
7+
public class IntroJitStatsDiagnoser
8+
{
9+
[Benchmark]
10+
public void Sleep() => Thread.Sleep(10);
11+
}
12+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using BenchmarkDotNet.Configs;
3+
using JetBrains.Annotations;
4+
5+
namespace BenchmarkDotNet.Diagnostics.Windows.Configs
6+
{
7+
[PublicAPI]
8+
[AttributeUsage(AttributeTargets.Class)]
9+
public class JitStatsDiagnoserAttribute : Attribute, IConfigSource
10+
{
11+
public JitStatsDiagnoserAttribute()
12+
{
13+
Config = ManualConfig.CreateEmpty().AddDiagnoser(new JitStatsDiagnoser());
14+
}
15+
16+
public IConfig Config { get; }
17+
}
18+
}

0 commit comments

Comments
 (0)