Skip to content

Commit 31f280d

Browse files
committed
Changed remaining RuntimeInformation properties to readonly fields.
Disabled allocating tests.
1 parent 9476e9b commit 31f280d

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

Diff for: src/BenchmarkDotNet/Engines/Engine.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ private ClockSpan Measure(Action<long> action, long invokeCount)
235235
Thread.Sleep(TimeSpan.FromMilliseconds(500));
236236
}
237237

238-
// GC collect before measuring allocations, as we do not collect during the measurement.
238+
// GC collect before measuring allocations.
239239
ForceGcCollect();
240240
var gcStats = MeasureWithGc(data.InvokeCount / data.UnrollFactor);
241241

Diff for: src/BenchmarkDotNet/Engines/GcStats.cs

-2
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ public static GcStats FromForced(int forcedFullGarbageCollections)
145145
if (RuntimeInformation.IsWasm)
146146
return null;
147147

148-
// Calling GC.Collect() before calling GC.GetTotalAllocatedBytes appears to interfere with the results for some reason,
149-
// so we just call the API without forcing a collection.
150148
#if NET6_0_OR_GREATER
151149
return GC.GetTotalAllocatedBytes(precise: true);
152150
#else

Diff for: src/BenchmarkDotNet/Portability/RuntimeInformation.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ private static bool IsAotMethod()
9797
&& Environment.GetEnvironmentVariable("DOTNET_TieredCompilation") != "0"
9898
&& (!AppContext.TryGetSwitch("System.Runtime.TieredCompilation", out isEnabled) || isEnabled));
9999

100-
public static bool IsRunningInContainer => string.Equals(Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER"), "true");
100+
public static readonly bool IsRunningInContainer = string.Equals(Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER"), "true");
101101

102-
internal static string ExecutableExtension => IsWindows() ? ".exe" : string.Empty;
102+
internal static readonly string ExecutableExtension = IsWindows() ? ".exe" : string.Empty;
103103

104-
internal static string ScriptFileExtension => IsWindows() ? ".bat" : ".sh";
104+
internal static readonly string ScriptFileExtension = IsWindows() ? ".bat" : ".sh";
105105

106106
internal static string GetArchitecture() => GetCurrentPlatform().ToString();
107107

Diff for: tests/BenchmarkDotNet.IntegrationTests/MemoryDiagnoserTests.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ namespace BenchmarkDotNet.IntegrationTests
2828
{
2929
public class MemoryDiagnoserTests
3030
{
31+
// TODO: re-enable allocating tests after https://github.com/dotnet/runtime/issues/101536 is fixed.
32+
private const string AllocatingSkipReason = "System.Runtime.InteropServices.RuntimeInformation allocates during GC collect";
33+
3134
private readonly ITestOutputHelper output;
3235

3336
public MemoryDiagnoserTests(ITestOutputHelper outputHelper) => output = outputHelper;
@@ -50,7 +53,7 @@ public class AccurateAllocations
5053
[Benchmark] public Task<int> AllocateTask() => Task.FromResult<int>(-12345);
5154
}
5255

53-
[Theory, MemberData(nameof(GetToolchains))]
56+
[Theory(Skip = AllocatingSkipReason), MemberData(nameof(GetToolchains))]
5457
[Trait(Constants.Category, Constants.BackwardCompatibilityCategory)]
5558
public void MemoryDiagnoserIsAccurate(IToolchain toolchain)
5659
{
@@ -70,7 +73,7 @@ public void MemoryDiagnoserIsAccurate(IToolchain toolchain)
7073
});
7174
}
7275

73-
[FactEnvSpecific("We don't want to test NativeAOT twice (for .NET Framework 4.6.2 and .NET 7.0)", EnvRequirement.DotNetCoreOnly)]
76+
[FactEnvSpecific("We don't want to test NativeAOT twice (for .NET Framework 4.6.2 and .NET 8.0)", EnvRequirement.DotNetCoreOnly, Skip = AllocatingSkipReason)]
7477
public void MemoryDiagnoserSupportsNativeAOT()
7578
{
7679
if (RuntimeInformation.IsMacOS())
@@ -79,7 +82,7 @@ public void MemoryDiagnoserSupportsNativeAOT()
7982
MemoryDiagnoserIsAccurate(NativeAotToolchain.Net80);
8083
}
8184

82-
[FactEnvSpecific("We don't want to test MonoVM twice (for .NET Framework 4.6.2 and .NET 8.0)", EnvRequirement.DotNetCoreOnly)]
85+
[FactEnvSpecific("We don't want to test MonoVM twice (for .NET Framework 4.6.2 and .NET 8.0)", EnvRequirement.DotNetCoreOnly, Skip = AllocatingSkipReason)]
8386
public void MemoryDiagnoserSupportsModernMono()
8487
{
8588
MemoryDiagnoserIsAccurate(MonoToolchain.Mono80);
@@ -207,7 +210,7 @@ public void WithOperationsPerInvoke()
207210
private void DoNotInline(object left, object right) { }
208211
}
209212

210-
[Theory, MemberData(nameof(GetToolchains))]
213+
[Theory(Skip = AllocatingSkipReason), MemberData(nameof(GetToolchains))]
211214
[Trait(Constants.Category, Constants.BackwardCompatibilityCategory)]
212215
public void AllocatedMemoryShouldBeScaledForOperationsPerInvoke(IToolchain toolchain)
213216
{
@@ -233,7 +236,7 @@ public byte[] SixtyFourBytesArray()
233236
}
234237
}
235238

236-
[TheoryEnvSpecific("Full Framework cannot measure precisely enough for low invocation counts.", EnvRequirement.DotNetCoreOnly), MemberData(nameof(GetToolchains))]
239+
[TheoryEnvSpecific("Full Framework cannot measure precisely enough for low invocation counts.", EnvRequirement.DotNetCoreOnly), MemberData(nameof(GetToolchains), Skip = AllocatingSkipReason)]
237240
[Trait(Constants.Category, Constants.BackwardCompatibilityCategory)]
238241
public void AllocationQuantumIsNotAnIssueForNetCore21Plus(IToolchain toolchain)
239242
{
@@ -298,7 +301,7 @@ public void Allocate()
298301
}
299302
}
300303

301-
[TheoryEnvSpecific("Full Framework cannot measure precisely enough", EnvRequirement.DotNetCoreOnly)]
304+
[TheoryEnvSpecific("Full Framework cannot measure precisely enough", EnvRequirement.DotNetCoreOnly, Skip = AllocatingSkipReason)]
302305
[MemberData(nameof(GetToolchains))]
303306
[Trait(Constants.Category, Constants.BackwardCompatibilityCategory)]
304307
public void MemoryDiagnoserIsAccurateForMultiThreadedBenchmarks(IToolchain toolchain)

0 commit comments

Comments
 (0)