diff --git a/src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/CommandBuilders/ASPNetBenchmarks.CommandBuilder.cs b/src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/CommandBuilders/ASPNetBenchmarks.CommandBuilder.cs index 0d5bbdc3d32..f367ddaec37 100644 --- a/src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/CommandBuilders/ASPNetBenchmarks.CommandBuilder.cs +++ b/src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/CommandBuilders/ASPNetBenchmarks.CommandBuilder.cs @@ -121,7 +121,53 @@ public static (string, string) Build(ASPNetBenchmarksConfiguration configuration // Add the extra metrics by including the configuration. commandStringBuilder.Append($" --config {Path.Combine("Commands", "RunCommand", "BaseSuite", "PercentileBasedMetricsConfiguration.yml")} "); - return (processName, commandStringBuilder.ToString()); + string commandString = commandStringBuilder.ToString(); + + // Apply overrides. + if (!string.IsNullOrEmpty(configuration.benchmark_settings.override_arguments)) + { + List> overrideCommands = GetCrankArgsAsList(configuration.benchmark_settings.override_arguments); + if (overrideCommands.Count > 0) + { + // Take the current commands and first replace all the keys that match the override commands. + // Subsequently, add the new overrides and then convert the key-value pair list back to a string. + List> currentCommands = GetCrankArgsAsList(commandString); + foreach (var item in overrideCommands) + { + var existing = currentCommands.Where(kv => kv.Key == item.Key).ToList(); + foreach (var kv in existing) + { + if (kv.Key != null) + { + currentCommands.Remove(kv); + } + } + + currentCommands.Add(item); + } + + commandString = string.Join(" ", currentCommands.Select(c => $"--{c.Key} {c.Value}")); + } + } + + return (processName, commandString); + } + + internal static List> GetCrankArgsAsList(string input) + { + var keyValuePairs = new List>(); + var splitStr = input.Split(new[] { "--" }, StringSplitOptions.RemoveEmptyEntries); + + foreach (var item in splitStr) + { + var keyValue = item.Split(' ', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + if (keyValue.Length == 2) + { + keyValuePairs.Add(new KeyValuePair(keyValue[0], keyValue[1])); + } + } + + return keyValuePairs; } } } diff --git a/src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/Configurations/ASPNetBenchmark.Configuration.cs b/src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/Configurations/ASPNetBenchmark.Configuration.cs index 2cb86f3acc4..fb3afba0eb8 100644 --- a/src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/Configurations/ASPNetBenchmark.Configuration.cs +++ b/src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/Configurations/ASPNetBenchmark.Configuration.cs @@ -25,6 +25,7 @@ public class BenchmarkSettings { public string? benchmark_file { get; set; } public string additional_arguments { get; set; } = ""; + public string? override_arguments { get; set; } = ""; public List benchmarkFilters { get; set; } = new(); } diff --git a/src/benchmarks/gc/GC.Infrastructure/README.md b/src/benchmarks/gc/GC.Infrastructure/README.md index 1b44bb7acb7..069bfbcbb2f 100644 --- a/src/benchmarks/gc/GC.Infrastructure/README.md +++ b/src/benchmarks/gc/GC.Infrastructure/README.md @@ -222,6 +222,19 @@ benchmark_settings: If there is a match, these filters will run in the order specified in the yaml file. +###### How To Override Parameters + +You can override parameters specified in the benchmark csv file by replacing all instances of the command arg with values in the `override_arguments` field. + +```yaml +benchmark_settings: + benchmark_file: C:\InfraRuns\RunNew_All\Suites\ASPNETBenchmarks\ASPNetBenchmarks.csv + additional_arguments: --chart --chart-type hex + override_arguments: --profile aspnet-citrine-win +``` + +As an example based on the configuration immediately above, all `--profile` values will be replaces with `--profile aspnet-citrine-win`. + ## All Commands The infrastructure can be run in modular manner. What this means is that you can invoke a particular command that runs some part of the infrastructure. A list of all the commands can be found here: