Skip to content

Commit

Permalink
run selected type from all types in exe #699
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsitnik committed Mar 24, 2018
1 parent 334af27 commit b958a1b
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 194 deletions.
5 changes: 4 additions & 1 deletion src/BenchmarkDotNet/Diagnosers/DiagnoserActionParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ namespace BenchmarkDotNet.Diagnosers
{
public class DiagnoserActionParameters
{
public DiagnoserActionParameters(Process process, Benchmark benchmark, IConfig config)
public DiagnoserActionParameters(Process process, Benchmark benchmark, BenchmarkId benchmarkId, IConfig config)
{
Process = process;
Benchmark = benchmark;
BenchmarkId = benchmarkId;
Config = config;
}

public Process Process { get; }

public Benchmark Benchmark { get; }

public BenchmarkId BenchmarkId { get; }

public IConfig Config { get; }
}
}
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Diagnosers/WindowsDisassembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private void CopyFromResources(Assembly assembly, string resourceName, string de
private string BuildArguments(DiagnoserActionParameters parameters, string resultsPath)
=> new StringBuilder(200)
.Append(parameters.Process.Id).Append(' ')
.Append("BenchmarkDotNet.Autogenerated.Runnable").Append(' ')
.Append("BenchmarkDotNet.Autogenerated.Runnable_").Append(parameters.BenchmarkId.Value).Append(' ')
.Append(DisassemblerConstants.DiassemblerEntryMethodName).Append(' ')
.Append(printAsm).Append(' ')
.Append(printIL).Append(' ')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class SynchronousProcessOutputLoggerWithDiagnoser
private readonly IDiagnoser diagnoser;
private readonly DiagnoserActionParameters diagnoserActionParameters;

public SynchronousProcessOutputLoggerWithDiagnoser(ILogger logger, Process process, IDiagnoser diagnoser, Benchmark benchmark, IConfig config)
public SynchronousProcessOutputLoggerWithDiagnoser(ILogger logger, Process process, IDiagnoser diagnoser, Benchmark benchmark, BenchmarkId benchmarkId, IConfig config)
{
if (!process.StartInfo.RedirectStandardOutput)
throw new NotSupportedException("set RedirectStandardOutput to true first");
Expand All @@ -25,7 +25,7 @@ public SynchronousProcessOutputLoggerWithDiagnoser(ILogger logger, Process proce
this.logger = logger;
this.process = process;
this.diagnoser = diagnoser;
diagnoserActionParameters = new DiagnoserActionParameters(process, benchmark, config);
diagnoserActionParameters = new DiagnoserActionParameters(process, benchmark, benchmarkId, config);

LinesWithResults = new List<string>();
LinesWithExtraOutput = new List<string>();
Expand Down
4 changes: 2 additions & 2 deletions src/BenchmarkDotNet/Running/BenchmarkBuildInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ public BenchmarkBuildInfo(Benchmark benchmark, ReadOnlyConfig config, int id)
{
Benchmark = benchmark;
Config = config;
Id = id;
Id = new BenchmarkId(id);
}

public Benchmark Benchmark { get; }

public ReadOnlyConfig Config { get; }

public int Id { get; }
public BenchmarkId Id { get; }
}
}
24 changes: 24 additions & 0 deletions src/BenchmarkDotNet/Running/BenchmarkId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;

namespace BenchmarkDotNet.Running
{
/// <summary>
/// represents an internal entity used to identify a benchmark within an executable with multiple benchmarks
/// </summary>
public struct BenchmarkId
{
public BenchmarkId(int value) => Value = value;

public int Value { get; }

public bool Equals(BenchmarkId other) => Value == other.Value;

public override bool Equals(object obj) => throw new InvalidOperationException("boxing");

public override int GetHashCode() => Value;

public string ToArgument() => $"-benchmarkId {Value}";

public override string ToString() => Value.ToString();
}
}
317 changes: 153 additions & 164 deletions src/BenchmarkDotNet/Running/BenchmarkRunner.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Templates/BenchmarkProgram.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace BenchmarkDotNet.Autogenerated
// which could cause the jitting/assembly loading to happen before we do anything
// we have some jitting diagnosers and we want them to catch all the informations!!

int id = int.Parse(args.Single());
int id = int.Parse(args.Last());

Type type = typeof(UniqueProgramName).GetTypeInfo().Assembly.GetType($"BenchmarkDotNet.Autogenerated.Runnable_{id}");

Expand Down
23 changes: 5 additions & 18 deletions src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public ExecuteResult Execute(ExecuteParameters executeParameters)
try
{
return Execute(
executeParameters.Benchmark,
executeParameters.Benchmark,
executeParameters.BenchmarkId,
executeParameters.Logger,
executeParameters.BuildResult.ArtifactsPaths,
executeParameters.Diagnoser,
Expand All @@ -53,19 +54,19 @@ public ExecuteResult Execute(ExecuteParameters executeParameters)
}
}

private ExecuteResult Execute(Benchmark benchmark, ILogger logger, ArtifactsPaths artifactsPaths, IDiagnoser diagnoser, string executableName, IConfig config, IResolver resolver)
private ExecuteResult Execute(Benchmark benchmark, BenchmarkId benchmarkId, ILogger logger, ArtifactsPaths artifactsPaths, IDiagnoser diagnoser, string executableName, IConfig config, IResolver resolver)
{
var startInfo = DotNetCliCommandExecutor.BuildStartInfo(
CustomDotNetCliPath,
artifactsPaths.BinariesDirectoryPath,
BuildArgs(diagnoser, executableName),
$"{executableName} {benchmarkId.ToArgument()}",
redirectStandardInput: true);

startInfo.SetEnvironmentVariables(benchmark, resolver);

using (var process = new Process { StartInfo = startInfo })
{
var loggerWithDiagnoser = new SynchronousProcessOutputLoggerWithDiagnoser(logger, process, diagnoser, benchmark, config);
var loggerWithDiagnoser = new SynchronousProcessOutputLoggerWithDiagnoser(logger, process, diagnoser, benchmark, benchmarkId, config);

ConsoleHandler.Instance.SetProcess(process);

Expand Down Expand Up @@ -95,19 +96,5 @@ private ExecuteResult Execute(Benchmark benchmark, ILogger logger, ArtifactsPath
return new ExecuteResult(true, process.ExitCode, Array.Empty<string>(), Array.Empty<string>());
}
}

private static string BuildArgs(IDiagnoser diagnoser, string executableName)
{
var args = new StringBuilder(50);

args.AppendFormat(executableName);

if (diagnoser != null)
{
args.Append($" {Engine.Signals.DiagnoserIsAttachedParam}");
}

return args.ToString();
}
}
}
8 changes: 4 additions & 4 deletions src/BenchmarkDotNet/Toolchains/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ public class Executor : IExecutor
public ExecuteResult Execute(ExecuteParameters executeParameters)
{
var exePath = executeParameters.BuildResult.ArtifactsPaths.ExecutablePath;
var args = executeParameters.Diagnoser == null ? string.Empty : Engine.Signals.DiagnoserIsAttachedParam;
var args = executeParameters.BenchmarkId.ToArgument();

if (!File.Exists(exePath))
{
return new ExecuteResult(false, -1, Array.Empty<string>(), Array.Empty<string>());
}

return Execute(executeParameters.Benchmark, executeParameters.Logger, exePath, null, args, executeParameters.Diagnoser, executeParameters.Resolver, executeParameters.Config);
return Execute(executeParameters.Benchmark, executeParameters.BenchmarkId, executeParameters.Logger, exePath, null, args, executeParameters.Diagnoser, executeParameters.Resolver, executeParameters.Config);
}

private ExecuteResult Execute(Benchmark benchmark, ILogger logger, string exePath, string workingDirectory, string args, IDiagnoser diagnoser, IResolver resolver, IConfig config)
private ExecuteResult Execute(Benchmark benchmark, BenchmarkId benchmarkId, ILogger logger, string exePath, string workingDirectory, string args, IDiagnoser diagnoser, IResolver resolver, IConfig config)
{
ConsoleHandler.EnsureInitialized(logger);

try
{
using (var process = new Process { StartInfo = CreateStartInfo(benchmark, exePath, args, workingDirectory, resolver) })
{
var loggerWithDiagnoser = new SynchronousProcessOutputLoggerWithDiagnoser(logger, process, diagnoser, benchmark, config);
var loggerWithDiagnoser = new SynchronousProcessOutputLoggerWithDiagnoser(logger, process, diagnoser, benchmark, benchmarkId, config);

return Execute(process, benchmark, loggerWithDiagnoser, logger);
}
Expand Down
1 change: 1 addition & 0 deletions src/BenchmarkDotNet/Toolchains/InProcess/InProcessHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public InProcessHost(Benchmark benchmark, ILogger logger, IDiagnoser diagnoser,
diagnoserActionParameters = new DiagnoserActionParameters(
Process.GetCurrentProcess(),
benchmark,
default,
config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ namespace BenchmarkDotNet.Toolchains.Parameters
{
public class ExecuteParameters
{
public ExecuteParameters(BuildResult buildResult, Benchmark benchmark, ILogger logger, IResolver resolver, IConfig config, IDiagnoser diagnoser = null)
public ExecuteParameters(BuildResult buildResult, Benchmark benchmark, BenchmarkId benchmarkId, ILogger logger, IResolver resolver, IConfig config,
IDiagnoser diagnoser = null)
{
BuildResult = buildResult;
Benchmark = benchmark;
BenchmarkId = benchmarkId;
Logger = logger;
Resolver = resolver;
Config = config;
Expand All @@ -23,6 +25,8 @@ public ExecuteParameters(BuildResult buildResult, Benchmark benchmark, ILogger l

public Benchmark Benchmark { get; }

public BenchmarkId BenchmarkId { get; }

public ILogger Logger { get; }

public IResolver Resolver { get; }
Expand Down

0 comments on commit b958a1b

Please sign in to comment.