|
| 1 | +Tachyon |
| 2 | +======= |
| 3 | + |
| 4 | +Tachyon is a new statistical sampling profiler that was added to Python 3.15 as |
| 5 | +:mod:`profiling.sampling`. This profiler enables powerful analysis of running |
| 6 | +Python processes with low overhead, without requiring code changes or a process |
| 7 | +restart. |
| 8 | + |
| 9 | +Unlike deterministic profilers such as :mod:`profiling.tracing`, which |
| 10 | +instrument every function call, :mod:`profiling.sampling` regularly collects |
| 11 | +stack traces from running processes. |
| 12 | + |
| 13 | +Key features include: |
| 14 | + |
| 15 | +Profiling without overhead |
| 16 | + :mod:`profiling.sampling` integrates into any running Python process without |
| 17 | + affecting its performance. This is ideal for debugging in production |
| 18 | + environments where your application cannot be restarted or slowed down. |
| 19 | +No code changes required |
| 20 | + Existing applications can be profiled without restarting. Simply point the |
| 21 | + profiler at a running process using its PID and start collecting data. |
| 22 | +Profiles running processes or modules |
| 23 | + :samp:`attach` |
| 24 | + profiles running processes using their PID. |
| 25 | + :samp:`run -m {MODULE}` |
| 26 | + runs modules and profiles them. |
| 27 | +Multiple profiling modes |
| 28 | + You can choose what to measure: |
| 29 | + |
| 30 | + ``--mode wall`` |
| 31 | + Default value that measures the actual elapsed time, including I/O, |
| 32 | + network latency, and blocking operations. This is ideal for |
| 33 | + understanding where your programme is spending time, including waiting |
| 34 | + for external resources. |
| 35 | + ``--mode cpu`` |
| 36 | + measures only active CPU execution time, excluding I/O wait times and |
| 37 | + blocking. Use this option to identify CPU-bound bottlenecks and optimise |
| 38 | + computing power. |
| 39 | + ``--mode gil`` |
| 40 | + measures the time spent on Python’s :abbr:`GIL (Global Interpreter |
| 41 | + Lock)`. Use this option to determine which threads are being slowed down |
| 42 | + by the GIL. |
| 43 | + ``--mode exception`` |
| 44 | + only collects samples from threads with an active exception. Use this |
| 45 | + option to analyse the overhead of exception handling. |
| 46 | + ``-a`` |
| 47 | + profiles all threads or only the main thread, increasing understanding |
| 48 | + of the behaviour of multithreaded applications. |
| 49 | + |
| 50 | +Multiple output formats |
| 51 | + Choose the visualisation that best suits your workflow: |
| 52 | + |
| 53 | + ``--pstats`` |
| 54 | + provides detailed tabular statistics, compatible with :mod:`pstats`. It |
| 55 | + displays timing at the function level with direct and cumulative samples |
| 56 | + and is best suited for detailed analysis and integration with existing |
| 57 | + Python profiling tools. |
| 58 | + ``--collapsed`` |
| 59 | + generates summarised stack traces. This format is specifically designed |
| 60 | + for creating `flame graphs |
| 61 | + <https://www.brendangregg.com/flamegraphs.html>`_ with external tools |
| 62 | + such as `Brendan Gregg’s FlameGraph scripts |
| 63 | + <https://github.com/brendangregg/FlameGraph>`_ or `Speedscope |
| 64 | + <https://jamie-wong.com/post/speedscope/>`_. |
| 65 | + ``--flamegraph`` |
| 66 | + generates a standalone interactive HTML flame graph using `D3.js |
| 67 | + <https://d3js.org/>`_, which opens directly in your browser for |
| 68 | + immediate visual analysis. |
| 69 | + ``--gecko`` |
| 70 | + generates a Gecko profiler format that is compatible with `Firefox |
| 71 | + Profiler <https://profiler.firefox.com>`_. The output can be uploaded to |
| 72 | + Firefox Profiler to perform advanced timeline-based analysis with |
| 73 | + features such as bar charts, markers, and network activity. |
| 74 | + ``--heatmap`` |
| 75 | + rgGenerates an interactive HTML heatmap visualisation and creates one |
| 76 | + heatmap per file, showing exactly where time is spent at the source code |
| 77 | + level. |
| 78 | + |
| 79 | +``--live`` |
| 80 | + `top <https://man7.org/linux/man-pages/man1/top.1.html>`_-like interface, |
| 81 | + allowing you to monitor your application’s performance during execution with |
| 82 | + interactive sorting and filtering. |
| 83 | +``--async-aware`` |
| 84 | + Profiles :doc:`async/await code <asyncio-example>`, showing you which |
| 85 | + coroutines are consuming time. Additional options show you only running |
| 86 | + tasks or all tasks, including those that are waiting. |
| 87 | +``--opcodes`` |
| 88 | + collects bytecode opcode information for instruction-level profiling and |
| 89 | + shows which bytecode instructions are being executed, including |
| 90 | + specialisations from the adaptive interpreter. |
| 91 | + |
| 92 | +.. seealso:: |
| 93 | + :mod:`profiling.sampling` |
0 commit comments