{
    "mode": "pydoc",
    "parameter": "tracemalloc",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/pydoc/tracemalloc/json",
    "generated": "2026-06-02T15:50:03Z",
    "sections": {
        "NAME": {
            "content": "tracemalloc\n",
            "subsections": []
        },
        "MODULE REFERENCE": {
            "content": "https://docs.python.org/3.10/library/tracemalloc.html\n\nThe following documentation is automatically generated from the Python\nsource files.  It may be incomplete, incorrect or include features that\nare considered implementation detail and may vary between Python\nimplementations.  When in doubt, consult the module reference at the\nlocation listed above.\n",
            "subsections": []
        },
        "CLASSES": {
            "content": "builtins.object\nBaseFilter\nDomainFilter\nFilter\nFrame\nSnapshot\nStatistic\nStatisticDiff\nTrace\ncollections.abc.Sequence(collections.abc.Reversible, collections.abc.Collection)\nTraceback\n",
            "subsections": [
                {
                    "name": "class BaseFilter",
                    "content": "|  BaseFilter(inclusive)\n|\n|  Methods defined here:\n|\n|  init(self, inclusive)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors defined here:\n|\n|  dict\n|      dictionary for instance variables (if defined)\n|\n|  weakref\n|      list of weak references to the object (if defined)\n"
                },
                {
                    "name": "class DomainFilter",
                    "content": "|  DomainFilter(inclusive, domain)\n|\n|  Method resolution order:\n|      DomainFilter\n|      BaseFilter\n|      builtins.object\n|\n|  Methods defined here:\n|\n|  init(self, inclusive, domain)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Readonly properties defined here:\n|\n|  domain\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors inherited from BaseFilter:\n|\n|  dict\n|      dictionary for instance variables (if defined)\n|\n|  weakref\n|      list of weak references to the object (if defined)\n"
                },
                {
                    "name": "class Filter",
                    "content": "|  Filter(inclusive, filenamepattern, lineno=None, allframes=False, domain=None)\n|\n|  Method resolution order:\n|      Filter\n|      BaseFilter\n|      builtins.object\n|\n|  Methods defined here:\n|\n|  init(self, inclusive, filenamepattern, lineno=None, allframes=False, domain=None)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Readonly properties defined here:\n|\n|  filenamepattern\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors inherited from BaseFilter:\n|\n|  dict\n|      dictionary for instance variables (if defined)\n|\n|  weakref\n|      list of weak references to the object (if defined)\n"
                },
                {
                    "name": "class Frame",
                    "content": "|  Frame(frame)\n|\n|  Frame of a traceback.\n|\n|  Methods defined here:\n|\n|  eq(self, other)\n|      Return self==value.\n|\n|  ge(self, other, NotImplemented=NotImplemented)\n|      Return a >= b.  Computed by @totalordering from (not a < b).\n|\n|  gt(self, other, NotImplemented=NotImplemented)\n|      Return a > b.  Computed by @totalordering from (not a < b) and (a != b).\n|\n|  hash(self)\n|      Return hash(self).\n|\n|  init(self, frame)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  le(self, other, NotImplemented=NotImplemented)\n|      Return a <= b.  Computed by @totalordering from (a < b) or (a == b).\n|\n|  lt(self, other)\n|      Return self<value.\n|\n|  repr(self)\n|      Return repr(self).\n|\n|  str(self)\n|      Return str(self).\n|\n|  ----------------------------------------------------------------------\n|  Readonly properties defined here:\n|\n|  filename\n|\n|  lineno\n"
                },
                {
                    "name": "class Snapshot",
                    "content": "|  Snapshot(traces, tracebacklimit)\n|\n|  Snapshot of traces of memory blocks allocated by Python.\n|\n|  Methods defined here:\n|\n|  init(self, traces, tracebacklimit)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  compareto(self, oldsnapshot, keytype, cumulative=False)\n|      Compute the differences with an old snapshot oldsnapshot. Get\n|      statistics as a sorted list of StatisticDiff instances, grouped by\n|      groupby.\n|\n|  dump(self, filename)\n|      Write the snapshot into a file.\n|\n|  filtertraces(self, filters)\n|      Create a new Snapshot instance with a filtered traces sequence, filters\n|      is a list of Filter or DomainFilter instances.  If filters is an empty\n|      list, return a new Snapshot instance with a copy of the traces.\n|\n|  statistics(self, keytype, cumulative=False)\n|      Group statistics by keytype. Return a sorted list of Statistic\n|      instances.\n|\n|  ----------------------------------------------------------------------\n|  Static methods defined here:\n|\n|  load(filename)\n|      Load a snapshot from a file.\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors defined here:\n|\n|  dict\n|      dictionary for instance variables (if defined)\n|\n|  weakref\n|      list of weak references to the object (if defined)\n"
                },
                {
                    "name": "class Statistic",
                    "content": "|  Statistic(traceback, size, count)\n|\n|  Statistic difference on memory allocations between two Snapshot instance.\n|\n|  Methods defined here:\n|\n|  eq(self, other)\n|      Return self==value.\n|\n|  hash(self)\n|      Return hash(self).\n|\n|  init(self, traceback, size, count)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  repr(self)\n|      Return repr(self).\n|\n|  str(self)\n|      Return str(self).\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors defined here:\n|\n|  count\n|\n|  size\n|\n|  traceback\n"
                },
                {
                    "name": "class StatisticDiff",
                    "content": "|  StatisticDiff(traceback, size, sizediff, count, countdiff)\n|\n|  Statistic difference on memory allocations between an old and a new\n|  Snapshot instance.\n|\n|  Methods defined here:\n|\n|  eq(self, other)\n|      Return self==value.\n|\n|  hash(self)\n|      Return hash(self).\n|\n|  init(self, traceback, size, sizediff, count, countdiff)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  repr(self)\n|      Return repr(self).\n|\n|  str(self)\n|      Return str(self).\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors defined here:\n|\n|  count\n|\n|  countdiff\n|\n|  size\n|\n|  sizediff\n|\n|  traceback\n"
                },
                {
                    "name": "class Trace",
                    "content": "|  Trace(trace)\n|\n|  Trace of a memory block.\n|\n|  Methods defined here:\n|\n|  eq(self, other)\n|      Return self==value.\n|\n|  hash(self)\n|      Return hash(self).\n|\n|  init(self, trace)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  repr(self)\n|      Return repr(self).\n|\n|  str(self)\n|      Return str(self).\n|\n|  ----------------------------------------------------------------------\n|  Readonly properties defined here:\n|\n|  domain\n|\n|  size\n|\n|  traceback\n"
                },
                {
                    "name": "class Traceback",
                    "content": "|  Traceback(frames, totalnframe=None)\n|\n|  Sequence of Frame instances sorted from the oldest frame\n|  to the most recent frame.\n|\n|  Method resolution order:\n|      Traceback\n|      collections.abc.Sequence\n|      collections.abc.Reversible\n|      collections.abc.Collection\n|      collections.abc.Sized\n|      collections.abc.Iterable\n|      collections.abc.Container\n|      builtins.object\n|\n|  Methods defined here:\n|\n|  contains(self, frame)\n|\n|  eq(self, other)\n|      Return self==value.\n|\n|  ge(self, other, NotImplemented=NotImplemented)\n|      Return a >= b.  Computed by @totalordering from (not a < b).\n|\n|  getitem(self, index)\n|\n|  gt(self, other, NotImplemented=NotImplemented)\n|      Return a > b.  Computed by @totalordering from (not a < b) and (a != b).\n|\n|  hash(self)\n|      Return hash(self).\n|\n|  init(self, frames, totalnframe=None)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  le(self, other, NotImplemented=NotImplemented)\n|      Return a <= b.  Computed by @totalordering from (a < b) or (a == b).\n|\n|  len(self)\n|\n|  lt(self, other)\n|      Return self<value.\n|\n|  repr(self)\n|      Return repr(self).\n|\n|  str(self)\n|      Return str(self).\n|\n|  format(self, limit=None, mostrecentfirst=False)\n|\n|  ----------------------------------------------------------------------\n|  Readonly properties defined here:\n|\n|  totalnframe\n|\n|  ----------------------------------------------------------------------\n|  Data and other attributes defined here:\n|\n|  abstractmethods = frozenset()\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from collections.abc.Sequence:\n|\n|  iter(self)\n|\n|  reversed(self)\n|\n|  count(self, value)\n|      S.count(value) -> integer -- return number of occurrences of value\n|\n|  index(self, value, start=0, stop=None)\n|      S.index(value, [start, [stop]]) -> integer -- return first index of value.\n|      Raises ValueError if the value is not present.\n|\n|      Supporting start and stop arguments is optional, but\n|      recommended.\n|\n|  ----------------------------------------------------------------------\n|  Class methods inherited from collections.abc.Reversible:\n|\n|  subclasshook(C) from abc.ABCMeta\n|      Abstract classes can override this to customize issubclass().\n|\n|      This is invoked early on by abc.ABCMeta.subclasscheck().\n|      It should return True, False or NotImplemented.  If it returns\n|      NotImplemented, the normal algorithm is used.  Otherwise, it\n|      overrides the normal algorithm (and the outcome is cached).\n|\n|  ----------------------------------------------------------------------\n|  Class methods inherited from collections.abc.Iterable:\n|\n|  classgetitem = GenericAlias(...) from abc.ABCMeta\n|      Represent a PEP 585 generic type\n|\n|      E.g. for t = list[int], t.origin is list and t.args is (int,).\n"
                }
            ]
        },
        "FUNCTIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "clear_traces",
                    "content": "Clear traces of memory blocks allocated by Python.\n"
                },
                {
                    "name": "get_object_traceback",
                    "content": "Get the traceback where the Python object *obj* was allocated.\nReturn a Traceback instance.\n\nReturn None if the tracemalloc module is not tracing memory allocations or\ndid not trace the allocation of the object.\n"
                },
                {
                    "name": "get_traceback_limit",
                    "content": "Get the maximum number of frames stored in the traceback of a trace.\n\nBy default, a trace of an allocated memory block only stores\nthe most recent frame: the limit is 1.\n"
                },
                {
                    "name": "get_traced_memory",
                    "content": "Get the current size and peak size of memory blocks traced by tracemalloc.\n\nReturns a tuple: (current: int, peak: int).\n"
                },
                {
                    "name": "get_tracemalloc_memory",
                    "content": "Get the memory usage in bytes of the tracemalloc module.\n\nThis memory is used internally to trace memory allocations.\n"
                },
                {
                    "name": "is_tracing",
                    "content": "Return True if the tracemalloc module is tracing Python memory allocations.\n"
                },
                {
                    "name": "reset_peak",
                    "content": "Set the peak size of memory blocks traced by tracemalloc to the current size.\n\nDo nothing if the tracemalloc module is not tracing memory allocations.\n"
                },
                {
                    "name": "start",
                    "content": "Start tracing Python memory allocations.\n\nAlso set the maximum number of frames stored in the traceback of a\ntrace to nframe.\n"
                },
                {
                    "name": "stop",
                    "content": "Stop tracing Python memory allocations.\n\nAlso clear traces of memory blocks allocated by Python.\n"
                },
                {
                    "name": "take_snapshot",
                    "content": "Take a snapshot of traces of memory blocks allocated by Python.\n"
                }
            ]
        },
        "FILE": {
            "content": "/usr/lib/python3.10/tracemalloc.py\n\n",
            "subsections": []
        }
    },
    "summary": "tracemalloc",
    "flags": [],
    "examples": [],
    "see_also": []
}