Skip to content

Convert HardwareCounter from enum to static class with const strings#1

Draft
Copilot wants to merge 2 commits intofeature/custom-hardware-countersfrom
copilot/change-hardwarecounter-to-class
Draft

Convert HardwareCounter from enum to static class with const strings#1
Copilot wants to merge 2 commits intofeature/custom-hardware-countersfrom
copilot/change-hardwarecounter-to-class

Conversation

Copy link

Copilot AI commented Jan 5, 2026

Converts HardwareCounter from an enum to a static class with const string fields, following the Column class pattern. This is a breaking change as requested.

Changes

Core API:

  • HardwareCounter is now a static class with const string fields instead of enum values
  • ToShortName() and TheGreaterTheBetter() converted from extension methods to static methods accepting strings
  • Added All property returning IReadOnlyList<string> of all counter names

Type signatures updated throughout:

  • HardwareCountersAttribute constructor: HardwareCounter[]string[]
  • IConfig.GetHardwareCounters(): IEnumerable<HardwareCounter>IEnumerable<string>
  • PmcStats.Counters: IReadOnlyDictionary<HardwareCounter, ...>IReadOnlyDictionary<string, ...>
  • PreciseMachineCounter.Counter: HardwareCounterstring
  • Config builders, parsers, and diagnostic components updated accordingly

Usage

Before and after usage remains identical at call sites:

// Still works the same way
[HardwareCounters(
    HardwareCounter.BranchMispredictions,
    HardwareCounter.CacheMisses)]
public class MyBenchmark { }

// Config API
config.AddHardwareCounters(HardwareCounter.CacheMisses);

// Values are now strings instead of enum members
string counter = HardwareCounter.Timer; // "Timer"

Users storing HardwareCounter as a type parameter or using it in generic constraints will need to update to string.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 1s1vsblobprodcus386.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build tests/BenchmarkDotNet.Tests/BenchmarkDotNet.Tests.csproj -c Release ACCEPT (dns block)
    • Triggering command: /usr/bin/dotnet dotnet build tests/BenchmarkDotNet.Tests/BenchmarkDotNet.Tests.csproj -c Release (dns block)
  • 7tjvsblobprodcus341.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build tests/BenchmarkDotNet.Tests/BenchmarkDotNet.Tests.csproj -c Release (dns block)
  • 8xbvsblobprodcus382.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build samples/BenchmarkDotNet.Samples/BenchmarkDotNet.Samples.csproj -c Release (dns block)
  • tphvsblobprodcus375.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build samples/BenchmarkDotNet.Samples/BenchmarkDotNet.Samples.csproj -c Release (dns block)
  • u3hvsblobprodcus371.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build samples/BenchmarkDotNet.Samples/BenchmarkDotNet.Samples.csproj -c Release (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

I think we should keep HardwareCounter, but take a breaking change and change it to a class instead of enum, with const strings for the existing options (similar to Column class).


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: ramartinez7 <44536177+ramartinez7@users.noreply.github.com>
Copilot AI changed the title [WIP] Change HardwareCounter from enum to class with const strings Convert HardwareCounter from enum to static class with const strings Jan 5, 2026
Copilot AI requested a review from ramartinez7 January 5, 2026 09:51
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.

2 participants