Файли
openidea/docs/en/guide/profiler.mdx
T
LU XIANGRUIтаwildcatDownstairs d1c07306e9 feat(profiler): profile Python runs with yappi (threads, asyncio) (#7466)
Profile on a Python run configuration uses yappi when the run's interpreter can import it: Automatic picks yappi, else py-spy where it can sample without root, else cProfile, and Settings › Python › Profiler gains a yappi choice (missing yappi offers `python -m pip install yappi`, or only the homepage under uv/poetry). yappi runs through python_profile.py with the wall clock and builtins, so a coroutine's time includes its awaits and every thread is profiled; the launcher writes the merged profile.pstats plus one pstats per thread and threads.json (busiest 64), converted to cProfile's call-count order and built-in names. Non-daemon threads and pools are waited for before saving, except after Stop. The Profiler view gets a thread selector (All threads merged, then each thread) when a run has two or more threads. The Rust CI job installs yappi 1.7.6 in a venv on GitHub-hosted runners for the real-interpreter tests.

Co-authored-by: wildcatDownstairs <[email protected]>
2026-12-05 10:10:00 +08:00

54 рядки
5.6 KiB
Plaintext
Неформатований Анотація Історія

Цей файл містить неоднозначні символи Юнікоду
Цей файл містить символи Юнікоду, які можна сплутати з іншими символами. Якщо ви вважаєте, що це зроблено навмисно, можете сміливо ігнорувати це попередження. Щоб показати їх, скористайтеся кнопкою Escape.
---
title: "Profiler"
description: "Profile a run configuration with a sampling profiler and explore the result as a flame graph, call tree or method list."
---
**Profile** runs a [run configuration](/en/guide/run) under an external sampling profiler. When the program exits (or you stop it), the IDE reads the samples and opens them in the Profiler tool window.
## Profile a run
- Use **Run › Profile** to profile the selected configuration.
- Choose **Profile '…'** from the gutter run icon menu or from the run widget's **More Actions** menu.
- **Profile Context Configuration** (in **Find Action…**, `⌘⇧A` / `Ctrl+Shift+A`) profiles the program or test at the caret.
The program runs in the Run tool window as usual. If the profiler is missing, a notification names it and offers **Install** (when there is an install command) or **Download…** (the profiler's download page).
## Supported runtimes
| Runtime | Configurations | Profiler | Platforms |
| --------------- | ------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ------------ |
| Node.js | `node`, `npx`, `tsx`, `ts-node` programs and npm, pnpm or yarn scripts | `node --cpu-prof` (set through `NODE_OPTIONS`, so every Node.js process of the run is profiled) | All |
| Python | scripts, modules, pytest | yappi, else `py-spy record`, else cProfile (see below) | All |
| JVM | configurations that start `java`, such as Application and JAR Application | async-profiler agent (set through `JAVA_TOOL_OPTIONS`) | macOS, Linux |
| Rust | `cargo run` | `perf record -g` | Linux |
| Native programs | native configurations | `perf record -g` | Linux |
Setting up the profilers:
- **yappi**: when the run's interpreter can import it, Profile uses it (Settings › Python › Profiler › Automatic). It profiles every thread on the wall clock, so a coroutine's time includes its awaits, and the snapshot has a thread selector: **All threads merged** or one thread (the 64 busiest are listed). On the wall clock a thread that only waits counts as busy and threads overlap, so merged times can exceed the run's duration. Choosing yappi when it is missing offers `python -m pip install yappi`.
- **py-spy**: the IDE looks next to the project's interpreter first, then on the search path. Without a package manager it offers `python -m pip install py-spy`.
- **async-profiler**: unpack a release from [async-profiler releases](https://github.com/async-profiler/async-profiler/releases) and put its `bin/asprof` on the `PATH`, or set `ASYNC_PROFILER_HOME` to the unpacked folder. The IDE cannot install it for you.
- **perf**: install your distribution's `linux-tools` / `linux-perf` package.
Not supported: Bun and Deno programs, JVM programs on Windows, native programs and `cargo run` on macOS and Windows, and Maven or Gradle configurations.
## Profile Python allocations
On macOS and Linux, **Profile '…' Allocations** runs a Python script, module or pytest configuration with [memray](https://github.com/bloomberg/memray) tracking its memory allocations. memray has to be installed in the project's interpreter; when it is missing, the notification offers the command that installs it. memray does not run on Windows.
The snapshot shows what was allocated **at the moment memory use was highest**, by allocation stack, with sizes in bytes. Memory freed before that moment is not listed. Every Python object allocation is tracked, so the program runs slower than usual. Only the profiled process is tracked, not its child processes.
## Read the results
Each profiled run becomes a snapshot. The last five snapshots stay available as tabs in the Profiler tool window header. Each snapshot has three views:
| View | What it shows |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Flame Graph** | Call stacks stacked from the root down; wider frames took more time. Click a frame to zoom into it, use **Reset Zoom** to go back. Hover a frame for its total and self weight. |
| **Call Tree** | The same stacks as an expandable tree, heaviest calls first. |
| **Method List** | One row per function with its self and total weight. Click the **Self**, **Total** or **Method** column header to sort. |
Double-click a frame or a row to open its source location. Type in **Search frames** in the header to highlight matching frames in the flame graph and filter the method list.
Snapshots are kept only for the current session; they are cleared when you switch projects or close the window.