4
4
using System . Threading ;
5
5
using BenchmarkDotNet . Characteristics ;
6
6
using BenchmarkDotNet . Configs ;
7
+ using BenchmarkDotNet . Detectors ;
7
8
using BenchmarkDotNet . Environments ;
8
9
using BenchmarkDotNet . Helpers ;
9
10
using BenchmarkDotNet . Jobs ;
@@ -28,11 +29,7 @@ public BuildPartition(BenchmarkBuildInfo[] benchmarks, IResolver resolver)
28
29
Resolver = resolver ;
29
30
RepresentativeBenchmarkCase = benchmarks [ 0 ] . BenchmarkCase ;
30
31
Benchmarks = benchmarks ;
31
- // Combine the benchmark's assembly name, folder info, and build partition id.
32
- string benchmarkAssemblyName = RepresentativeBenchmarkCase . Descriptor . Type . Assembly . GetName ( ) . Name ;
33
- string folderInfo = RepresentativeBenchmarkCase . Job . FolderInfo ;
34
- int id = Interlocked . Increment ( ref s_partitionCounter ) ;
35
- ProgramName = $ "{ benchmarkAssemblyName } -{ folderInfo } -{ id } ";
32
+ ProgramName = GetProgramName ( RepresentativeBenchmarkCase , Interlocked . Increment ( ref s_partitionCounter ) ) ;
36
33
LogBuildOutput = benchmarks [ 0 ] . Config . Options . IsSet ( ConfigOptions . LogBuildOutput ) ;
37
34
GenerateMSBuildBinLog = benchmarks [ 0 ] . Config . Options . IsSet ( ConfigOptions . GenerateMSBuildBinLog ) ;
38
35
}
@@ -85,6 +82,33 @@ private static string GetResolvedAssemblyLocation(Assembly assembly) =>
85
82
// manually construct the path.
86
83
assembly . Location . Length == 0 ? Path . Combine ( AppContext . BaseDirectory , assembly . GetName ( ) . Name ) : assembly . Location ;
87
84
85
+ internal static string GetProgramName ( BenchmarkCase representativeBenchmarkCase , int id )
86
+ {
87
+ // Combine the benchmark's assembly name, folder info, and build partition id.
88
+ string benchmarkAssemblyName = representativeBenchmarkCase . Descriptor . Type . Assembly . GetName ( ) . Name ;
89
+ string folderInfo = representativeBenchmarkCase . Job . FolderInfo ;
90
+ var programName = $ "{ benchmarkAssemblyName } -{ folderInfo } -{ id } ";
91
+ // Very long program name can cause the path to exceed Windows' 260 character limit,
92
+ // for example BenchmarkDotNet.IntegrationTests.ManualRunning.MultipleFrameworks.
93
+ // 36 is an arbitrary limit, but it's the length of Guid strings which is what was used previously.
94
+ const int MaxLength = 36 ;
95
+ if ( ! OsDetector . IsWindows ( ) || programName . Length <= MaxLength )
96
+ {
97
+ return programName ;
98
+ }
99
+ programName = $ "{ benchmarkAssemblyName } -{ id } ";
100
+ if ( programName . Length <= MaxLength )
101
+ {
102
+ return programName ;
103
+ }
104
+ programName = $ "{ folderInfo } -{ id } ";
105
+ if ( programName . Length <= MaxLength )
106
+ {
107
+ return programName ;
108
+ }
109
+ return id . ToString ( ) ;
110
+ }
111
+
88
112
internal bool ForcedNoDependenciesForIntegrationTests
89
113
{
90
114
get
@@ -100,4 +124,4 @@ internal bool ForcedNoDependenciesForIntegrationTests
100
124
}
101
125
}
102
126
}
103
- }
127
+ }
0 commit comments