Skip to content
Merged
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
Next Next commit
Merge exporters by exporter.Name instead of exporter.GetType()
  • Loading branch information
bstordrup committed Aug 9, 2023
commit 4cb0a9ee087e97db477397bd0eaa1db8c5218bf1
36 changes: 18 additions & 18 deletions src/BenchmarkDotNet/Configs/ImmutableConfigBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using BenchmarkDotNet.Analysers;
using BenchmarkDotNet.Analysers;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Order;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Validators;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;

namespace BenchmarkDotNet.Configs
{
Expand Down Expand Up @@ -109,28 +109,28 @@ void AddWarning(string message)
configAnalyse.Add(conclusion);
}

var mergeDictionary = new Dictionary<System.Type, IExporter>();
var mergeDictionary = new Dictionary<string, IExporter>();

foreach (var exporter in exporters)
{
var exporterType = exporter.GetType();
if (mergeDictionary.ContainsKey(exporterType))
var exporterName = exporter.Name;
if (mergeDictionary.ContainsKey(exporterName))
{
AddWarning($"The exporter {exporterType} is already present in configuration. There may be unexpected results.");
AddWarning($"The exporter {exporterName} is already present in configuration. There may be unexpected results.");
}
mergeDictionary[exporterType] = exporter;
mergeDictionary[exporterName] = exporter;
}


foreach (var diagnoser in uniqueDiagnosers)
foreach (var exporter in diagnoser.Exporters)
{
var exporterType = exporter.GetType();
if (mergeDictionary.ContainsKey(exporterType))
var exporterName = exporter.Name;
if (mergeDictionary.ContainsKey(exporterName))
{
AddWarning($"The exporter {exporterType} of {diagnoser.GetType().Name} is already present in configuration. There may be unexpected results.");
AddWarning($"The exporter {exporterName} of {diagnoser.GetType().Name} is already present in configuration. There may be unexpected results.");
}
mergeDictionary[exporterType] = exporter;
mergeDictionary[exporterName] = exporter;
}

var result = mergeDictionary.Values.ToList();
Expand All @@ -143,7 +143,7 @@ void AddWarning(string message)
if (hardwareCounterDiagnoser != default(IHardwareCountersDiagnoser) && disassemblyDiagnoser != default(DisassemblyDiagnoser))
result.Add(new InstructionPointerExporter(hardwareCounterDiagnoser, disassemblyDiagnoser));

for (int i = result.Count - 1; i >=0; i--)
for (int i = result.Count - 1; i >= 0; i--)
if (result[i] is IExporterDependencies exporterDependencies)
foreach (var dependency in exporterDependencies.Dependencies)
/*
Expand All @@ -165,7 +165,7 @@ void AddWarning(string message)
* "The CsvMeasurementsExporter is already present in the configuration. There may be unexpected results of RPlotExporter.
*
*/
if (!result.Any(exporter=> exporter.GetType() == dependency.GetType()))
if (!result.Any(exporter => exporter.GetType() == dependency.GetType()))
result.Insert(i, dependency); // All the exporter dependencies should be added before the exporter
else
{
Expand All @@ -186,9 +186,9 @@ private static ImmutableHashSet<IAnalyser> GetAnalysers(IEnumerable<IAnalyser> a
builder.Add(analyser);

foreach (var diagnoser in uniqueDiagnosers)
foreach (var analyser in diagnoser.Analysers)
if (!builder.Contains(analyser))
builder.Add(analyser);
foreach (var analyser in diagnoser.Analysers)
if (!builder.Contains(analyser))
builder.Add(analyser);

return builder.ToImmutable();
}
Expand Down