bpo-37961, tracemalloc: add Traceback.total_nframe (GH-15545)

Add a total_nframe field to the traces collected by the tracemalloc module.
This field indicates the original number of frames before it was truncated.
This commit is contained in:
Julien Danjou 2019-10-15 14:00:16 +02:00 committed by Victor Stinner
parent f3ef06a7cb
commit 8d59eb1b66
5 changed files with 114 additions and 64 deletions

View file

@ -313,6 +313,9 @@ Functions
frames. By default, a trace of a memory block only stores the most recent
frame: the limit is ``1``. *nframe* must be greater or equal to ``1``.
You can still read the original number of total frames that composed the
traceback by looking at the :attr:`Traceback.total_nframe` attribute.
Storing more than ``1`` frame is only useful to compute statistics grouped
by ``'traceback'`` or to compute cumulative statistics: see the
:meth:`Snapshot.compare_to` and :meth:`Snapshot.statistics` methods.
@ -659,6 +662,9 @@ Traceback
When a snapshot is taken, tracebacks of traces are limited to
:func:`get_traceback_limit` frames. See the :func:`take_snapshot` function.
The original number of frames of the traceback is stored in the
:attr:`Traceback.total_nframe` attribute. That allows to know if a traceback
has been truncated by the traceback limit.
The :attr:`Trace.traceback` attribute is an instance of :class:`Traceback`
instance.
@ -666,6 +672,15 @@ Traceback
.. versionchanged:: 3.7
Frames are now sorted from the oldest to the most recent, instead of most recent to oldest.
.. attribute:: total_nframe
Total number of frames that composed the traceback before truncation.
This attribute can be set to ``None`` if the information is not
available.
.. versionchanged:: 3.9
The :attr:`Traceback.total_nframe` attribute was added.
.. method:: format(limit=None, most_recent_first=False)
Format the traceback as a list of lines with newlines. Use the