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,32 @@ 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
+ if ( ! OsDetector . IsWindows ( ) || programName . Length <= 36 )
95
+ {
96
+ return programName ;
97
+ }
98
+ programName = $ "{ benchmarkAssemblyName } -{ id } ";
99
+ if ( programName . Length <= 36 )
100
+ {
101
+ return programName ;
102
+ }
103
+ programName = $ "{ folderInfo } -{ id } ";
104
+ if ( programName . Length <= 36 )
105
+ {
106
+ return programName ;
107
+ }
108
+ return id . ToString ( ) ;
109
+ }
110
+
88
111
internal bool ForcedNoDependenciesForIntegrationTests
89
112
{
90
113
get
0 commit comments