feat(run-report): write the run report when a game ends #14235

Merged
oneandonlydean merged 8 commits from upstream-pr/14235 into main 2026-11-05 08:24:11 +00:00
oneandonlydean commented 2026-11-01 02:30:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-11-01T02:30:04Z.


What

Writes the run report when a converted game ends: anyps5-report.json, in the format of #14165. It holds the build revision and whether the build is modified, the game (title ID, content version, name), the machine (OS version, CPU model, memory), and the list of unimplemented functions that were called. It is on by default; --aps5-report=off or APS5_REPORT=0 turns it off (--aps5-report=on / APS5_REPORT=1 forces it on for a process that is not a converted game). With the report off nothing is collected or written.

This is the second of four PRs. It writes only what a run that ends through exit can know. Milestones, frame counts, GPU, shader and image-format counters are marked as not collected (coverage false); they come in the next PR. A run that crashes, aborts or is killed writes no report yet; that is the last PR.

  • Written next to the executable; when that folder cannot be written, to reports/<run id>/ in the data folder. Written atomically (temporary file, then rename) through a folder walk that refuses links.
  • When: the guest's exit and _exit; on Linux and macOS also when the entry returns or the host calls std::exit (an atexit hook). On Windows only exit and _exit write a report, because a DLL's exit handlers run inside the loader lock.
  • Every text value goes through one filter for user names, host names, addresses and account numbers; a value that does not fit the schema is dropped (null), never guessed.
  • NotImplemented_nid_no_patch(name) becomes a macro that also passes __FILE__ and __LINE__, so missing.functions can name the library and the source line. The definitions are parenthesised so the macro does not rewrite them. The root CMakeLists.txt adds -fmacro-prefix-map=<source dir>/= for C++ on GCC and Clang so that the paths of first-party code in the binaries are source-tree relative: strings finds no absolute source-tree path for core/, tools/ or demo/ files in any library or test binary (test binaries still contain build-directory strings such as .../libs/unpatched). C sources of the third-party libraries are not covered by the flag and still carry their build path.
  • libkernel supplies the game metadata through a provider; each library that registers itself with the report is stamped with the same build revision, so anyps5.modified is null rather than a guess when a library comes from another build.

Tested

Linux only. run_report_tests: 47 passed, 0 failed, 2 not run (the comma-decimal locale test, when no such locale is installed; the junction test, Windows only). tools/tests/test_run_report_schema.py 27 tests, tools/tests/test_run_report_docs.py 6 tests, and tools/tests/validate_run_report_dump.py (every report the test binary writes validates against the schema): 10 valid. ctest of the tests selected from this diff (6 CMake directories, including the root one) plus public_headers (65): 502 tests, 100% passed, none skipped. The new test child-guest-root-not-fixed-at-load runs in a child process (so no earlier test can have touched the path resolver); it fails on the previous process-detection code and passes now (see below).
Cost of the report, a game-less entry (run_report_tests --child exit), 300 runs, three rounds, report off versus on, median of the round medians: 1.46 ms off, 1.71 ms on, so about 0.25 ms added to a run that writes one report (no title measured).
Not run: Windows and macOS (the platform code in RunReport.cpp), and the junction test (Windows only); the comma-decimal locale test is skipped when no such locale is installed. Not tested with a title.

A bug found on the way: detecting a game process by resolving /app0/... through the runtime's path resolver from a static initialiser fixes libc's guest root at load time (it records the working directory on first use). Six existing tests that change directory afterwards failed (guest_fopen_errors, guest_record_lock_owners, guest_path_errors, guest_app_icon, guest_app_info, guest_directory_link_types). This PR checks <cwd>/app0/sce_sys/param.json|param.sfo directly instead.

Things reviewers may question

  • Default on. A file is written next to the executable without being asked. Whether a run is a game depends on a working-directory check (app0/sce_sys/param.json or .sfo under the current directory at load); APS5_REPORT=1 forces it for anything else.
  • The NotImplemented_nid_no_patch macro changes 24,572 call sites in 366 files without editing them. Any code that declares or defines NotImplemented_nid_no_patch(const char*) in a file that includes General.hpp must write it as (NotImplemented_nid_no_patch)(...); a test that stubs it and links library sources also needs a NotImplementedAt_nid_no_patch stub. This PR updates the four such files on main. Open PRs that add such a definition in a test file: #9803, #9970, #10378, #12741 and #13560 (each defines the stub in a test file that links library sources); they will fail to link until they add NotImplementedAt_nid_no_patch.
  • Build paths. __FILE__ is embedded at each site; the prefix map above makes it source-relative for first-party C++ on GCC and Clang. MSVC has no equivalent flag, third-party C sources still embed their build path, and the schema test only runs where jsonschema is installed (the workflow installs it; run_report_schema is registered in ctest only when Python has it).
  • Windows: no atexit hook, so a return from the entry writes no report there. The Windows and macOS code has not been run.
  • Exit cost. Finish waits up to 3 seconds for a finish that is already in progress on another thread, and up to 1 second for the game metadata provider; a normal single-threaded exit does neither. Measured start-up and exit cost: see Tested.
  • Size. RunReport.cpp is about 1,600 lines, of which roughly 400 are the platform path-safety code (WriteAtomically, ReadBounded, FolderIsReachable).
  • A generated RunReportRevision.hpp and a CMake custom target stamp the revision into libc and the libraries that register themselves.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5103674815 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14235). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-11-01T02:30:04Z. --- ### What Writes the run report when a converted game ends: `anyps5-report.json`, in the format of #14165. It holds the build revision and whether the build is modified, the game (title ID, content version, name), the machine (OS version, CPU model, memory), and the list of unimplemented functions that were called. It is on by default; `--aps5-report=off` or `APS5_REPORT=0` turns it off (`--aps5-report=on` / `APS5_REPORT=1` forces it on for a process that is not a converted game). With the report off nothing is collected or written. This is the second of four PRs. It writes only what a run that ends through `exit` can know. Milestones, frame counts, GPU, shader and image-format counters are marked as not collected (`coverage` false); they come in the next PR. A run that crashes, aborts or is killed writes no report yet; that is the last PR. - Written next to the executable; when that folder cannot be written, to `reports/<run id>/` in the data folder. Written atomically (temporary file, then rename) through a folder walk that refuses links. - When: the guest's `exit` and `_exit`; on Linux and macOS also when the entry returns or the host calls `std::exit` (an `atexit` hook). On Windows only `exit` and `_exit` write a report, because a DLL's exit handlers run inside the loader lock. - Every text value goes through one filter for user names, host names, addresses and account numbers; a value that does not fit the schema is dropped (null), never guessed. - `NotImplemented_nid_no_patch(name)` becomes a macro that also passes `__FILE__` and `__LINE__`, so `missing.functions` can name the library and the source line. The definitions are parenthesised so the macro does not rewrite them. The root `CMakeLists.txt` adds `-fmacro-prefix-map=<source dir>/=` for C++ on GCC and Clang so that the paths of first-party code in the binaries are source-tree relative: `strings` finds no absolute source-tree path for `core/`, `tools/` or `demo/` files in any library or test binary (test binaries still contain build-directory strings such as `.../libs/unpatched`). C sources of the third-party libraries are not covered by the flag and still carry their build path. - `libkernel` supplies the game metadata through a provider; each library that registers itself with the report is stamped with the same build revision, so `anyps5.modified` is `null` rather than a guess when a library comes from another build. ### Tested Linux only. `run_report_tests`: 47 passed, 0 failed, 2 not run (the comma-decimal locale test, when no such locale is installed; the junction test, Windows only). `tools/tests/test_run_report_schema.py` 27 tests, `tools/tests/test_run_report_docs.py` 6 tests, and `tools/tests/validate_run_report_dump.py` (every report the test binary writes validates against the schema): 10 valid. ctest of the tests selected from this diff (6 CMake directories, including the root one) plus `public_headers` (65): 502 tests, 100% passed, none skipped. The new test `child-guest-root-not-fixed-at-load` runs in a child process (so no earlier test can have touched the path resolver); it fails on the previous process-detection code and passes now (see below). Cost of the report, a game-less entry (`run_report_tests --child exit`), 300 runs, three rounds, report off versus on, median of the round medians: 1.46 ms off, 1.71 ms on, so about 0.25 ms added to a run that writes one report (no title measured). Not run: Windows and macOS (the platform code in `RunReport.cpp`), and the junction test (Windows only); the comma-decimal locale test is skipped when no such locale is installed. Not tested with a title. A bug found on the way: detecting a game process by resolving `/app0/...` through the runtime's path resolver from a static initialiser fixes libc's guest root at load time (it records the working directory on first use). Six existing tests that change directory afterwards failed (`guest_fopen_errors`, `guest_record_lock_owners`, `guest_path_errors`, `guest_app_icon`, `guest_app_info`, `guest_directory_link_types`). This PR checks `<cwd>/app0/sce_sys/param.json|param.sfo` directly instead. ### Things reviewers may question - **Default on.** A file is written next to the executable without being asked. Whether a run is a game depends on a working-directory check (`app0/sce_sys/param.json` or `.sfo` under the current directory at load); `APS5_REPORT=1` forces it for anything else. - **The `NotImplemented_nid_no_patch` macro** changes 24,572 call sites in 366 files without editing them. Any code that declares or defines `NotImplemented_nid_no_patch(const char*)` in a file that includes `General.hpp` must write it as `(NotImplemented_nid_no_patch)(...)`; a test that stubs it and links library sources also needs a `NotImplementedAt_nid_no_patch` stub. This PR updates the four such files on `main`. Open PRs that add such a definition in a test file: #9803, #9970, #10378, #12741 and #13560 (each defines the stub in a test file that links library sources); they will fail to link until they add `NotImplementedAt_nid_no_patch`. - **Build paths.** `__FILE__` is embedded at each site; the prefix map above makes it source-relative for first-party C++ on GCC and Clang. MSVC has no equivalent flag, third-party C sources still embed their build path, and the schema test only runs where `jsonschema` is installed (the workflow installs it; `run_report_schema` is registered in ctest only when Python has it). - **Windows:** no `atexit` hook, so a return from the entry writes no report there. The Windows and macOS code has not been run. - **Exit cost.** `Finish` waits up to 3 seconds for a finish that is already in progress on another thread, and up to 1 second for the game metadata provider; a normal single-threaded exit does neither. Measured start-up and exit cost: see Tested. - **Size.** `RunReport.cpp` is about 1,600 lines, of which roughly 400 are the platform path-safety code (`WriteAtomically`, `ReadBounded`, `FolderIsReachable`). - A generated `RunReportRevision.hpp` and a CMake custom target stamp the revision into `libc` and the libraries that register themselves. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_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 - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-02 07:08:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T07:08:01Z.

Review: DISMISSED


Changes requested: this PR breaks the Emscripten portability build with a link error

The Emscripten library-portability job fails on this head at link time, and the cause is this PR. It changes NotImplemented_nid_no_patch in core/libs/prx/libc/include/General.hpp into a macro that calls a new function, NotImplementedAt_nid_no_patch(name, __FILE__, __LINE__). The Emscripten test emscripten_module_unwind compiles libkernel/Module/src/Module.cpp, which uses that macro, and it defines only NotImplemented_nid_no_patch (core/libs/tests/emscripten/EmscriptenModuleUnwind.cpp, line 18). The new symbol is not defined in that link, so it fails.

What I ran

  • Head a6bb84be17d6c58584ce6bdbfeb603cf462db496; base 90cc8d57a5c98bc1ae1237c94516c025031c7c58. The PR touches the libc run-report files, General.hpp, General.cpp, the libc and root CMake files, a schema workflow and the docs (the full list was not counted).
  • Read the General.hpp change at the head (lines 15-17: the new declaration and the macro) and the base (line 15: the function). Read the new definition in General.cpp (around lines 1020-1030).
  • Read the emscripten_module_unwind_tests target in core/libs/tests/emscripten/CMakeLists.txt: it compiles EmscriptenModuleUnwind.cpp, libkernel/Module/src/Module.cpp and libSceSysmodule/Export.cpp. It does not compile General.cpp.
  • Read EmscriptenModuleUnwind.cpp at the base and at the head: both define NotImplemented_nid_no_patch(const char*) at line 18; neither defines NotImplementedAt_nid_no_patch.
  • Hosted: the library-portability job fails with wasm-ld: error: … undefined symbol: NotImplementedAt_nid_no_patch in emscripten_module_unwind_tests.dir/…/Module.cpp.o. No NotImplementedAt appears anywhere in the base.
  • Hosted, other jobs: conventions, eligibility, labels, report, schema, the three macOS and Ubuntu and Windows relinkers, relinker-asan and the write-watch jobs passed; windows was cancelled; linux skipped.
  • Read-only checks from the trusted main checkout: diff check, conventions and PR template, and the stack check all passed (no declared dependencies, no errors). ABI audit passed with warnings: 16 findings, not read in detail.
  • No MarcZX10 review at this head.

Results

Check Result Note
Diff check passed
Conventions and PR template passed conventions check from the main checkout
Mergeability and dependencies passed stack check passed; no declared dependencies; no errors
Emscripten library-portability (hosted) failed link error: undefined symbol: NotImplementedAt_nid_no_patch in emscripten_module_unwind_tests; caused by the new macro in General.hpp
NotImplementedAt_nid_no_patch defined for the Emscripten test no the test defines only NotImplemented_nid_no_patch
Windows CTest cancelled no result for this head
Relinkers and relinker-asan (hosted) passed all succeeded
ABI audit (main-checkout tool) passed with warnings 16 findings, not read in detail
Negative controls not run no local build
Hosted CI failed library-portability failed; windows cancelled
Read-only check output

Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. ABI audit: passed with warnings (16). Stack check: passed, no errors. Hosted: gh api repos/boykopovar/AnyPS5/commits/a6bb84be17d6c58584ce6bdbfeb603cf462db496/check-runs, and the library-portability job log.

Negative control

Not run here. A negative control needs a local build, and code from this head is not run here.

Findings

Blocking

  • The Emscripten library-portability job fails at link time on this head. The new macro in General.hpp (lines 16-17) makes Module.cpp call NotImplementedAt_nid_no_patch, which core/libs/tests/emscripten/EmscriptenModuleUnwind.cpp does not define. Fix one of these: define NotImplementedAt_nid_no_patch in that test with the new signature, or keep the call sites linking as they did before. Then rerun the library-portability job.

Non-blocking

  • The ABI audit reports 16 findings that were not read in detail.

Sources

Not verified

  • The 16 ABI findings.
  • Whether any other test target builds Module.cpp without General.cpp.
  • The Windows result (cancelled).

To get this to a good state

  • Define NotImplementedAt_nid_no_patch in EmscriptenModuleUnwind.cpp, or change the macro so the Emscripten target still links. Rerun library-portability.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5733091257 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14235#pullrequestreview-5733091257). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-02T07:08:01Z. **Review:** DISMISSED --- # Changes requested: this PR breaks the Emscripten portability build with a link error The Emscripten `library-portability` job fails on this head at link time, and the cause is this PR. It changes `NotImplemented_nid_no_patch` in `core/libs/prx/libc/include/General.hpp` into a macro that calls a new function, `NotImplementedAt_nid_no_patch(name, __FILE__, __LINE__)`. The Emscripten test `emscripten_module_unwind` compiles `libkernel/Module/src/Module.cpp`, which uses that macro, and it defines only `NotImplemented_nid_no_patch` (`core/libs/tests/emscripten/EmscriptenModuleUnwind.cpp`, line 18). The new symbol is not defined in that link, so it fails. ## What I ran - Head `a6bb84be17d6c58584ce6bdbfeb603cf462db496`; base `90cc8d57a5c98bc1ae1237c94516c025031c7c58`. The PR touches the libc run-report files, `General.hpp`, `General.cpp`, the libc and root CMake files, a schema workflow and the docs (the full list was not counted). - Read the `General.hpp` change at the head (lines 15-17: the new declaration and the macro) and the base (line 15: the function). Read the new definition in `General.cpp` (around lines 1020-1030). - Read the `emscripten_module_unwind_tests` target in `core/libs/tests/emscripten/CMakeLists.txt`: it compiles `EmscriptenModuleUnwind.cpp`, `libkernel/Module/src/Module.cpp` and `libSceSysmodule/Export.cpp`. It does not compile `General.cpp`. - Read `EmscriptenModuleUnwind.cpp` at the base and at the head: both define `NotImplemented_nid_no_patch(const char*)` at line 18; neither defines `NotImplementedAt_nid_no_patch`. - Hosted: the `library-portability` job fails with `wasm-ld: error: … undefined symbol: NotImplementedAt_nid_no_patch` in `emscripten_module_unwind_tests.dir/…/Module.cpp.o`. No `NotImplementedAt` appears anywhere in the base. - Hosted, other jobs: conventions, eligibility, labels, report, schema, the three macOS and Ubuntu and Windows relinkers, relinker-asan and the write-watch jobs passed; `windows` was cancelled; linux skipped. - Read-only checks from the trusted main checkout: diff check, conventions and PR template, and the stack check all passed (no declared dependencies, no errors). ABI audit passed with warnings: 16 findings, not read in detail. - No MarcZX10 review at this head. ## Results | Check | Result | Note | | --- | --- | --- | | Diff check | passed | | | Conventions and PR template | passed | conventions check from the main checkout | | Mergeability and dependencies | passed | stack check passed; no declared dependencies; no errors | | Emscripten `library-portability` (hosted) | failed | link error: `undefined symbol: NotImplementedAt_nid_no_patch` in `emscripten_module_unwind_tests`; caused by the new macro in `General.hpp` | | `NotImplementedAt_nid_no_patch` defined for the Emscripten test | no | the test defines only `NotImplemented_nid_no_patch` | | Windows CTest | cancelled | no result for this head | | Relinkers and relinker-asan (hosted) | passed | all succeeded | | ABI audit (main-checkout tool) | passed with warnings | 16 findings, not read in detail | | Negative controls | not run | no local build | | Hosted CI | failed | `library-portability` failed; `windows` cancelled | <details><summary>Read-only check output</summary> Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. ABI audit: passed with warnings (16). Stack check: passed, no errors. Hosted: `gh api repos/boykopovar/AnyPS5/commits/a6bb84be17d6c58584ce6bdbfeb603cf462db496/check-runs`, and the `library-portability` job log. </details> ## Negative control Not run here. A negative control needs a local build, and code from this head is not run here. ## Findings **Blocking** - The Emscripten `library-portability` job fails at link time on this head. The new macro in `General.hpp` (lines 16-17) makes `Module.cpp` call `NotImplementedAt_nid_no_patch`, which `core/libs/tests/emscripten/EmscriptenModuleUnwind.cpp` does not define. Fix one of these: define `NotImplementedAt_nid_no_patch` in that test with the new signature, or keep the call sites linking as they did before. Then rerun the `library-portability` job. **Non-blocking** - The ABI audit reports 16 findings that were not read in detail. ## Sources - Header: https://github.com/boykopovar/AnyPS5/blob/a6bb84be17d6c58584ce6bdbfeb603cf462db496/core/libs/prx/libc/include/General.hpp (lines 15-17) - Definition: https://github.com/boykopovar/AnyPS5/blob/a6bb84be17d6c58584ce6bdbfeb603cf462db496/core/libs/prx/libc/src/General.cpp (around lines 1020-1030) - Emscripten target: https://github.com/boykopovar/AnyPS5/blob/a6bb84be17d6c58584ce6bdbfeb603cf462db496/core/libs/tests/emscripten/CMakeLists.txt - Test stub: https://github.com/boykopovar/AnyPS5/blob/a6bb84be17d6c58584ce6bdbfeb603cf462db496/core/libs/tests/emscripten/EmscriptenModuleUnwind.cpp (line 18) - Hosted log: `library-portability` job on a6bb84be17d6c58584ce6bdbfeb603cf462db496 ## Not verified - The 16 ABI findings. - Whether any other test target builds `Module.cpp` without `General.cpp`. - The Windows result (cancelled). ## To get this to a good state - Define `NotImplementedAt_nid_no_patch` in `EmscriptenModuleUnwind.cpp`, or change the macro so the Emscripten target still links. Rerun `library-portability`.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!14235
No description provided.