fix(tools): read sampler module names that contain spaces in symbolize_samples #13861

Merged
roboterspinne merged 1 commit from upstream-pr/13861 into main 2026-11-02 00:44:40 +00:00
roboterspinne commented 2026-10-31 10:03:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-31T10:03:36Z.


What

The Windows samplers (APS5_SAMPLE_WORKER, APS5_SAMPLE_COMMITTER, APS5_SAMPLE_THREADS) write a module's base name unquoted with %s: WorkerSampler.cpp:202 writes <module> 0x<offset> <self> <inclusive>, line 288 writes the same line indented by two spaces under a thread line, and line 186 writes # module <module> 0x<size> 0x<timestamp>. On 45e39c7ad1 (line numbers below refer to it) tools/symbolize_samples.py splits both kinds of line on whitespace and wants an exact field count: read_headers keeps a record only with five fields (line 234) and load reads an address line only with four (line 267). A module whose name contains a space, such as a Windows output named My Game.exe (relinker --windows eboot.elf "My Game.exe"), gives six and five fields instead. The record is dropped, so the module counts as having no # module record and stays unsymbolized, and each of its address lines falls through to the collapsed-stack parser (line 272), which also ignores --thread; samples.stacks is then no longer empty, so summarize takes the collapsed-stack branch (line 297) and ignores every address line of the other modules. For the address file # 5 samples, My Game.exe 0x1011 3 3, ntdll.dll 0x10 2 2, # module My Game.exe 0x3000 0x6ad92ac4 and a matching My Game.exe in --libs, the tool printed 3 samples and 3 100.0% My Game.exe 0x1011 3; it now prints 5 samples, 3 60.0% My Game.exe!short and 2 40.0% ntdll.dll+0x10.

  • read_headers splits a # module line into #, module and the rest, and takes the size and the timestamp from the right end of the rest, so the name keeps its spaces. Names are still compared case-insensitively.
  • load takes an address line's offset and counts from the right end of the stripped line (rsplit(None, 3)), so the name keeps its spaces and the two-space indentation of thread files does not become part of it. # <n> samples, thread <id> samples <n> and collapsed-stack lines are read as before; collapsed stacks already split their count off with rpartition(" ") and their frames at +0x.
  • A # module line with more than five fields was ignored before. It is now a record whose name is everything between module and the last two fields, and when either of those two is not hexadecimal it ends with the same usage error that a malformed five-field record already gave. The samplers never write such a line.

pr_overlap.py --branch reports no overlap with open pull requests. #12498, #12499, #13812 and #13813 also change tools/symbolize_samples.py and its test, in other lines; #13812 adds a check a few lines below the address-line branch of load.

Tested

Windows 11, conda Python 3.13.9, on 695da932b3 (based on 45e39c7ad1; main at c3c45d73ab changed neither file and merges cleanly):

  • python tools/tests/test_symbolize_samples.py: 38 tests, OK, 4 skipped (three need the privilege to create symbolic links on Windows, one needs an unprivileged POSIX user).
  • The new test_module_names_with_spaces_keep_their_samples_and_records covers an address file with another module, a thread file under --thread, and a collapsed-stack file with the record; on 45e39c7ad1 it fails with '3 samples' != '5 samples'.
  • python tools/check_conventions.py with this title and description passed on 695da932b3.

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:5096544154 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13861). Originally posted by [roboterspinne](https://github.com/roboterspinne) on 2026-10-31T10:03:36Z. --- ### What The Windows samplers (`APS5_SAMPLE_WORKER`, `APS5_SAMPLE_COMMITTER`, `APS5_SAMPLE_THREADS`) write a module's base name unquoted with `%s`: `WorkerSampler.cpp:202` writes `<module> 0x<offset> <self> <inclusive>`, line 288 writes the same line indented by two spaces under a `thread` line, and line 186 writes `# module <module> 0x<size> 0x<timestamp>`. On 45e39c7ad1 (line numbers below refer to it) `tools/symbolize_samples.py` splits both kinds of line on whitespace and wants an exact field count: `read_headers` keeps a record only with five fields (line 234) and `load` reads an address line only with four (line 267). A module whose name contains a space, such as a Windows output named `My Game.exe` (`relinker --windows eboot.elf "My Game.exe"`), gives six and five fields instead. The record is dropped, so the module counts as having no `# module` record and stays unsymbolized, and each of its address lines falls through to the collapsed-stack parser (line 272), which also ignores `--thread`; `samples.stacks` is then no longer empty, so `summarize` takes the collapsed-stack branch (line 297) and ignores every address line of the other modules. For the address file `# 5 samples`, `My Game.exe 0x1011 3 3`, `ntdll.dll 0x10 2 2`, `# module My Game.exe 0x3000 0x6ad92ac4` and a matching `My Game.exe` in `--libs`, the tool printed `3 samples` and `3 100.0% My Game.exe 0x1011 3`; it now prints `5 samples`, `3 60.0% My Game.exe!short` and `2 40.0% ntdll.dll+0x10`. - `read_headers` splits a `# module` line into `#`, `module` and the rest, and takes the size and the timestamp from the right end of the rest, so the name keeps its spaces. Names are still compared case-insensitively. - `load` takes an address line's offset and counts from the right end of the stripped line (`rsplit(None, 3)`), so the name keeps its spaces and the two-space indentation of thread files does not become part of it. `# <n> samples`, `thread <id> samples <n>` and collapsed-stack lines are read as before; collapsed stacks already split their count off with `rpartition(" ")` and their frames at `+0x`. - A `# module` line with more than five fields was ignored before. It is now a record whose name is everything between `module` and the last two fields, and when either of those two is not hexadecimal it ends with the same usage error that a malformed five-field record already gave. The samplers never write such a line. `pr_overlap.py --branch` reports no overlap with open pull requests. #12498, #12499, #13812 and #13813 also change `tools/symbolize_samples.py` and its test, in other lines; #13812 adds a check a few lines below the address-line branch of `load`. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11, conda Python 3.13.9, on 695da932b3 (based on 45e39c7ad1; `main` at c3c45d73ab changed neither file and merges cleanly): - `python tools/tests/test_symbolize_samples.py`: 38 tests, OK, 4 skipped (three need the privilege to create symbolic links on Windows, one needs an unprivileged POSIX user). - The new `test_module_names_with_spaces_keep_their_samples_and_records` covers an address file with another module, a thread file under `--thread`, and a collapsed-stack file with the record; on 45e39c7ad1 it fails with `'3 samples' != '5 samples'`. - `python tools/check_conventions.py` with this title and description passed on 695da932b3. ### 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
MarcZX10 commented 2026-10-31 10:13:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T10:13:50Z.

Review: APPROVED


Reviewed — looks good

The space-preserving parser change is supported by the exact-head tests and no blocking issue was found.

What I ran

Reviewed head 695da932b3f78bc5ae688b88661b65a80b0c6ce4 against PR base b7d3fd3c5218d21b626c2211c7521643efa4d572. The merge preview onto that base was clean. Environment: Linux x86_64, Python 3. The repository precheck ran these commands:

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13861
python3 -m unittest tools.tests.test_symbolize_samples

Results

Check Result
Diff and conventions/template Passed
Python syntax, test registration, dependency/merge preview Passed
tools.tests.test_symbolize_samples Passed: 38 tests, 2 skipped
Hosted CI Linux relinker, Windows relinker, and ASAN passed; macOS relinker jobs queued at final check
Unedited unit test output
.................................s...s
----------------------------------------------------------------------
Ran 38 tests in 0.928s

OK (skipped=2)

Negative control

Assertion Change made New test failed?
Module names with spaces retain their sample records Ran the new test against the PR base implementation Yes; expected 5 samples, got 3 samples
Unedited negative-control failure
FAIL: test_module_names_with_spaces_keep_their_samples_and_records
AssertionError: '3 samples' != '5 samples'
Ran 38 tests in 1.037s
FAILED (failures=1, skipped=2)

Not verified

I did not build or compile locally. The macOS hosted relinker jobs were still queued; the approval is based on the exact-head source review, focused Python test, negative control, and completed Linux/Windows/ASAN jobs.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5722306654 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13861#pullrequestreview-5722306654). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-31T10:13:50Z. **Review:** APPROVED --- # Reviewed — looks good The space-preserving parser change is supported by the exact-head tests and no blocking issue was found. ## What I ran Reviewed head `695da932b3f78bc5ae688b88661b65a80b0c6ce4` against PR base `b7d3fd3c5218d21b626c2211c7521643efa4d572`. The merge preview onto that base was clean. Environment: Linux x86_64, Python 3. The repository precheck ran these commands: ```sh python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13861 python3 -m unittest tools.tests.test_symbolize_samples ``` ## Results | Check | Result | |---|---| | Diff and conventions/template | Passed | | Python syntax, test registration, dependency/merge preview | Passed | | `tools.tests.test_symbolize_samples` | Passed: 38 tests, 2 skipped | | Hosted CI | Linux relinker, Windows relinker, and ASAN passed; macOS relinker jobs queued at final check | <details> <summary>Unedited unit test output</summary> ```text .................................s...s ---------------------------------------------------------------------- Ran 38 tests in 0.928s OK (skipped=2) ``` </details> ## Negative control | Assertion | Change made | New test failed? | |---|---|---| | Module names with spaces retain their sample records | Ran the new test against the PR base implementation | Yes; expected `5 samples`, got `3 samples` | <details> <summary>Unedited negative-control failure</summary> ```text FAIL: test_module_names_with_spaces_keep_their_samples_and_records AssertionError: '3 samples' != '5 samples' Ran 38 tests in 1.037s FAILED (failures=1, skipped=2) ``` </details> ## Not verified I did not build or compile locally. The macOS hosted relinker jobs were still queued; the approval is based on the exact-head source review, focused Python test, negative control, and completed Linux/Windows/ASAN jobs.
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!13861
No description provided.