[ SYSTEM ]: Linux srv.persadacompanies.com 4.18.0-553.56.1.el8_10.x86_64 #1 SMP Tue Jun 10 05:00:59 EDT 2025 x86_64
[ SERVER ]: Apache | PHP: 8.4.19
[ USER ]: persadamedika | IP: 45.64.1.108
GEFORCE FILE MANAGER
/
usr
/
lib64
/
python3.12
/
UPLOAD:
NAME
SIZE
QUICK PERMS
ACTIONS
📁 __pycache__
SET
[ DEL ]
📁 asyncio
SET
[ DEL ]
📁 collections
SET
[ DEL ]
📁 concurrent
SET
[ DEL ]
📁 config-3.12-x86_64-linux-gnu
SET
[ DEL ]
📁 ctypes
SET
[ DEL ]
📁 curses
SET
[ DEL ]
📁 dbm
SET
[ DEL ]
📁 email
SET
[ DEL ]
📁 encodings
SET
[ DEL ]
📁 ensurepip
SET
[ DEL ]
📁 html
SET
[ DEL ]
📁 http
SET
[ DEL ]
📁 importlib
SET
[ DEL ]
📁 json
SET
[ DEL ]
📁 lib-dynload
SET
[ DEL ]
📁 lib2to3
SET
[ DEL ]
📁 logging
SET
[ DEL ]
📁 multiprocessing
SET
[ DEL ]
📁 pydoc_data
SET
[ DEL ]
📁 re
SET
[ DEL ]
📁 site-packages
SET
[ DEL ]
📁 sqlite3
SET
[ DEL ]
📁 tomllib
SET
[ DEL ]
📁 unittest
SET
[ DEL ]
📁 urllib
SET
[ DEL ]
📁 venv
SET
[ DEL ]
📁 wsgiref
SET
[ DEL ]
📁 xml
SET
[ DEL ]
📁 xmlrpc
SET
[ DEL ]
📁 zipfile
SET
[ DEL ]
📁 zoneinfo
SET
[ DEL ]
📄 LICENSE.txt
13,936 B
SET
[ EDIT ]
|
[ DEL ]
📄 __future__.py
5,218 B
SET
[ EDIT ]
|
[ DEL ]
📄 __hello__.py
227 B
SET
[ EDIT ]
|
[ DEL ]
📄 _aix_support.py
4,021 B
SET
[ EDIT ]
|
[ DEL ]
📄 _collections_abc.py
32,089 B
SET
[ EDIT ]
|
[ DEL ]
📄 _compat_pickle.py
8,761 B
SET
[ EDIT ]
|
[ DEL ]
📄 _compression.py
5,681 B
SET
[ EDIT ]
|
[ DEL ]
📄 _markupbase.py
14,653 B
SET
[ EDIT ]
|
[ DEL ]
📄 _osx_support.py
22,023 B
SET
[ EDIT ]
|
[ DEL ]
📄 _py_abc.py
6,189 B
SET
[ EDIT ]
|
[ DEL ]
📄 _pydatetime.py
92,087 B
SET
[ EDIT ]
|
[ DEL ]
📄 _pydecimal.py
227,283 B
SET
[ EDIT ]
|
[ DEL ]
📄 _pyio.py
93,593 B
SET
[ EDIT ]
|
[ DEL ]
📄 _pylong.py
10,790 B
SET
[ EDIT ]
|
[ DEL ]
📄 _sitebuiltins.py
3,128 B
SET
[ EDIT ]
|
[ DEL ]
📄 _strptime.py
28,393 B
SET
[ EDIT ]
|
[ DEL ]
📄 _sysconfigdata__linux_x86_64-linux-gnu.py
72,132 B
SET
[ EDIT ]
|
[ DEL ]
📄 _threading_local.py
7,220 B
SET
[ EDIT ]
|
[ DEL ]
📄 _weakrefset.py
5,893 B
SET
[ EDIT ]
|
[ DEL ]
📄 abc.py
6,538 B
SET
[ EDIT ]
|
[ DEL ]
📄 aifc.py
34,211 B
SET
[ EDIT ]
|
[ DEL ]
📄 antigravity.py
500 B
SET
[ EDIT ]
|
[ DEL ]
📄 argparse.py
101,155 B
SET
[ EDIT ]
|
[ DEL ]
📄 ast.py
64,452 B
SET
[ EDIT ]
|
[ DEL ]
📄 base64.py
20,634 B
SET
[ EDIT ]
|
[ DEL ]
📄 bdb.py
33,573 B
SET
[ EDIT ]
|
[ DEL ]
📄 bisect.py
3,423 B
SET
[ EDIT ]
|
[ DEL ]
📄 bz2.py
11,847 B
SET
[ EDIT ]
|
[ DEL ]
📄 cProfile.py
6,555 B
SET
[ EDIT ]
|
[ DEL ]
📄 calendar.py
25,864 B
SET
[ EDIT ]
|
[ DEL ]
📄 cgi.py
34,418 B
SET
[ EDIT ]
|
[ DEL ]
📄 cgitb.py
12,421 B
SET
[ EDIT ]
|
[ DEL ]
📄 chunk.py
5,500 B
SET
[ EDIT ]
|
[ DEL ]
📄 cmd.py
14,873 B
SET
[ EDIT ]
|
[ DEL ]
📄 code.py
10,962 B
SET
[ EDIT ]
|
[ DEL ]
📄 codecs.py
36,870 B
SET
[ EDIT ]
|
[ DEL ]
📄 codeop.py
5,908 B
SET
[ EDIT ]
|
[ DEL ]
📄 colorsys.py
4,062 B
SET
[ EDIT ]
|
[ DEL ]
📄 compileall.py
20,507 B
SET
[ EDIT ]
|
[ DEL ]
📄 configparser.py
53,789 B
SET
[ EDIT ]
|
[ DEL ]
📄 contextlib.py
27,637 B
SET
[ EDIT ]
|
[ DEL ]
📄 contextvars.py
129 B
SET
[ EDIT ]
|
[ DEL ]
📄 copy.py
8,412 B
SET
[ EDIT ]
|
[ DEL ]
📄 copyreg.py
7,614 B
SET
[ EDIT ]
|
[ DEL ]
📄 crypt.py
3,913 B
SET
[ EDIT ]
|
[ DEL ]
📄 csv.py
16,386 B
SET
[ EDIT ]
|
[ DEL ]
📄 dataclasses.py
62,085 B
SET
[ EDIT ]
|
[ DEL ]
📄 datetime.py
268 B
SET
[ EDIT ]
|
[ DEL ]
📄 decimal.py
2,805 B
SET
[ EDIT ]
|
[ DEL ]
📄 difflib.py
83,368 B
SET
[ EDIT ]
|
[ DEL ]
📄 dis.py
30,227 B
SET
[ EDIT ]
|
[ DEL ]
📄 doctest.py
106,749 B
SET
[ EDIT ]
|
[ DEL ]
📄 enum.py
81,540 B
SET
[ EDIT ]
|
[ DEL ]
📄 filecmp.py
10,381 B
SET
[ EDIT ]
|
[ DEL ]
📄 fileinput.py
15,714 B
SET
[ EDIT ]
|
[ DEL ]
📄 fnmatch.py
5,999 B
SET
[ EDIT ]
|
[ DEL ]
📄 fractions.py
38,147 B
SET
[ EDIT ]
|
[ DEL ]
📄 ftplib.py
34,735 B
SET
[ EDIT ]
|
[ DEL ]
📄 functools.py
37,940 B
SET
[ EDIT ]
|
[ DEL ]
📄 genericpath.py
5,572 B
SET
[ EDIT ]
|
[ DEL ]
📄 getopt.py
7,488 B
SET
[ EDIT ]
|
[ DEL ]
📄 getpass.py
5,990 B
SET
[ EDIT ]
|
[ DEL ]
📄 gettext.py
21,320 B
SET
[ EDIT ]
|
[ DEL ]
📄 glob.py
8,732 B
SET
[ EDIT ]
|
[ DEL ]
📄 graphlib.py
9,648 B
SET
[ EDIT ]
|
[ DEL ]
📄 gzip.py
25,402 B
SET
[ EDIT ]
|
[ DEL ]
📄 hashlib.py
9,683 B
SET
[ EDIT ]
|
[ DEL ]
📄 heapq.py
23,024 B
SET
[ EDIT ]
|
[ DEL ]
📄 hmac.py
8,043 B
SET
[ EDIT ]
|
[ DEL ]
📄 imaplib.py
54,209 B
SET
[ EDIT ]
|
[ DEL ]
📄 imghdr.py
4,398 B
SET
[ EDIT ]
|
[ DEL ]
📄 inspect.py
127,125 B
SET
[ EDIT ]
|
[ DEL ]
📄 io.py
3,582 B
SET
[ EDIT ]
|
[ DEL ]
📄 ipaddress.py
81,414 B
SET
[ EDIT ]
|
[ DEL ]
📄 keyword.py
1,073 B
SET
[ EDIT ]
|
[ DEL ]
📄 linecache.py
5,800 B
SET
[ EDIT ]
|
[ DEL ]
📄 locale.py
78,599 B
SET
[ EDIT ]
|
[ DEL ]
📄 lzma.py
13,277 B
SET
[ EDIT ]
|
[ DEL ]
📄 mailbox.py
78,911 B
SET
[ EDIT ]
|
[ DEL ]
📄 mailcap.py
9,333 B
SET
[ EDIT ]
|
[ DEL ]
📄 mimetypes.py
23,037 B
SET
[ EDIT ]
|
[ DEL ]
📄 modulefinder.py
23,699 B
SET
[ EDIT ]
|
[ DEL ]
📄 netrc.py
6,922 B
SET
[ EDIT ]
|
[ DEL ]
📄 nntplib.py
41,087 B
SET
[ EDIT ]
|
[ DEL ]
📄 ntpath.py
32,324 B
SET
[ EDIT ]
|
[ DEL ]
📄 nturl2path.py
2,374 B
SET
[ EDIT ]
|
[ DEL ]
📄 numbers.py
11,467 B
SET
[ EDIT ]
|
[ DEL ]
📄 opcode.py
13,174 B
SET
[ EDIT ]
|
[ DEL ]
📄 operator.py
10,965 B
SET
[ EDIT ]
|
[ DEL ]
📄 optparse.py
60,369 B
SET
[ EDIT ]
|
[ DEL ]
📄 os.py
40,821 B
SET
[ EDIT ]
|
[ DEL ]
📄 pathlib.py
51,052 B
SET
[ EDIT ]
|
[ DEL ]
📄 pdb.py
70,297 B
SET
[ EDIT ]
|
[ DEL ]
📄 pickle.py
66,911 B
SET
[ EDIT ]
|
[ DEL ]
📄 pickletools.py
94,052 B
SET
[ EDIT ]
|
[ DEL ]
📄 pipes.py
8,978 B
SET
[ EDIT ]
|
[ DEL ]
📄 pkgutil.py
18,281 B
SET
[ EDIT ]
|
[ DEL ]
📄 platform.py
43,388 B
SET
[ EDIT ]
|
[ DEL ]
📄 plistlib.py
28,342 B
SET
[ EDIT ]
|
[ DEL ]
📄 poplib.py
14,742 B
SET
[ EDIT ]
|
[ DEL ]
📄 posixpath.py
17,483 B
SET
[ EDIT ]
|
[ DEL ]
📄 pprint.py
24,158 B
SET
[ EDIT ]
|
[ DEL ]
📄 profile.py
23,092 B
SET
[ EDIT ]
|
[ DEL ]
📄 pstats.py
29,289 B
SET
[ EDIT ]
|
[ DEL ]
📄 pty.py
6,137 B
SET
[ EDIT ]
|
[ DEL ]
📄 py_compile.py
7,837 B
SET
[ EDIT ]
|
[ DEL ]
📄 pyclbr.py
11,396 B
SET
[ EDIT ]
|
[ DEL ]
📄 pydoc.py
113,508 B
SET
[ EDIT ]
|
[ DEL ]
📄 queue.py
11,496 B
SET
[ EDIT ]
|
[ DEL ]
📄 quopri.py
7,183 B
SET
[ EDIT ]
|
[ DEL ]
📄 random.py
34,689 B
SET
[ EDIT ]
|
[ DEL ]
📄 reprlib.py
7,148 B
SET
[ EDIT ]
|
[ DEL ]
📄 rlcompleter.py
7,827 B
SET
[ EDIT ]
|
[ DEL ]
📄 runpy.py
12,885 B
SET
[ EDIT ]
|
[ DEL ]
📄 sched.py
6,351 B
SET
[ EDIT ]
|
[ DEL ]
📄 secrets.py
1,984 B
SET
[ EDIT ]
|
[ DEL ]
📄 selectors.py
19,671 B
SET
[ EDIT ]
|
[ DEL ]
📄 shelve.py
8,560 B
SET
[ EDIT ]
|
[ DEL ]
📄 shlex.py
13,353 B
SET
[ EDIT ]
|
[ DEL ]
📄 shutil.py
56,762 B
SET
[ EDIT ]
|
[ DEL ]
📄 signal.py
2,495 B
SET
[ EDIT ]
|
[ DEL ]
📄 site.py
23,439 B
SET
[ EDIT ]
|
[ DEL ]
📄 smtplib.py
43,531 B
SET
[ EDIT ]
|
[ DEL ]
📄 sndhdr.py
7,448 B
SET
[ EDIT ]
|
[ DEL ]
📄 socket.py
37,815 B
SET
[ EDIT ]
|
[ DEL ]
📄 socketserver.py
28,065 B
SET
[ EDIT ]
|
[ DEL ]
📄 sre_compile.py
231 B
SET
[ EDIT ]
|
[ DEL ]
📄 sre_constants.py
232 B
SET
[ EDIT ]
|
[ DEL ]
📄 sre_parse.py
229 B
SET
[ EDIT ]
|
[ DEL ]
📄 ssl.py
50,904 B
SET
[ EDIT ]
|
[ DEL ]
📄 stat.py
5,485 B
SET
[ EDIT ]
|
[ DEL ]
📄 statistics.py
50,227 B
SET
[ EDIT ]
|
[ DEL ]
📄 string.py
11,786 B
SET
[ EDIT ]
|
[ DEL ]
📄 stringprep.py
12,917 B
SET
[ EDIT ]
|
[ DEL ]
📄 struct.py
257 B
SET
[ EDIT ]
|
[ DEL ]
📄 subprocess.py
88,747 B
SET
[ EDIT ]
|
[ DEL ]
📄 sunau.py
18,478 B
SET
[ EDIT ]
|
[ DEL ]
📄 symtable.py
12,477 B
SET
[ EDIT ]
|
[ DEL ]
📄 sysconfig.py
33,773 B
SET
[ EDIT ]
|
[ DEL ]
📄 tabnanny.py
11,531 B
SET
[ EDIT ]
|
[ DEL ]
📄 tarfile.py
114,250 B
SET
[ EDIT ]
|
[ DEL ]
📄 telnetlib.py
23,334 B
SET
[ EDIT ]
|
[ DEL ]
📄 tempfile.py
32,386 B
SET
[ EDIT ]
|
[ DEL ]
📄 textwrap.py
19,718 B
SET
[ EDIT ]
|
[ DEL ]
📄 this.py
1,003 B
SET
[ EDIT ]
|
[ DEL ]
📄 threading.py
59,742 B
SET
[ EDIT ]
|
[ DEL ]
📄 timeit.py
13,463 B
SET
[ EDIT ]
|
[ DEL ]
📄 token.py
2,511 B
SET
[ EDIT ]
|
[ DEL ]
📄 tokenize.py
21,570 B
SET
[ EDIT ]
|
[ DEL ]
📄 trace.py
29,352 B
SET
[ EDIT ]
|
[ DEL ]
📄 traceback.py
46,393 B
SET
[ EDIT ]
|
[ DEL ]
📄 tracemalloc.py
18,047 B
SET
[ EDIT ]
|
[ DEL ]
📄 tty.py
2,035 B
SET
[ EDIT ]
|
[ DEL ]
📄 types.py
10,993 B
SET
[ EDIT ]
|
[ DEL ]
📄 typing.py
118,836 B
SET
[ EDIT ]
|
[ DEL ]
📄 uu.py
7,341 B
SET
[ EDIT ]
|
[ DEL ]
📄 uuid.py
29,656 B
SET
[ EDIT ]
|
[ DEL ]
📄 warnings.py
21,909 B
SET
[ EDIT ]
|
[ DEL ]
📄 wave.py
22,769 B
SET
[ EDIT ]
|
[ DEL ]
📄 weakref.py
21,513 B
SET
[ EDIT ]
|
[ DEL ]
📄 webbrowser.py
24,141 B
SET
[ EDIT ]
|
[ DEL ]
📄 xdrlib.py
5,942 B
SET
[ EDIT ]
|
[ DEL ]
📄 zipapp.py
7,543 B
SET
[ EDIT ]
|
[ DEL ]
📄 zipimport.py
27,840 B
SET
[ EDIT ]
|
[ DEL ]
DELETE SELECTED
[ CLOSE ]
EDIT: tracemalloc.py
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): if not isinstance(other, Statistic): return NotImplemented 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): if not isinstance(other, StatisticDiff): return NotImplemented 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): if not isinstance(other, Frame): return NotImplemented return (self._frame == other._frame) def __lt__(self, other): if not isinstance(other, Frame): return NotImplemented 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", '_total_nframe') def __init__(self, frames, total_nframe=None): 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)) self._total_nframe = total_nframe @property def total_nframe(self): return self._total_nframe 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): if not isinstance(other, Traceback): return NotImplemented return (self._frames == other._frames) def __lt__(self, other): if not isinstance(other, Traceback): return NotImplemented return (self._frames < other._frames) def __str__(self): return str(self[0]) def __repr__(self): s = f"<Traceback {tuple(self)}" if self._total_nframe is None: s += ">" else: s += f" total_nframe={self.total_nframe}>" return s 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): if not isinstance(other, Trace): return NotImplemented 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): if not isinstance(other, _Traces): return NotImplemented 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, total_nframe = 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, total_nframe = 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, total_nframe = 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, total_nframe = 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)