Skip to content
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

Feature Request: Add RPlot exporter images to html exporter #2690

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
31 changes: 31 additions & 0 deletions samples/BenchmarkDotNet.Samples/IntroIntegratedExporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes.Exporters;
using BenchmarkDotNet.Exporters.IntegratedExporter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BenchmarkDotNet.Samples
{
[IntegratedExporter(IntegratedExportType.HtmlExporterWithRPlotExporter)]
public class IntroIntegratedExporter
{
[Benchmark]
public void Benchmark()
{
var result = Calculate();
}

private int Calculate()
{
int sum = 0;
for (int i = 0; i < 1000; i++)
{
sum += i;
}
return sum;
}
}
}
39 changes: 39 additions & 0 deletions samples/BenchmarkDotNet.Samples/IntroRPlot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Exporters;


namespace BenchmarkDotNet.Samples
{
//[MemoryDiagnoser]
//[Config(typeof(Config))]
[RPlotExporter]
public class IntroRPlot
{
[Benchmark]
public void Benchmark()
{
var result = Calculate();
}

private int Calculate()
{
int sum = 0;
for (int i = 0; i < 1000; i++)
{
sum += i;
}
return sum;
}
}

public class Config : ManualConfig
{
public Config()
{
//AddExporter(CsvMeasurementsExporter.Default);
//AddExporter(RPlotExporter.Default);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using BenchmarkDotNet.Exporters.IntegratedExporter;
using System;
using System.Collections.Generic;
using System.Text;

namespace BenchmarkDotNet.Attributes.Exporters
{
public class IntegratedExporterAttribute : IntegratedExporterConfigBaseAttribute
{
protected IntegratedExporterAttribute()
{ }

public IntegratedExporterAttribute(IntegratedExportType integratedExporterType) : base(integratedExporterType)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Exporters.IntegratedExporter;
using JetBrains.Annotations;

namespace BenchmarkDotNet.Attributes
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Assembly)]
public class IntegratedExporterConfigBaseAttribute : Attribute, IConfigSource
{
// CLS-Compliant Code requires a constructor without an array in the argument list
[PublicAPI]
protected IntegratedExporterConfigBaseAttribute()
{
Config = ManualConfig.CreateEmpty();
}

protected IntegratedExporterConfigBaseAttribute(IntegratedExportType exporter)
{
Config = ManualConfig.CreateEmpty().SetIntegratedExporterType(exporter);
}

public IConfig Config { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using BenchmarkDotNet.Exporters;
using System;
using System.Collections.Generic;

namespace BenchmarkDotNet.Attributes
{
public class RPlotExporterAttribute : ExporterConfigBaseAttribute
{
public RPlotExporterAttribute() : base(DefaultExporters.RPlot)

public RPlotExporterAttribute() : base(new RPlotExporter())
{
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/BenchmarkDotNet/Configs/ConfigExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel;
using System.Globalization;
Expand Down Expand Up @@ -36,6 +37,7 @@ public static class ConfigExtensions
[Obsolete("This method will soon be removed, please start using .AddExporter() instead.")]
[EditorBrowsable(EditorBrowsableState.Never)] public static IConfig With(this IConfig config, params IExporter[] exporters) => config.AddExporter(exporters);
[PublicAPI] public static ManualConfig AddExporter(this IConfig config, params IExporter[] exporters) => config.With(m => m.AddExporter(exporters));
[PublicAPI] public static ManualConfig AddIntegratedExporter(this IConfig config, List<IExporter>? dependencies, IExporter withExporter, IExporter exporter) => config.With(m => m.AddIntegratedExporter(dependencies, withExporter, exporter));

[Obsolete("This method will soon be removed, please start using .AddDiagnoser() instead.")]
[EditorBrowsable(EditorBrowsableState.Never)] public static IConfig With(this IConfig config, params IDiagnoser[] diagnosers) => config.AddDiagnoser(diagnosers);
Expand Down
3 changes: 3 additions & 0 deletions src/BenchmarkDotNet/Configs/DebugConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.EventProcessors;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Exporters.IntegratedExporter;
using BenchmarkDotNet.Filters;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Loggers;
Expand Down Expand Up @@ -58,6 +59,8 @@ public abstract class DebugConfig : IConfig
public IEnumerable<IValidator> GetValidators() => Array.Empty<IValidator>();
public IEnumerable<IColumnProvider> GetColumnProviders() => DefaultColumnProviders.Instance;
public IEnumerable<IExporter> GetExporters() => Array.Empty<IExporter>();
public IEnumerable<IntegratedExporterData> GetIntegratedExporters() => Array.Empty<IntegratedExporterData>();
public IIntegratedExporter GetIntegratedExporter() => null;
public IEnumerable<ILogger> GetLoggers() => new[] { ConsoleLogger.Default };
public IEnumerable<IDiagnoser> GetDiagnosers() => Array.Empty<IDiagnoser>();
public IEnumerable<IAnalyser> GetAnalysers() => Array.Empty<IAnalyser>();
Expand Down
9 changes: 8 additions & 1 deletion src/BenchmarkDotNet/Configs/DefaultConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using BenchmarkDotNet.EventProcessors;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Exporters.Csv;
using BenchmarkDotNet.Exporters.IntegratedExporter;
using BenchmarkDotNet.Filters;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Loggers;
Expand Down Expand Up @@ -40,6 +41,10 @@ public IEnumerable<IExporter> GetExporters()
yield return HtmlExporter.Default;
}

public IEnumerable<IntegratedExporterData> GetIntegratedExporters() => Array.Empty<IntegratedExporterData>();

public IIntegratedExporter GetIntegratedExporter() => null;

public IEnumerable<ILogger> GetLoggers()
{
if (LinqPadLogger.IsAvailable)
Expand Down Expand Up @@ -77,7 +82,7 @@ public IEnumerable<IValidator> GetValidators()
public IOrderer Orderer => null;
public ICategoryDiscoverer? CategoryDiscoverer => null;

public ConfigUnionRule UnionRule => ConfigUnionRule.Union;
public ConfigUnionRule UnionRule { get; set; } = ConfigUnionRule.Union;

public CultureInfo CultureInfo => null;

Expand Down Expand Up @@ -113,5 +118,7 @@ public string ArtifactsPath
public IEnumerable<EventProcessor> GetEventProcessors() => Array.Empty<EventProcessor>();

public IEnumerable<IColumnHidingRule> GetColumnHidingRules() => Array.Empty<IColumnHidingRule>();


}
}
2 changes: 2 additions & 0 deletions src/BenchmarkDotNet/Configs/IConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.EventProcessors;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Exporters.IntegratedExporter;
using BenchmarkDotNet.Filters;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Loggers;
Expand All @@ -20,6 +21,7 @@ public interface IConfig
{
IEnumerable<IColumnProvider> GetColumnProviders();
IEnumerable<IExporter> GetExporters();
IEnumerable<IntegratedExporterData> GetIntegratedExporters();
IEnumerable<ILogger> GetLoggers();
IEnumerable<IDiagnoser> GetDiagnosers();
IEnumerable<IAnalyser> GetAnalysers();
Expand Down
6 changes: 6 additions & 0 deletions src/BenchmarkDotNet/Configs/ImmutableConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.EventProcessors;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Exporters.IntegratedExporter;
using BenchmarkDotNet.Filters;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Loggers;
Expand All @@ -24,6 +25,7 @@ public sealed class ImmutableConfig : IConfig
// if something is an array here instead of hashset it means it must have a guaranteed order of elements
private readonly ImmutableArray<IColumnProvider> columnProviders;
private readonly ImmutableArray<IExporter> exporters;
private readonly ImmutableArray<IntegratedExporterData> integratedExporters;
private readonly ImmutableHashSet<ILogger> loggers;
private readonly ImmutableHashSet<IDiagnoser> diagnosers;
private readonly ImmutableHashSet<IAnalyser> analysers;
Expand All @@ -41,6 +43,7 @@ internal ImmutableConfig(
ImmutableHashSet<HardwareCounter> uniqueHardwareCounters,
ImmutableHashSet<IDiagnoser> uniqueDiagnosers,
ImmutableArray<IExporter> uniqueExporters,
ImmutableArray<IntegratedExporterData> uniqueIntegratedExporters,
ImmutableHashSet<IAnalyser> uniqueAnalyzers,
ImmutableHashSet<IValidator> uniqueValidators,
ImmutableHashSet<IFilter> uniqueFilters,
Expand All @@ -63,6 +66,7 @@ internal ImmutableConfig(
hardwareCounters = uniqueHardwareCounters;
diagnosers = uniqueDiagnosers;
exporters = uniqueExporters;
integratedExporters = uniqueIntegratedExporters;
analysers = uniqueAnalyzers;
validators = uniqueValidators;
filters = uniqueFilters;
Expand Down Expand Up @@ -92,6 +96,7 @@ internal ImmutableConfig(

public IEnumerable<IColumnProvider> GetColumnProviders() => columnProviders;
public IEnumerable<IExporter> GetExporters() => exporters;
public IEnumerable<IntegratedExporterData> GetIntegratedExporters() => integratedExporters;
public IEnumerable<ILogger> GetLoggers() => loggers;
public IEnumerable<IDiagnoser> GetDiagnosers() => diagnosers;
public IEnumerable<IAnalyser> GetAnalysers() => analysers;
Expand All @@ -105,6 +110,7 @@ internal ImmutableConfig(

public ILogger GetCompositeLogger() => new CompositeLogger(loggers);
public IExporter GetCompositeExporter() => new CompositeExporter(exporters);
public IExporter GetCompositeIntegratedExporter() => new CompositeIntegratedExporter(integratedExporters);
public IValidator GetCompositeValidator() => new CompositeValidator(validators);
public IAnalyser GetCompositeAnalyser() => new CompositeAnalyser(analysers);
public IDiagnoser GetCompositeDiagnoser() => new CompositeDiagnoser(diagnosers);
Expand Down
28 changes: 26 additions & 2 deletions src/BenchmarkDotNet/Configs/ImmutableConfigBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Reflection;
using BenchmarkDotNet.Analysers;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Exporters.IntegratedExporter;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Order;
using BenchmarkDotNet.Reports;
Expand Down Expand Up @@ -43,7 +45,28 @@ public static ImmutableConfig Create(IConfig source)

var uniqueHardwareCounters = source.GetHardwareCounters().Where(counter => counter != HardwareCounter.NotSet).ToImmutableHashSet();
var uniqueDiagnosers = GetDiagnosers(source.GetDiagnosers(), uniqueHardwareCounters);
var uniqueExporters = GetExporters(source.GetExporters(), uniqueDiagnosers, configAnalyse);

var integratedExporters = source?.GetIntegratedExporters();
IEnumerable<IExporter>? distinctExporters = null;

if (integratedExporters?.Any() == true)
{
distinctExporters = source.GetExporters()
.Where(e =>
!integratedExporters.Any(ie =>
ie.Exporter.GetType() == e.GetType() ||
ie.WithExporter.GetType() == e.GetType() ||
ie.Dependencies?.Any(d => d.GetType() == e.GetType()) == true))
.ToList();
}
else
{
distinctExporters = source.GetExporters();
}

var allUniqueExporters = GetExporters(distinctExporters, uniqueDiagnosers, configAnalyse);

// Check for integrated exporters
var uniqueAnalyzers = GetAnalysers(source.GetAnalysers(), uniqueDiagnosers);

var uniqueValidators = GetValidators(source.GetValidators(), MandatoryValidators, source.Options);
Expand All @@ -60,7 +83,8 @@ public static ImmutableConfig Create(IConfig source)
uniqueLoggers,
uniqueHardwareCounters,
uniqueDiagnosers,
uniqueExporters,
allUniqueExporters,
integratedExporters?.ToImmutableArray() ?? new ImmutableArray<IntegratedExporterData>(),
uniqueAnalyzers,
uniqueValidators,
uniqueFilters,
Expand Down
Loading
Loading