class tracemalloc.Snapshot
Snapshot of traces of memory blocks allocated by Python.
The take_snapshot()
function creates a snapshot instance.
-
compare_to(old_snapshot: Snapshot, group_by: str, cumulative: bool=False)
-
Compute the differences with an old snapshot. Get statistics as a sorted list of
StatisticDiff
instances grouped by group_by.See the
Snapshot.statistics()
method for group_by and cumulative parameters.The result is sorted from the biggest to the smallest by: absolute value of
StatisticDiff.size_diff
,StatisticDiff.size
, absolute value ofStatisticDiff.count_diff
,Statistic.count
and then byStatisticDiff.traceback
.
-
dump(filename)
-
Write the snapshot into a file.
Use
load()
to reload the snapshot.
-
filter_traces(filters)
-
Create a new
Snapshot
instance with a filteredtraces
sequence, filters is a list ofFilter
instances. If filters is an empty list, return a newSnapshot
instance with a copy of the traces.All inclusive filters are applied at once, a trace is ignored if no inclusive filters match it. A trace is ignored if at least one exclusive filter matches it.
-
classmethod load(filename)
-
Load a snapshot from a file.
See also
dump()
.
-
statistics(group_by: str, cumulative: bool=False)
-
Get statistics as a sorted list of
Statistic
instances grouped by group_by:group_by description 'filename'
filename 'lineno'
filename and line number 'traceback'
traceback If cumulative is
True
, cumulate size and count of memory blocks of all frames of the traceback of a trace, not only the most recent frame. The cumulative mode can only be used with group_by equals to'filename'
and'lineno'
.The result is sorted from the biggest to the smallest by:
Statistic.size
,Statistic.count
and then byStatistic.traceback
.
-
traceback_limit
-
Maximum number of frames stored in the traceback of
traces
: result of theget_traceback_limit()
when the snapshot was taken.
-
traces
-
Traces of all memory blocks allocated by Python: sequence of
Trace
instances.The sequence has an undefined order. Use the
Snapshot.statistics()
method to get a sorted list of statistics.
Please login to continue.