48 lines
2.7 KiB
C#
48 lines
2.7 KiB
C#
using System.Text;
|
|
|
|
namespace AyCode.Core.Benchmarks.Reporting;
|
|
|
|
/// <summary>
|
|
/// Context bundle for the unified benchmark report writer. Same record on both sides (Console / BDN),
|
|
/// only the <see cref="SourceTag"/> differs ("Console" / "Bdn") — that drives the filename prefix
|
|
/// (e.g. <c>Console.FullBenchmark_Release_{timestamp}.LLM</c> vs <c>Bdn.FullBenchmark_Release_{timestamp}.LLM</c>).
|
|
/// The <see cref="ResultsDirectory"/> resolution walks up from <see cref="AppContext.BaseDirectory"/> to the
|
|
/// nearest <c>AyCode.Core.sln</c> and combines with <c>Test_Benchmark_Results\Benchmark</c> — works across
|
|
/// build modes (Debug / Release / AOT publish) and worktrees (each worktree has its own .sln, so its bench
|
|
/// results land alongside its code).
|
|
/// </summary>
|
|
public sealed record ReportingContext(
|
|
string SourceTag,
|
|
string ResultsDirectory,
|
|
string BuildConfiguration,
|
|
UTF8Encoding Utf8NoBom)
|
|
{
|
|
/// <summary>
|
|
/// Resolves the canonical <see cref="ResultsDirectory"/> by walking up from
|
|
/// <see cref="AppContext.BaseDirectory"/> to the nearest <c>AyCode.Core.sln</c>, then combining
|
|
/// with <c>Test_Benchmark_Results\Benchmark</c>. The build configuration is supplied by the caller
|
|
/// (Console resolves via <c>#if AYCODE_NATIVEAOT|DEBUG|else Release</c>; BDN-side currently mirrors
|
|
/// the JIT vs AOT discriminator from <see cref="System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeCompiled"/>).
|
|
/// </summary>
|
|
public static ReportingContext Create(string sourceTag, string buildConfiguration) =>
|
|
new(sourceTag, ResolveResultsDirectory(), buildConfiguration, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
|
|
|
|
/// <summary>
|
|
/// Walk-up from the assembly's BaseDirectory to find the repo root (marker: <c>AyCode.Core.sln</c>).
|
|
/// Returns <c>{repoRoot}\Test_Benchmark_Results\Benchmark</c>. Worktree-aware: if running from a
|
|
/// worktree, the walk finds the worktree's own .sln (each worktree has its own checkout), so
|
|
/// results land in the worktree's results folder — the natural place when the worktree's code
|
|
/// changes are what produced the numbers.
|
|
/// </summary>
|
|
private static string ResolveResultsDirectory()
|
|
{
|
|
var dir = new DirectoryInfo(AppContext.BaseDirectory);
|
|
while (dir != null && !File.Exists(Path.Combine(dir.FullName, "AyCode.Core.sln")))
|
|
dir = dir.Parent;
|
|
if (dir == null)
|
|
throw new InvalidOperationException(
|
|
"Cannot locate repo root (AyCode.Core.sln) from AppContext.BaseDirectory: " + AppContext.BaseDirectory);
|
|
return Path.Combine(dir.FullName, "Test_Benchmark_Results", "Benchmark");
|
|
}
|
|
}
|