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

Added support to get exported file paths #2619

Open
filzrev opened this issue Aug 20, 2024 · 1 comment
Open

Added support to get exported file paths #2619

filzrev opened this issue Aug 20, 2024 · 1 comment

Comments

@filzrev
Copy link

filzrev commented Aug 20, 2024

I want to get exported files that are created by Exporters (e.g. MarkdownExporter's output)

Related logics are implemented by ExporterBase.cs.
But it's defined as internal. So it can't be used from external code.

https://github.com/dotnet/BenchmarkDotNet/blob/master/src/BenchmarkDotNet/Exporters/ExporterBase.cs#L51-L55

Is it possible to add supporting feature that get ExportedFiles from benchmark results?
For example.

1. Add ExportedFiles information to benchmark results summary.

If it can add ExportedFiles property to existing benchmark summary reports.
If it's possible It can be used in a simpler way.

But Exported files are created by following lines.
https://github.com/dotnet/BenchmarkDotNet/blob/master/src/BenchmarkDotNet/Running/BenchmarkRunnerClean.cs#L292-L297

So might not possible to modify Summary object on above lines. (Because summary is designed as immutable)

2. Change ExporterBase::GetArtifactFullName API to public.

If GetArtifactFullName API can be changed to public
It can get exported files with following code.

var exportedFiles = config.GetExporters().OfType<ExporterBase>().Select(x=> x.GetArtifactFullName(summary))

Note

Some exporter ( e,g, RPlotExporter) seems that don't inherited from ExporterBase. (that output multiple files?)
So it might be better to adding GetArtifactFullNames to IExporter interface.

@filzrev
Copy link
Author

filzrev commented Feb 1, 2025

As a temporary workaround.

It can get exported file path by calling ExporterBase.GetArtifactFullName internal method by using UnsafeAccessor (or reflection).

Example code to extract exported file paths

  private static string[] ExtractExportedFiles(Summary summary)
  {
      var config = summary.BenchmarksCases[0].Config;
      var exporters = config.GetExporters().OfType<ExporterBase>();

      return config.GetExporters()
                   .OfType<ExporterBase>()
                   .Select(x => GetArtifactFullName(x, summary))
                   .ToArray();
  }

   [UnsafeAccessor(UnsafeAccessorKind.Method, Name = nameof(GetArtifactFullName))]
   private static extern string GetArtifactFullName(ExporterBase target, Summary summary);

But above workaround code is not works as expected for some exporters.

  • Exporter is not derived from ExporterBase class.
  • Exporter output multiple files.

And it won't work if BenchmarkDotNet internal structures are changed.
(e.g. PR #2690 changing HtmlExporter's base class)

I hope the IExporter interface expose APIs to get Exporter's artifacts paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant