Commit 1c24692
feat: add import profiler tool with dynamic loaded lines code volume … (#17467)
### Overview
This PR introduces `profiler.py`, a zero-dependency, process-isolated
import profiling tool designed to benchmark Python SDK modules with
extreme precision and zero dynamic cache interference.
To evaluate authentic import initialization overhead without the
"observer effect", the profiler leverages a Master/Worker architecture.
The master orchestrator executes each benchmark iteration inside a
completely isolated, dynamically spawned subprocess. By bypassing
Python's `sys.modules` cache and sweeping disk-level `__pycache__`
directories, the tool guarantees a 100% authentic "cold-start"
evaluation every time.
### Key Telemetry Vectors & Features
- **Initialization Latency (ms):** Measured at high resolution natively,
securely omitting VM startup skew.
- **Physical Memory Deltas (RAM):** Employs a dual-strategy approach
tracking both internal block allocator shifts via `tracemalloc`
(cross-platform), and pure OS-level physical memory footprints via
`/proc/self/statm` deltas (Linux RSS) to catch heavy C/C++ backend
extensions like `protobuf`.
- **Deterministic Code Volume (LOC):** Tracks the physical delta of
`sys.modules` across the import window, traversing disk paths to
aggregate the exact number of physical Lines of Code (LOC) injected into
the interpreter.
- **CPU Pinning:** Binds worker processes to a single CPU core via
`taskset` on Linux to eliminate OS-level context-switching jitter across
iterations.
- **Diagnostic Tooling:** Supports one-off diagnostic tracing for
bottleneck discovery via `--trace` (`-X importtime`) and `--cprofile`.
*A comprehensive breakdown of the architecture, data pipeline, and trace
log analysis is documented in
[`scripts/import_profiler/documentation.md`](./scripts/import_profiler/documentation.md).*
### Related Links
- **Design Doc:** `
[go/sdk-performance-design](http://goto.google.com/sdk-performance-design)`
- **Related Issue:**
googleapis/python-aiplatform#4749
---------
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>1 parent 8a1270c commit 1c24692
2 files changed
Lines changed: 408 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
0 commit comments