Skip to content
Merged
Changes from all commits
Commits
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
31 changes: 20 additions & 11 deletions src/BenchmarkDotNet/Detectors/OsDetector.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using BenchmarkDotNet.Extensions;
using BenchmarkDotNet.Helpers;
using Microsoft.Win32;
using Perfolizer.Models;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using static System.Runtime.InteropServices.RuntimeInformation;
using System.Runtime.InteropServices;

#if NETSTANDARD
using BenchmarkDotNet.Extensions;
#endif

namespace BenchmarkDotNet.Detectors;

Expand Down Expand Up @@ -52,14 +54,21 @@ private static OsInfo ResolveOs()
}
}

string operatingSystem = OSDescription;
string operatingSystemVersion = Environment.OSVersion.ToString();
if (IsWindows())
{
var osVersion = RuntimeInformation.OSDescription.Split(' ').LastOrDefault() ?? ""; // `Microsoft Windows 10.0.26200`
int? ubr = GetWindowsUbr();
if (ubr != null)
operatingSystemVersion += $".{ubr}";
return new OsInfo
{
Name = "Windows",
Version = ubr == null
? osVersion
: $"{osVersion}.{ubr}",
};
}

string operatingSystem = RuntimeInformation.OSDescription;
string operatingSystemVersion = Environment.OSVersion.ToString();
return new OsInfo
{
Name = operatingSystem,
Expand Down Expand Up @@ -115,7 +124,7 @@ internal static bool IsWindows() =>
#if NET6_0_OR_GREATER
OperatingSystem.IsWindows(); // prefer linker-friendly OperatingSystem APIs
#else
IsOSPlatform(OSPlatform.Windows);
RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
#endif


Expand All @@ -124,7 +133,7 @@ internal static bool IsLinux() =>
#if NET6_0_OR_GREATER
OperatingSystem.IsLinux();
#else
IsOSPlatform(OSPlatform.Linux);
RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
#endif

[SupportedOSPlatformGuard("macos")]
Expand All @@ -133,7 +142,7 @@ internal static bool IsMacOS() =>
#if NET6_0_OR_GREATER
OperatingSystem.IsMacOS();
#else
IsOSPlatform(OSPlatform.OSX);
RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
#endif

[SupportedOSPlatformGuard("android")]
Expand All @@ -159,6 +168,6 @@ internal static bool IsTvOS() =>
#if NET6_0_OR_GREATER
OperatingSystem.IsTvOS();
#else
IsOSPlatform(OSPlatform.Create("TVOS"));
RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS"));
#endif
}
Loading