3
3
using System . Collections . Immutable ;
4
4
using System . IO ;
5
5
using System . Linq ;
6
+ using System . Text . RegularExpressions ;
6
7
using BenchmarkDotNet . Analysers ;
7
8
using BenchmarkDotNet . Characteristics ;
8
9
using BenchmarkDotNet . Columns ;
@@ -42,6 +43,7 @@ internal static Summary[] Run(BenchmarkRunInfo[] benchmarkRunInfos)
42
43
var rootArtifactsFolderPath = GetRootArtifactsFolderPath ( benchmarkRunInfos ) ;
43
44
var resultsFolderPath = GetResultsFolderPath ( rootArtifactsFolderPath , benchmarkRunInfos ) ;
44
45
var logFilePath = Path . Combine ( rootArtifactsFolderPath , title + ".log" ) ;
46
+ var idToResume = GetIdToResume ( rootArtifactsFolderPath , title , benchmarkRunInfos ) ;
45
47
46
48
using ( var streamLogger = new StreamLogger ( GetLogFileStreamWriter ( benchmarkRunInfos , logFilePath ) ) )
47
49
{
@@ -62,7 +64,7 @@ internal static Summary[] Run(BenchmarkRunInfo[] benchmarkRunInfos)
62
64
return new [ ] { Summary . ValidationFailed ( title , resultsFolderPath , logFilePath ) } ;
63
65
64
66
int totalBenchmarkCount = supportedBenchmarks . Sum ( benchmarkInfo => benchmarkInfo . BenchmarksCases . Length ) ;
65
- int benchmarksToRunCount = totalBenchmarkCount ;
67
+ int benchmarksToRunCount = totalBenchmarkCount - ( idToResume + 1 ) ; // ids are indexed from 0
66
68
compositeLogger . WriteLineHeader ( "// ***** BenchmarkRunner: Start *****" ) ;
67
69
compositeLogger . WriteLineHeader ( $ "// ***** Found { totalBenchmarkCount } benchmark(s) in total *****") ;
68
70
var globalChronometer = Chronometer . Start ( ) ;
@@ -84,6 +86,16 @@ internal static Summary[] Run(BenchmarkRunInfo[] benchmarkRunInfos)
84
86
85
87
foreach ( var benchmarkRunInfo in supportedBenchmarks ) // we run them in the old order now using the new build artifacts
86
88
{
89
+ if ( idToResume >= 0 )
90
+ {
91
+ var benchmarkWithHighestIdForGivenType = benchmarkRunInfo . BenchmarksCases . Last ( ) ;
92
+ if ( benchmarkToBuildResult [ benchmarkWithHighestIdForGivenType ] . Id . Value <= idToResume )
93
+ {
94
+ compositeLogger . WriteLineInfo ( $ "Skipping { benchmarkRunInfo . BenchmarksCases . Length } benchmark(s) defined by { benchmarkRunInfo . Type . GetCorrectCSharpTypeName ( ) } .") ;
95
+ continue ;
96
+ }
97
+ }
98
+
87
99
var summary = Run ( benchmarkRunInfo , benchmarkToBuildResult , resolver , compositeLogger , artifactsToCleanup ,
88
100
resultsFolderPath , logFilePath , totalBenchmarkCount , in runsChronometer , ref benchmarksToRunCount ) ;
89
101
@@ -678,5 +690,36 @@ private static void PrintValidationErrors(ILogger logger, IEnumerable<Validation
678
690
logger . WriteLine ( ) ;
679
691
}
680
692
}
693
+
694
+ private static int GetIdToResume ( string rootArtifactsFolderPath , string currentLogFileName , BenchmarkRunInfo [ ] benchmarkRunInfos )
695
+ {
696
+ if ( benchmarkRunInfos . Any ( benchmark => benchmark . Config . Options . IsSet ( ConfigOptions . Resume ) ) )
697
+ {
698
+ var directoryInfo = new DirectoryInfo ( rootArtifactsFolderPath ) ;
699
+ var logFilesExceptCurrent = directoryInfo
700
+ . GetFiles ( $ "{ currentLogFileName . Split ( '-' ) [ 0 ] } *")
701
+ . Where ( file => Path . GetFileNameWithoutExtension ( file . Name ) != currentLogFileName )
702
+ . ToArray ( ) ;
703
+
704
+ if ( logFilesExceptCurrent . Length > 0 )
705
+ {
706
+ var previousRunLogFile = logFilesExceptCurrent
707
+ . OrderByDescending ( o => o . LastWriteTime )
708
+ . First ( ) ;
709
+
710
+ var regex = new Regex ( "--benchmarkId (.*?) in" , RegexOptions . Compiled ) ;
711
+ foreach ( var line in File . ReadLines ( previousRunLogFile . FullName ) . Reverse ( ) )
712
+ {
713
+ var match = regex . Match ( line ) ;
714
+ if ( match . Success )
715
+ {
716
+ return int . Parse ( match . Groups [ 1 ] . Value ) ;
717
+ }
718
+ }
719
+ }
720
+ }
721
+
722
+ return - 1 ;
723
+ }
681
724
}
682
725
}
0 commit comments