Repository navigation
fix(apple): pin C locale for perf ps reads on macOS - #5424
pcbeingused33 wants to merge 1 commit into
Conversation
BSD ps formats %cpu with LC_NUMERIC, so on a de_DE/fr_FR/es_ES host it prints 12,5 and parseApplePsOutput dropped every row. Pin LC_ALL for the host ps reads and accept a comma decimal separator in the parser.
There was a problem hiding this comment.
1 issue found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/platform-apple/src/core/perf-target.ts">
<violation number="1" location="packages/platform-apple/src/core/perf-target.ts:17">
P2: `C.UTF-8` is not a locale provided by macOS, so this override does not establish the UTF-8 character locale it claims. BSD `ps` can therefore render non-ASCII argv in C-locale escapes; `matchesAppleExecutableProcess` compares that output with the raw executable path, so perf can miss apps whose executable path contains non-ASCII characters. Remove `LC_ALL` and pin the valid macOS categories instead: `LC_NUMERIC=C` and `LC_CTYPE=UTF-8`.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
|
|
||
| // BSD ps formats %cpu with the user's LC_NUMERIC (`12,5` under de_DE); pin a C locale that | ||
| // keeps argv as UTF-8 text, and still accept a comma from reads that cannot be pinned. | ||
| const PS_LOCALE_ENV: NodeJS.ProcessEnv = { LC_ALL: 'C.UTF-8' }; |
There was a problem hiding this comment.
P2: C.UTF-8 is not a locale provided by macOS, so this override does not establish the UTF-8 character locale it claims. BSD ps can therefore render non-ASCII argv in C-locale escapes; matchesAppleExecutableProcess compares that output with the raw executable path, so perf can miss apps whose executable path contains non-ASCII characters. Remove LC_ALL and pin the valid macOS categories instead: LC_NUMERIC=C and LC_CTYPE=UTF-8.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/platform-apple/src/core/perf-target.ts, line 17:
<comment>`C.UTF-8` is not a locale provided by macOS, so this override does not establish the UTF-8 character locale it claims. BSD `ps` can therefore render non-ASCII argv in C-locale escapes; `matchesAppleExecutableProcess` compares that output with the raw executable path, so perf can miss apps whose executable path contains non-ASCII characters. Remove `LC_ALL` and pin the valid macOS categories instead: `LC_NUMERIC=C` and `LC_CTYPE=UTF-8`.</comment>
<file context>
@@ -12,6 +12,10 @@ import { runAppleToolCommand, runXcrun, type ScopedSimctlCommand } from './tool-
+// BSD ps formats %cpu with the user's LC_NUMERIC (`12,5` under de_DE); pin a C locale that
+// keeps argv as UTF-8 text, and still accept a comma from reads that cannot be pinned.
+const PS_LOCALE_ENV: NodeJS.ProcessEnv = { LC_ALL: 'C.UTF-8' };
+
export type AppleProcessSample = {
</file context>
| const PS_LOCALE_ENV: NodeJS.ProcessEnv = { LC_ALL: 'C.UTF-8' }; | |
| const PS_LOCALE_ENV: NodeJS.ProcessEnv = { LC_ALL: undefined, LC_NUMERIC: 'C', LC_CTYPE: 'UTF-8' }; |
|
Thanks for the fix. The change at 41ac39e looks good: it pins the C locale for the The open inline thread about C.UTF-8 does not apply: macOS 27.0 ships that locale and the same pin already exists in host-process.ts:272, and a host without it falls back to C, which still gives ".". Please resolve it: #5424 (comment) |
Summary
perfon macOS reads CPU and memory fromps -axo pid=,%cpu=,rss=,command=. BSDpsformats%cpuwith the hostLC_NUMERIC, so underde_DE,fr_FRores_ESit prints12,5.parseApplePsOutputonly accepts a.decimal, so every row is dropped and the app process is never found.The host
psreads inperf-target.tsnow passenvOverrides: { LC_ALL: 'C.UTF-8' }, the same pinhost-process.tsalready uses for itspsreads (and the same fix #4682 applied tolstart). The parser also accepts a comma decimal, for reads that cannot be pinned, such assimctl spawn ps.Before / after
psrow underLANG=de_DE.UTF-8:123 12,5 45678 /Applications/Test.app/Contents/MacOS/TestValidation
41ac39e. Two new tests inperf-target.test.ts: comma-decimal parsing, and the locale pin on the macOSpscall. Both fail onmainand pass with the fix.vitest runonperf-target.test.tsandperf.test.tspasses (27 tests).oxfmt --checkandtsc --noEmitare clean.psenvironment and parsing.This change was prepared with AI assistance.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.