Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../usr/lib64/python3....
File: tracemalloc.py
from collections import Sequence, Iterable
[0] Fix | Delete
from functools import total_ordering
[1] Fix | Delete
import fnmatch
[2] Fix | Delete
import linecache
[3] Fix | Delete
import os.path
[4] Fix | Delete
import pickle
[5] Fix | Delete
[6] Fix | Delete
# Import types and functions implemented in C
[7] Fix | Delete
from _tracemalloc import *
[8] Fix | Delete
from _tracemalloc import _get_object_traceback, _get_traces
[9] Fix | Delete
[10] Fix | Delete
[11] Fix | Delete
def _format_size(size, sign):
[12] Fix | Delete
for unit in ('B', 'KiB', 'MiB', 'GiB', 'TiB'):
[13] Fix | Delete
if abs(size) < 100 and unit != 'B':
[14] Fix | Delete
# 3 digits (xx.x UNIT)
[15] Fix | Delete
if sign:
[16] Fix | Delete
return "%+.1f %s" % (size, unit)
[17] Fix | Delete
else:
[18] Fix | Delete
return "%.1f %s" % (size, unit)
[19] Fix | Delete
if abs(size) < 10 * 1024 or unit == 'TiB':
[20] Fix | Delete
# 4 or 5 digits (xxxx UNIT)
[21] Fix | Delete
if sign:
[22] Fix | Delete
return "%+.0f %s" % (size, unit)
[23] Fix | Delete
else:
[24] Fix | Delete
return "%.0f %s" % (size, unit)
[25] Fix | Delete
size /= 1024
[26] Fix | Delete
[27] Fix | Delete
[28] Fix | Delete
class Statistic:
[29] Fix | Delete
"""
[30] Fix | Delete
Statistic difference on memory allocations between two Snapshot instance.
[31] Fix | Delete
"""
[32] Fix | Delete
[33] Fix | Delete
__slots__ = ('traceback', 'size', 'count')
[34] Fix | Delete
[35] Fix | Delete
def __init__(self, traceback, size, count):
[36] Fix | Delete
self.traceback = traceback
[37] Fix | Delete
self.size = size
[38] Fix | Delete
self.count = count
[39] Fix | Delete
[40] Fix | Delete
def __hash__(self):
[41] Fix | Delete
return hash((self.traceback, self.size, self.count))
[42] Fix | Delete
[43] Fix | Delete
def __eq__(self, other):
[44] Fix | Delete
return (self.traceback == other.traceback
[45] Fix | Delete
and self.size == other.size
[46] Fix | Delete
and self.count == other.count)
[47] Fix | Delete
[48] Fix | Delete
def __str__(self):
[49] Fix | Delete
text = ("%s: size=%s, count=%i"
[50] Fix | Delete
% (self.traceback,
[51] Fix | Delete
_format_size(self.size, False),
[52] Fix | Delete
self.count))
[53] Fix | Delete
if self.count:
[54] Fix | Delete
average = self.size / self.count
[55] Fix | Delete
text += ", average=%s" % _format_size(average, False)
[56] Fix | Delete
return text
[57] Fix | Delete
[58] Fix | Delete
def __repr__(self):
[59] Fix | Delete
return ('<Statistic traceback=%r size=%i count=%i>'
[60] Fix | Delete
% (self.traceback, self.size, self.count))
[61] Fix | Delete
[62] Fix | Delete
def _sort_key(self):
[63] Fix | Delete
return (self.size, self.count, self.traceback)
[64] Fix | Delete
[65] Fix | Delete
[66] Fix | Delete
class StatisticDiff:
[67] Fix | Delete
"""
[68] Fix | Delete
Statistic difference on memory allocations between an old and a new
[69] Fix | Delete
Snapshot instance.
[70] Fix | Delete
"""
[71] Fix | Delete
__slots__ = ('traceback', 'size', 'size_diff', 'count', 'count_diff')
[72] Fix | Delete
[73] Fix | Delete
def __init__(self, traceback, size, size_diff, count, count_diff):
[74] Fix | Delete
self.traceback = traceback
[75] Fix | Delete
self.size = size
[76] Fix | Delete
self.size_diff = size_diff
[77] Fix | Delete
self.count = count
[78] Fix | Delete
self.count_diff = count_diff
[79] Fix | Delete
[80] Fix | Delete
def __hash__(self):
[81] Fix | Delete
return hash((self.traceback, self.size, self.size_diff,
[82] Fix | Delete
self.count, self.count_diff))
[83] Fix | Delete
[84] Fix | Delete
def __eq__(self, other):
[85] Fix | Delete
return (self.traceback == other.traceback
[86] Fix | Delete
and self.size == other.size
[87] Fix | Delete
and self.size_diff == other.size_diff
[88] Fix | Delete
and self.count == other.count
[89] Fix | Delete
and self.count_diff == other.count_diff)
[90] Fix | Delete
[91] Fix | Delete
def __str__(self):
[92] Fix | Delete
text = ("%s: size=%s (%s), count=%i (%+i)"
[93] Fix | Delete
% (self.traceback,
[94] Fix | Delete
_format_size(self.size, False),
[95] Fix | Delete
_format_size(self.size_diff, True),
[96] Fix | Delete
self.count,
[97] Fix | Delete
self.count_diff))
[98] Fix | Delete
if self.count:
[99] Fix | Delete
average = self.size / self.count
[100] Fix | Delete
text += ", average=%s" % _format_size(average, False)
[101] Fix | Delete
return text
[102] Fix | Delete
[103] Fix | Delete
def __repr__(self):
[104] Fix | Delete
return ('<StatisticDiff traceback=%r size=%i (%+i) count=%i (%+i)>'
[105] Fix | Delete
% (self.traceback, self.size, self.size_diff,
[106] Fix | Delete
self.count, self.count_diff))
[107] Fix | Delete
[108] Fix | Delete
def _sort_key(self):
[109] Fix | Delete
return (abs(self.size_diff), self.size,
[110] Fix | Delete
abs(self.count_diff), self.count,
[111] Fix | Delete
self.traceback)
[112] Fix | Delete
[113] Fix | Delete
[114] Fix | Delete
def _compare_grouped_stats(old_group, new_group):
[115] Fix | Delete
statistics = []
[116] Fix | Delete
for traceback, stat in new_group.items():
[117] Fix | Delete
previous = old_group.pop(traceback, None)
[118] Fix | Delete
if previous is not None:
[119] Fix | Delete
stat = StatisticDiff(traceback,
[120] Fix | Delete
stat.size, stat.size - previous.size,
[121] Fix | Delete
stat.count, stat.count - previous.count)
[122] Fix | Delete
else:
[123] Fix | Delete
stat = StatisticDiff(traceback,
[124] Fix | Delete
stat.size, stat.size,
[125] Fix | Delete
stat.count, stat.count)
[126] Fix | Delete
statistics.append(stat)
[127] Fix | Delete
[128] Fix | Delete
for traceback, stat in old_group.items():
[129] Fix | Delete
stat = StatisticDiff(traceback, 0, -stat.size, 0, -stat.count)
[130] Fix | Delete
statistics.append(stat)
[131] Fix | Delete
return statistics
[132] Fix | Delete
[133] Fix | Delete
[134] Fix | Delete
@total_ordering
[135] Fix | Delete
class Frame:
[136] Fix | Delete
"""
[137] Fix | Delete
Frame of a traceback.
[138] Fix | Delete
"""
[139] Fix | Delete
__slots__ = ("_frame",)
[140] Fix | Delete
[141] Fix | Delete
def __init__(self, frame):
[142] Fix | Delete
# frame is a tuple: (filename: str, lineno: int)
[143] Fix | Delete
self._frame = frame
[144] Fix | Delete
[145] Fix | Delete
@property
[146] Fix | Delete
def filename(self):
[147] Fix | Delete
return self._frame[0]
[148] Fix | Delete
[149] Fix | Delete
@property
[150] Fix | Delete
def lineno(self):
[151] Fix | Delete
return self._frame[1]
[152] Fix | Delete
[153] Fix | Delete
def __eq__(self, other):
[154] Fix | Delete
return (self._frame == other._frame)
[155] Fix | Delete
[156] Fix | Delete
def __lt__(self, other):
[157] Fix | Delete
return (self._frame < other._frame)
[158] Fix | Delete
[159] Fix | Delete
def __hash__(self):
[160] Fix | Delete
return hash(self._frame)
[161] Fix | Delete
[162] Fix | Delete
def __str__(self):
[163] Fix | Delete
return "%s:%s" % (self.filename, self.lineno)
[164] Fix | Delete
[165] Fix | Delete
def __repr__(self):
[166] Fix | Delete
return "<Frame filename=%r lineno=%r>" % (self.filename, self.lineno)
[167] Fix | Delete
[168] Fix | Delete
[169] Fix | Delete
@total_ordering
[170] Fix | Delete
class Traceback(Sequence):
[171] Fix | Delete
"""
[172] Fix | Delete
Sequence of Frame instances sorted from the most recent frame
[173] Fix | Delete
to the oldest frame.
[174] Fix | Delete
"""
[175] Fix | Delete
__slots__ = ("_frames",)
[176] Fix | Delete
[177] Fix | Delete
def __init__(self, frames):
[178] Fix | Delete
Sequence.__init__(self)
[179] Fix | Delete
# frames is a tuple of frame tuples: see Frame constructor for the
[180] Fix | Delete
# format of a frame tuple
[181] Fix | Delete
self._frames = frames
[182] Fix | Delete
[183] Fix | Delete
def __len__(self):
[184] Fix | Delete
return len(self._frames)
[185] Fix | Delete
[186] Fix | Delete
def __getitem__(self, index):
[187] Fix | Delete
if isinstance(index, slice):
[188] Fix | Delete
return tuple(Frame(trace) for trace in self._frames[index])
[189] Fix | Delete
else:
[190] Fix | Delete
return Frame(self._frames[index])
[191] Fix | Delete
[192] Fix | Delete
def __contains__(self, frame):
[193] Fix | Delete
return frame._frame in self._frames
[194] Fix | Delete
[195] Fix | Delete
def __hash__(self):
[196] Fix | Delete
return hash(self._frames)
[197] Fix | Delete
[198] Fix | Delete
def __eq__(self, other):
[199] Fix | Delete
return (self._frames == other._frames)
[200] Fix | Delete
[201] Fix | Delete
def __lt__(self, other):
[202] Fix | Delete
return (self._frames < other._frames)
[203] Fix | Delete
[204] Fix | Delete
def __str__(self):
[205] Fix | Delete
return str(self[0])
[206] Fix | Delete
[207] Fix | Delete
def __repr__(self):
[208] Fix | Delete
return "<Traceback %r>" % (tuple(self),)
[209] Fix | Delete
[210] Fix | Delete
def format(self, limit=None):
[211] Fix | Delete
lines = []
[212] Fix | Delete
if limit is not None and limit < 0:
[213] Fix | Delete
return lines
[214] Fix | Delete
for frame in self[:limit]:
[215] Fix | Delete
lines.append(' File "%s", line %s'
[216] Fix | Delete
% (frame.filename, frame.lineno))
[217] Fix | Delete
line = linecache.getline(frame.filename, frame.lineno).strip()
[218] Fix | Delete
if line:
[219] Fix | Delete
lines.append(' %s' % line)
[220] Fix | Delete
return lines
[221] Fix | Delete
[222] Fix | Delete
[223] Fix | Delete
def get_object_traceback(obj):
[224] Fix | Delete
"""
[225] Fix | Delete
Get the traceback where the Python object *obj* was allocated.
[226] Fix | Delete
Return a Traceback instance.
[227] Fix | Delete
[228] Fix | Delete
Return None if the tracemalloc module is not tracing memory allocations or
[229] Fix | Delete
did not trace the allocation of the object.
[230] Fix | Delete
"""
[231] Fix | Delete
frames = _get_object_traceback(obj)
[232] Fix | Delete
if frames is not None:
[233] Fix | Delete
return Traceback(frames)
[234] Fix | Delete
else:
[235] Fix | Delete
return None
[236] Fix | Delete
[237] Fix | Delete
[238] Fix | Delete
class Trace:
[239] Fix | Delete
"""
[240] Fix | Delete
Trace of a memory block.
[241] Fix | Delete
"""
[242] Fix | Delete
__slots__ = ("_trace",)
[243] Fix | Delete
[244] Fix | Delete
def __init__(self, trace):
[245] Fix | Delete
# trace is a tuple: (domain: int, size: int, traceback: tuple).
[246] Fix | Delete
# See Traceback constructor for the format of the traceback tuple.
[247] Fix | Delete
self._trace = trace
[248] Fix | Delete
[249] Fix | Delete
@property
[250] Fix | Delete
def domain(self):
[251] Fix | Delete
return self._trace[0]
[252] Fix | Delete
[253] Fix | Delete
@property
[254] Fix | Delete
def size(self):
[255] Fix | Delete
return self._trace[1]
[256] Fix | Delete
[257] Fix | Delete
@property
[258] Fix | Delete
def traceback(self):
[259] Fix | Delete
return Traceback(self._trace[2])
[260] Fix | Delete
[261] Fix | Delete
def __eq__(self, other):
[262] Fix | Delete
return (self._trace == other._trace)
[263] Fix | Delete
[264] Fix | Delete
def __hash__(self):
[265] Fix | Delete
return hash(self._trace)
[266] Fix | Delete
[267] Fix | Delete
def __str__(self):
[268] Fix | Delete
return "%s: %s" % (self.traceback, _format_size(self.size, False))
[269] Fix | Delete
[270] Fix | Delete
def __repr__(self):
[271] Fix | Delete
return ("<Trace domain=%s size=%s, traceback=%r>"
[272] Fix | Delete
% (self.domain, _format_size(self.size, False), self.traceback))
[273] Fix | Delete
[274] Fix | Delete
[275] Fix | Delete
class _Traces(Sequence):
[276] Fix | Delete
def __init__(self, traces):
[277] Fix | Delete
Sequence.__init__(self)
[278] Fix | Delete
# traces is a tuple of trace tuples: see Trace constructor
[279] Fix | Delete
self._traces = traces
[280] Fix | Delete
[281] Fix | Delete
def __len__(self):
[282] Fix | Delete
return len(self._traces)
[283] Fix | Delete
[284] Fix | Delete
def __getitem__(self, index):
[285] Fix | Delete
if isinstance(index, slice):
[286] Fix | Delete
return tuple(Trace(trace) for trace in self._traces[index])
[287] Fix | Delete
else:
[288] Fix | Delete
return Trace(self._traces[index])
[289] Fix | Delete
[290] Fix | Delete
def __contains__(self, trace):
[291] Fix | Delete
return trace._trace in self._traces
[292] Fix | Delete
[293] Fix | Delete
def __eq__(self, other):
[294] Fix | Delete
return (self._traces == other._traces)
[295] Fix | Delete
[296] Fix | Delete
def __repr__(self):
[297] Fix | Delete
return "<Traces len=%s>" % len(self)
[298] Fix | Delete
[299] Fix | Delete
[300] Fix | Delete
def _normalize_filename(filename):
[301] Fix | Delete
filename = os.path.normcase(filename)
[302] Fix | Delete
if filename.endswith('.pyc'):
[303] Fix | Delete
filename = filename[:-1]
[304] Fix | Delete
return filename
[305] Fix | Delete
[306] Fix | Delete
[307] Fix | Delete
class BaseFilter:
[308] Fix | Delete
def __init__(self, inclusive):
[309] Fix | Delete
self.inclusive = inclusive
[310] Fix | Delete
[311] Fix | Delete
def _match(self, trace):
[312] Fix | Delete
raise NotImplementedError
[313] Fix | Delete
[314] Fix | Delete
[315] Fix | Delete
class Filter(BaseFilter):
[316] Fix | Delete
def __init__(self, inclusive, filename_pattern,
[317] Fix | Delete
lineno=None, all_frames=False, domain=None):
[318] Fix | Delete
super().__init__(inclusive)
[319] Fix | Delete
self.inclusive = inclusive
[320] Fix | Delete
self._filename_pattern = _normalize_filename(filename_pattern)
[321] Fix | Delete
self.lineno = lineno
[322] Fix | Delete
self.all_frames = all_frames
[323] Fix | Delete
self.domain = domain
[324] Fix | Delete
[325] Fix | Delete
@property
[326] Fix | Delete
def filename_pattern(self):
[327] Fix | Delete
return self._filename_pattern
[328] Fix | Delete
[329] Fix | Delete
def _match_frame_impl(self, filename, lineno):
[330] Fix | Delete
filename = _normalize_filename(filename)
[331] Fix | Delete
if not fnmatch.fnmatch(filename, self._filename_pattern):
[332] Fix | Delete
return False
[333] Fix | Delete
if self.lineno is None:
[334] Fix | Delete
return True
[335] Fix | Delete
else:
[336] Fix | Delete
return (lineno == self.lineno)
[337] Fix | Delete
[338] Fix | Delete
def _match_frame(self, filename, lineno):
[339] Fix | Delete
return self._match_frame_impl(filename, lineno) ^ (not self.inclusive)
[340] Fix | Delete
[341] Fix | Delete
def _match_traceback(self, traceback):
[342] Fix | Delete
if self.all_frames:
[343] Fix | Delete
if any(self._match_frame_impl(filename, lineno)
[344] Fix | Delete
for filename, lineno in traceback):
[345] Fix | Delete
return self.inclusive
[346] Fix | Delete
else:
[347] Fix | Delete
return (not self.inclusive)
[348] Fix | Delete
else:
[349] Fix | Delete
filename, lineno = traceback[0]
[350] Fix | Delete
return self._match_frame(filename, lineno)
[351] Fix | Delete
[352] Fix | Delete
def _match(self, trace):
[353] Fix | Delete
domain, size, traceback = trace
[354] Fix | Delete
res = self._match_traceback(traceback)
[355] Fix | Delete
if self.domain is not None:
[356] Fix | Delete
if self.inclusive:
[357] Fix | Delete
return res and (domain == self.domain)
[358] Fix | Delete
else:
[359] Fix | Delete
return res or (domain != self.domain)
[360] Fix | Delete
return res
[361] Fix | Delete
[362] Fix | Delete
[363] Fix | Delete
class DomainFilter(BaseFilter):
[364] Fix | Delete
def __init__(self, inclusive, domain):
[365] Fix | Delete
super().__init__(inclusive)
[366] Fix | Delete
self._domain = domain
[367] Fix | Delete
[368] Fix | Delete
@property
[369] Fix | Delete
def domain(self):
[370] Fix | Delete
return self._domain
[371] Fix | Delete
[372] Fix | Delete
def _match(self, trace):
[373] Fix | Delete
domain, size, traceback = trace
[374] Fix | Delete
return (domain == self.domain) ^ (not self.inclusive)
[375] Fix | Delete
[376] Fix | Delete
[377] Fix | Delete
class Snapshot:
[378] Fix | Delete
"""
[379] Fix | Delete
Snapshot of traces of memory blocks allocated by Python.
[380] Fix | Delete
"""
[381] Fix | Delete
[382] Fix | Delete
def __init__(self, traces, traceback_limit):
[383] Fix | Delete
# traces is a tuple of trace tuples: see _Traces constructor for
[384] Fix | Delete
# the exact format
[385] Fix | Delete
self.traces = _Traces(traces)
[386] Fix | Delete
self.traceback_limit = traceback_limit
[387] Fix | Delete
[388] Fix | Delete
def dump(self, filename):
[389] Fix | Delete
"""
[390] Fix | Delete
Write the snapshot into a file.
[391] Fix | Delete
"""
[392] Fix | Delete
with open(filename, "wb") as fp:
[393] Fix | Delete
pickle.dump(self, fp, pickle.HIGHEST_PROTOCOL)
[394] Fix | Delete
[395] Fix | Delete
@staticmethod
[396] Fix | Delete
def load(filename):
[397] Fix | Delete
"""
[398] Fix | Delete
Load a snapshot from a file.
[399] Fix | Delete
"""
[400] Fix | Delete
with open(filename, "rb") as fp:
[401] Fix | Delete
return pickle.load(fp)
[402] Fix | Delete
[403] Fix | Delete
def _filter_trace(self, include_filters, exclude_filters, trace):
[404] Fix | Delete
if include_filters:
[405] Fix | Delete
if not any(trace_filter._match(trace)
[406] Fix | Delete
for trace_filter in include_filters):
[407] Fix | Delete
return False
[408] Fix | Delete
if exclude_filters:
[409] Fix | Delete
if any(not trace_filter._match(trace)
[410] Fix | Delete
for trace_filter in exclude_filters):
[411] Fix | Delete
return False
[412] Fix | Delete
return True
[413] Fix | Delete
[414] Fix | Delete
def filter_traces(self, filters):
[415] Fix | Delete
"""
[416] Fix | Delete
Create a new Snapshot instance with a filtered traces sequence, filters
[417] Fix | Delete
is a list of Filter or DomainFilter instances. If filters is an empty
[418] Fix | Delete
list, return a new Snapshot instance with a copy of the traces.
[419] Fix | Delete
"""
[420] Fix | Delete
if not isinstance(filters, Iterable):
[421] Fix | Delete
raise TypeError("filters must be a list of filters, not %s"
[422] Fix | Delete
% type(filters).__name__)
[423] Fix | Delete
if filters:
[424] Fix | Delete
include_filters = []
[425] Fix | Delete
exclude_filters = []
[426] Fix | Delete
for trace_filter in filters:
[427] Fix | Delete
if trace_filter.inclusive:
[428] Fix | Delete
include_filters.append(trace_filter)
[429] Fix | Delete
else:
[430] Fix | Delete
exclude_filters.append(trace_filter)
[431] Fix | Delete
new_traces = [trace for trace in self.traces._traces
[432] Fix | Delete
if self._filter_trace(include_filters,
[433] Fix | Delete
exclude_filters,
[434] Fix | Delete
trace)]
[435] Fix | Delete
else:
[436] Fix | Delete
new_traces = self.traces._traces.copy()
[437] Fix | Delete
return Snapshot(new_traces, self.traceback_limit)
[438] Fix | Delete
[439] Fix | Delete
def _group_by(self, key_type, cumulative):
[440] Fix | Delete
if key_type not in ('traceback', 'filename', 'lineno'):
[441] Fix | Delete
raise ValueError("unknown key_type: %r" % (key_type,))
[442] Fix | Delete
if cumulative and key_type not in ('lineno', 'filename'):
[443] Fix | Delete
raise ValueError("cumulative mode cannot by used "
[444] Fix | Delete
"with key type %r" % key_type)
[445] Fix | Delete
[446] Fix | Delete
stats = {}
[447] Fix | Delete
tracebacks = {}
[448] Fix | Delete
if not cumulative:
[449] Fix | Delete
for trace in self.traces._traces:
[450] Fix | Delete
domain, size, trace_traceback = trace
[451] Fix | Delete
try:
[452] Fix | Delete
traceback = tracebacks[trace_traceback]
[453] Fix | Delete
except KeyError:
[454] Fix | Delete
if key_type == 'traceback':
[455] Fix | Delete
frames = trace_traceback
[456] Fix | Delete
elif key_type == 'lineno':
[457] Fix | Delete
frames = trace_traceback[:1]
[458] Fix | Delete
else: # key_type == 'filename':
[459] Fix | Delete
frames = ((trace_traceback[0][0], 0),)
[460] Fix | Delete
traceback = Traceback(frames)
[461] Fix | Delete
tracebacks[trace_traceback] = traceback
[462] Fix | Delete
try:
[463] Fix | Delete
stat = stats[traceback]
[464] Fix | Delete
stat.size += size
[465] Fix | Delete
stat.count += 1
[466] Fix | Delete
except KeyError:
[467] Fix | Delete
stats[traceback] = Statistic(traceback, size, 1)
[468] Fix | Delete
else:
[469] Fix | Delete
# cumulative statistics
[470] Fix | Delete
for trace in self.traces._traces:
[471] Fix | Delete
domain, size, trace_traceback = trace
[472] Fix | Delete
for frame in trace_traceback:
[473] Fix | Delete
try:
[474] Fix | Delete
traceback = tracebacks[frame]
[475] Fix | Delete
except KeyError:
[476] Fix | Delete
if key_type == 'lineno':
[477] Fix | Delete
frames = (frame,)
[478] Fix | Delete
else: # key_type == 'filename':
[479] Fix | Delete
frames = ((frame[0], 0),)
[480] Fix | Delete
traceback = Traceback(frames)
[481] Fix | Delete
tracebacks[frame] = traceback
[482] Fix | Delete
try:
[483] Fix | Delete
stat = stats[traceback]
[484] Fix | Delete
stat.size += size
[485] Fix | Delete
stat.count += 1
[486] Fix | Delete
except KeyError:
[487] Fix | Delete
stats[traceback] = Statistic(traceback, size, 1)
[488] Fix | Delete
return stats
[489] Fix | Delete
[490] Fix | Delete
def statistics(self, key_type, cumulative=False):
[491] Fix | Delete
"""
[492] Fix | Delete
Group statistics by key_type. Return a sorted list of Statistic
[493] Fix | Delete
instances.
[494] Fix | Delete
"""
[495] Fix | Delete
grouped = self._group_by(key_type, cumulative)
[496] Fix | Delete
statistics = list(grouped.values())
[497] Fix | Delete
statistics.sort(reverse=True, key=Statistic._sort_key)
[498] Fix | Delete
return statistics
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function