From 83800034b63c881ccdb54cd70e6e61654351878f Mon Sep 17 00:00:00 2001 From: marcnet80 <46241368+marcnet80@users.noreply.github.com> Date: Thu, 25 Aug 2022 14:47:53 +0300 Subject: [PATCH] Hide columns for multiple runtime (#1621) * #1603: Don't display Job and Toolchain column when running benchmarks for multiple runtimes * pedantic improvements: rename IsMultipleRuntime to IsMultipleRuntimes make it Lazy don't use Count() when Length is available * use simpler way of checking whether Id was assigned by the user in explicit way Co-authored-by: marcgit80@gmail.com Co-authored-by: Adam Sitnik --- .../Columns/JobCharacteristicColumn.cs | 18 +++++++++++++++++- src/BenchmarkDotNet/Reports/Summary.cs | 10 +++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/BenchmarkDotNet/Columns/JobCharacteristicColumn.cs b/src/BenchmarkDotNet/Columns/JobCharacteristicColumn.cs index 74f7b2b8ba..77c4cbc7a5 100644 --- a/src/BenchmarkDotNet/Columns/JobCharacteristicColumn.cs +++ b/src/BenchmarkDotNet/Columns/JobCharacteristicColumn.cs @@ -28,7 +28,6 @@ private JobCharacteristicColumn(Characteristic characteristic) public string Id { get; } public string ColumnName { get; } - public bool IsAvailable(Summary summary) => true; public bool AlwaysShow => false; public ColumnCategory Category => ColumnCategory.Job; public int PriorityInCategory => 0; @@ -38,6 +37,23 @@ private JobCharacteristicColumn(Characteristic characteristic) public bool IsDefault(Summary summary, BenchmarkCase benchmarkCase) => !benchmarkCase.Job.HasValue(characteristic); + public bool IsAvailable(Summary summary) + { + if (summary.IsMultipleRuntimes) + { + if (nameof(Toolchains.Toolchain).Equals(ColumnName)) + { + return false; + } + if (nameof(Job).Equals(ColumnName)) + { + return summary.BenchmarksCases.Any(x => x.Job.HasValue(CharacteristicObject.IdCharacteristic)); + } + } + + return true; + } + public string GetValue(Summary summary, BenchmarkCase benchmarkCase) { if (!benchmarkCase.Job.HasValue(characteristic) && EnvironmentResolver.Instance.CanResolve(characteristic)) diff --git a/src/BenchmarkDotNet/Reports/Summary.cs b/src/BenchmarkDotNet/Reports/Summary.cs index 87e96695eb..85e066b163 100644 --- a/src/BenchmarkDotNet/Reports/Summary.cs +++ b/src/BenchmarkDotNet/Reports/Summary.cs @@ -30,11 +30,12 @@ public class Summary [PublicAPI] public ImmutableArray BenchmarksCases { get; } [PublicAPI] public ImmutableArray Reports { get; } - private ImmutableDictionary ReportMap {get; } - private BaseliningStrategy BaseliningStrategy {get; } - internal DisplayPrecisionManager DisplayPrecisionManager { get; } + private ImmutableDictionary ReportMap { get; } + private BaseliningStrategy BaseliningStrategy { get; } + private bool? isMultipleRuntimes; + public Summary( string title, ImmutableArray reports, @@ -75,6 +76,9 @@ public Summary( public int GetNumberOfExecutedBenchmarks() => Reports.Count(report => report.ExecuteResults.Any(result => result.FoundExecutable)); + public bool IsMultipleRuntimes + => isMultipleRuntimes ??= BenchmarksCases.Length > 1 ? BenchmarksCases.Select(benchmark => benchmark.GetRuntime()).Distinct().Count() > 1 : false; + internal static Summary NothingToRun(string title, string resultsDirectoryPath, string logFilePath) => new Summary(title, ImmutableArray.Empty, HostEnvironmentInfo.GetCurrent(), resultsDirectoryPath, logFilePath, TimeSpan.Zero, DefaultCultureInfo.Instance, ImmutableArray.Empty);