Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 440d703

Browse files
committed
Issue #29109: Enhance tracemalloc documentation
* Wrong parameter name, 'group_by' instead of 'key_type' * Don't round up numbers when explaining the examples. If they exactly match what can be read in the script output, it is to easier to understand (4.8 MiB vs 4855 KiB) * Fix incorrect method link that was pointing to another module Patch written by Loic Pefferkorn.
1 parent 74b1bcc commit 440d703

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

Doc/library/tracemalloc.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Example of output of the Python test suite::
6666
<string>:5: size=49.7 KiB, count=148, average=344 B
6767
/usr/lib/python3.4/sysconfig.py:411: size=48.0 KiB, count=1, average=48.0 KiB
6868

69-
We can see that Python loaded ``4.8 MiB`` data (bytecode and constants) from
69+
We can see that Python loaded ``4855 KiB`` data (bytecode and constants) from
7070
modules and that the :mod:`collections` module allocated ``244 KiB`` to build
7171
:class:`~collections.namedtuple` types.
7272

@@ -106,8 +106,8 @@ Example of output before/after running some tests of the Python test suite::
106106
/usr/lib/python3.4/urllib/parse.py:476: size=71.8 KiB (+71.8 KiB), count=969 (+969), average=76 B
107107
/usr/lib/python3.4/contextlib.py:38: size=67.2 KiB (+67.2 KiB), count=126 (+126), average=546 B
108108

109-
We can see that Python has loaded ``8.2 MiB`` of module data (bytecode and
110-
constants), and that this is ``4.4 MiB`` more than had been loaded before the
109+
We can see that Python has loaded ``8173 KiB`` of module data (bytecode and
110+
constants), and that this is ``4428 KiB`` more than had been loaded before the
111111
tests, when the previous snapshot was taken. Similarly, the :mod:`linecache`
112112
module has cached ``940 KiB`` of Python source code to format tracebacks, all
113113
of it since the previous snapshot.
@@ -176,7 +176,7 @@ Example of output of the Python test suite (traceback limited to 25 frames)::
176176
"__main__", fname, loader, pkg_name)
177177

178178
We can see that the most memory was allocated in the :mod:`importlib` module to
179-
load data (bytecode and constants) from modules: ``870 KiB``. The traceback is
179+
load data (bytecode and constants) from modules: ``870.1 KiB``. The traceback is
180180
where the :mod:`importlib` loaded data most recently: on the ``import pdb``
181181
line of the :mod:`doctest` module. The traceback may change if a new module is
182182
loaded.
@@ -192,12 +192,12 @@ ignoring ``<frozen importlib._bootstrap>`` and ``<unknown>`` files::
192192
import os
193193
import tracemalloc
194194

195-
def display_top(snapshot, group_by='lineno', limit=10):
195+
def display_top(snapshot, key_type='lineno', limit=10):
196196
snapshot = snapshot.filter_traces((
197197
tracemalloc.Filter(False, "<frozen importlib._bootstrap>"),
198198
tracemalloc.Filter(False, "<unknown>"),
199199
))
200-
top_stats = snapshot.statistics(group_by)
200+
top_stats = snapshot.statistics(key_type)
201201

202202
print("Top %s lines" % limit)
203203
for index, stat in enumerate(top_stats[:limit], 1):
@@ -438,12 +438,12 @@ Snapshot
438438

439439
The :func:`take_snapshot` function creates a snapshot instance.
440440

441-
.. method:: compare_to(old_snapshot: Snapshot, group_by: str, cumulative: bool=False)
441+
.. method:: compare_to(old_snapshot: Snapshot, key_type: str, cumulative: bool=False)
442442

443443
Compute the differences with an old snapshot. Get statistics as a sorted
444-
list of :class:`StatisticDiff` instances grouped by *group_by*.
444+
list of :class:`StatisticDiff` instances grouped by *key_type*.
445445

446-
See the :meth:`Snapshot.statistics` method for *group_by* and *cumulative*
446+
See the :meth:`Snapshot.statistics` method for *key_type* and *cumulative*
447447
parameters.
448448

449449
The result is sorted from the biggest to the smallest by: absolute value
@@ -478,13 +478,13 @@ Snapshot
478478
See also :meth:`dump`.
479479

480480

481-
.. method:: statistics(group_by: str, cumulative: bool=False)
481+
.. method:: statistics(key_type: str, cumulative: bool=False)
482482

483483
Get statistics as a sorted list of :class:`Statistic` instances grouped
484-
by *group_by*:
484+
by *key_type*:
485485

486486
===================== ========================
487-
group_by description
487+
key_type description
488488
===================== ========================
489489
``'filename'`` filename
490490
``'lineno'`` filename and line number
@@ -493,7 +493,7 @@ Snapshot
493493

494494
If *cumulative* is ``True``, cumulate size and count of memory blocks of
495495
all frames of the traceback of a trace, not only the most recent frame.
496-
The cumulative mode can only be used with *group_by* equals to
496+
The cumulative mode can only be used with *key_type* equals to
497497
``'filename'`` and ``'lineno'``.
498498

499499
The result is sorted from the biggest to the smallest by:

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,7 @@ Alecsandru Patrascu
11271127
Randy Pausch
11281128
Samuele Pedroni
11291129
Justin Peel
1130+
Loic Pefferkorn
11301131
Marcel van der Peijl
11311132
Berker Peksag
11321133
Andreas Pelme

0 commit comments

Comments
 (0)