Skip to content

Commit f86874a

Browse files
dotnet#1603: Don't display Job and Toolchain column when running benchmarks for multiple runtimes
1 parent 3a9c9e2 commit f86874a

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

src/BenchmarkDotNet/Columns/JobCharacteristicColumn.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ private JobCharacteristicColumn(Characteristic characteristic)
2828

2929
public string Id { get; }
3030
public string ColumnName { get; }
31-
public bool IsAvailable(Summary summary) => true;
3231
public bool AlwaysShow => false;
3332
public ColumnCategory Category => ColumnCategory.Job;
3433
public int PriorityInCategory => 0;
@@ -38,6 +37,23 @@ private JobCharacteristicColumn(Characteristic characteristic)
3837

3938
public bool IsDefault(Summary summary, BenchmarkCase benchmarkCase) => !benchmarkCase.Job.HasValue(characteristic);
4039

40+
public bool IsAvailable(Summary summary)
41+
{
42+
if (summary.IsMultipleRuntime)
43+
{
44+
if (nameof(Toolchains.Toolchain).Equals(ColumnName))
45+
{
46+
return false;
47+
}
48+
if (nameof(Job).Equals(ColumnName))
49+
{
50+
return summary.BenchmarksCases.Any(x => !x.Job.IsGeneratedJobId());
51+
}
52+
}
53+
54+
return true;
55+
}
56+
4157
public string GetValue(Summary summary, BenchmarkCase benchmarkCase)
4258
{
4359
if (!benchmarkCase.Job.HasValue(characteristic) && EnvironmentResolver.Instance.CanResolve(characteristic))
Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
11
using System;
2+
using System.Linq;
23
using BenchmarkDotNet.Characteristics;
34

45
namespace BenchmarkDotNet.Jobs
56
{
67
public static class JobIdGenerator
78
{
9+
private const int JobIdLength = 10;
10+
private const string JobIdPrefix = "Job-";
11+
private const string DefaultJobId = "DefaultJob";
12+
813
public static string GenerateRandomId(Job job)
914
{
1015
string presentation = CharacteristicSetPresenter.Display.ToPresentation(job);
11-
if (presentation == "")
12-
return "DefaultJob";
16+
if (presentation == string.Empty)
17+
return DefaultJobId;
1318
int seed = presentation.GetHashCode();
1419
var random = new Random(seed);
15-
string id = "";
20+
string id = string.Empty;
1621
for (int i = 0; i < 6; i++)
17-
id += (char) ('A' + random.Next(26));
18-
return "Job-" + id;
22+
id += (char)('A' + random.Next(26));
23+
return JobIdPrefix + id;
24+
}
25+
26+
public static bool IsGeneratedJobId(this Job job)
27+
{
28+
return job.ResolvedId == DefaultJobId
29+
|| (job.ResolvedId.Length == JobIdLength
30+
&& job.ResolvedId.StartsWith(JobIdPrefix)
31+
&& job.ResolvedId.Replace(JobIdPrefix, string.Empty)
32+
.ToCharArray()
33+
.All(x => char.IsLetter(x)));
1934
}
2035
}
2136
}

src/BenchmarkDotNet/Reports/Summary.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public Summary(
7575

7676
public int GetNumberOfExecutedBenchmarks() => Reports.Count(report => report.ExecuteResults.Any(result => result.FoundExecutable));
7777

78+
public bool IsMultipleRuntime => BenchmarksCases.Count() > 1 ? BenchmarksCases.Where(benchmark => benchmark.Job.Environment.Runtime != null).Any(benchmark => !benchmark.Job.Environment.Runtime.Equals(BenchmarksCases[0].Job.Environment.Runtime)) : false;
79+
7880
internal static Summary NothingToRun(string title, string resultsDirectoryPath, string logFilePath)
7981
=> new Summary(title, ImmutableArray<BenchmarkReport>.Empty, HostEnvironmentInfo.GetCurrent(), resultsDirectoryPath, logFilePath, TimeSpan.Zero, DefaultCultureInfo.Instance, ImmutableArray<ValidationError>.Empty);
8082

0 commit comments

Comments
 (0)