Tachyon¶
Tachyon is a new statistical sampling profiler that was added to Python 3.15 as
profiling.sampling. This profiler enables powerful analysis of running
Python processes with low overhead, without requiring code changes or a process
restart.
Unlike deterministic profilers such as profiling.tracing, which
instrument every function call, profiling.sampling regularly collects
stack traces from running processes.
Key features include:
- Profiling without overhead
profiling.samplingintegrates into any running Python process without affecting its performance. This is ideal for debugging in production environments where your application cannot be restarted or slowed down.- No code changes required
Existing applications can be profiled without restarting. Simply point the profiler at a running process using its PID and start collecting data.
- Profiles running processes or modules
attachprofiles running processes using their PID.
run -m MODULEruns modules and profiles them.
- Multiple profiling modes
You can choose what to measure:
--mode wallDefault value that measures the actual elapsed time, including I/O, network latency, and blocking operations. This is ideal for understanding where your programme is spending time, including waiting for external resources.
--mode cpumeasures only active CPU execution time, excluding I/O wait times and blocking. Use this option to identify CPU-bound bottlenecks and optimise computing power.
--mode gilmeasures the time spent on Python’s GIL. Use this option to determine which threads are being slowed down by the GIL.
--mode exceptiononly collects samples from threads with an active exception. Use this option to analyse the overhead of exception handling.
-aprofiles all threads or only the main thread, increasing understanding of the behaviour of multithreaded applications.
- Multiple output formats
Choose the visualisation that best suits your workflow:
--pstatsprovides detailed tabular statistics, compatible with
pstats. It displays timing at the function level with direct and cumulative samples and is best suited for detailed analysis and integration with existing Python profiling tools.--collapsedgenerates summarised stack traces. This format is specifically designed for creating flame graphs with external tools such as Brendan Gregg’s FlameGraph scripts or Speedscope.
--flamegraphgenerates a standalone interactive HTML flame graph using D3.js, which opens directly in your browser for immediate visual analysis.
--geckogenerates a Gecko profiler format that is compatible with Firefox Profiler. The output can be uploaded to Firefox Profiler to perform advanced timeline-based analysis with features such as bar charts, markers, and network activity.
--heatmaprgGenerates an interactive HTML heatmap visualisation and creates one heatmap per file, showing exactly where time is spent at the source code level.
--livetop-like interface, allowing you to monitor your application’s performance during execution with interactive sorting and filtering.
--async-awareProfiles async/await code, showing you which coroutines are consuming time. Additional options show you only running tasks or all tasks, including those that are waiting.
--opcodescollects bytecode opcode information for instruction-level profiling and shows which bytecode instructions are being executed, including specialisations from the adaptive interpreter.
See also