Skip to content

passed args to benchmark runner #1292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jan 29, 2021
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Running;

namespace BenchmarkDotNet.ConsoleArguments.ListBenchmarks
{
Expand All @@ -14,6 +18,18 @@ public BenchmarkCasesPrinter(ListBenchmarkCaseMode listBenchmarkCaseMode)
: new FlatBenchmarkCasesPrinter();
}

public static void PrintList(ILogger nonNullLogger, IConfig effectiveConfig, IReadOnlyList<Type> allAvailableTypesWithRunnableBenchmarks, CommandLineOptions options)
{
var printer = new BenchmarkCasesPrinter(options.ListBenchmarkCaseMode);

var testNames = TypeFilter.Filter(effectiveConfig, allAvailableTypesWithRunnableBenchmarks)
.SelectMany(p => p.BenchmarksCases)
.Select(p => p.Descriptor.GetFilterName())
.Distinct();

printer.Print(testNames, nonNullLogger);
}

public void Print(IEnumerable<string> testNames, ILogger logger) => printer.Print(testNames, logger);
}
}
27 changes: 16 additions & 11 deletions src/BenchmarkDotNet/Running/BenchmarkRunnerDirty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ namespace BenchmarkDotNet.Running
public static class BenchmarkRunner
{
[PublicAPI]
public static Summary Run<T>(IConfig config = null)
public static Summary Run<T>(IConfig config = null, string[] args = null)
{
using (DirtyAssemblyResolveHelper.Create())
return RunWithExceptionHandling(() => RunWithDirtyAssemblyResolveHelper(typeof(T), config));
return RunWithExceptionHandling(() => RunWithDirtyAssemblyResolveHelper(typeof(T), config, args));
}

[PublicAPI]
public static Summary Run(Type type, IConfig config = null)
public static Summary Run(Type type, IConfig config = null, string[] args = null)
{
using (DirtyAssemblyResolveHelper.Create())
return RunWithExceptionHandling(() => RunWithDirtyAssemblyResolveHelper(type, config));
return RunWithExceptionHandling(() => RunWithDirtyAssemblyResolveHelper(type, config, args));
}

[PublicAPI]
Expand All @@ -38,10 +38,10 @@ public static Summary Run(Type type, MethodInfo[] methods, IConfig config = null
}

[PublicAPI]
public static Summary[] Run(Assembly assembly, IConfig config = null)
public static Summary[] Run(Assembly assembly, IConfig config = null, string[] args = null)
{
using (DirtyAssemblyResolveHelper.Create())
return RunWithExceptionHandling(() => RunWithDirtyAssemblyResolveHelper(assembly, config));
return RunWithExceptionHandling(() => RunWithDirtyAssemblyResolveHelper(assembly, config, args));
}

[PublicAPI]
Expand Down Expand Up @@ -73,16 +73,21 @@ public static Summary RunSource(string source, IConfig config = null)
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static Summary RunWithDirtyAssemblyResolveHelper(Type type, IConfig config)
=> BenchmarkRunnerClean.Run(new[] { BenchmarkConverter.TypeToBenchmarks(type, config) }).Single();
private static Summary RunWithDirtyAssemblyResolveHelper(Type type, IConfig config, string[] args)
=> (args == null
? BenchmarkRunnerClean.Run(new[] { BenchmarkConverter.TypeToBenchmarks(type, config) })
: new BenchmarkSwitcher(new[] { type }).RunWithDirtyAssemblyResolveHelper(args, config, false))
.Single();

[MethodImpl(MethodImplOptions.NoInlining)]
private static Summary RunWithDirtyAssemblyResolveHelper(Type type, MethodInfo[] methods, IConfig config = null)
=> BenchmarkRunnerClean.Run(new[] { BenchmarkConverter.MethodsToBenchmarks(type, methods, config) }).Single();

[MethodImpl(MethodImplOptions.NoInlining)]
private static Summary[] RunWithDirtyAssemblyResolveHelper(Assembly assembly, IConfig config = null)
=> BenchmarkRunnerClean.Run(assembly.GetRunnableBenchmarks().Select(type => BenchmarkConverter.TypeToBenchmarks(type, config)).ToArray());
private static Summary[] RunWithDirtyAssemblyResolveHelper(Assembly assembly, IConfig config, string[] args)
=> args == null
? BenchmarkRunnerClean.Run(assembly.GetRunnableBenchmarks().Select(type => BenchmarkConverter.TypeToBenchmarks(type, config)).ToArray())
: new BenchmarkSwitcher(assembly).RunWithDirtyAssemblyResolveHelper(args, config, false).ToArray();

[MethodImpl(MethodImplOptions.NoInlining)]
private static Summary[] RunWithDirtyAssemblyResolveHelper(BenchmarkRunInfo[] benchmarkRunInfos)
Expand Down Expand Up @@ -126,4 +131,4 @@ private static Summary[] RunWithExceptionHandling(Func<Summary[]> run)
}
}
}
}
}
6 changes: 3 additions & 3 deletions src/BenchmarkDotNet/Running/BenchmarkSwitcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ public IEnumerable<Summary> Run(string[] args = null, IConfig config = null)
// we need to keep the logic that uses it in a separate method and create DirtyAssemblyResolveHelper first
// so it can ignore the version mismatch ;)
using (DirtyAssemblyResolveHelper.Create())
return RunWithDirtyAssemblyResolveHelper(args, config);
return RunWithDirtyAssemblyResolveHelper(args, config, true);
}

[MethodImpl(MethodImplOptions.NoInlining)]
private IEnumerable<Summary> RunWithDirtyAssemblyResolveHelper(string[] args, IConfig config)
internal IEnumerable<Summary> RunWithDirtyAssemblyResolveHelper(string[] args, IConfig config, bool askUserForInput)
{
var notNullArgs = args ?? Array.Empty<string>();
var notNullConfig = config ?? DefaultConfig.Instance;
Expand Down Expand Up @@ -105,7 +105,7 @@ private IEnumerable<Summary> RunWithDirtyAssemblyResolveHelper(string[] args, IC
return Array.Empty<Summary>();
}

var benchmarksToFilter = options.UserProvidedFilters
var benchmarksToFilter = options.UserProvidedFilters || !askUserForInput
? allAvailableTypesWithRunnableBenchmarks
: userInteraction.AskUser(allAvailableTypesWithRunnableBenchmarks, logger);

Expand Down