Skip to content

Fix #2740: Use CpuInfo.Unknown if CpuDetector.Detect() does not find supported OS #2742

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

Merged
merged 1 commit into from
May 27, 2025

Conversation

BraedenLS
Copy link
Contributor

The nullability of HostEnvironmentInfo's Cpu property was mistakenly going unnoticed. This caused a null reference exception in the ZeroMeasurementAnalyser. I corrected this by making it nullable and checking for it in the analyser. Preventing it from breaking for all not-yet supported OS CpuDetectors

@BraedenLS
Copy link
Contributor Author

BraedenLS commented May 27, 2025

@dotnet-policy-service agree company="Lake Shore Cryotronics"

Copy link
Member

@AndreyAkinshin AndreyAkinshin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the main issue is that HostEnvironmentInfo assigns null to the non-nullable Cpu. I would prefer to keep HostEnvironmentInfo.Cpu as Lazy<CpuInfo> (a non-nullable value) to avoid multiple null checks. CpuInfo is already designed to potentially miss any of its properties. A better solution would be to introduce CpuInfo.Unknown on the Perfolizer side and use it in HostEnvironmentInfo if all the CpuDetectors fail to detect the CPU. I will release a new version of Perfolizer and bump it in BenchmarkDotNet.

@AndreyAkinshin
Copy link
Member

CpuInfo.Unknown is available in the latest master. @BraedenLS, I suggest upgrading the HostEnvironmentInfo.Cpu lazy definition to use CpuInfo.Unknown if CpuDetector.CrossPlatform.Detect() returns null.

@BraedenLS BraedenLS force-pushed the bugfix/handle-null-cpu-info branch from b473dd0 to 01b34ba Compare May 27, 2025 20:53
@BraedenLS
Copy link
Contributor Author

Rebased and implemented.

@BraedenLS BraedenLS changed the title Fix #2740: Add nullability to HostEnvironmentInfo's CpuInfo Fix #2740: Use CpuInfo.Unknown if CpuDetector.Detect() does not find supported OS May 27, 2025
@AndreyAkinshin AndreyAkinshin merged commit c0bcfb9 into dotnet:master May 27, 2025
1 check passed
@AndreyAkinshin AndreyAkinshin added this to the v0.15.1 milestone May 27, 2025
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