For most performance analysis, use the statistical profiler
(:mod:`profiling.sampling`). It has minimal overhead, works for both development
-and production, and provides rich visualization options including flamegraphs,
+and production, and provides rich visualization options including flame graphs,
heatmaps, GIL analysis, and more.
Use the deterministic profiler (:mod:`profiling.tracing`) when you need **exact
+--------------------+------------------------------+------------------------------+
| **Accuracy** | Statistical estimate | Exact call counts |
+--------------------+------------------------------+------------------------------+
-| **Output formats** | pstats, flamegraph, heatmap, | pstats |
+| **Output formats** | pstats, flame graph, heatmap,| pstats |
| | gecko, collapsed | |
+--------------------+------------------------------+------------------------------+
| **Profiling modes**| Wall-clock, CPU, GIL | Wall-clock |
One of the main strengths of the sampling profiler is its variety of output
formats. Beyond traditional pstats tables, it can generate interactive
-flamegraphs that visualize call hierarchies, line-level source heatmaps that
+flame graphs that visualize call hierarchies, line-level source heatmaps that
show exactly where time is spent in your code, and Firefox Profiler output for
timeline-based analysis.
python -m profiling.sampling run -m mypackage.module
This runs the script under the profiler and prints a summary of where time was
-spent. For an interactive flamegraph::
+spent. For an interactive flame graph::
python -m profiling.sampling run --flamegraph script.py
Both profilers collect function-level statistics, though they present them in
different formats. The sampling profiler offers multiple visualizations
-(flamegraphs, heatmaps, Firefox Profiler, pstats tables), while the
+(flame graphs, heatmaps, Firefox Profiler, pstats tables), while the
deterministic profiler produces pstats-compatible output. Regardless of format,
the underlying concepts are the same.
**Caller/Callee relationships**
Which functions called a given function (callers) and which functions it
- called (callees). Flamegraphs visualize this as nested rectangles; pstats
+ called (callees). Flame graphs visualize this as nested rectangles; pstats
can display it via the :meth:`~pstats.Stats.print_callers` and
:meth:`~pstats.Stats.print_callees` methods.
.. seealso::
:mod:`profiling.sampling`
- Statistical sampling profiler with flamegraphs, heatmaps, and GIL analysis.
+ Statistical sampling profiler with flame graphs, heatmaps, and GIL analysis.
Recommended for most users.
:mod:`profiling.tracing`
* :pep:`799`: :ref:`A dedicated profiling package for organizing Python
profiling tools <whatsnew315-profiling-package>`
* :pep:`799`: :ref:`Tachyon: High frequency statistical sampling profiler
- profiling tools <whatsnew315-sampling-profiler>`
+ <whatsnew315-sampling-profiler>`
* :pep:`798`: :ref:`Unpacking in Comprehensions
<whatsnew315-unpacking-in-comprehensions>`
* :pep:`686`: :ref:`Python now uses UTF-8 as the default encoding
timing with direct and cumulative samples. Best for detailed analysis and integration with
existing Python profiling tools.
* ``--collapsed``: Generates collapsed stack traces (one line per stack). This format is
- specifically designed for creating flamegraphs with external tools like Brendan Gregg's
+ specifically designed for creating flame graphs with external tools like Brendan Gregg's
FlameGraph scripts or speedscope.
- * ``--flamegraph``: Generates a self-contained interactive HTML flamegraph using D3.js.
- Opens directly in your browser for immediate visual analysis. Flamegraphs show the call
+ * ``--flamegraph``: Generates a self-contained interactive HTML flame graph using D3.js.
+ Opens directly in your browser for immediate visual analysis. Flame graphs show the call
hierarchy where width represents time spent, making it easy to spot bottlenecks at a glance.
- * ``--gecko``: Generates Gecko Profiler format compatible with Firefox Profiler
- (https://profiler.firefox.com). Upload the output to Firefox Profiler for advanced
+ * ``--gecko``: Generates Gecko Profiler format compatible with `Firefox Profiler
+ <https://profiler.firefox.com>`__. Upload the output to Firefox Profiler for advanced
timeline-based analysis with features like stack charts, markers, and network activity.
* ``--heatmap``: Generates an interactive HTML heatmap visualization with line-level sample
counts. Creates a directory with per-file heatmaps showing exactly where time is spent
(Contributed by Pablo Galindo and László Kiss Kollár in :gh:`135953` and :gh:`138122`.)
+
.. _whatsnew315-unpacking-in-comprehensions:
:pep:`798`: Unpacking in Comprehensions
(Contributed by Adam Hartz in :gh:`143055`.)
+
.. _whatsnew315-improved-error-messages:
Improved error messages
making it a :term:`generic type`.
(Contributed by James Hilton-Balfe in :gh:`128335`.)
+
New modules
===========
inline code when color output is enabled.
(Contributed by Savannah Ostrowski in :gh:`142390`.)
+
base64
------
* Added the *ignorechars* parameter in :func:`~base64.b64decode`.
(Contributed by Serhiy Storchaka in :gh:`144001`.)
+
binascii
--------
between :class:`~collections.Counter` objects.
(Contributed by Raymond Hettinger in :gh:`138682`.)
+
collections.abc
---------------
(Contributed by Andrea Oliveri in :gh:`134004`.)
-
difflib
-------
mimetypes
---------
-* Add ``application/dicom`` MIME type for ``.dcm`` extension. (Contributed by Benedikt Johannes in :gh:`144217`.)
-* Add ``application/node`` MIME type for ``.cjs`` extension. (Contributed by John Franey in :gh:`140937`.)
+* Add ``application/dicom`` MIME type for ``.dcm`` extension.
+ (Contributed by Benedikt Johannes in :gh:`144217`.)
+* Add ``application/node`` MIME type for ``.cjs`` extension.
+ (Contributed by John Franey in :gh:`140937`.)
* Add ``application/toml``. (Contributed by Gil Forcada in :gh:`139959`.)
* Add ``image/jxl``. (Contributed by Foolbar in :gh:`144213`.)
* Rename ``application/x-texinfo`` to ``application/texinfo``.
* The :ref:`command-line interface <sqlite3-cli>` has several new features:
- * SQL keyword completion on <tab>.
- (Contributed by Long Tan in :gh:`133393`.)
+ * SQL keyword completion on <tab>.
+ (Contributed by Long Tan in :gh:`133393`.)
- * Prompts, error messages, and help text are now colored.
- This is enabled by default, see :ref:`using-on-controlling-color` for
- details.
- (Contributed by Stan Ulbrych and Łukasz Langa in :gh:`133461`.)
+ * Prompts, error messages, and help text are now colored.
+ This is enabled by default, see :ref:`using-on-controlling-color` for
+ details.
+ (Contributed by Stan Ulbrych and Łukasz Langa in :gh:`133461`.)
- * Table, index, trigger, view, column, function, and schema completion on <tab>.
- (Contributed by Long Tan in :gh:`136101`.)
+ * Table, index, trigger, view, column, function, and schema completion on <tab>.
+ (Contributed by Long Tan in :gh:`136101`.)
ssl
* Added new methods for managing groups used for SSL key agreement
- * :meth:`ssl.SSLContext.set_groups` sets the groups allowed for doing
- key agreement, extending the previous
- :meth:`ssl.SSLContext.set_ecdh_curve` method.
- This new API provides the ability to list multiple groups and
- supports fixed-field and post-quantum groups in addition to ECDH
- curves. This method can also be used to control what key shares
- are sent in the TLS handshake.
- * :meth:`ssl.SSLSocket.group` returns the group selected for doing key
- agreement on the current connection after the TLS handshake completes.
- This call requires OpenSSL 3.2 or later.
- * :meth:`ssl.SSLContext.get_groups` returns a list of all available key
- agreement groups compatible with the minimum and maximum TLS versions
- currently set in the context. This call requires OpenSSL 3.5 or later.
-
- (Contributed by Ron Frederick in :gh:`136306`.)
+ * :meth:`ssl.SSLContext.set_groups` sets the groups allowed for doing
+ key agreement, extending the previous
+ :meth:`ssl.SSLContext.set_ecdh_curve` method.
+ This new API provides the ability to list multiple groups and
+ supports fixed-field and post-quantum groups in addition to ECDH
+ curves. This method can also be used to control what key shares
+ are sent in the TLS handshake.
+ * :meth:`ssl.SSLSocket.group` returns the group selected for doing key
+ agreement on the current connection after the TLS handshake completes.
+ This call requires OpenSSL 3.2 or later.
+ * :meth:`ssl.SSLContext.get_groups` returns a list of all available key
+ agreement groups compatible with the minimum and maximum TLS versions
+ currently set in the context. This call requires OpenSSL 3.5 or later.
+
+ (Contributed by Ron Frederick in :gh:`136306`.)
* Added a new method :meth:`ssl.SSLContext.set_ciphersuites` for setting TLS 1.3
ciphers. For TLS 1.2 or earlier, :meth:`ssl.SSLContext.set_ciphers` should
selected for the server to complete the TLS handshake on the current
connection. This call requires OpenSSL 3.5 or later.
- (Contributed by Ron Frederick in :gh:`138252`.)
+ (Contributed by Ron Frederick in :gh:`138252`.)
+
subprocess
----------
traditional busy loop (non-blocking call and short sleeps).
(Contributed by Giampaolo Rodola in :gh:`83069`).
+
symtable
--------
arguments: *nolinestop* which allows the search to
continue across line boundaries;
and *strictlimits* which restricts the search to within the specified range.
- (Contributed by Rihaan Meher in :gh:`130848`)
+ (Contributed by Rihaan Meher in :gh:`130848`.)
* A new method :meth:`!tkinter.Text.search_all` has been introduced.
This method allows for searching for all matches of a pattern
using Tcl's ``-all`` and ``-overlap`` options.
- (Contributed by Rihaan Meher in :gh:`130848`)
+ (Contributed by Rihaan Meher in :gh:`130848`.)
* Added new methods :meth:`!pack_content`, :meth:`!place_content` and
:meth:`!grid_content` which use Tk commands with new names (introduced
in Tk 8.6) instead of :meth:`!*_slaves` methods which use Tk commands
with outdated names.
- (Contributed by Serhiy Storchaka in :gh:`143754`)
+ (Contributed by Serhiy Storchaka in :gh:`143754`.)
.. _whatsnew315-tomllib-1-1-0:
(Contributed by Chris Eibl, Ken Jin, and Brandt Bucher in :gh:`143068`.
Special thanks to the MSVC team including Hulon Jenkins.)
+
base64 & binascii
-----------------
two orders of magnitude less memory.
(Contributed by James Seo and Serhiy Storchaka in :gh:`101178`.)
+
csv
---
* Removed deprecated ``package`` parameter
from :func:`importlib.resources.files` function.
- (Contributed by Semyon Moroz in :gh:`138044`)
+ (Contributed by Semyon Moroz in :gh:`138044`.)
pathlib
* If the :c:macro:`Py_TPFLAGS_MANAGED_DICT` or :c:macro:`Py_TPFLAGS_MANAGED_WEAKREF`
flag is set then :c:macro:`Py_TPFLAGS_HAVE_GC` must be set too.
- (Contributed by Sergey Miryanov in :gh:`134786`)
+ (Contributed by Sergey Miryanov in :gh:`134786`.)
Porting to Python 3.15
:manpage:`PR_SET_VMA_ANON_NAME <PR_SET_VMA(2const)>` (Linux 5.17 or newer).
Annotations are visible in ``/proc/<pid>/maps`` if the kernel supports the feature
and :option:`-X dev <-X>` is passed to the Python or Python is built in :ref:`debug mode <debug-build>`.
- (Contributed by Donghee Na in :gh:`141770`)
+ (Contributed by Donghee Na in :gh:`141770`.)
Porting to Python 3.15