Skip to content

gh-138122: Simplify Tachyon's macOS and Windows inspection - #161956

Merged
pablogsal merged 12 commits into
python:mainfrom
pablogsal:rewrite-profiler-platform-inspection
Nov 15, 2026
Merged

pablogsal merged 12 commits into
python:mainfrom
pablogsal:rewrite-profiler-platform-inspection

Conversation

@pablogsal

@pablogsal pablogsal commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Rewrite the platform-specific lookup code used by Tachyon. macOS now searches dyld's UUID array first, then the full image list, then executable memory regions. It reads 64-bit Mach-O headers from target memory, with a 4 KiB initial read and a fallback for larger load commands. Native thread IDs replace the inferred pthread offset and cache for CPU state.

Windows now queries each target thread through NtQueryInformationThread. This removes the system-wide process snapshot and its buffer. The query checks the returned process and thread IDs and closes the handle after each call. Native thread IDs remain unsigned throughout the lookup.

Runtime initialization no longer repeats the PyRuntime lookup. Asyncio offset discovery waits until the first async request. If the target exits before that request, the profiler raises ProcessLookupError instead of an asyncio-unavailable error.

Related to #138122 (PEP 799) and #135953 (the original profiler proposal).

@pablogsal pablogsal added skip news needs backport to 3.15 bugs and security fixes labels Nov 14, 2026
@pablogsal

Copy link
Copy Markdown
Member Author

CC @maurycy

@pablogsal pablogsal changed the title Rewrite Tachyon's macOS and Windows inspection code gh-138122: Simplify Tachyon's macOS and Windows inspection Nov 14, 2026
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Nov 14, 2026
@pablogsal
pablogsal marked this pull request as ready for review November 14, 2026 00:59
@pablogsal pablogsal added type-refactor Code refactoring (with no changes in behavior) and removed type-feature A feature request or enhancement labels Nov 14, 2026
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Nov 14, 2026
@pablogsal pablogsal removed the type-feature A feature request or enhancement label Nov 14, 2026
@maurycy

maurycy commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

@pablogsal pablogsal#147

maurycy and others added 2 commits November 14, 2026 08:49
- Search `dyld.uuidArray` first, then `infoArray`, then memory
- Replace dyld snapshot retries and timestamp checks with candidate validation and a fallback to mapped images
- Support only little-endian 64-bit Mach-O images: arm64 and x86_64, including Rosetta.
- Single 4KiB read for headers and load commands
- Remove duplicate `PyRuntime` lookups
- Lazy asyncio debug initialization unless it's needed?
Use dyld UUID entries for runtime discovery and defer asyncio offset lookup.
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Nov 14, 2026
Check the known runtime address when optional image lookup fails, and preserve fatal exceptions through async discovery.

Copy link
Copy Markdown
Member Author

@maurycy I merged your changes, thanks again! I also fixed the case where the target exits before the first async read, so it still raises ProcessLookupError. Can you take another look and approve if everything looks good?

@maurycy

maurycy commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

@pablogsal Thank you for merging my changes! I approve. CI fix: pablogsal#148

@pablogsal
pablogsal enabled auto-merge (squash) November 15, 2026 13:38
@pablogsal pablogsal removed the type-feature A feature request or enhancement label Nov 15, 2026
@pablogsal
pablogsal merged commit d8bc666 into python:main Nov 15, 2026
99 of 101 checks passed
@pablogsal
pablogsal deleted the rewrite-profiler-platform-inspection branch November 15, 2026 21:56
@miss-islington-app

Copy link
Copy Markdown

Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Nov 15, 2026

Copy link
Copy Markdown

GH-162067 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 15, 2026
pablogsal added a commit that referenced this pull request Nov 15, 2026
…-161956) (#162067)

(cherry picked from commit d8bc666)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news type-refactor Code refactoring (with no changes in behavior)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants