Skip to content

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

Open
pablogsal wants to merge 10 commits into
python:mainfrom
pablogsal:rewrite-profiler-platform-inspection
Open

pablogsal wants to merge 10 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?

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

Labels

awaiting core review needs backport to 3.15 bugs and security fixes skip news type-feature A feature request or enhancement type-refactor Code refactoring (with no changes in behavior)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants