17
17
using BenchmarkDotNet . Jobs ;
18
18
using BenchmarkDotNet . Loggers ;
19
19
using BenchmarkDotNet . Mathematics ;
20
+ using BenchmarkDotNet . Portability ;
20
21
using BenchmarkDotNet . Reports ;
21
22
using BenchmarkDotNet . Toolchains ;
22
23
using BenchmarkDotNet . Toolchains . Parameters ;
@@ -41,8 +42,11 @@ internal static Summary[] Run(BenchmarkRunInfo[] benchmarkRunInfos)
41
42
var resolver = DefaultResolver ;
42
43
var artifactsToCleanup = new List < string > ( ) ;
43
44
44
- var title = GetTitle ( benchmarkRunInfos ) ;
45
45
var rootArtifactsFolderPath = GetRootArtifactsFolderPath ( benchmarkRunInfos ) ;
46
+ var maxTitleLength = RuntimeInformation . IsWindows ( )
47
+ ? 254 - rootArtifactsFolderPath . Length
48
+ : int . MaxValue ;
49
+ var title = GetTitle ( benchmarkRunInfos , maxTitleLength ) ;
46
50
var resultsFolderPath = GetResultsFolderPath ( rootArtifactsFolderPath , benchmarkRunInfos ) ;
47
51
var logFilePath = Path . Combine ( rootArtifactsFolderPath , title + ".log" ) ;
48
52
var idToResume = GetIdToResume ( rootArtifactsFolderPath , title , benchmarkRunInfos ) ;
@@ -573,7 +577,7 @@ private static string GetRootArtifactsFolderPath(BenchmarkRunInfo[] benchmarkRun
573
577
return customPath != default ? customPath . CreateIfNotExists ( ) : defaultPath ;
574
578
}
575
579
576
- private static string GetTitle ( BenchmarkRunInfo [ ] benchmarkRunInfos )
580
+ private static string GetTitle ( BenchmarkRunInfo [ ] benchmarkRunInfos , int desiredMaxLength = int . MaxValue )
577
581
{
578
582
// few types might have the same name: A.Name and B.Name will both report "Name"
579
583
// in that case, we can not use the type name as file name because they would be getting overwritten #529
@@ -582,8 +586,22 @@ private static string GetTitle(BenchmarkRunInfo[] benchmarkRunInfos)
582
586
var fileNamePrefix = ( uniqueTargetTypes . Length == 1 )
583
587
? FolderNameHelper . ToFolderName ( uniqueTargetTypes [ 0 ] )
584
588
: "BenchmarkRun" ;
589
+ string dateTimeSuffix = DateTime . Now . ToString ( DateTimeFormat ) ;
585
590
586
- return $ "{ fileNamePrefix } -{ DateTime . Now . ToString ( DateTimeFormat ) } ";
591
+ int maxFileNamePrefixLength = desiredMaxLength - dateTimeSuffix . Length - 1 ;
592
+ if ( maxFileNamePrefixLength <= 2 )
593
+ return dateTimeSuffix ;
594
+
595
+ if ( fileNamePrefix . Length > maxFileNamePrefixLength )
596
+ {
597
+ int length1 = maxFileNamePrefixLength / 2 ;
598
+ int length2 = maxFileNamePrefixLength - length1 - 1 ;
599
+ fileNamePrefix = fileNamePrefix . Substring ( 0 , length1 ) +
600
+ "-" +
601
+ fileNamePrefix . Substring ( fileNamePrefix . Length - length2 , length2 ) ;
602
+ }
603
+
604
+ return $ "{ fileNamePrefix } -{ dateTimeSuffix } ";
587
605
}
588
606
589
607
private static string GetResultsFolderPath ( string rootArtifactsFolderPath , BenchmarkRunInfo [ ] benchmarkRunInfos )
0 commit comments