16
16
using BenchmarkDotNet . Jobs ;
17
17
using BenchmarkDotNet . Loggers ;
18
18
using BenchmarkDotNet . Mathematics ;
19
+ using BenchmarkDotNet . Portability ;
19
20
using BenchmarkDotNet . Reports ;
20
21
using BenchmarkDotNet . Toolchains ;
21
22
using BenchmarkDotNet . Toolchains . Parameters ;
@@ -144,12 +145,15 @@ private static Summary Run(BenchmarkRunInfo benchmarkRunInfo,
144
145
var cultureInfo = config . CultureInfo ?? DefaultCultureInfo . Instance ;
145
146
var reports = new List < BenchmarkReport > ( ) ;
146
147
string title = GetTitle ( new [ ] { benchmarkRunInfo } ) ;
148
+ var consoleTitle = RuntimeInformation . IsWindows ( ) ? Console . Title : string . Empty ;
147
149
148
150
logger . WriteLineInfo ( $ "// Found { benchmarks . Length } benchmarks:") ;
149
151
foreach ( var benchmark in benchmarks )
150
152
logger . WriteLineInfo ( $ "// { benchmark . DisplayInfo } ") ;
151
153
logger . WriteLine ( ) ;
152
154
155
+ UpdateTitle ( totalBenchmarkCount , benchmarksToRunCount ) ;
156
+
153
157
using ( var powerManagementApplier = new PowerManagementApplier ( logger ) )
154
158
{
155
159
bool stop = false ;
@@ -218,6 +222,11 @@ private static Summary Run(BenchmarkRunInfo benchmarkRunInfo,
218
222
}
219
223
}
220
224
225
+ if ( RuntimeInformation . IsWindows ( ) )
226
+ {
227
+ Console . Title = consoleTitle ;
228
+ }
229
+
221
230
var runEnd = runsChronometer . GetElapsed ( ) ;
222
231
223
232
return new Summary ( title ,
@@ -227,7 +236,7 @@ private static Summary Run(BenchmarkRunInfo benchmarkRunInfo,
227
236
logFilePath ,
228
237
runEnd . GetTimeSpan ( ) - runStart . GetTimeSpan ( ) ,
229
238
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
231
240
config . GetColumnHidingRules ( ) . ToImmutableArray ( ) ) ;
232
241
}
233
242
@@ -614,15 +623,34 @@ private static void Cleanup(HashSet<string> artifactsToCleanup)
614
623
}
615
624
}
616
625
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
+
617
634
private static void LogProgress ( ILogger logger , in StartedClock runsChronometer , int totalBenchmarkCount , int benchmarksToRunCount )
618
635
{
619
636
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 ) ;
622
638
DateTime estimatedEnd = DateTime . Now . Add ( fromNow ) ;
623
639
string message = $ "// ** Remained { benchmarksToRunCount } ({ ( double ) benchmarksToRunCount / totalBenchmarkCount : P1} ) benchmark(s) to run." +
624
640
$ " Estimated finish { estimatedEnd : yyyy-MM-dd H:mm} ({ ( int ) fromNow . TotalHours } h { fromNow . Minutes } m from now) **";
625
641
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 ;
626
654
}
627
655
}
628
656
}
0 commit comments