Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
495855a
allow MosCpuDetector to run on .NET 5+
alastairlundy Jun 4, 2025
3a75c1e
Revert "allow MosCpuDetector to run on .NET 5+"
alastairlundy Jun 4, 2025
3fbf726
add WmiLightCpu Detector
alastairlundy Jun 4, 2025
5972f77
Fix WmicCpuDetector being chosen if not available
alastairlundy Jun 4, 2025
7dc92b0
enable NativeAOT
alastairlundy Jun 5, 2025
fd5f096
simplify IsApplicable
alastairlundy Jun 5, 2025
9b9a5eb
Update spacing of SupportedOsPlatform attribute
alastairlundy Jun 5, 2025
8762345
Merge branch 'master' into fix-unknown-processor-windows
alastairlundy Jun 6, 2025
589f23a
Revert "Fix WmicCpuDetector being chosen if not available"
alastairlundy Jun 7, 2025
2bfbd44
Merge branch 'fix-unknown-processor-windows' of https://github.com/al…
alastairlundy Jun 7, 2025
a62fe32
add WMIC deprecation remarks
alastairlundy Jun 7, 2025
56aa5ca
remove WmiLight code
alastairlundy Jun 7, 2025
e7ad945
update WmiCpuInfoParser to return null if Processor Name isn't detected
alastairlundy Jun 7, 2025
29e2f96
remove WmiLightCpuDetector reference from WindowsCpuDetector
alastairlundy Jun 7, 2025
f9a5c34
Update WmicCpuInfoParser.cs
alastairlundy Jun 7, 2025
c181db9
check if wmicOutput is null or empty instead
alastairlundy Jun 7, 2025
18f44b8
add PowershellWmiCpuDetector (parser still not complete)
alastairlundy Jun 7, 2025
fa77462
return null if there's no version of powershell installed
alastairlundy Jun 7, 2025
0f3dd87
fix Powershell 7+ check
alastairlundy Jun 7, 2025
b6d9fb4
rework search statement given that regex isn't supported
alastairlundy Jun 7, 2025
8d0fbb9
add parser code
alastairlundy Jun 7, 2025
aca21d0
add PowershellWmiCpuDetector to WindowsCpuDetector
alastairlundy Jun 7, 2025
74c1b6c
rename variable to lower case
alastairlundy Jun 7, 2025
52155fa
improve checking of latest powershell 7+ version
alastairlundy Jun 7, 2025
d974b1a
use explicit typing
alastairlundy Jun 7, 2025
c7aa4e2
fix frequency addition issue
alastairlundy Jun 7, 2025
fa4ea57
revert to how WMIC parser handles processor frequency
alastairlundy Jun 7, 2025
3a8d884
add string is null or empty check to WmiCpuDetector
alastairlundy Jun 8, 2025
b4ceb96
invoke Powershell as "PowerShell" if the file isn't found
alastairlundy Jun 8, 2025
bc3b8e7
add nominal Frequency detection and improve max frequency detection
alastairlundy Jun 8, 2025
06e82da
fix issue with detecting latest Powershell
alastairlundy Jun 8, 2025
32f0d57
update comment
alastairlundy Jun 9, 2025
ef2385b
Update PowershellWmiCpuDetector.cs
alastairlundy Jun 9, 2025
fb87c98
refactor Powershell locating code to PowershellLocator
alastairlundy Jun 9, 2025
59b36be
simplify frequency checks
alastairlundy Jun 9, 2025
be3fbfe
Create PowershellWmiParserTests.cs
alastairlundy Jun 9, 2025
677bd1b
fix null being returned when object is expected.
alastairlundy Jun 9, 2025
c856ab0
rename test
alastairlundy Jun 9, 2025
8fbccd5
Merge branch 'dotnet:master' into fix-unknown-processor-windows
alastairlundy Jun 9, 2025
c54ee51
simplify max frequency check
alastairlundy Jun 9, 2025
1d86ff2
use """ for string in parser test
alastairlundy Jun 9, 2025
a13283b
Merge branch 'fix-unknown-processor-windows' of https://github.com/al…
alastairlundy Jun 9, 2025
589566f
Update PowershellWmiCpuInfoParserTests.cs
alastairlundy Jun 9, 2025
3e3d67b
reduce indentation with """
alastairlundy Jun 9, 2025
106cac1
remove unnecessary test info
alastairlundy Jun 9, 2025
2413529
move string null check to caller
alastairlundy Jun 9, 2025
476cad5
add nominal frequency support for MosCpuDetector
alastairlundy Jun 9, 2025
caf07ad
Update src/BenchmarkDotNet/Detectors/Cpu/Windows/PowershellWmiCpuDete…
alastairlundy Jun 9, 2025
2e0867a
remove nullability of parser
alastairlundy Jun 9, 2025
30768de
check if tempMaxFrequency > 0 before assignment
alastairlundy Jun 9, 2025
afb3220
remove nullability of WmicCpuInfoParser
alastairlundy Jun 9, 2025
ffc2b75
Merge branch 'fix-unknown-processor-windows' of https://github.com/al…
alastairlundy Jun 9, 2025
b60ad9f
use file scoped namespace
alastairlundy Jun 9, 2025
f300e4e
use double instead of int
alastairlundy Jun 9, 2025
85d6f1b
add null check to LinuxCpuDetector
alastairlundy Jun 9, 2025
f6d6eaf
change nullability of LinuxCpuParser
alastairlundy Jun 9, 2025
a5f7153
update LinuxCpuInfoParser nominal and max frequency detection
alastairlundy Jun 9, 2025
65c45b9
Update LinuxCpuInfoParser.cs
alastairlundy Jun 9, 2025
d2741e1
fix nullability check
alastairlundy Jun 9, 2025
d1172a3
simplify nominal frequency comparison
alastairlundy Jun 9, 2025
8307016
add null check to macOS
alastairlundy Jun 9, 2025
f7a6d37
Merge branch 'fix-unknown-processor-windows' of https://github.com/al…
alastairlundy Jun 9, 2025
cca1e5b
Merge branch 'dotnet:master' into fix-unknown-processor-windows
alastairlundy Jun 9, 2025
d5eb7e4
don't accept null string from detector
alastairlundy Jun 9, 2025
bbd6a8a
Merge branch 'fix-unknown-processor-windows' of https://github.com/al…
alastairlundy Jun 9, 2025
b85d12d
fix LinuxCpuInfo parser test issues and improve robustness of Linux C…
alastairlundy Jun 11, 2025
9609f83
fix Powershell Wmi Parser parsing issues
alastairlundy Jun 11, 2025
8059686
fix .net framework cpu parsing issue
alastairlundy Jun 11, 2025
183f353
do implicit conversion to double from uint
alastairlundy Jun 13, 2025
5f1328f
Merge branch 'master' into fix-unknown-processor-windows
alastairlundy Jun 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/BenchmarkDotNet/BenchmarkDotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.6" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
<PackageReference Include="System.Management" Version="6.0.0" />
<PackageReference Include="WmiLight" Version="6.13.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
namespace BenchmarkDotNet.Detectors.Cpu.Windows;

internal class WindowsCpuDetector() : CpuDetector(new MosCpuDetector(), new WmicCpuDetector());
internal class WindowsCpuDetector() : CpuDetector(new MosCpuDetector(),
new WmiLightCpuDetector(), new WmicCpuDetector());
69 changes: 69 additions & 0 deletions src/BenchmarkDotNet/Detectors/Cpu/Windows/WmiLightCpuDetector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using BenchmarkDotNet.Extensions;
using BenchmarkDotNet.Portability;

using Perfolizer.Horology;
using Perfolizer.Models;

using System.Collections.Generic;

using WmiLight;

namespace BenchmarkDotNet.Detectors.Cpu.Windows
{
internal class WmiLightCpuDetector : ICpuDetector
{

#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public CpuInfo? Detect()
{
if (!IsApplicable()) return null;

HashSet<string> processorModelNames = new HashSet<string>();
int physicalCoreCount = 0;
int logicalCoreCount = 0;
int processorsCount = 0;
int sumMaxFrequency = 0;

using (WmiConnection connection = new WmiConnection())
{
foreach (WmiObject processor in connection.CreateQuery("SELECT * FROM Win32_Processor"))
{
string name = processor[WmicCpuInfoKeyNames.Name]?.ToString();
if (!string.IsNullOrEmpty(name))
{
processorModelNames.Add(name);
processorsCount++;
physicalCoreCount += (int)(uint)processor[WmicCpuInfoKeyNames.NumberOfCores];
logicalCoreCount += (int)(uint)processor[WmicCpuInfoKeyNames.NumberOfLogicalProcessors];
sumMaxFrequency = (int)(uint)processor[WmicCpuInfoKeyNames.MaxClockSpeed];
}
}
}

string processorName = processorModelNames.Count > 0 ? string.Join(", ", processorModelNames) : null;
Frequency? maxFrequency = sumMaxFrequency > 0 && processorsCount > 0
? Frequency.FromMHz(sumMaxFrequency * 1.0 / processorsCount)
: null;

return new CpuInfo
{
ProcessorName = processorName,
PhysicalProcessorCount = processorsCount > 0 ? processorsCount : null,
PhysicalCoreCount = physicalCoreCount > 0 ? physicalCoreCount : null,
LogicalCoreCount = logicalCoreCount > 0 ? logicalCoreCount : null,
NominalFrequencyHz = maxFrequency?.Hertz.RoundToLong(),
MaxFrequencyHz = maxFrequency?.Hertz.RoundToLong()
};
}

#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public bool IsApplicable()
{
return OsDetector.IsWindows() && !RuntimeInformation.IsMono;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class WmicCpuDetector : ICpuDetector
{
private const string DefaultWmicPath = @"C:\Windows\System32\wbem\WMIC.exe";

public bool IsApplicable() => OsDetector.IsWindows();
public bool IsApplicable() => OsDetector.IsWindows() && File.Exists(DefaultWmicPath);

public CpuInfo? Detect()
{
Expand Down
Loading