Closed
Description
Hi,
When I run any Benchmark on my Laptop on Windows the Processor Model is not detected by BenchmarkDotNet.
BenchmarkDotNet v0.15.0, Windows 11 (10.0.26100.4061/24H2/2024Update/HudsonValley)
Unknown processor
.NET SDK 9.0.300
[Host] : .NET 8.0.16 (8.0.1625.21506), X64 RyuJIT AVX2
.NET 9.0 : .NET 9.0.5 (9.0.525.21509), X64 RyuJIT AVX2
Job=.NET 9.0 Runtime=.NET 9.0
0.13.12 behaved the same when I used it before updating to 0.15.0 .
The processor is: 12th Gen Intel(R) Core(TM) i7-1270P
The Number of Cores is 12
The Number of Logical Processors is 16.
I saw in a previous bug report a wmic output was requested. I couldn't find wmic in the suggested file path: C:\Windows\System32\wbem
and couldn't find any environment variable corresponding to wmic.
Thanks in advance.
Activity
AndreyAkinshin commentedon Jun 4, 2025
@alastairlundy could you please run the below command in PowerShell and share if it prints the processor model?
Get-CimInstance Win32_Processor
alastairlundy commentedon Jun 4, 2025
Thanks for the quick reply.
The output from that command is:
AndreyAkinshin commentedon Jun 4, 2025
BenchmarkDotNet has two strategies for detecting the CPU model on Windows (see WindowsCpuDetector): MosCpuDetector and WmicCpuDetector. If Wmic is not installed,
MosCpuDetector
is the only available detector. However, it is only enabled in .NET Framework, not in .NET Core/.NET 5+. SinceGet-CimInstance Win32_Processor
provides the expected CPU information, we have two possible solutions:ManagementObjectSearcher
works on Windows with .NET 5+ (I currently do not have access to a Windows machine to verify this), we should updateMosCpuDetector.IsApplicable
.Get-CimInstance Win32_Processor
via PowerShell, similar to how we call wmic.PRs are welcome.
alastairlundy commentedon Jun 4, 2025
The .NET docs website entry for it says that it requires a dependency on this Nuget package for .NET Standard 2.0 and .NET 5+.
Figuring out how to add that dependency only on required TFMs (i.e. .NET 5+ and not .NET Framework) seems like it would be quite messy unless either a .NET Framework TFM was added to BenchmarkDotNet, or, if there's no objection, adding it as a dependency for all TFMs.Edit: Actually it looks like version 6.0 of that package is already a dependency of BenchmarkDotNet so I don't see why the
MosCpuDetector
class couldn't be tweaked to run it on .NET 5+. Though it also may be worth updating that dependency to a newer version since the latest stable version is 9.0.5 .If I were to work on a PR for this that calls Powershell, would you guys want the code to go into
MosCpuDetector
or a new Detector class?@AndreyAkinshin Do you have a preference for either solution?
timcassell commentedon Jun 4, 2025
That would be best if it solves the issue.
alastairlundy commentedon Jun 4, 2025
Unfortunately it looks like the
System.Management
package wrongly declares it works on .NET 5+ (See this and this) in that the code relies on a dll that isn't present if .NET Framework isn't installed on the target device.In my fork I've enabled
MosCpuDetector
to run on .NET 5+ and tested it.It works and the CPU is properly detected in BenchmarkDotNet sample benchmarks, but only because I also have .NET Framework installed. If I didn't have .NET Framework installed it would likely not work.
I think
MosCpuDetector
should stay disabled on .NET 5+, and use a detector that works on .NET 5+ on Windows without WMIC and without .NET Framework once that is available.I'll give the Powershell based detector a shot.
timcassell commentedon Jun 4, 2025
.Net Framework comes installed on Windows standard. I don't think we need to support the fringe case of Windows without Framework. Framework has no end support date.
timcassell commentedon Jun 4, 2025
dotnet/runtime#66386 (comment) Suggests to use WMILight instead of System.Management, which you could try.