BenchmarkDotNet icon indicating copy to clipboard operation
BenchmarkDotNet copied to clipboard

Not Set Hardware Counter throws Argument Null Exception

Open emreyigit opened this issue 3 years ago • 1 comments

Hi,

First, thank you for your effort. BenchmarkDotNet is a great tool.

Issue:

I have encountered an interesting exception.

When you set

... AddHardwareCounters(HardwareCounter.NotSet) ... on configs,

.net throws

System.ArgumentNullException: 'Value cannot be null. (Parameter 'key')

on https://github.com/dotnet/BenchmarkDotNet/blob/34817bfdd8909711b4802415808d26849aaed98e/src/BenchmarkDotNet.Diagnostics.Windows/HardwareCounters.cs#L56

Since HardwareCounter.NotSet is enum, there could be a proper way to handle/prevent it at
https://github.com/dotnet/BenchmarkDotNet/blob/34817bfdd8909711b4802415808d26849aaed98e/src/BenchmarkDotNet.Diagnostics.Windows/HardwareCounters.cs#L53

I believe.

If you consider to fix it, I may create a PR.

Regards, Emre

emreyigit avatar Dec 03 '21 10:12 emreyigit

If you consider to fix it, I may create a PR.

@emreyigit A PR would be welcomed!

You might also consider filtering out HardwareCounter.NotSet in the AddHardwareCounters method:

https://github.com/dotnet/BenchmarkDotNet/blob/63e28c100a42a6492d09a0b93a8a4c141061bb0d/src/BenchmarkDotNet/Configs/ManualConfig.cs#L172-L175

adamsitnik avatar Dec 06 '21 10:12 adamsitnik