Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions Doc/c-api/arg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,14 @@ There are three ways strings and buffers can be converted to C:
``z`` (:class:`str` or ``None``) [const char \*]
Like ``s``, but the Python object may also be ``None``, in which case the C
pointer is set to ``NULL``.
It is the same as ``s?`` with the C pointer was initialized to ``NULL``.

``z*`` (:class:`str`, :term:`bytes-like object` or ``None``) [Py_buffer]
Like ``s*``, but the Python object may also be ``None``, in which case the
``buf`` member of the :c:type:`Py_buffer` structure is set to ``NULL``.
It is the same as ``s*?`` with the ``buf`` member of the :c:type:`Py_buffer`
structure was initialized to ``NULL``.

``z#`` (:class:`str`, read-only :term:`bytes-like object` or ``None``) [const char \*, :c:type:`Py_ssize_t`]
Like ``s#``, but the Python object may also be ``None``, in which case the C
pointer is set to ``NULL``.
It is the same as ``s#?`` with the C pointer was initialized to ``NULL``.

``y`` (read-only :term:`bytes-like object`) [const char \*]
This format converts a bytes-like object to a C pointer to a
Expand Down Expand Up @@ -394,17 +390,6 @@ Other objects
Non-tuple sequences are deprecated if *items* contains format units
which store a borrowed buffer or a borrowed reference.

``unit?`` (anything or ``None``) [*matching-variable(s)*]
``?`` modifies the behavior of the preceding format unit.
The C variable(s) corresponding to that parameter should be initialized
to their default value --- when the argument is ``None``,
:c:func:`PyArg_ParseTuple` does not touch the contents of the corresponding
C variable(s).
If the argument is not ``None``, it is parsed according to the specified
format unit.

.. versionadded:: 3.14

A few other characters have a meaning in a format string. These may not occur
inside nested parentheses. They are:

Expand Down
9 changes: 5 additions & 4 deletions Doc/c-api/perfmaps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
Support for Perf Maps
----------------------

On supported platforms (as of this writing, only Linux), the runtime can take
On supported platforms (Linux and macOS), the runtime can take
advantage of *perf map files* to make Python functions visible to an external
profiling tool (such as `perf <https://perf.wiki.kernel.org/index.php/Main_Page>`_).
A running process may create a file in the ``/tmp`` directory, which contains entries
that can map a section of executable code to a name. This interface is described in the
profiling tool (such as `perf <https://perf.wiki.kernel.org/index.php/Main_Page>`_ or
`samply <https://github.com/mstange/samply/>`_). A running process may create a
file in the ``/tmp`` directory, which contains entries that can map a section
of executable code to a name. This interface is described in the
`documentation of the Linux Perf tool <https://git.kernel.org/pub/scm/linux/
kernel/git/torvalds/linux.git/tree/tools/perf/Documentation/jit-interface.txt>`_.

Expand Down
56 changes: 41 additions & 15 deletions Doc/howto/perf_profiling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,35 @@

.. _perf_profiling:

==============================================
Python support for the Linux ``perf`` profiler
==============================================
========================================================
Python support for the ``perf map`` compatible profilers
========================================================

:author: Pablo Galindo

`The Linux perf profiler <https://perf.wiki.kernel.org>`_
is a very powerful tool that allows you to profile and obtain
information about the performance of your application.
``perf`` also has a very vibrant ecosystem of tools
that aid with the analysis of the data that it produces.
`The Linux perf profiler <https://perf.wiki.kernel.org>`_ and
`samply <https://github.com/mstange/samply>`_ are powerful tools that allow you to
profile and obtain information about the performance of your application.
Both tools have vibrant ecosystems that aid with the analysis of the data they produce.

The main problem with using the ``perf`` profiler with Python applications is that
``perf`` only gets information about native symbols, that is, the names of
The main problem with using these profilers with Python applications is that
they only get information about native symbols, that is, the names of
functions and procedures written in C. This means that the names and file names
of Python functions in your code will not appear in the output of ``perf``.
of Python functions in your code will not appear in the profiler output.

Since Python 3.12, the interpreter can run in a special mode that allows Python
functions to appear in the output of the ``perf`` profiler. When this mode is
functions to appear in the output of compatible profilers. When this mode is
enabled, the interpreter will interpose a small piece of code compiled on the
fly before the execution of every Python function and it will teach ``perf`` the
fly before the execution of every Python function and it will teach the profiler the
relationship between this piece of code and the associated Python function using
:doc:`perf map files <../c-api/perfmaps>`.

.. note::

Support for the ``perf`` profiler is currently only available for Linux on
select architectures. Check the output of the ``configure`` build step or
Support for profiling is available on Linux and macOS on select architectures.
Perf is available on Linux, while samply can be used on both Linux and macOS.
samply support on macOS is available starting from Python 3.15.
Check the output of the ``configure`` build step or
check the output of ``python -m sysconfig | grep HAVE_PERF_TRAMPOLINE``
to see if your system is supported.

Expand Down Expand Up @@ -148,6 +149,31 @@ Instead, if we run the same experiment with ``perf`` support enabled we get:



Using the samply profiler
-------------------------

samply is a modern profiler that can be used as an alternative to perf.
It uses the same perf map files that Python generates, making it compatible
with Python's profiling support. samply is particularly useful on macOS
where perf is not available.

To use samply with Python, first install it following the instructions at
https://github.com/mstange/samply, then run::

$ samply record PYTHONPERFSUPPORT=1 python my_script.py

This will open a web interface where you can analyze the profiling data
interactively. The advantage of samply is that it provides a modern
web-based interface for analyzing profiling data and works on both Linux
and macOS.

On macOS, samply support requires Python 3.15 or later. Also on macOS, samply
can't profile signed Python executables due to restrictions by macOS. You can
profile with Python binaries that you've compiled yourself, or which are
unsigned or locally-signed (such as anything installed by Homebrew). In
order to attach to running processes on macOS, run ``samply setup`` once (and
every time samply is updated) to self-sign the samply binary.

How to enable ``perf`` profiling support
----------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/annotationlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ code execution even with no access to any globals or builtins. For example:

>>> def f(x: (1).__class__.__base__.__subclasses__()[-1].__init__.__builtins__["print"]("Hello world")): pass
...
>>> annotationlib.get_annotations(f, format=annotationlib.Format.SOURCE)
>>> annotationlib.get_annotations(f, format=annotationlib.Format.STRING)
Hello world
{'x': 'None'}

Expand Down
18 changes: 9 additions & 9 deletions Doc/library/os.path.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ the :mod:`glob` module.)
Any iterable can now be passed, rather than just sequences.


.. function:: commonprefix(list)
.. function:: commonprefix(list, /)

Return the longest path prefix (taken character-by-character) that is a
prefix of all paths in *list*. If *list* is empty, return the empty string
Expand Down Expand Up @@ -199,14 +199,14 @@ the :mod:`glob` module.)
Accepts a :term:`path-like object`.


.. function:: getatime(path)
.. function:: getatime(path, /)

Return the time of last access of *path*. The return value is a floating-point number giving
the number of seconds since the epoch (see the :mod:`time` module). Raise
:exc:`OSError` if the file does not exist or is inaccessible.


.. function:: getmtime(path)
.. function:: getmtime(path, /)

Return the time of last modification of *path*. The return value is a floating-point number
giving the number of seconds since the epoch (see the :mod:`time` module).
Expand All @@ -216,7 +216,7 @@ the :mod:`glob` module.)
Accepts a :term:`path-like object`.


.. function:: getctime(path)
.. function:: getctime(path, /)

Return the system's ctime which, on some systems (like Unix) is the time of the
last metadata change, and, on others (like Windows), is the creation time for *path*.
Expand All @@ -228,7 +228,7 @@ the :mod:`glob` module.)
Accepts a :term:`path-like object`.


.. function:: getsize(path)
.. function:: getsize(path, /)

Return the size, in bytes, of *path*. Raise :exc:`OSError` if the file does
not exist or is inaccessible.
Expand Down Expand Up @@ -351,7 +351,7 @@ the :mod:`glob` module.)
.. versionadded:: 3.13


.. function:: join(path, *paths)
.. function:: join(path, /, *paths)

Join one or more path segments intelligently. The return value is the
concatenation of *path* and all members of *\*paths*, with exactly one
Expand Down Expand Up @@ -402,7 +402,7 @@ the :mod:`glob` module.)
Accepts a :term:`path-like object`.


.. function:: realpath(path, *, strict=False)
.. function:: realpath(path, /, *, strict=False)

Return the canonical path of the specified filename, eliminating any symbolic
links encountered in the path (if they are supported by the operating
Expand Down Expand Up @@ -471,7 +471,7 @@ the :mod:`glob` module.)
Accepts a :term:`path-like object`.


.. function:: samefile(path1, path2)
.. function:: samefile(path1, path2, /)

Return ``True`` if both pathname arguments refer to the same file or directory.
This is determined by the device number and i-node number and raises an
Expand All @@ -498,7 +498,7 @@ the :mod:`glob` module.)
Accepts a :term:`path-like object`.


.. function:: samestat(stat1, stat2)
.. function:: samestat(stat1, stat2, /)

Return ``True`` if the stat tuples *stat1* and *stat2* refer to the same file.
These structures may have been returned by :func:`os.fstat`,
Expand Down
Loading
Loading