feat(trace): record host, title and per-frame benchmark data #7080
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7080"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Rengundom on 2026-10-17T10:35:01Z.
What
Adds what a benchmark report needs to the trace summaries, so results from different machines can be compared and recomputed.
APS5_TRACE_SUMMARY_EVERY,APS5_TRACE_FRAMES/APS5_TRACE_SECONDS) now also has the host'scpu(brand string),cpu_threadsandmemory_mib, and, whenapp0/sce_sys/param.jsonis present,title_id,titleandcontent_version.param.json'scontentVersionis now read (empty when absent).APS5_TRACE_BENCH=1together withAPS5_TRACE_SUMMARY_EVERYrewritesaps5-bench-<commit>-<pid>.json.gzat each interval (inAPS5_TRACE_DIRor the working directory): formataps5-bench/1, the summary's identity fields, and per intervalstart_s,end_s,first_present,resolution,gpu_busy_msandframe_us, the whole microseconds between consecutive presents. The last 240 intervals are kept andintervals_droppedcounts older ones. Frame times cost 4 bytes per present; the file is formatted and compressed on a writer thread. Any other value of the switch, or the switch withoutAPS5_TRACE_SUMMARY_EVERY, fails the first present.param.jsonfields.Documented in
docs/dev/BUILD.md(summary fields) anddocs/user/USAGE.md(Benchmark reports).Tested
agc_performance_trace_testsandparam_json_parser_tests, with the new cases, pass.APS5_TRACE_SUMMARY_EVERY=10andAPS5_TRACE_BENCH=1writesaps5-bench-<commit>-<pid>.json.gzandaps5-summary.jsonl.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-17T10:35:07Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T10:51:39Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
docs/dev/BUILD.mdcore/libs/prx/libkernel/AppMetadata/src/ParamJsonParser.cppcore/libs/tests/ParamJsonParser.cppdocs/dev/BUILD.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libkernel/AppMetadata/src/ParamJsonParser.cppcore/libs/tests/ParamJsonParser.cppdocs/dev/BUILD.mddocs/user/USAGE.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/user/USAGE.mdcore/libs/tests/ParamJsonParser.cppdocs/dev/debt/libSceAgcDriver.mddocs/user/USAGE.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/user/USAGE.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/BUILD.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mddocs/user/USAGE.mddocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mddocs/user/USAGE.mddocs/dev/ENVIRONMENT.mdcore/libs/prx/libkernel/AppMetadata/src/AppMetadata.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/BUILD.mddocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mddocs/user/USAGE.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/ENVIRONMENT.mddocs/dev/ENVIRONMENT.mddocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mddocs/user/USAGE.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/user/USAGE.mddocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdImported from boykopovar/AnyPS5. Originally posted by Rengundom on 2026-10-17T11:06:05Z.
Checked the pr-overlap list: none of these implement the same functions. #6044 moves
tests/ParamJsonParser.cpp, so whichever of the two merges second rebases.Imported from boykopovar/AnyPS5. Originally posted by ionut27001 on 2026-10-19T09:41:07Z.
Thanks, this is useful for comparing runs across machines. I read the diff against current
main(it still merges cleanly at64e2a810a) and have four points, the first two about the benchmark file itself:The bench file is rewritten in place.
FlushIntervalhands each snapshot toTraceFile::WriteGzip, which opens the path withstd::ios::truncand then streams the compressed data. If the title crashes or is killed during a rewrite, the file is left truncated and every interval collected so far is lost, and a crash is a likely moment for that. Writing to a temporary name next to it and replacing the old file once the write is complete would keep the last good report.Two pending snapshots can end up in one file.
ProfileOutput::runjoins pending writes into one batch while the batch stays within 64 KiB (batch.size() + pending.front().size() <= 65536). That suits the append-onlyaps5-summary.jsonl, but each benchWriteis a whole file, so if the writer falls one interval behind while the snapshots are still small (for example withAPS5_TRACE_SUMMARY_EVERY=1and a slow disk),WriteGzipreceives two JSON objects back to back and the file is not valid JSON until the next rewrite. Keeping only the newest pending snapshot for this writer would avoid it.The file is formatted on the presenter thread. The PR body and
docs/dev/BUILD.mdsay the file "is formatted and compressed on a writer thread", butTraceFormat::Bench(...)runs insideFlushInterval, beforeWrite, so only the compression happens on the writer thread. I timed a standalone loop that does the same per-framestd::to_stringappends asBench, on a Ryzen 7 5800X3D with GCC 15.2 at -O2: 9.4 ms for a full file of 240 intervals × 1800 frames (30 s intervals at 60 fps, 2.6 MB of text) and 16.8 ms with 3600 frames per interval. The cost grows as intervals accumulate, so in a long run the present that closes an interval is delayed by that much, and the delay lands in the next interval's firstframe_us, which is the data being recorded. Formatting on the writer thread (or correcting the docs) would settle it.Non-x86 hosts. Both the interval and the window summaries go through
identity(), which now callshost(), andprocessorName()throws when the host is not x86 or reports no brand string. On such a host the existing summary lines and the window trace now fail where they worked before. SinceTraceSummary::hostis already optional, leaving it empty there would keep the old output.Smaller notes:
contentVersionis read inparseParamJson, which every title-metadata call goes through (ensureTitleLoaded). A non-string value now fails the parse, and a value of 16 characters or more makescopyToFixedBufferthrowlength_error, for every caller of the title metadata and not only the trace. Real values look like01.002.000, so this is unlikely, but it is a new failure mode for a field only the trace uses.intervals_droppedcount inFlushInterval;BenchFormatpassesintervals_droppeddirectly.The formatting test, the switch parsing and the
param.jsoncases look good to me. I have not built or run the branch; the timing above comes from a standalone copy of the formatting loop.Imported from boykopovar/AnyPS5. Originally posted by Rengundom on 2026-10-19T11:25:15Z.
Thanks @ionut27001, this was a really useful review. I've pushed a follow-up commit that addresses all of it:
<name>.tmpand then moved over the old one (MoveFileExWwithMOVEFILE_REPLACE_EXISTINGon Windows,std::filesystem::renameelsewhere). If the title crashes or is killed during a rewrite, the last complete report is kept.TraceBenchWriterinstead of aProfileOutput. It holds only the newest pending snapshot, so a newer snapshot replaces an older unwritten one instead of being appended to it.aps5-summary.jsonlstill goes throughProfileOutput.TraceFormat::Benchnow runs on the writer thread. Each interval is kept as ashared_ptr<const TraceBenchInterval>, so the presenter only hands over the list of pointers and doesn't copy any intervals. The only per-interval work left on the presenter isFrameMicrosecondsover that interval's own presents, and that doesn't grow as intervals pile up. I've correctedBUILD.mdto match.processorName()returnsstd::nulloptinstead of throwing when there's no brand string or the host isn't x86.TraceSummary::hostis then left empty, so the summary lines and the window trace print the same fields as before.Smaller notes:
contentVersion: a value that isn't a string is ignored byparseParamJson, and a value too long for the 16-byte buffer is left empty. Neither one fails the title metadata anymore. I updated the parser test to match.BenchRotationcovers the 240-interval limit andintervals_dropped, now handled byTraceBench::Keep. I also added:BenchWriterKeepsNewest: keeps the writer busy, sends three snapshots, and checks that only the newest one is written after the first.BenchWriterStopWrites: checks that a snapshot still waiting when the writer stops gets written.ReplaceGzipFile: includes a rewrite made to fail partway, and checks that the previous file is still intact.The performance trace and
param.jsontests pass locally (Linux, clang), and the conventions check passes.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T16:47:21Z.
Review: DISMISSED
The full Build fails on Windows for this head (run 39283488108,
windows: agc_performance_trace, main does not fail it):It comes from the new
ReplaceGzipFiletest (core/libs/prx/libSceAgcDriver/tests/PerformanceTrace.cpp, thestd::filesystem::create_directory(temporary)case): with a directory at<name>.tmp,WriteGzip'sofstream(exceptions enabled) throwsstd::ios_base::failureout of libstdc++ and on Windows it never reaches thecatch (const std::exception&).Suggested direction: make the failure come from
ReplaceGzipitself instead of the stream, e.g. create a directory at the destinationpathso thatMoveFileExW/std::filesystem::renamefails and throwsstd::system_errorfrom the exe, and check that the previous file and the.tmphandling are what you expect. Everything else in the diff looks good.Imported from boykopovar/AnyPS5. Originally posted by Rengundom on 2026-10-20T00:59:27Z.
The Windows failure is fixed in
9abcd4586.ReplaceGzipnow does the final move with anerror_code. If the move fails, it removes the temporary file and throwsstd::system_error, instead of relying on a stream exception that MinGW couldn't unwind.std::system_erroris thrown.tmpfile is left behindI ran
ctest -R agc_performance_tracelocally on Windows (MinGW) and it passes.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T07:23:53Z.
Thanks for the Windows fix. Moving the failure onto the final move with an
error_code, then cleaning up.tmpand throwingstd::system_error, looks right to me.One gap in the test: the new blocked-destination case no longer covers what
ReplaceGzipexists for, which is that a failed rewrite keeps the last good file. It blocks a different file's destination and checks thataps5-bench.json.gzis untouched, and any implementation passes that. To check, I swappedReplaceGzip's body for a plain in-placeWriteGzip(path, text)and ran both versions ofReplaceGzipFileon Linux:The in-place version passes the current case because libstdc++'s
std::ios_base::failurederives fromstd::system_error, so writing into the blocked directory is caught too.Could you keep your new case and bring back the 19 Oct one (a directory at
<name>.tmp, then check the previous file is unchanged) behind#ifndef _WIN32? Linux CI then catches a regression to in-place writes, and Windows still avoids the stream exception that MinGW couldn't deliver. A comment on the guard saying why it's there would help the next reader.Imported from boykopovar/AnyPS5. Originally posted by Rengundom on 2026-10-20T07:53:35Z.
@oneandonlydean Thanks, good catch. The blocked-destination case only checked a different file, so it couldn't tell an atomic replace from an in-place write.
The 19 Oct case is back beside it in
ReplaceGzipFile: a directory at<name>.tmpmakes the write fail, and the test checks that the previousaps5-bench.json.gzis unchanged. It's behind#ifndef _WIN32, with a comment saying why: thestd::ios_base::failurefrom inside MinGW's ofstream couldn't unwind to the test's catch. There's a matching debt entry indocs/dev/debt/libSceAgcDriver.md.I ran your experiment on Linux. As committed, it passes. With
ReplaceGzipreplaced by an in-placeWriteGzip(path, text), the restored case fails with "a failed rewrite damaged the previous benchmark file". On Windows (MinGW),agc_performance_tracepasses and runs only the blocked-move case.