Skip to content

Commit 8d23796

Browse files
Update console title with benchmark information (#2140)
1 parent 095975f commit 8d23796

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/BenchmarkDotNet/Running/BenchmarkRunnerClean.cs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using BenchmarkDotNet.Jobs;
1717
using BenchmarkDotNet.Loggers;
1818
using BenchmarkDotNet.Mathematics;
19+
using BenchmarkDotNet.Portability;
1920
using BenchmarkDotNet.Reports;
2021
using BenchmarkDotNet.Toolchains;
2122
using BenchmarkDotNet.Toolchains.Parameters;
@@ -144,12 +145,15 @@ private static Summary Run(BenchmarkRunInfo benchmarkRunInfo,
144145
var cultureInfo = config.CultureInfo ?? DefaultCultureInfo.Instance;
145146
var reports = new List<BenchmarkReport>();
146147
string title = GetTitle(new[] { benchmarkRunInfo });
148+
var consoleTitle = RuntimeInformation.IsWindows() ? Console.Title : string.Empty;
147149

148150
logger.WriteLineInfo($"// Found {benchmarks.Length} benchmarks:");
149151
foreach (var benchmark in benchmarks)
150152
logger.WriteLineInfo($"// {benchmark.DisplayInfo}");
151153
logger.WriteLine();
152154

155+
UpdateTitle(totalBenchmarkCount, benchmarksToRunCount);
156+
153157
using (var powerManagementApplier = new PowerManagementApplier(logger))
154158
{
155159
bool stop = false;
@@ -218,6 +222,11 @@ private static Summary Run(BenchmarkRunInfo benchmarkRunInfo,
218222
}
219223
}
220224

225+
if (RuntimeInformation.IsWindows())
226+
{
227+
Console.Title = consoleTitle;
228+
}
229+
221230
var runEnd = runsChronometer.GetElapsed();
222231

223232
return new Summary(title,
@@ -227,7 +236,7 @@ private static Summary Run(BenchmarkRunInfo benchmarkRunInfo,
227236
logFilePath,
228237
runEnd.GetTimeSpan() - runStart.GetTimeSpan(),
229238
cultureInfo,
230-
Validate(new[] {benchmarkRunInfo }, NullLogger.Instance), // validate them once again, but don't print the output
239+
Validate(new[] { benchmarkRunInfo }, NullLogger.Instance), // validate them once again, but don't print the output
231240
config.GetColumnHidingRules().ToImmutableArray());
232241
}
233242

@@ -614,15 +623,34 @@ private static void Cleanup(HashSet<string> artifactsToCleanup)
614623
}
615624
}
616625

626+
private static void UpdateTitle(int totalBenchmarkCount, int benchmarksToRunCount)
627+
{
628+
if (!Console.IsOutputRedirected && (RuntimeInformation.IsWindows() || RuntimeInformation.IsLinux() || RuntimeInformation.IsMacOSX()))
629+
{
630+
Console.Title = $"{benchmarksToRunCount}/{totalBenchmarkCount} Remaining";
631+
}
632+
}
633+
617634
private static void LogProgress(ILogger logger, in StartedClock runsChronometer, int totalBenchmarkCount, int benchmarksToRunCount)
618635
{
619636
int executedBenchmarkCount = totalBenchmarkCount - benchmarksToRunCount;
620-
double avgSecondsPerBenchmark = runsChronometer.GetElapsed().GetTimeSpan().TotalSeconds / executedBenchmarkCount;
621-
TimeSpan fromNow = TimeSpan.FromSeconds(avgSecondsPerBenchmark * benchmarksToRunCount);
637+
TimeSpan fromNow = GetEstimatedFinishTime(runsChronometer, benchmarksToRunCount, executedBenchmarkCount);
622638
DateTime estimatedEnd = DateTime.Now.Add(fromNow);
623639
string message = $"// ** Remained {benchmarksToRunCount} ({(double)benchmarksToRunCount / totalBenchmarkCount:P1}) benchmark(s) to run." +
624640
$" Estimated finish {estimatedEnd:yyyy-MM-dd H:mm} ({(int)fromNow.TotalHours}h {fromNow.Minutes}m from now) **";
625641
logger.WriteLineHeader(message);
642+
643+
if (!Console.IsOutputRedirected && (RuntimeInformation.IsWindows() || RuntimeInformation.IsLinux() || RuntimeInformation.IsMacOSX()))
644+
{
645+
Console.Title = $"{benchmarksToRunCount}/{totalBenchmarkCount} Remaining - {(int)fromNow.TotalHours}h {fromNow.Minutes}m to finish";
646+
}
647+
}
648+
649+
private static TimeSpan GetEstimatedFinishTime(in StartedClock runsChronometer, int benchmarksToRunCount, int executedBenchmarkCount)
650+
{
651+
double avgSecondsPerBenchmark = executedBenchmarkCount > 0 ? runsChronometer.GetElapsed().GetTimeSpan().TotalSeconds / executedBenchmarkCount : 0;
652+
TimeSpan fromNow = TimeSpan.FromSeconds(avgSecondsPerBenchmark * benchmarksToRunCount);
653+
return fromNow;
626654
}
627655
}
628656
}

0 commit comments

Comments
 (0)