Current Path: > > lib64 > python3.8 >
Operation : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64 Software : Apache Server IP : 162.0.232.56 | Your IP: 216.73.216.111 Domains : 1034 Domain(s) Permission : [ 0755 ]
Name | Type | Size | Last Modified | Actions |
---|---|---|---|---|
__pycache__ | Directory | - | - | |
asyncio | Directory | - | - | |
collections | Directory | - | - | |
concurrent | Directory | - | - | |
config-3.8-x86_64-linux-gnu | Directory | - | - | |
ctypes | Directory | - | - | |
curses | Directory | - | - | |
dbm | Directory | - | - | |
distutils | Directory | - | - | |
Directory | - | - | ||
encodings | Directory | - | - | |
ensurepip | Directory | - | - | |
html | Directory | - | - | |
http | Directory | - | - | |
importlib | Directory | - | - | |
json | Directory | - | - | |
lib-dynload | Directory | - | - | |
lib2to3 | Directory | - | - | |
logging | Directory | - | - | |
multiprocessing | Directory | - | - | |
pydoc_data | Directory | - | - | |
site-packages | Directory | - | - | |
sqlite3 | Directory | - | - | |
tkinter | Directory | - | - | |
turtledemo | Directory | - | - | |
unittest | Directory | - | - | |
urllib | Directory | - | - | |
venv | Directory | - | - | |
wsgiref | Directory | - | - | |
xml | Directory | - | - | |
xmlrpc | Directory | - | - | |
LICENSE.txt | File | 13937 bytes | June 06 2023 13:32:21. | |
__future__.py | File | 5147 bytes | June 06 2023 13:32:21. | |
__phello__.foo.py | File | 64 bytes | June 06 2023 13:32:21. | |
_bootlocale.py | File | 1801 bytes | June 06 2023 13:32:21. | |
_collections_abc.py | File | 26100 bytes | June 06 2023 13:32:21. | |
_compat_pickle.py | File | 8749 bytes | June 06 2023 13:32:21. | |
_compression.py | File | 5340 bytes | June 06 2023 13:32:21. | |
_dummy_thread.py | File | 6027 bytes | June 06 2023 13:32:21. | |
_markupbase.py | File | 14598 bytes | June 06 2023 13:32:21. | |
_osx_support.py | File | 21774 bytes | June 06 2023 13:32:21. | |
_py_abc.py | File | 6189 bytes | June 06 2023 13:32:21. | |
_pydecimal.py | File | 228666 bytes | June 06 2023 13:32:21. | |
_pyio.py | File | 93177 bytes | June 06 2023 13:32:21. | |
_sitebuiltins.py | File | 3115 bytes | June 06 2023 13:32:21. | |
_strptime.py | File | 25268 bytes | June 06 2023 13:32:21. | |
_sysconfigdata__linux_x86_64-linux-gnu.py | File | 38510 bytes | October 17 2023 18:12:19. | |
_sysconfigdata_d_linux_x86_64-linux-gnu.py | File | 38237 bytes | October 17 2023 18:03:44. | |
_threading_local.py | File | 7220 bytes | June 06 2023 13:32:21. | |
_weakrefset.py | File | 5735 bytes | June 06 2023 13:32:21. | |
abc.py | File | 4489 bytes | June 06 2023 13:32:21. | |
aifc.py | File | 32814 bytes | June 06 2023 13:32:21. | |
antigravity.py | File | 477 bytes | June 06 2023 13:32:21. | |
argparse.py | File | 96015 bytes | June 06 2023 13:32:21. | |
ast.py | File | 19234 bytes | June 06 2023 13:32:21. | |
asynchat.py | File | 11328 bytes | June 06 2023 13:32:21. | |
asyncore.py | File | 20094 bytes | June 06 2023 13:32:21. | |
base64.py | File | 20382 bytes | June 06 2023 13:32:21. | |
bdb.py | File | 32056 bytes | June 06 2023 13:32:21. | |
binhex.py | File | 13954 bytes | June 06 2023 13:32:21. | |
bisect.py | File | 2214 bytes | June 06 2023 13:32:21. | |
bz2.py | File | 12558 bytes | June 06 2023 13:32:21. | |
cProfile.py | File | 7010 bytes | June 06 2023 13:32:21. | |
calendar.py | File | 24832 bytes | June 06 2023 13:32:21. | |
cgi.py | File | 33934 bytes | October 17 2023 18:02:14. | |
cgitb.py | File | 12096 bytes | June 06 2023 13:32:21. | |
chunk.py | File | 5435 bytes | June 06 2023 13:32:21. | |
cmd.py | File | 14860 bytes | June 06 2023 13:32:21. | |
code.py | File | 10622 bytes | June 06 2023 13:32:21. | |
codecs.py | File | 36667 bytes | June 06 2023 13:32:21. | |
codeop.py | File | 6330 bytes | June 06 2023 13:32:21. | |
colorsys.py | File | 4064 bytes | June 06 2023 13:32:21. | |
compileall.py | File | 13678 bytes | June 06 2023 13:32:21. | |
configparser.py | File | 54374 bytes | June 06 2023 13:32:21. | |
contextlib.py | File | 24995 bytes | June 06 2023 13:32:21. | |
contextvars.py | File | 129 bytes | June 06 2023 13:32:21. | |
copy.py | File | 8661 bytes | June 06 2023 13:32:21. | |
copyreg.py | File | 7135 bytes | June 06 2023 13:32:21. | |
crypt.py | File | 3610 bytes | June 06 2023 13:32:21. | |
csv.py | File | 16144 bytes | June 06 2023 13:32:21. | |
dataclasses.py | File | 49973 bytes | June 06 2023 13:32:21. | |
datetime.py | File | 88287 bytes | June 06 2023 13:32:21. | |
decimal.py | File | 320 bytes | June 06 2023 13:32:21. | |
difflib.py | File | 84058 bytes | June 06 2023 13:32:21. | |
dis.py | File | 20570 bytes | June 06 2023 13:32:21. | |
doctest.py | File | 104543 bytes | June 06 2023 13:32:21. | |
dummy_threading.py | File | 2815 bytes | June 06 2023 13:32:21. | |
enum.py | File | 38136 bytes | June 06 2023 13:32:21. | |
filecmp.py | File | 9830 bytes | June 06 2023 13:32:21. | |
fileinput.py | File | 14709 bytes | June 06 2023 13:32:21. | |
fnmatch.py | File | 4079 bytes | June 06 2023 13:32:21. | |
formatter.py | File | 15143 bytes | June 06 2023 13:32:21. | |
fractions.py | File | 24329 bytes | June 06 2023 13:32:21. | |
ftplib.py | File | 35129 bytes | June 06 2023 13:32:21. | |
functools.py | File | 37406 bytes | June 06 2023 13:32:21. | |
genericpath.py | File | 4975 bytes | June 06 2023 13:32:21. | |
getopt.py | File | 7489 bytes | June 06 2023 13:32:21. | |
getpass.py | File | 5994 bytes | June 06 2023 13:32:21. | |
gettext.py | File | 27138 bytes | June 06 2023 13:32:21. | |
glob.py | File | 5697 bytes | June 06 2023 13:32:21. | |
gzip.py | File | 21413 bytes | June 06 2023 13:32:21. | |
hashlib.py | File | 8333 bytes | October 17 2023 18:02:14. | |
heapq.py | File | 22877 bytes | June 06 2023 13:32:21. | |
hmac.py | File | 7850 bytes | October 17 2023 18:02:14. | |
imaplib.py | File | 53606 bytes | June 06 2023 13:32:21. | |
imghdr.py | File | 3808 bytes | June 06 2023 13:32:21. | |
imp.py | File | 10536 bytes | June 06 2023 13:32:21. | |
inspect.py | File | 118550 bytes | June 06 2023 13:32:21. | |
io.py | File | 3541 bytes | June 06 2023 13:32:21. | |
ipaddress.py | File | 71644 bytes | June 06 2023 13:32:21. | |
keyword.py | File | 945 bytes | June 06 2023 13:32:21. | |
linecache.py | File | 5330 bytes | June 06 2023 13:32:21. | |
locale.py | File | 78191 bytes | June 06 2023 13:32:21. | |
lzma.py | File | 12983 bytes | June 06 2023 13:32:21. | |
mailbox.py | File | 78661 bytes | June 06 2023 13:32:21. | |
mailcap.py | File | 9067 bytes | June 06 2023 13:32:21. | |
mimetypes.py | File | 21664 bytes | June 06 2023 13:32:21. | |
modulefinder.py | File | 24430 bytes | June 06 2023 13:32:21. | |
netrc.py | File | 5566 bytes | June 06 2023 13:32:21. | |
nntplib.py | File | 43261 bytes | June 06 2023 13:32:21. | |
ntpath.py | File | 27734 bytes | June 06 2023 13:32:21. | |
nturl2path.py | File | 2887 bytes | June 06 2023 13:32:21. | |
numbers.py | File | 10244 bytes | June 06 2023 13:32:21. | |
opcode.py | File | 5808 bytes | June 06 2023 13:32:21. | |
operator.py | File | 10711 bytes | June 06 2023 13:32:21. | |
optparse.py | File | 60369 bytes | June 06 2023 13:32:21. | |
os.py | File | 38995 bytes | June 06 2023 13:32:21. | |
pathlib.py | File | 52610 bytes | June 06 2023 13:32:21. | |
pdb.py | File | 62738 bytes | June 06 2023 13:32:21. | |
pickle.py | File | 64467 bytes | June 06 2023 13:32:21. | |
pickletools.py | File | 93486 bytes | June 06 2023 13:32:21. | |
pipes.py | File | 8916 bytes | June 06 2023 13:32:21. | |
pkgutil.py | File | 21500 bytes | June 06 2023 13:32:21. | |
platform.py | File | 40425 bytes | June 06 2023 13:32:21. | |
plistlib.py | File | 32220 bytes | June 06 2023 13:32:21. | |
poplib.py | File | 15077 bytes | June 06 2023 13:32:21. | |
posixpath.py | File | 15627 bytes | June 06 2023 13:32:21. | |
pprint.py | File | 21484 bytes | June 06 2023 13:32:21. | |
profile.py | File | 23546 bytes | June 06 2023 13:32:21. | |
pstats.py | File | 27345 bytes | June 06 2023 13:32:21. | |
pty.py | File | 4807 bytes | June 06 2023 13:32:21. | |
py_compile.py | File | 8203 bytes | October 17 2023 18:02:14. | |
pyclbr.py | File | 15255 bytes | June 06 2023 13:32:21. | |
pydoc.py | File | 106700 bytes | October 17 2023 18:12:57. | |
queue.py | File | 11356 bytes | June 06 2023 13:32:21. | |
quopri.py | File | 7252 bytes | June 06 2023 13:32:21. | |
random.py | File | 28802 bytes | June 06 2023 13:32:21. | |
re.py | File | 15861 bytes | June 06 2023 13:32:21. | |
reprlib.py | File | 5267 bytes | June 06 2023 13:32:21. | |
rlcompleter.py | File | 7097 bytes | June 06 2023 13:32:21. | |
runpy.py | File | 12052 bytes | June 06 2023 13:32:21. | |
sched.py | File | 6442 bytes | June 06 2023 13:32:21. | |
secrets.py | File | 2038 bytes | June 06 2023 13:32:21. | |
selectors.py | File | 18561 bytes | June 06 2023 13:32:21. | |
shelve.py | File | 8527 bytes | June 06 2023 13:32:21. | |
shlex.py | File | 13325 bytes | June 06 2023 13:32:21. | |
shutil.py | File | 51761 bytes | June 06 2023 13:32:21. | |
signal.py | File | 2273 bytes | June 06 2023 13:32:21. | |
site.py | File | 21838 bytes | October 17 2023 18:02:14. | |
smtpd.py | File | 34709 bytes | June 06 2023 13:32:21. | |
smtplib.py | File | 45001 bytes | June 06 2023 13:32:21. | |
sndhdr.py | File | 7099 bytes | June 06 2023 13:32:21. | |
socket.py | File | 35243 bytes | June 06 2023 13:32:21. | |
socketserver.py | File | 27296 bytes | June 06 2023 13:32:21. | |
sre_compile.py | File | 26695 bytes | June 06 2023 13:32:21. | |
sre_constants.py | File | 7154 bytes | June 06 2023 13:32:21. | |
sre_parse.py | File | 40230 bytes | June 06 2023 13:32:21. | |
ssl.py | File | 50760 bytes | June 06 2023 13:32:21. | |
stat.py | File | 5485 bytes | June 06 2023 13:32:21. | |
statistics.py | File | 39690 bytes | June 06 2023 13:32:21. | |
string.py | File | 10535 bytes | June 06 2023 13:32:21. | |
stringprep.py | File | 12917 bytes | June 06 2023 13:32:21. | |
struct.py | File | 257 bytes | June 06 2023 13:32:21. | |
subprocess.py | File | 78250 bytes | June 06 2023 13:32:21. | |
sunau.py | File | 18375 bytes | June 06 2023 13:32:21. | |
symbol.py | File | 2109 bytes | October 17 2023 18:04:15. | |
symtable.py | File | 8021 bytes | June 06 2023 13:32:21. | |
sysconfig.py | File | 24896 bytes | October 17 2023 18:12:55. | |
tabnanny.py | File | 11406 bytes | June 06 2023 13:32:21. | |
tarfile.py | File | 106473 bytes | October 17 2023 18:02:14. | |
telnetlib.py | File | 23254 bytes | June 06 2023 13:32:21. | |
tempfile.py | File | 27537 bytes | June 06 2023 13:32:21. | |
textwrap.py | File | 19407 bytes | June 06 2023 13:32:21. | |
this.py | File | 1003 bytes | June 06 2023 13:32:21. | |
threading.py | File | 50820 bytes | June 06 2023 13:32:21. | |
timeit.py | File | 13480 bytes | June 06 2023 13:32:21. | |
token.py | File | 2368 bytes | June 06 2023 13:32:21. | |
tokenize.py | File | 25841 bytes | June 06 2023 13:32:21. | |
trace.py | File | 29870 bytes | June 06 2023 13:32:21. | |
traceback.py | File | 23611 bytes | June 06 2023 13:32:21. | |
tracemalloc.py | File | 17076 bytes | June 06 2023 13:32:21. | |
tty.py | File | 879 bytes | June 06 2023 13:32:21. | |
turtle.py | File | 143716 bytes | June 06 2023 13:32:21. | |
types.py | File | 9713 bytes | June 06 2023 13:32:21. | |
typing.py | File | 68962 bytes | June 06 2023 13:32:21. | |
uu.py | File | 7277 bytes | October 17 2023 18:12:57. | |
uuid.py | File | 30515 bytes | October 17 2023 18:02:14. | |
warnings.py | File | 19688 bytes | June 06 2023 13:32:21. | |
wave.py | File | 18230 bytes | June 06 2023 13:32:21. | |
weakref.py | File | 21387 bytes | June 06 2023 13:32:21. | |
webbrowser.py | File | 24083 bytes | June 06 2023 13:32:21. | |
xdrlib.py | File | 5913 bytes | June 06 2023 13:32:21. | |
zipapp.py | File | 7535 bytes | June 06 2023 13:32:21. | |
zipfile.py | File | 87728 bytes | June 06 2023 13:32:21. | |
zipimport.py | File | 30765 bytes | June 06 2023 13:32:21. |
from collections.abc import Sequence, Iterable from functools import total_ordering import fnmatch import linecache import os.path import pickle # Import types and functions implemented in C from _tracemalloc import * from _tracemalloc import _get_object_traceback, _get_traces def _format_size(size, sign): for unit in ('B', 'KiB', 'MiB', 'GiB', 'TiB'): if abs(size) < 100 and unit != 'B': # 3 digits (xx.x UNIT) if sign: return "%+.1f %s" % (size, unit) else: return "%.1f %s" % (size, unit) if abs(size) < 10 * 1024 or unit == 'TiB': # 4 or 5 digits (xxxx UNIT) if sign: return "%+.0f %s" % (size, unit) else: return "%.0f %s" % (size, unit) size /= 1024 class Statistic: """ Statistic difference on memory allocations between two Snapshot instance. """ __slots__ = ('traceback', 'size', 'count') def __init__(self, traceback, size, count): self.traceback = traceback self.size = size self.count = count def __hash__(self): return hash((self.traceback, self.size, self.count)) def __eq__(self, other): return (self.traceback == other.traceback and self.size == other.size and self.count == other.count) def __str__(self): text = ("%s: size=%s, count=%i" % (self.traceback, _format_size(self.size, False), self.count)) if self.count: average = self.size / self.count text += ", average=%s" % _format_size(average, False) return text def __repr__(self): return ('<Statistic traceback=%r size=%i count=%i>' % (self.traceback, self.size, self.count)) def _sort_key(self): return (self.size, self.count, self.traceback) class StatisticDiff: """ Statistic difference on memory allocations between an old and a new Snapshot instance. """ __slots__ = ('traceback', 'size', 'size_diff', 'count', 'count_diff') def __init__(self, traceback, size, size_diff, count, count_diff): self.traceback = traceback self.size = size self.size_diff = size_diff self.count = count self.count_diff = count_diff def __hash__(self): return hash((self.traceback, self.size, self.size_diff, self.count, self.count_diff)) def __eq__(self, other): return (self.traceback == other.traceback and self.size == other.size and self.size_diff == other.size_diff and self.count == other.count and self.count_diff == other.count_diff) def __str__(self): text = ("%s: size=%s (%s), count=%i (%+i)" % (self.traceback, _format_size(self.size, False), _format_size(self.size_diff, True), self.count, self.count_diff)) if self.count: average = self.size / self.count text += ", average=%s" % _format_size(average, False) return text def __repr__(self): return ('<StatisticDiff traceback=%r size=%i (%+i) count=%i (%+i)>' % (self.traceback, self.size, self.size_diff, self.count, self.count_diff)) def _sort_key(self): return (abs(self.size_diff), self.size, abs(self.count_diff), self.count, self.traceback) def _compare_grouped_stats(old_group, new_group): statistics = [] for traceback, stat in new_group.items(): previous = old_group.pop(traceback, None) if previous is not None: stat = StatisticDiff(traceback, stat.size, stat.size - previous.size, stat.count, stat.count - previous.count) else: stat = StatisticDiff(traceback, stat.size, stat.size, stat.count, stat.count) statistics.append(stat) for traceback, stat in old_group.items(): stat = StatisticDiff(traceback, 0, -stat.size, 0, -stat.count) statistics.append(stat) return statistics @total_ordering class Frame: """ Frame of a traceback. """ __slots__ = ("_frame",) def __init__(self, frame): # frame is a tuple: (filename: str, lineno: int) self._frame = frame @property def filename(self): return self._frame[0] @property def lineno(self): return self._frame[1] def __eq__(self, other): return (self._frame == other._frame) def __lt__(self, other): return (self._frame < other._frame) def __hash__(self): return hash(self._frame) def __str__(self): return "%s:%s" % (self.filename, self.lineno) def __repr__(self): return "<Frame filename=%r lineno=%r>" % (self.filename, self.lineno) @total_ordering class Traceback(Sequence): """ Sequence of Frame instances sorted from the oldest frame to the most recent frame. """ __slots__ = ("_frames",) def __init__(self, frames): Sequence.__init__(self) # frames is a tuple of frame tuples: see Frame constructor for the # format of a frame tuple; it is reversed, because _tracemalloc # returns frames sorted from most recent to oldest, but the # Python API expects oldest to most recent self._frames = tuple(reversed(frames)) def __len__(self): return len(self._frames) def __getitem__(self, index): if isinstance(index, slice): return tuple(Frame(trace) for trace in self._frames[index]) else: return Frame(self._frames[index]) def __contains__(self, frame): return frame._frame in self._frames def __hash__(self): return hash(self._frames) def __eq__(self, other): return (self._frames == other._frames) def __lt__(self, other): return (self._frames < other._frames) def __str__(self): return str(self[0]) def __repr__(self): return "<Traceback %r>" % (tuple(self),) def format(self, limit=None, most_recent_first=False): lines = [] if limit is not None: if limit > 0: frame_slice = self[-limit:] else: frame_slice = self[:limit] else: frame_slice = self if most_recent_first: frame_slice = reversed(frame_slice) for frame in frame_slice: lines.append(' File "%s", line %s' % (frame.filename, frame.lineno)) line = linecache.getline(frame.filename, frame.lineno).strip() if line: lines.append(' %s' % line) return lines def get_object_traceback(obj): """ Get the traceback where the Python object *obj* was allocated. Return a Traceback instance. Return None if the tracemalloc module is not tracing memory allocations or did not trace the allocation of the object. """ frames = _get_object_traceback(obj) if frames is not None: return Traceback(frames) else: return None class Trace: """ Trace of a memory block. """ __slots__ = ("_trace",) def __init__(self, trace): # trace is a tuple: (domain: int, size: int, traceback: tuple). # See Traceback constructor for the format of the traceback tuple. self._trace = trace @property def domain(self): return self._trace[0] @property def size(self): return self._trace[1] @property def traceback(self): return Traceback(self._trace[2]) def __eq__(self, other): return (self._trace == other._trace) def __hash__(self): return hash(self._trace) def __str__(self): return "%s: %s" % (self.traceback, _format_size(self.size, False)) def __repr__(self): return ("<Trace domain=%s size=%s, traceback=%r>" % (self.domain, _format_size(self.size, False), self.traceback)) class _Traces(Sequence): def __init__(self, traces): Sequence.__init__(self) # traces is a tuple of trace tuples: see Trace constructor self._traces = traces def __len__(self): return len(self._traces) def __getitem__(self, index): if isinstance(index, slice): return tuple(Trace(trace) for trace in self._traces[index]) else: return Trace(self._traces[index]) def __contains__(self, trace): return trace._trace in self._traces def __eq__(self, other): return (self._traces == other._traces) def __repr__(self): return "<Traces len=%s>" % len(self) def _normalize_filename(filename): filename = os.path.normcase(filename) if filename.endswith('.pyc'): filename = filename[:-1] return filename class BaseFilter: def __init__(self, inclusive): self.inclusive = inclusive def _match(self, trace): raise NotImplementedError class Filter(BaseFilter): def __init__(self, inclusive, filename_pattern, lineno=None, all_frames=False, domain=None): super().__init__(inclusive) self.inclusive = inclusive self._filename_pattern = _normalize_filename(filename_pattern) self.lineno = lineno self.all_frames = all_frames self.domain = domain @property def filename_pattern(self): return self._filename_pattern def _match_frame_impl(self, filename, lineno): filename = _normalize_filename(filename) if not fnmatch.fnmatch(filename, self._filename_pattern): return False if self.lineno is None: return True else: return (lineno == self.lineno) def _match_frame(self, filename, lineno): return self._match_frame_impl(filename, lineno) ^ (not self.inclusive) def _match_traceback(self, traceback): if self.all_frames: if any(self._match_frame_impl(filename, lineno) for filename, lineno in traceback): return self.inclusive else: return (not self.inclusive) else: filename, lineno = traceback[0] return self._match_frame(filename, lineno) def _match(self, trace): domain, size, traceback = trace res = self._match_traceback(traceback) if self.domain is not None: if self.inclusive: return res and (domain == self.domain) else: return res or (domain != self.domain) return res class DomainFilter(BaseFilter): def __init__(self, inclusive, domain): super().__init__(inclusive) self._domain = domain @property def domain(self): return self._domain def _match(self, trace): domain, size, traceback = trace return (domain == self.domain) ^ (not self.inclusive) class Snapshot: """ Snapshot of traces of memory blocks allocated by Python. """ def __init__(self, traces, traceback_limit): # traces is a tuple of trace tuples: see _Traces constructor for # the exact format self.traces = _Traces(traces) self.traceback_limit = traceback_limit def dump(self, filename): """ Write the snapshot into a file. """ with open(filename, "wb") as fp: pickle.dump(self, fp, pickle.HIGHEST_PROTOCOL) @staticmethod def load(filename): """ Load a snapshot from a file. """ with open(filename, "rb") as fp: return pickle.load(fp) def _filter_trace(self, include_filters, exclude_filters, trace): if include_filters: if not any(trace_filter._match(trace) for trace_filter in include_filters): return False if exclude_filters: if any(not trace_filter._match(trace) for trace_filter in exclude_filters): return False return True def filter_traces(self, filters): """ Create a new Snapshot instance with a filtered traces sequence, filters is a list of Filter or DomainFilter instances. If filters is an empty list, return a new Snapshot instance with a copy of the traces. """ if not isinstance(filters, Iterable): raise TypeError("filters must be a list of filters, not %s" % type(filters).__name__) if filters: include_filters = [] exclude_filters = [] for trace_filter in filters: if trace_filter.inclusive: include_filters.append(trace_filter) else: exclude_filters.append(trace_filter) new_traces = [trace for trace in self.traces._traces if self._filter_trace(include_filters, exclude_filters, trace)] else: new_traces = self.traces._traces.copy() return Snapshot(new_traces, self.traceback_limit) def _group_by(self, key_type, cumulative): if key_type not in ('traceback', 'filename', 'lineno'): raise ValueError("unknown key_type: %r" % (key_type,)) if cumulative and key_type not in ('lineno', 'filename'): raise ValueError("cumulative mode cannot by used " "with key type %r" % key_type) stats = {} tracebacks = {} if not cumulative: for trace in self.traces._traces: domain, size, trace_traceback = trace try: traceback = tracebacks[trace_traceback] except KeyError: if key_type == 'traceback': frames = trace_traceback elif key_type == 'lineno': frames = trace_traceback[:1] else: # key_type == 'filename': frames = ((trace_traceback[0][0], 0),) traceback = Traceback(frames) tracebacks[trace_traceback] = traceback try: stat = stats[traceback] stat.size += size stat.count += 1 except KeyError: stats[traceback] = Statistic(traceback, size, 1) else: # cumulative statistics for trace in self.traces._traces: domain, size, trace_traceback = trace for frame in trace_traceback: try: traceback = tracebacks[frame] except KeyError: if key_type == 'lineno': frames = (frame,) else: # key_type == 'filename': frames = ((frame[0], 0),) traceback = Traceback(frames) tracebacks[frame] = traceback try: stat = stats[traceback] stat.size += size stat.count += 1 except KeyError: stats[traceback] = Statistic(traceback, size, 1) return stats def statistics(self, key_type, cumulative=False): """ Group statistics by key_type. Return a sorted list of Statistic instances. """ grouped = self._group_by(key_type, cumulative) statistics = list(grouped.values()) statistics.sort(reverse=True, key=Statistic._sort_key) return statistics def compare_to(self, old_snapshot, key_type, cumulative=False): """ Compute the differences with an old snapshot old_snapshot. Get statistics as a sorted list of StatisticDiff instances, grouped by group_by. """ new_group = self._group_by(key_type, cumulative) old_group = old_snapshot._group_by(key_type, cumulative) statistics = _compare_grouped_stats(old_group, new_group) statistics.sort(reverse=True, key=StatisticDiff._sort_key) return statistics def take_snapshot(): """ Take a snapshot of traces of memory blocks allocated by Python. """ if not is_tracing(): raise RuntimeError("the tracemalloc module must be tracing memory " "allocations to take a snapshot") traces = _get_traces() traceback_limit = get_traceback_limit() return Snapshot(traces, traceback_limit)
SILENT KILLER Tool