Skip to content

Commit adf8e6d

Browse files
am11timcassell
andauthored
Add DOTNET_ environment vars (#2643)
* Add DOTNET_ environment vars * Update tests/BenchmarkDotNet.IntegrationTests/MemoryDiagnoserTests.cs --------- Co-authored-by: Tim Cassell <[email protected]>
1 parent 3a2d115 commit adf8e6d

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

samples/BenchmarkDotNet.Samples/IntroEnvVars.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ public class IntroEnvVars
1010
{
1111
private class ConfigWithCustomEnvVars : ManualConfig
1212
{
13-
private const string JitNoInline = "COMPlus_JitNoInline";
14-
1513
public ConfigWithCustomEnvVars()
1614
{
1715
AddJob(Job.Default.WithRuntime(CoreRuntime.Core80).WithId("Inlining enabled"));
1816
AddJob(Job.Default.WithRuntime(CoreRuntime.Core80)
19-
.WithEnvironmentVariables(new EnvironmentVariable(JitNoInline, "1"))
17+
.WithEnvironmentVariables([
18+
new EnvironmentVariable("DOTNET_JitNoInline", "1"),
19+
new EnvironmentVariable("COMPlus_JitNoInline", "1")
20+
])
2021
.WithId("Inlining disabled"));
2122
}
2223
}
@@ -27,4 +28,4 @@ public void Foo()
2728
// Benchmark body
2829
}
2930
}
30-
}
31+
}

src/BenchmarkDotNet/Extensions/ProcessExtensions.cs

+18-12
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,18 @@ public static bool TrySetAffinity(
125125
internal static void SetEnvironmentVariables(this ProcessStartInfo start, BenchmarkCase benchmarkCase, IResolver resolver)
126126
{
127127
if (benchmarkCase.Job.Environment.Runtime is ClrRuntime clrRuntime && !string.IsNullOrEmpty(clrRuntime.Version))
128-
start.EnvironmentVariables["COMPLUS_Version"] = clrRuntime.Version;
128+
SetClrEnvironmentVariables(start, "Version", clrRuntime.Version);
129129

130130
if (benchmarkCase.Job.Environment.Runtime is MonoRuntime monoRuntime && !string.IsNullOrEmpty(monoRuntime.MonoBclPath))
131131
start.EnvironmentVariables["MONO_PATH"] = monoRuntime.MonoBclPath;
132132

133133
if (benchmarkCase.Config.HasPerfCollectProfiler())
134134
{
135135
// enable tracing configuration inside of CoreCLR (https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/linux-performance-tracing.md#collecting-a-trace)
136-
start.EnvironmentVariables["COMPlus_PerfMapEnabled"] = "1";
137-
start.EnvironmentVariables["COMPlus_EnableEventLog"] = "1";
136+
SetClrEnvironmentVariables(start, "PerfMapEnabled", "1");
137+
SetClrEnvironmentVariables(start, "EnableEventLog", "1");
138138
// enable BDN Event Source (https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/linux-performance-tracing.md#filtering)
139-
start.EnvironmentVariables["COMPlus_EventSourceFilter"] = EngineEventSource.SourceName;
139+
SetClrEnvironmentVariables(start, "EventSourceFilter", EngineEventSource.SourceName);
140140
// workaround for https://github.com/dotnet/runtime/issues/71786, will be solved by next perf version
141141
start.EnvironmentVariables["DOTNET_EnableWriteXorExecute"] = "0";
142142
}
@@ -258,21 +258,27 @@ private static void SetCoreRunEnvironmentVariables(this ProcessStartInfo start,
258258
{
259259
var gcMode = benchmarkCase.Job.Environment.Gc;
260260

261-
start.EnvironmentVariables["COMPlus_gcServer"] = gcMode.ResolveValue(GcMode.ServerCharacteristic, resolver) ? "1" : "0";
262-
start.EnvironmentVariables["COMPlus_gcConcurrent"] = gcMode.ResolveValue(GcMode.ConcurrentCharacteristic, resolver) ? "1" : "0";
261+
SetClrEnvironmentVariables(start, "gcServer", gcMode.ResolveValue(GcMode.ServerCharacteristic, resolver) ? "1" : "0");
262+
SetClrEnvironmentVariables(start, "gcConcurrent", gcMode.ResolveValue(GcMode.ConcurrentCharacteristic, resolver) ? "1" : "0");
263263

264264
if (gcMode.HasValue(GcMode.CpuGroupsCharacteristic))
265-
start.EnvironmentVariables["COMPlus_GCCpuGroup"] = gcMode.ResolveValue(GcMode.CpuGroupsCharacteristic, resolver) ? "1" : "0";
265+
SetClrEnvironmentVariables(start, "GCCpuGroup", gcMode.ResolveValue(GcMode.CpuGroupsCharacteristic, resolver) ? "1" : "0");
266266
if (gcMode.HasValue(GcMode.AllowVeryLargeObjectsCharacteristic))
267-
start.EnvironmentVariables["COMPlus_gcAllowVeryLargeObjects"] = gcMode.ResolveValue(GcMode.AllowVeryLargeObjectsCharacteristic, resolver) ? "1" : "0";
267+
SetClrEnvironmentVariables(start, "gcAllowVeryLargeObjects", gcMode.ResolveValue(GcMode.AllowVeryLargeObjectsCharacteristic, resolver) ? "1" : "0");
268268
if (gcMode.HasValue(GcMode.RetainVmCharacteristic))
269-
start.EnvironmentVariables["COMPlus_GCRetainVM"] = gcMode.ResolveValue(GcMode.RetainVmCharacteristic, resolver) ? "1" : "0";
269+
SetClrEnvironmentVariables(start, "GCRetainVM", gcMode.ResolveValue(GcMode.RetainVmCharacteristic, resolver) ? "1" : "0");
270270
if (gcMode.HasValue(GcMode.NoAffinitizeCharacteristic))
271-
start.EnvironmentVariables["COMPlus_GCNoAffinitize"] = gcMode.ResolveValue(GcMode.NoAffinitizeCharacteristic, resolver) ? "1" : "0";
271+
SetClrEnvironmentVariables(start, "GCNoAffinitize", gcMode.ResolveValue(GcMode.NoAffinitizeCharacteristic, resolver) ? "1" : "0");
272272
if (gcMode.HasValue(GcMode.HeapAffinitizeMaskCharacteristic))
273-
start.EnvironmentVariables["COMPlus_GCHeapAffinitizeMask"] = gcMode.HeapAffinitizeMask.ToString("X");
273+
SetClrEnvironmentVariables(start, "GCHeapAffinitizeMask", gcMode.HeapAffinitizeMask.ToString("X"));
274274
if (gcMode.HasValue(GcMode.HeapCountCharacteristic))
275-
start.EnvironmentVariables["COMPlus_GCHeapCount"] = gcMode.HeapCount.ToString("X");
275+
SetClrEnvironmentVariables(start, "GCHeapCount", gcMode.HeapCount.ToString("X"));
276+
}
277+
278+
private static void SetClrEnvironmentVariables(ProcessStartInfo start, string suffix, string value)
279+
{
280+
start.EnvironmentVariables[$"DOTNET_{suffix}"] = value;
281+
start.EnvironmentVariables[$"COMPlus_{suffix}"] = value;
276282
}
277283
}
278284
}

tests/BenchmarkDotNet.IntegrationTests/MemoryDiagnoserTests.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,11 @@ private IConfig CreateConfig(IToolchain toolchain)
321321
.WithGcForce(false)
322322
.WithGcServer(false)
323323
.WithGcConcurrent(false)
324-
.WithEnvironmentVariable("COMPlus_TieredCompilation", "0") // Tiered JIT can allocate some memory on a background thread, let's disable it to make our tests less flaky (#1542)
324+
.WithEnvironmentVariables([
325+
// Tiered JIT can allocate some memory on a background thread, let's disable it to make our tests less flaky (#1542)
326+
new EnvironmentVariable("DOTNET_TieredCompilation", "0"),
327+
new EnvironmentVariable("COMPlus_TieredCompilation", "0")
328+
])
325329
.WithToolchain(toolchain))
326330
.AddColumnProvider(DefaultColumnProviders.Instance)
327331
.AddDiagnoser(MemoryDiagnoser.Default)

0 commit comments

Comments
 (0)