Skip to content

Add hardware counter profile#3184

Open
bugRanger wants to merge 10 commits into
dotnet:masterfrom
bugRanger:feature/specific-hardware-counter
Open

Add hardware counter profile#3184
bugRanger wants to merge 10 commits into
dotnet:masterfrom
bugRanger:feature/specific-hardware-counter

Conversation

@bugRanger

@bugRanger bugRanger commented Jun 24, 2026

Copy link
Copy Markdown

SUMMARY

It's great that version 1 added counter support, but the expected counter names don't always match what the system provides.

Based on previous attempts (1, 2), providing free input strings provides versatility, but there are also drawbacks:

  • Inconvenient for teams working in different configurations;
  • Strings in attributes lead to a lot of duplicate code;

Therefore, an option with a profile description for extracting the required value sets could solve these problems.

UPD: Added simple test for ETW with custom profile, output result:

BenchmarkDotNet v0.16.0-develop (2026-06-25), Windows 10 (10.0.19045.6456/22H2/2022Update)
AMD Ryzen 7 5700G with Radeon Graphics 3.80GHz, 1 CPU, 16 logical and 8 physical cores
Memory: 27,9 GB Total, 13,77 GB Available
.NET SDK 10.0.103
  [Host] : .NET 8.0.24 (8.0.24, 8.0.2426.7010), X64 RyuJIT x86-64-v3
  Dry    : .NET 8.0.24 (8.0.24, 8.0.2426.7010), X64 RyuJIT x86-64-v3

Job=Dry  IterationCount=1  LaunchCount=1  
RunStrategy=ColdStart  UnrollFactor=1  

| Method         | Mean     | Error | FakeCacheMisses1/Op | FakeCacheMisses3/Op | FakeCacheMisses2/Op |
|--------------- |---------:|------:|--------------------:|--------------------:|--------------------:|
| SortedBranch   | 143.1 μs |    NA |             581,632 |             581,632 |              45,056 |
| UnsortedBranch | 180.3 μs |    NA |             577,536 |             577,536 |              45,056 |

@bugRanger

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

@timcassell

Copy link
Copy Markdown
Collaborator

It's an interesting approach. But it looks like you can only remap existing HardwareCounter enum members to machine-specific hardware counter names. I'm by no means an expert when it comes to hardware counters, but do we need to handle the case of a hardware counter that is not mapped to an existing enum member? Or in those cases we will just need to expand the enum to cover new cases?

@@ -0,0 +1,50 @@
<Project Sdk="Microsoft.NET.Sdk">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this project is not expected to be executed on CI.

Is it able to define these tests on BenchmarkDotNet.IntegrationTests.ManualRunning project side?


public class HardwareCounterTests(ITestOutputHelper output) : BenchmarkTestExecutor(output)
{
[Fact]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test has ETW namespace.
Is this test works on non-Windows environment?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not expect it to. #388 (comment)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not expect it to.

In that case, I think it need to replace [Fact] to use [EnvSpecificFact(EnvRequirement.WindowsOnly)].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants