Tachyon: High frequency statistical sampling profiler
4 months ago
- #profiling
- #python
- #performance
- The profiling.sampling module (Tachyon) provides statistical profiling of Python programs through periodic stack sampling.
- Tachyon can run scripts directly or attach to any running Python process without requiring code changes or restarts.
- Statistical profiling builds a picture of program behavior by periodically capturing snapshots of the call stack.
- Time values in Tachyon's output are estimates derived from sample counts, not direct measurements.
- Statistical sampling is not ideal for very short scripts, exact call counts, or comparing small performance differences.
- Tachyon operates through three subcommands: run (launch and profile), attach (profile running process), and replay (convert binary profiles).
- The profiler supports multiple output formats including pstats, flame graphs, heatmaps, and Gecko format for Firefox Profiler.
- Sampling can be configured with options like interval, duration, thread selection, and blocking mode.
- Four profiling modes are available: wall-clock, CPU, GIL, and exception modes.
- Async-aware profiling is available for asyncio programs, reconstructing call stacks based on task structure.