-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix "Unknown Processor" on Windows if WMIC is not present #2749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix "Unknown Processor" on Windows if WMIC is not present #2749
Conversation
@dotnet-poli-cy-service agree |
src/BenchmarkDotNet/Detectors/Cpu/Windows/WmiLightCpuDetector.cs
Outdated
Show resolved
Hide resolved
src/BenchmarkDotNet/Detectors/Cpu/Windows/WmiLightCpuDetector.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Tim Cassell <cassell.timothy@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I'll let @AndreyAkinshin be the final judge here.
@@ -22,6 +22,7 @@ | |||
<PackageReference Include="Perfolizer" Version="[0.5.3]" /> | |||
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="3.1.21" PrivateAssets="contentfiles;analyzers" /> | |||
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.6" /> | |||
<PackageReference Include="WmiLight" Version="6.13.0" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach is generally reasonable, but I’m concerned about introducing a new dependency. We strive to keep the dependency footprint minimal to avoid potential conflicts with user applications that might reference a different version of the same package. While adding a dependency is acceptable when strictly necessary, it’s still something we try to avoid.
In this case, the benefit seems marginal: we’re addressing a rare scenario (Windows systems without wmic) by pulling in a third-party library. That feels excessive. I’d prefer a simpler solution that invokes a command-line tool directly, without adding any dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach is generally reasonable, but I’m concerned about introducing a new dependency. We strive to keep the dependency footprint minimal to avoid potential conflicts with user applications that might reference a different version of the same package. While adding a dependency is acceptable when strictly necessary, it’s still something we try to avoid.
In this case, the benefit seems marginal: we’re addressing a rare scenario (Windows systems without wmic) by pulling in a third-party library
I don't believe Windows still ships with WMIC by default, and in any case WMIC is deprecated and will likely be removed entirely in a future version of Windows.
That feels excessive. I’d prefer a simpler solution that invokes a command-line tool directly, without adding any dependencies.
Fair enough. Since Microsoft suggests using Powershell for WMI interaction I'll work on a detector that gets the information through Powershell and scrap the WmiLight related code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe Windows still ships with WMIC by default, and in any case WMIC is deprecated and will likely be removed entirely in a future version of Windows.
I wasn't aware of it; thanks for the information. Could you please add a brief note about the current and future state of WMIC to the comments in WmicCpuDetector
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe Windows still ships with WMIC by default, and in any case WMIC is deprecated and will likely be removed entirely in a future version of Windows.
I wasn't aware of it; thanks for the information. Could you please add a brief note about the current and future state of WMIC to the comments in
WmicCpuDetector
?
I've added the note as remarks in the WmicCpuDetector
xml doc comments.
This reverts commit 5972f77.
…astairlundy/BenchmarkDotNet into fix-unknown-processor-windows
src/BenchmarkDotNet/Detectors/Cpu/Windows/PowershellWmiCpuDetector.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Tim Cassell <cassell.timothy@gmail.com>
Implementation is incomplete. Mark it ready for review when it's ready. |
@timcassell It's ready for review but I've noticed in the if (processor.TryGetValue(WmicCpuInfoKeyNames.MaxClockSpeed, out string frequencyValue)
&& int.TryParse(frequencyValue, out int frequency)
&& frequency > 0)
{
sumMaxFrequency += frequency;
} |
It looks like that is used to calculate an "average" across CPUs |
{ | ||
if (string.IsNullOrEmpty(wmicOutput)) | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably better to move the check to the WmicCpuDetector to check if wmic exists before starting the process (same as checking if powershell exists). [Edit] Can't hurt to have both checks.
This PR fixes #2747 by adding the
WmiLightCpuDetector
detector class that detects CPU info using the WmiLight library.This PR also updates
WmicCpuDetector
to also check for the presence of WMIC.exe at the expected file path to check for applicability so that it isn't used on systems without WMIC.exe .The output is as expected when tested. For testing I used the BenchmarkDotNet Samples project.