Skip to content

fix(apple): pin C locale for perf ps reads on macOS - #5424

Open
pcbeingused33 wants to merge 1 commit into
callstack:mainfrom
pcbeingused33:fix/perf-ps-c-locale
Open

pcbeingused33 wants to merge 1 commit into
callstack:mainfrom
pcbeingused33:fix/perf-ps-c-locale

Conversation

@pcbeingused33

@pcbeingused33 pcbeingused33 commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

perf on macOS reads CPU and memory from ps -axo pid=,%cpu=,rss=,command=. BSD ps formats %cpu with the host LC_NUMERIC, so under de_DE, fr_FR or es_ES it prints 12,5. parseApplePsOutput only accepts a . decimal, so every row is dropped and the app process is never found.

The host ps reads in perf-target.ts now pass envOverrides: { LC_ALL: 'C.UTF-8' }, the same pin host-process.ts already uses for its ps reads (and the same fix #4682 applied to lstart). The parser also accepts a comma decimal, for reads that cannot be pinned, such as simctl spawn ps.

Before / after

ps row under LANG=de_DE.UTF-8: 123 12,5 45678 /Applications/Test.app/Contents/MacOS/Test

before: parseApplePsOutput -> []   (perf finds no process)
after:  parseApplePsOutput -> [{ pid: 123, cpuPercent: 12.5, rssKb: 45678, ... }]

Validation

  • Tested at 41ac39e. Two new tests in perf-target.test.ts: comma-decimal parsing, and the locale pin on the macOS ps call. Both fail on main and pass with the fix.
  • vitest run on perf-target.test.ts and perf.test.ts passes (27 tests). oxfmt --check and tsc --noEmit are clean.
  • No macOS device run; the change only affects the ps environment and parsing.

This change was prepared with AI assistance.


Proof this PR
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff

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.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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' };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Suggested change
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' };

@thymikee

thymikee commented Dec 6, 2026

Copy link
Copy Markdown
Member

Thanks for the fix. The change at 41ac39e looks good: it pins the C locale for the ps reads on macOS, so the decimal separator stays "." and the parsing no longer depends on the host locale (https://github.com/callstack/agent-device/blob/41ac39e/packages/platform-apple/src/core/perf-target.ts#L17). No conflicts, and the only cancelled checks are the two Body rules jobs, which do not run this code; the other 17 checks pass. Not verified here: older macOS releases, and whether simctl spawn ps ever prints a comma. Nothing further is needed before merge.

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)

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Dec 6, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants