1
- using System ;
1
+ using System ;
2
2
using System . Collections . Generic ;
3
3
using System . ComponentModel ;
4
4
using System . Diagnostics ;
9
9
using BenchmarkDotNet . Loggers ;
10
10
using BenchmarkDotNet . Portability ;
11
11
using BenchmarkDotNet . Running ;
12
+ using BenchmarkDotNet . Toolchains . CoreRun ;
12
13
using JetBrains . Annotations ;
13
14
14
15
namespace BenchmarkDotNet . Extensions
@@ -119,6 +120,12 @@ internal static void SetEnvironmentVariables(this ProcessStartInfo start, Benchm
119
120
if ( benchmarkCase . Job . Environment . Runtime is MonoRuntime monoRuntime && ! string . IsNullOrEmpty ( monoRuntime . MonoBclPath ) )
120
121
start . EnvironmentVariables [ "MONO_PATH" ] = monoRuntime . MonoBclPath ;
121
122
123
+ // corerun does not understand runtimeconfig.json files;
124
+ // we have to set "COMPlus_GC*" environment variables as documented in
125
+ // https://docs.microsoft.com/en-us/dotnet/core/run-time-config/garbage-collector
126
+ if ( benchmarkCase . Job . Infrastructure . Toolchain is CoreRunToolchain _)
127
+ start . SetCoreRunEnvironmentVariables ( benchmarkCase ) ;
128
+
122
129
if ( ! benchmarkCase . Job . HasValue ( EnvironmentMode . EnvironmentVariablesCharacteristic ) )
123
130
return ;
124
131
@@ -221,5 +228,24 @@ private static int RunProcessAndIgnoreOutput(string fileName, string arguments,
221
228
return process . ExitCode ;
222
229
}
223
230
}
231
+
232
+ private static void SetCoreRunEnvironmentVariables ( this ProcessStartInfo start , BenchmarkCase benchmarkCase )
233
+ {
234
+ var gcMode = benchmarkCase . Job . Environment . Gc ;
235
+ if ( ! gcMode . HasChanges )
236
+ return ; // do nothing for the default settings
237
+
238
+ start . EnvironmentVariables [ "COMPlus_gcServer" ] = gcMode . Server ? "1" : "0" ;
239
+ start . EnvironmentVariables [ "COMPlus_gcConcurrent" ] = gcMode . Concurrent ? "1" : "0" ;
240
+ start . EnvironmentVariables [ "COMPlus_GCCpuGroup" ] = gcMode . CpuGroups ? "1" : "0" ;
241
+ start . EnvironmentVariables [ "COMPlus_gcAllowVeryLargeObjects" ] = gcMode . AllowVeryLargeObjects ? "1" : "0" ;
242
+ start . EnvironmentVariables [ "COMPlus_GCRetainVM" ] = gcMode . RetainVm ? "1" : "0" ;
243
+ start . EnvironmentVariables [ "COMPlus_GCNoAffinitize" ] = gcMode . NoAffinitize ? "1" : "0" ;
244
+
245
+ if ( gcMode . HasValue ( GcMode . HeapAffinitizeMaskCharacteristic ) )
246
+ start . EnvironmentVariables [ "COMPlus_GCHeapAffinitizeMask" ] = gcMode . HeapAffinitizeMask . ToString ( "X" ) ;
247
+ if ( gcMode . HasValue ( GcMode . HeapCountCharacteristic ) )
248
+ start . EnvironmentVariables [ "COMPlus_GCHeapCount" ] = gcMode . HeapCount . ToString ( "X" ) ;
249
+ }
224
250
}
225
- }
251
+ }
0 commit comments