feat(pipeline): MP0 - FrameProfiler facade (CPU/GPU/alloc/stages, 5s report)
Permanent frame profiler: FrameBoundary() at the top of OnRender measures CPU frame time (swap-to-swap delta), brackets the frame in a GpuFrameTimer TimeElapsed query (self-disabled under ACDREAM_WB_DIAG=1), and samples per-frame allocated bytes + GC collection deltas. BeginStage(FrameStage) scopes attribute CPU time to Update/Upload/ImGui. Emits one [frame-prof] report line every ~5s while RenderingDiagnostics.FrameProfEnabled is on; zero-cost stage scopes when off. Report formatting is a pure static method, unit-tested for invariant-culture formatting and the gpu=off fallback text. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
0a5f7d4924
commit
73bb8777a9
2 changed files with 245 additions and 0 deletions
48
tests/AcDream.App.Tests/FrameProfilerReportTests.cs
Normal file
48
tests/AcDream.App.Tests/FrameProfilerReportTests.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
using AcDream.App.Diagnostics;
|
||||
using Xunit;
|
||||
|
||||
namespace AcDream.App.Tests;
|
||||
|
||||
public class FrameProfilerReportTests
|
||||
{
|
||||
[Fact]
|
||||
public void FormatReport_IsInvariantAndComplete()
|
||||
{
|
||||
var cpu = new FrameStatsBuffer(16);
|
||||
var gpu = new FrameStatsBuffer(16);
|
||||
var alloc = new FrameStatsBuffer(16);
|
||||
var stages = new[] { new FrameStatsBuffer(16), new FrameStatsBuffer(16), new FrameStatsBuffer(16) };
|
||||
for (long i = 1; i <= 10; i++)
|
||||
{
|
||||
cpu.Push(i * 1000); // 1..10 ms in µs
|
||||
gpu.Push(i * 100);
|
||||
alloc.Push(i * 1024); // bytes
|
||||
stages[0].Push(i * 200);
|
||||
stages[1].Push(i * 50);
|
||||
stages[2].Push(i * 10);
|
||||
}
|
||||
|
||||
string line = FrameProfiler.FormatReport(
|
||||
frameCount: 10, cpu: cpu, gpu: gpu, gpuActive: true,
|
||||
alloc: alloc, gc0: 3, gc1: 1, gc2: 0, stages: stages);
|
||||
|
||||
Assert.StartsWith("[frame-prof]", line);
|
||||
Assert.Contains("n=10", line);
|
||||
Assert.Contains("cpu_ms p50=5.0 p95=10.0 p99=10.0 max=10.0", line);
|
||||
Assert.Contains("gpu_ms p50=0.5", line);
|
||||
Assert.Contains("alloc_kb p50=5.0 max=10.0", line);
|
||||
Assert.Contains("gc=3/1/0", line);
|
||||
Assert.Contains("upd p50=1.0", line); // stage 0: 200µs·5 = 1.0 ms
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FormatReport_GpuInactive_SaysWhy()
|
||||
{
|
||||
var empty = new FrameStatsBuffer(4);
|
||||
string line = FrameProfiler.FormatReport(
|
||||
frameCount: 0, cpu: empty, gpu: empty, gpuActive: false,
|
||||
alloc: empty, gc0: 0, gc1: 0, gc2: 0,
|
||||
stages: new[] { empty, empty, empty });
|
||||
Assert.Contains("gpu=off(wbdiag)", line);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue