Skip to content

Commit 643fd81

Browse files
Add OpenMetrics to --exporters (#3137)
* Add OpenMetrics to --exporters Allow the OpenMetrics exporter to be specified through `--exporters`. * Update --exporters documentation Add all the possible options. * Add tests for all --exporters options Add tests for all the possible `--exporters` options.
1 parent ec08761 commit 643fd81

4 files changed

Lines changed: 37 additions & 3 deletions

File tree

docs/articles/guides/console-args.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ dotnet run -c Release -- --filter * --runtimes net6.0 net8.0 --statisticalTest 5
257257

258258
* `-j`, `--job` (Default: Default) Dry/Short/Medium/Long or Default
259259
* `-r`, `--runtimes` Full target framework moniker for .NET Core and .NET. For Mono just 'Mono'. For NativeAOT please append target runtime version (example: 'nativeaot7.0'). First one will be marked as baseline!
260-
* `-e`, `--exporters` GitHub/StackOverflow/RPlot/CSV/JSON/HTML/XML
260+
* `-e`, `--exporters` GitHub/StackOverflow/RPlot/CSV/JSON/HTML/XML/CSVMeasurements/Markdown/Atlassian/Plain/BriefJSON/FullJSON/Asciidoc/BriefXML/FullXML/OpenMetrics
261261
* `-m`, `--memory` (Default: false) Prints memory statistics
262262
* `-t`, `--threading` (Default: false) Prints threading statistics
263263
* `--exceptions` (Default: false) Prints exception statistics

src/BenchmarkDotNet/ConsoleArguments/CommandLineOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class CommandLineOptions
2626
[Option('r', "runtimes", Required = false, HelpText = "Full target framework moniker for .NET Core and .NET. For Mono just 'Mono'. For NativeAOT please append target runtime version (example: 'nativeaot7.0'). First one will be marked as baseline!")]
2727
public IEnumerable<string> Runtimes { get; set; } = [];
2828

29-
[Option('e', "exporters", Required = false, HelpText = "GitHub/StackOverflow/RPlot/CSV/JSON/HTML/XML")]
29+
[Option('e', "exporters", Required = false, HelpText = "GitHub/StackOverflow/RPlot/CSV/JSON/HTML/XML/CSVMeasurements/Markdown/Atlassian/Plain/BriefJSON/FullJSON/Asciidoc/BriefXML/FullXML/OpenMetrics")]
3030
public IEnumerable<string> Exporters { get; set; } = [];
3131

3232
[Option('m', "memory", Required = false, Default = false, HelpText = "Prints memory statistics")]

src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ private static bool IsUnitlessNumber(string value)
7171
{ "asciidoc", new[] { AsciiDocExporter.Default } },
7272
{ "xml", new[] { XmlExporter.Default } },
7373
{ "briefxml", new[] { XmlExporter.Brief } },
74-
{ "fullxml", new[] { XmlExporter.Full } }
74+
{ "fullxml", new[] { XmlExporter.Full } },
75+
{ "openmetrics", new[] { Exporters.OpenMetrics.OpenMetricsExporter.Default } }
7576
};
7677

7778
public static (bool isSuccess, IConfig? config, CommandLineOptions? options) Parse(string[] args, ILogger logger, IConfig? globalConfig = null)

tests/BenchmarkDotNet.Tests/ConfigParserTests.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
using BenchmarkDotNet.Environments;
88
using BenchmarkDotNet.Exporters;
99
using BenchmarkDotNet.Exporters.Csv;
10+
using BenchmarkDotNet.Exporters.Json;
11+
using BenchmarkDotNet.Exporters.OpenMetrics;
12+
using BenchmarkDotNet.Exporters.Xml;
1013
using BenchmarkDotNet.Jobs;
1114
using BenchmarkDotNet.Loggers;
1215
using BenchmarkDotNet.Portability;
@@ -27,6 +30,26 @@ namespace BenchmarkDotNet.Tests
2730
public class ConfigParserTests
2831
{
2932
public ITestOutputHelper Output { get; }
33+
public static TheoryData<string, IExporter[]> Exporters => new()
34+
{
35+
{ "csv", [CsvExporter.Default] },
36+
{ "csvmeasurements", [CsvMeasurementsExporter.Default] },
37+
{ "html", [HtmlExporter.Default] },
38+
{ "markdown", [MarkdownExporter.Default] },
39+
{ "atlassian", [MarkdownExporter.Atlassian] },
40+
{ "stackoverflow", [MarkdownExporter.StackOverflow] },
41+
{ "github", [MarkdownExporter.GitHub] },
42+
{ "plain", [PlainExporter.Default] },
43+
{ "rplot", [CsvMeasurementsExporter.Default, RPlotExporter.Default] },
44+
{ "json", [JsonExporter.Default] },
45+
{ "briefjson", [JsonExporter.Brief] },
46+
{ "fulljson", [JsonExporter.Full] },
47+
{ "asciidoc", [AsciiDocExporter.Default] },
48+
{ "xml", [XmlExporter.Default] },
49+
{ "briefxml", [XmlExporter.Brief] },
50+
{ "fullxml", [XmlExporter.Full] },
51+
{ "openmetrics", [OpenMetricsExporter.Default] }
52+
};
3053

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

@@ -53,6 +76,16 @@ public void SimpleConfigParsedCorrectly(params string[] args)
5376
Assert.Empty(config.GetLoggers());
5477
}
5578

79+
[Theory]
80+
[MemberData(nameof(Exporters))]
81+
public void ExportersAreParsedCorrectly(string exporter, IExporter[] expectedExporters)
82+
{
83+
var config = ConfigParser.Parse(["--exporters", exporter], new OutputLogger(Output)).config;
84+
85+
Assert.NotNull(config);
86+
Assert.Equal(expectedExporters, config.GetExporters().ToArray());
87+
}
88+
5689
[Fact]
5790
public void SimpleConfigAlternativeVersionParsedCorrectly()
5891
{

0 commit comments

Comments
 (0)