On this page
  1. tracemalloc.Snapshot
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

tracemalloc.Snapshot

Prev: tracemalloc.Sequence | Up: tracemalloc | Next: tracemalloc.start
Rel: tracemalloc.BaseFilter, tracemalloc.clear_traces, tracemalloc.DomainFilter, tracemalloc.Filter
Ref: docs.python.org — tracemalloc.Snapshot
Tags: #public #python3 #stdlib #tracemalloc


Import

import tracemalloc
from tracemalloc import Snapshot

Signature & Overview

tracemalloc.Snapshot(traces, traceback_limit)

Snapshot of traces of memory blocks allocated by Python.

Methods & Attributes

Usage

import tracemalloc

tracemalloc.start()
try:
    s1 = tracemalloc.take_snapshot()
    _big = [0] * 5000
    s2 = tracemalloc.take_snapshot()
    diff = s2.compare_to(s1, 'lineno')
    assert isinstance(s1, tracemalloc.Snapshot) and len(diff) >= 1
finally:
    tracemalloc.stop()

Gotchas

REPL Inspect

from tracemalloc import Snapshot
help(Snapshot)

Linked from

Related notes