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
11 changes: 10 additions & 1 deletion src/BenchmarkDotNet/Running/BuildPartition.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Reflection;
using System.Threading;
using BenchmarkDotNet.Characteristics;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
Expand All @@ -18,12 +19,20 @@ namespace BenchmarkDotNet.Running
{
public class BuildPartition
{
// We use an auto-increment global counter instead of Guid to guarantee uniqueness per benchmark run (Guid has a small chance to collide),
// assuming there are fewer than 4 billion build partitions (a safe assumption).
internal static int s_partitionCounter;

public BuildPartition(BenchmarkBuildInfo[] benchmarks, IResolver resolver)
{
Resolver = resolver;
RepresentativeBenchmarkCase = benchmarks[0].BenchmarkCase;
Benchmarks = benchmarks;
ProgramName = benchmarks[0].Config.Options.IsSet(ConfigOptions.KeepBenchmarkFiles) ? RepresentativeBenchmarkCase.Job.FolderInfo : Guid.NewGuid().ToString();
// 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}";
LogBuildOutput = benchmarks[0].Config.Options.IsSet(ConfigOptions.LogBuildOutput);
GenerateMSBuildBinLog = benchmarks[0].Config.Options.IsSet(ConfigOptions.GenerateMSBuildBinLog);
}
Expand Down
10 changes: 7 additions & 3 deletions tests/BenchmarkDotNet.IntegrationTests/InProcessEmitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Tests.Loggers;
using BenchmarkDotNet.Tests.XUnit;
using BenchmarkDotNet.Toolchains.InProcess.Emit;
Expand Down Expand Up @@ -68,10 +69,13 @@ private void DiffEmit(Summary summary)
if (!Portability.RuntimeInformation.IsFullFramework)
return;

var caseName = summary.BenchmarksCases.First().Job.ToString();
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}.exe",
$@"{caseName}Emitted.dll",
$@"{caseName}-{BuildPartition.s_partitionCounter}.exe",
$@"{caseName}-{BuildPartition.s_partitionCounter - 1}Emitted.dll",
ConsoleLogger.Default);
}

Expand Down
Loading