Skip to content

fix(apple): scope perf processes to the resolved app executable - #2406

Merged
thymikee merged 3 commits into
mainfrom
fix/apple-perf-executable-scope
Sep 9, 2026
Merged

fix(apple): scope perf processes to the resolved app executable#2406
thymikee merged 3 commits into
mainfrom
fix/apple-perf-executable-scope

Conversation

@thiagobrez

@thiagobrez thiagobrez commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Apple performance sampling could include another simulator’s copy of an app: after resolving the selected app’s executable path, a failed path match still fell back to its basename. Keep matching scoped to the resolved executable (including /private/var aliases); use name matching only when no path is available.

Five files: extract the process identity helper, add regression coverage, and clarify profiling scope in CLI help and docs. This is a separate diagnostic fix discovered while investigating #2362; it does not change touch delivery.

Validation

Head 33fbe8dc806c23152c2824177e34dbc6ab4cdae1:

  • Process-selection regression: two failures before the fix; all four new cases and 24 existing performance tests pass afterward.
  • pnpm check:affected --run passes, including 2,141 related tests, build, lint, formatting, type and architecture checks.
  • Live iOS 26.5 / Xcode 26.6 at 726eeffd2: ran the same Scenario Lab app on two owned simulators (PIDs 4297 and 4495). perf cpu profile start --kind xctrace --template "Time Profiler" selected only PID 4495 on the requested simulator; the drag and committed-event check passed.
  • Limitation: capture stop exceeded its 45-second grace period. A direct xcrun xctrace record --time-limit 10s control also exceeded 90 seconds. Process selection is proven; successful trace/report generation remains unverified. Owned sessions, captures and simulators were cleaned up.

CI caught eager import growth. Load the helper on demand; all 549 startup-guard tests and a live perf memory sample pass at the new head. CI and iOS smoke pass; all PR checks are green.

Copilot AI lite review requested due to automatic review settings September 8, 2026 23:49
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-09-09 06:31 UTC

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Size Report

Metric Base Current Diff
Installed (including dependencies) 4.51 MB 4.51 MB +319 B
Package (unpacked) 4.51 MB 4.51 MB +319 B
Package (download) 1.34 MB 1.34 MB +155 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 26.0 ms 26.5 ms +0.5 ms
CLI --help 74.3 ms 74.2 ms -0.1 ms

Copilot AI 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.

🟢 Approval recommended

The behavioral change is narrowly scoped with targeted regression tests, and the only remaining feedback is a minor CLI wording tweak.

Pull request overview

This PR tightens Apple perf process selection so iOS simulator/macOS profiling targets only the resolved app executable path (including /private/var/var aliases), preventing accidental sampling of another simulator’s app instance with the same basename.

Changes:

  • Extracted executable/process identity matching into a dedicated helper (perf-process-identity.ts) and updated Apple perf code to use it.
  • Adjusted matching behavior to avoid falling back to basename matching when an executable path is known but doesn’t match.
  • Added regression tests for the new matching rules and updated CLI/docs text to clarify profiling scope.
File summaries
File Description
website/docs/docs/debugging-profiling.md Documents that simulator/macOS perf targets the resolved executable to avoid cross-simulator name collisions.
src/commands/perf/index.ts Updates CLI help text to describe the new Apple process targeting behavior.
packages/platform-apple/src/core/perf.ts Uses the extracted process identity helper and removes the in-file implementation.
packages/platform-apple/src/core/perf-process-identity.ts New helper implementing path-scoped matching (with /private/var aliasing) plus token parsing.
packages/platform-apple/src/core/tests/perf-process-identity.test.ts Regression coverage for path-scoped matching, alias handling, and name-only fallback when no path exists.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/commands/perf/index.ts Outdated
Copilot AI review requested due to automatic review settings September 8, 2026 23:57

Copilot AI 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.

🟡 Changes recommended

readProcessCommandToken truncates commands when the executable path contains spaces, which can corrupt processName values and undermine robustness for apps whose executable names include spaces.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment on lines +33 to +35
export function readProcessCommandToken(command: string): string {
const [token = ''] = command.trim().split(/\s+/, 1);
return token;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The display-name limitation is pre-existing: readProcessCommandToken and its memgraph callers have the same implementation at the merge base. At 33fbe8d the parser remains private to perf.ts; the extracted matcher checks the full resolved path before using a token, and its regression covers paths with spaces and arguments. I am keeping this change scoped to excluding other app instances. Plumbing the resolved executableName into memgraph display fields is a separate improvement; quoted/escaped argv handling would need a concrete ps output case.

Copilot AI review requested due to automatic review settings September 9, 2026 00:10
@thiagobrez

Copy link
Copy Markdown
Contributor Author

Fixed the coverage failure in 33fbe8dc806c23152c2824177e34dbc6ab4cdae1. The extraction had added an eager module to perf-facade; the matcher now loads inside the existing async process-sampling function, preserving the import budget.

All 549 startup-guard tests plus the 28 performance tests pass, as does pnpm check:affected --run on the exact new head (2,141 related tests). The rebuilt CLI also successfully sampled our iOS 26.5 app’s memory through the changed path. The owned session and simulator were cleaned up. New CI is running.

Copilot AI 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.

🟢 Approval recommended

The change is narrowly scoped, removes the incorrect basename fallback when an executable path is known, includes targeted regression tests, and updates user-facing docs/help accordingly.

Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@thiagobrez

Copy link
Copy Markdown
Contributor Author

All PR checks now pass at 33fbe8dc806c23152c2824177e34dbc6ab4cdae1, including coverage and provider integration and iOS smoke. The startup import regression is fixed and verified by the formerly failing guard. Live process-selection and memory-sampling evidence, plus the unresolved Apple trace-stop limitation, are recorded in the body.

@thymikee

thymikee commented Sep 9, 2026

Copy link
Copy Markdown
Member

Code review is clean at 33fbe8d. The resolved-path match excludes other copies of the app, with reported live two-simulator selection and exact-head memory sampling; checks pass and there are no conflicts. Ready for human review; the separately reproduced xctrace stop limitation still prevents claiming a completed trace/report.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Sep 9, 2026
@thymikee
thymikee merged commit e7d97f7 into main Sep 9, 2026
21 checks passed
@thymikee
thymikee deleted the fix/apple-perf-executable-scope branch September 9, 2026 06:29
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.

3 participants