Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions src/BenchmarkDotNet/ConsoleArguments/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class CommandLineOptions
[Option('e', "exporters", Required = false, HelpText = "GitHub/StackOverflow/RPlot/CSV/JSON/HTML/XML")]
public IEnumerable<string> Exporters { get; set; }

[Option( "customExporter", Required = false, HelpText = "The assembly-qualified name of the Custom Exporter type")]
public string CustomExporter { get; set; }

[Option('m', "memory", Required = false, Default = false, HelpText = "Prints memory statistics")]
public bool UseMemoryDiagnoser { get; set; }

Expand Down
18 changes: 18 additions & 0 deletions src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public static class ConfigParser
{ "verylong", Job.VeryLongRun }
};

public static void RegisterCustomExporter(string commandLineName, IExporter exporter) => CustomExporters.Add(commandLineName, exporter);
private static readonly IDictionary<string, IExporter> CustomExporters = new Dictionary<string, IExporter>();

[SuppressMessage("ReSharper", "StringLiteralTypo")]
[SuppressMessage("ReSharper", "CoVariantArrayConversion")]
private static readonly IReadOnlyDictionary<string, IExporter[]> AvailableExporters =
Expand Down Expand Up @@ -252,6 +255,20 @@ private static bool Validate(CommandLineOptions options, ILogger logger)
}
}

if (!string.IsNullOrWhiteSpace(options.CustomExporter))
{
try
{
var customExporter = Activator.CreateInstance(Type.GetType(options.CustomExporter));
CustomExporters["customExporter"] = (IExporter)customExporter;
}
catch (Exception ex)
{
logger.WriteLineError(ex.ToString());
}

}

foreach (string exporter in options.Exporters)
if (!AvailableExporters.ContainsKey(exporter))
{
Expand Down Expand Up @@ -339,6 +356,7 @@ private static IConfig CreateConfig(CommandLineOptions options, IConfig globalCo
config.AddJob(baseJob);

config.AddExporter(options.Exporters.SelectMany(exporter => AvailableExporters[exporter]).ToArray());
config.AddExporter(CustomExporters.Select(c => c.Value).ToArray());

config.AddHardwareCounters(options.HardwareCounters
.Select(counterName => (HardwareCounter)Enum.Parse(typeof(HardwareCounter), counterName, ignoreCase: true))
Expand Down
16 changes: 16 additions & 0 deletions tests/BenchmarkDotNet.Tests/ConfigParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,31 @@
using Perfolizer.Horology;
using Perfolizer.Mathematics.SignificanceTesting;
using Perfolizer.Mathematics.Thresholds;
using BenchmarkDotNet.Exporters.Json;

namespace BenchmarkDotNet.Tests
{
public class CustomExporterTestClass : JsonExporterBase { }
public class ConfigParserTests
{
public ITestOutputHelper Output { get; }

public ConfigParserTests(ITestOutputHelper output) => Output = output;

[Theory]
[InlineData("--customExporter", "BenchmarkDotNet.Tests.CustomExporterTestClass, BenchmarkDotNet.Tests")]
public void CustomExporterConfigParsedCorrectly(params string[] args)
{
var config = ConfigParser.Parse(args, new OutputLogger(Output)).config;

var customExporter = config.GetExporters().ToList();
Assert.Equal("CustomExporterTestClass", customExporter[0].Name);
Assert.Empty(config.GetColumnProviders());
Assert.Empty(config.GetDiagnosers());
Assert.Empty(config.GetAnalysers());
Assert.Empty(config.GetLoggers());
}

[Theory]
[InlineData("--job=dry", "--exporters", "html", "rplot")]
[InlineData("--JOB=dry", "--EXPORTERS", "html", "rplot")] // case insensitive
Expand Down