Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions src/BenchmarkDotNet/Running/BuildPartition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading;
using BenchmarkDotNet.Characteristics;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Detectors;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Helpers;
using BenchmarkDotNet.Jobs;
Expand All @@ -28,11 +29,7 @@ public BuildPartition(BenchmarkBuildInfo[] benchmarks, IResolver resolver)
Resolver = resolver;
RepresentativeBenchmarkCase = benchmarks[0].BenchmarkCase;
Benchmarks = benchmarks;
// Combine the benchmark's assembly name, folder info, and build partition id.
string benchmarkAssemblyName = RepresentativeBenchmarkCase.Descriptor.Type.Assembly.GetName().Name;
string folderInfo = RepresentativeBenchmarkCase.Job.FolderInfo;
int id = Interlocked.Increment(ref s_partitionCounter);
ProgramName = $"{benchmarkAssemblyName}-{folderInfo}-{id}";
ProgramName = GetProgramName(RepresentativeBenchmarkCase, Interlocked.Increment(ref s_partitionCounter));
LogBuildOutput = benchmarks[0].Config.Options.IsSet(ConfigOptions.LogBuildOutput);
GenerateMSBuildBinLog = benchmarks[0].Config.Options.IsSet(ConfigOptions.GenerateMSBuildBinLog);
}
Expand Down Expand Up @@ -85,6 +82,33 @@ private static string GetResolvedAssemblyLocation(Assembly assembly) =>
// manually construct the path.
assembly.Location.Length == 0 ? Path.Combine(AppContext.BaseDirectory, assembly.GetName().Name) : assembly.Location;

internal static string GetProgramName(BenchmarkCase representativeBenchmarkCase, int id)
{
// Combine the benchmark's assembly name, folder info, and build partition id.
string benchmarkAssemblyName = representativeBenchmarkCase.Descriptor.Type.Assembly.GetName().Name;
string folderInfo = representativeBenchmarkCase.Job.FolderInfo;
var programName = $"{benchmarkAssemblyName}-{folderInfo}-{id}";
// Very long program name can cause the path to exceed Windows' 260 character limit,
// for example BenchmarkDotNet.IntegrationTests.ManualRunning.MultipleFrameworks.
// 36 is an arbitrary limit, but it's the length of Guid strings which is what was used previously.
const int MaxLength = 36;
if (!OsDetector.IsWindows() || programName.Length <= MaxLength)
{
return programName;
}
programName = $"{benchmarkAssemblyName}-{id}";
if (programName.Length <= MaxLength)
{
return programName;
}
programName = $"{folderInfo}-{id}";
if (programName.Length <= MaxLength)
{
return programName;
}
return id.ToString();
}

internal bool ForcedNoDependenciesForIntegrationTests
{
get
Expand All @@ -100,4 +124,4 @@ internal bool ForcedNoDependenciesForIntegrationTests
}
}
}
}
}
5 changes: 2 additions & 3 deletions tests/BenchmarkDotNet.IntegrationTests/InProcessEmitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ private void DiffEmit(Summary summary)
return;

var benchmarkCase = summary.BenchmarksCases.First();
var caseName = $"{benchmarkCase.Descriptor.Type.Assembly.GetName().Name}-{benchmarkCase.Job.FolderInfo}";
// The benchmark config built jobs with 2 toolchains, 1 InProcessEmit and 1 Roslyn,
// so we need to subtract 1 from the partition counter to obtain the emit output.
NaiveRunnableEmitDiff.RunDiff(
$@"{caseName}-{BuildPartition.s_partitionCounter}.exe",
$@"{caseName}-{BuildPartition.s_partitionCounter - 1}Emitted.dll",
$@"{BuildPartition.GetProgramName(benchmarkCase, BuildPartition.s_partitionCounter)}.exe",
$@"{BuildPartition.GetProgramName(benchmarkCase, BuildPartition.s_partitionCounter - 1)}Emitted.dll",
ConsoleLogger.Default);
}

Expand Down