feat(libc): write the called imports to APS5_TRACE_CALLS_FILE every 10 seconds #9439

Merged
milescoviello merged 1 commit from upstream-pr/9439 into main 2026-10-25 16:42:51 +00:00
milescoviello commented 2026-10-21 22:07:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T22:07:10Z.


What

An executable converted with --trace-imports counts its calls to the libraries in APS5_TRACE_CALLS, but only a crash or an abort report prints them, and then only the 32 most called imports. A run that ends normally, or is killed at a timeout, leaves no record of what it called.

With APS5_TRACE_CALLS_FILE set to a path, the first traced import starts a thread that rewrites that file every 10 seconds. It holds one line per import called so far, most called first: the number of calls, the library and the import name. A run that is killed keeps its last rewrite.

245557 libc.prx gQX+4GDQjpM#guest
3866 libSceAgc.prx 57labkp+rSQ

I used it to list what the 10 retail games on my test host actually call (200 to 476 different imports in 2 to 5 minutes each) and to check which of them reach a function that still has a NotImplemented_nid_no_patch path. The crash report couldn't answer that, because none of those runs crashed in a library.

How

  • CallTrace.cpp: WriteCallCounts takes every import record with a nonzero count, sorts the records by count (stable, so equal counts keep their order), and writes the lines through a std::ofstream on a std::filesystem::path.
  • StartCallCountWriter runs once, when the first traced import sets up the trace. It reads APS5_TRACE_CALLS_FILE, through _wgetenv on Windows as the other path variables do, and starts a detached thread that rewrites the file every 10 seconds.
  • WriteCallCounts_nid_no_patch(const char* utf8Path) writes the same file on demand. It returns false for a null or empty path, or when the file can't be written. The test uses it.
  • ENVIRONMENT.md, TRACING.md and the tracing section of USAGE.md describe the variable.

Tested

  • Rebased onto main 17f5335562, with no conflicts, as head ba73390965. guest_call_trace and guest_call_trace_abort pass 3 of 3 on Linux (Ubuntu 26.04.1, GCC 15.2, Release), and 3 of 3 on the Windows 11 VM (WinLibs GCC 15.2.0, Release) on this head and on its merge base. Conventions are clean, and the overlap scan shows no line-level overlap. The Windows runs cover the direct path-writing call; the 10-second writer thread is still exercised only by the Linux title runs below. The other results are from pre-rebase heads.

Linux (Ubuntu 26.04.1, GCC 15.2, Release), on main 0c6a5bd593, then rebased onto a6dcea9279. That merge doesn't touch these files.

  • guest_call_trace, guest_call_trace_abort and guest_call_trace_abort_race pass 3 of 3.

  • The new checks in guest_call_trace run after the existing calls and compare the written file exactly: 80001 Integers, 3 Blocks, 2 Doubles, 1 Mixed, 1 Variadic, in that order, each with the library name it was traced under. They also check that a path under a regular file, a null path and an empty path return false.

  • On main the test doesn't build, because WriteCallCounts_nid_no_patch is new.

  • Titles: Steins;Gate, Ghost of Tsushima, Forspoken, MGS4, Astro Bot, Crimson Desert, MXGP 26, Super Meat Boy 3D, CoD Black Ops II and Borderlands 4, converted with --trace-imports, APS5_TRACE_CALLS=all and APS5_TRACE_CALLS_FILE=calls.txt, for 120 to 300 s each. Every run left its file (204 to 476 lines), including the two that were killed (Ghost of Tsushima at 54 s, Astro Bot at 75 s). These runs used an earlier local version of this change that wrote the same lines unsorted.

  • Windows 11 VM, WinLibs GCC 15.2.0, Release, head f1a1c05784 and its merge base a6dcea9279: guest_call_trace and guest_call_trace_abort (the two that run on Windows) pass 3 of 3 on both. So the new checks, the exact file contents included, pass there.

Not tested: macOS, and the 10-second writer thread on Windows (the test calls WriteCallCounts_nid_no_patch directly; the titles above ran on Linux).

  • Used by @klosixgaming-arch (comment) on 15 titles with main 1a745ae38e and this branch, APS5_TRACE_CALLS=all, about 2 minutes each. It showed which census stubs and absent imports titles actually call, not just link: sceSystemServiceParamGetInt in all 13 titles that boot far enough, and timespec_get 19,588 times in one title (#9388's case).

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: none needed (libc only)
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4959012410 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9439). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-21T22:07:10Z. --- ### What An executable converted with `--trace-imports` counts its calls to the libraries in `APS5_TRACE_CALLS`, but only a crash or an abort report prints them, and then only the 32 most called imports. A run that ends normally, or is killed at a timeout, leaves no record of what it called. With `APS5_TRACE_CALLS_FILE` set to a path, the first traced import starts a thread that rewrites that file every 10 seconds. It holds one line per import called so far, most called first: the number of calls, the library and the import name. A run that is killed keeps its last rewrite. ``` 245557 libc.prx gQX+4GDQjpM#guest 3866 libSceAgc.prx 57labkp+rSQ ``` I used it to list what the 10 retail games on my test host actually call (200 to 476 different imports in 2 to 5 minutes each) and to check which of them reach a function that still has a `NotImplemented_nid_no_patch` path. The crash report couldn't answer that, because none of those runs crashed in a library. ### How - `CallTrace.cpp`: `WriteCallCounts` takes every import record with a nonzero count, sorts the records by count (stable, so equal counts keep their order), and writes the lines through a `std::ofstream` on a `std::filesystem::path`. - `StartCallCountWriter` runs once, when the first traced import sets up the trace. It reads `APS5_TRACE_CALLS_FILE`, through `_wgetenv` on Windows as the other path variables do, and starts a detached thread that rewrites the file every 10 seconds. - `WriteCallCounts_nid_no_patch(const char* utf8Path)` writes the same file on demand. It returns false for a null or empty path, or when the file can't be written. The test uses it. - `ENVIRONMENT.md`, `TRACING.md` and the tracing section of `USAGE.md` describe the variable. ### Tested - **Rebased** onto `main` 17f5335562, with no conflicts, as head `ba73390965`. `guest_call_trace` and `guest_call_trace_abort` pass 3 of 3 on Linux (Ubuntu 26.04.1, GCC 15.2, Release), and 3 of 3 on the Windows 11 VM (WinLibs GCC 15.2.0, Release) on this head and on its merge base. Conventions are clean, and the overlap scan shows no line-level overlap. The Windows runs cover the direct path-writing call; the 10-second writer thread is still exercised only by the Linux title runs below. The other results are from pre-rebase heads. Linux (Ubuntu 26.04.1, GCC 15.2, Release), on `main` 0c6a5bd593, then rebased onto a6dcea9279. That merge doesn't touch these files. - `guest_call_trace`, `guest_call_trace_abort` and `guest_call_trace_abort_race` pass 3 of 3. - The new checks in `guest_call_trace` run after the existing calls and compare the written file exactly: `80001 Integers`, `3 Blocks`, `2 Doubles`, `1 Mixed`, `1 Variadic`, in that order, each with the library name it was traced under. They also check that a path under a regular file, a null path and an empty path return false. - On `main` the test doesn't build, because `WriteCallCounts_nid_no_patch` is new. - Titles: Steins;Gate, Ghost of Tsushima, Forspoken, MGS4, Astro Bot, Crimson Desert, MXGP 26, Super Meat Boy 3D, CoD Black Ops II and Borderlands 4, converted with `--trace-imports`, `APS5_TRACE_CALLS=all` and `APS5_TRACE_CALLS_FILE=calls.txt`, for 120 to 300 s each. Every run left its file (204 to 476 lines), including the two that were killed (Ghost of Tsushima at 54 s, Astro Bot at 75 s). These runs used an earlier local version of this change that wrote the same lines unsorted. - Windows 11 VM, WinLibs GCC 15.2.0, Release, head f1a1c05784 and its merge base a6dcea9279: `guest_call_trace` and `guest_call_trace_abort` (the two that run on Windows) pass 3 of 3 on both. So the new checks, the exact file contents included, pass there. Not tested: macOS, and the 10-second writer thread on Windows (the test calls `WriteCallCounts_nid_no_patch` directly; the titles above ran on Linux). - Used by @klosixgaming-arch ([comment](https://github.com/boykopovar/AnyPS5/pull/9439#issuecomment-6352720993)) on 15 titles with `main` 1a745ae38e and this branch, `APS5_TRACE_CALLS=all`, about 2 minutes each. It showed which census stubs and absent imports titles actually call, not just link: `sceSystemServiceParamGetInt` in all 13 titles that boot far enough, and `timespec_get` 19,588 times in one title (#9388's case). ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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: none needed (libc only) - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-22 04:40:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:40:44Z.

Review: DISMISSED


The fixed-capacity import records remain stable while counts are sampled atomically, the output sorts every nonzero record with deterministic tie ordering, and the Linux report covers both the on-demand API and periodic file snapshots during real title runs (including runs later killed). Windows validates the direct path-writing API, while the periodic thread itself is explicitly untested there.

The branch was rebased onto 6ef5a1c4c9, but current upstream main has since advanced to 17f5335562. Please update to current main and rerun the focused guest_call_trace tests plus conventions and overlap. Since the file-path/environment handling has a Windows-specific _wgetenv branch, please also run the updated Windows focused test or state why that environment is unavailable. Hosted product jobs remain skipped. I did not run local tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609342020 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9439#pullrequestreview-5609342020). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T04:40:44Z. **Review:** DISMISSED --- The fixed-capacity import records remain stable while counts are sampled atomically, the output sorts every nonzero record with deterministic tie ordering, and the Linux report covers both the on-demand API and periodic file snapshots during real title runs (including runs later killed). Windows validates the direct path-writing API, while the periodic thread itself is explicitly untested there. The branch was rebased onto `6ef5a1c4c9`, but current upstream main has since advanced to `17f5335562`. Please update to current main and rerun the focused `guest_call_trace` tests plus conventions and overlap. Since the file-path/environment handling has a Windows-specific `_wgetenv` branch, please also run the updated Windows focused test or state why that environment is unavailable. Hosted product jobs remain skipped. I did not run local tests.
milescoviello commented 2026-10-22 04:53:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-22T04:53:15Z.


@MarcZX10 rebased onto main 17f5335562 as ba73390965, with no conflicts. guest_call_trace and guest_call_trace_abort pass 3 of 3 on Linux, and 3 of 3 on the Windows 11 VM on this head and on its merge base. Conventions are clean, and the overlap scan has no line-level entry.

On Windows the tests cover WriteCallCounts_nid_no_patch, the direct path-writing call that the writer thread repeats. The thread itself only starts when a traced title sets up its imports, and writes after 10 s. No test runs that long, and my traced title runs are on Linux, so the Windows thread remains untested, as the Tested section says.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6333027761 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9439#issuecomment-6333027761). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-22T04:53:15Z. --- @MarcZX10 rebased onto `main` 17f5335562 as `ba73390965`, with no conflicts. `guest_call_trace` and `guest_call_trace_abort` pass 3 of 3 on Linux, and 3 of 3 on the Windows 11 VM on this head and on its merge base. Conventions are clean, and the overlap scan has no line-level entry. On Windows the tests cover `WriteCallCounts_nid_no_patch`, the direct path-writing call that the writer thread repeats. The thread itself only starts when a traced title sets up its imports, and writes after 10 s. No test runs that long, and my traced title runs are on Linux, so the Windows thread remains untested, as the Tested section says. AI-assisted: yes (Claude Code)
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!9439
No description provided.