1
1
using System ;
2
2
using System . IO ;
3
3
using System . Reflection ;
4
+ using System . Threading ;
4
5
using BenchmarkDotNet . Characteristics ;
5
6
using BenchmarkDotNet . Configs ;
6
7
using BenchmarkDotNet . Environments ;
@@ -18,15 +19,20 @@ namespace BenchmarkDotNet.Running
18
19
{
19
20
public class BuildPartition
20
21
{
22
+ // We use an auto-increment global counter instead of Guid to guarantee uniqueness per benchmark run (Guid has a small chance to collide),
23
+ // assuming there are fewer than 4 billion build partitions (a safe assumption).
24
+ private static int s_partitionCounter ;
25
+
21
26
public BuildPartition ( BenchmarkBuildInfo [ ] benchmarks , IResolver resolver )
22
27
{
23
28
Resolver = resolver ;
24
29
RepresentativeBenchmarkCase = benchmarks [ 0 ] . BenchmarkCase ;
25
30
Benchmarks = benchmarks ;
26
- var keepBenchmarkFiles = benchmarks [ 0 ] . Config . Options . IsSet ( ConfigOptions . KeepBenchmarkFiles ) ;
27
- var guid = Guid . NewGuid ( ) . ToString ( ) ;
28
- ProgramName = keepBenchmarkFiles ? RepresentativeBenchmarkCase . Job . FolderInfo : guid ;
29
- ProgramDirectory = keepBenchmarkFiles ? Path . Combine ( RepresentativeBenchmarkCase . Job . FolderInfo , guid ) : guid ;
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 } ";
30
36
LogBuildOutput = benchmarks [ 0 ] . Config . Options . IsSet ( ConfigOptions . LogBuildOutput ) ;
31
37
GenerateMSBuildBinLog = benchmarks [ 0 ] . Config . Options . IsSet ( ConfigOptions . GenerateMSBuildBinLog ) ;
32
38
}
@@ -35,8 +41,6 @@ public BuildPartition(BenchmarkBuildInfo[] benchmarks, IResolver resolver)
35
41
36
42
public string ProgramName { get ; }
37
43
38
- public string ProgramDirectory { get ; }
39
-
40
44
/// <summary>
41
45
/// the benchmarks are grouped by the build settings
42
46
/// so you can use this benchmark to get the runtime settings
0 commit comments