Skip to content

Commit

Permalink
Fix builds when --keepFiles is specified (#2423)
Browse files Browse the repository at this point in the history
* Include guid in build artifacts directory when --keepFiles is specified.

* Use an auto-incremented id instead of guid.
Always use same ProgramName regardless of --keepFiles.
Include benchmark assembly name in ProgramName.

* Fix InProcessBenchmarkEmitsSameIL tests.

* Added comment from PR feedback.
  • Loading branch information
timcassell authored Dec 12, 2024
1 parent 6367ad8 commit fe5b2f5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
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

0 comments on commit fe5b2f5

Please sign in to comment.