jgdv.debugging.malloc_tool

See EOF for license/metadata/notes as applicable

Functions

must_be_started(fn)

Classes

MallocTool

see tracemalloc

Module Contents

jgdv.debugging.malloc_tool.must_be_started(fn) <Unknown>[source]
Parameters:

fn (collections.abc.Callable[Concatenate[MallocTool, must_be_started.I], must_be_started.O])

Return type:

collections.abc.Callable[Concatenate[MallocTool, must_be_started.I], must_be_started.O]

class jgdv.debugging.malloc_tool.MallocTool(*, frame_count=5, logger=None)[source]

see tracemalloc in the stdlib. eg:

with MallocTool(frame_count=2) as dm:
    dm.whitelist(__file__)
    dm.blacklist("\*tracemalloc.py", all_frames=False)
    val = 2
    dm.snapshot("simple")
    vals = [random.random() for x in range(1000)]
    dm.current()
    dm.snapshot("list")
    vals = None
    dm.current()
    dm.snapshot("cleared")

dm.compare("simple", "list")
dm.compare("list", "cleared")
dm.compare("list", "simple")
dm.inspect("list")
Parameters:
_check_file_pat(file_pat, file_name) <Unknown>[source]
Parameters:
  • file_pat (str)

  • file_name (str)

Return type:

bool

_get_snapshot(val, *, filter=True) <Unknown>[source]

Retrieve a snapshot, with control of whether it is filtered or not

Parameters:
Return type:

tracemalloc.Snapshot

abstractmethod _get_top_n(stats, count=10) <Unknown>[source]

Get the top {count} sized objects of a difference

Parameters:
Return type:

list[tracemalloc.StatisticDiff]

_human(num, *, sign=False) <Unknown>[source]

Format a sized number in a human readable way. optionally with a sign prefix

Parameters:
Return type:

str

_print_diff_frames(
stat,
*,
idx=None,
fullpath=False,
) <Unknown>[source]

Print a diff, with stacktrace

Parameters:
Return type:

None

_print_diff_noframes(
stat,
*,
idx=None,
fullpath=False,
) <Unknown>[source]

Print a diff without showing the stacktrace

Parameters:
Return type:

None

_print_obj_stat_frames(
stat,
*,
idx=None,
fullpath=False,
) <Unknown>[source]

Print a stacktrace for a a given object diff

Parameters:
Return type:

None

blacklist(
file_pat,
*,
lineno=None,
all_frames=True,
) <Unknown>[source]

Blacklist a file pattern

Parameters:
  • file_pat (str)

  • lineno (jgdv.Maybe[int])

  • all_frames (bool)

Return type:

Self

compare(
val1,
val2,
*,
form='traceback',
filter=True,
fullpath=False,
count=10,
) <Unknown>[source]

Compare two snapshots, with control over filtering, output formatting, and the number of objects to report about

Parameters:
Return type:

None

current(val=None) <Unknown>[source]

Print a brief report about the current memory state

Parameters:

val (jgdv.Maybe[object])

Return type:

None

inspect(
val,
*,
form='traceback',
filter=True,
fullpath=False,
) <Unknown>[source]

Inspect a single snapshot of the memory state

Parameters:
Return type:

None

snapshot(name=None) <Unknown>[source]

Take a snapshot of the current memory state

Parameters:

name (jgdv.Maybe[str])

Return type:

None

whitelist(
file_pat,
*,
lineno=None,
all_frames=True,
) <Unknown>[source]

Add a filter to whitelist a file pattern

Parameters:
  • file_pat (str)

  • lineno (jgdv.Maybe[int])

  • all_frames (bool)

Return type:

Self

_allocation_loc_msg: str
_change_msg: str
_cmp_enter_msg: str
_curr_mem_msg: str
_diff_msg: str
_enter_msg: str
_exit_msg: str
_gen_exit_msg = '[TraceMalloc]: -- %s --'
_inspect_msg: str
_logger: logging.Logger
_stat_line_msg: str
_stat_line_no_frames_msg = '[TraceMalloc]: (obj:%s) %-15s : %-50s (%s:%s)'
_take_snap_msg: str
filters: list[tracemalloc.Filter]
frame_count: int
named_snapshots: dict[str, tracemalloc.Snapshot]
snapshots: list[tracemalloc.Snapshot]
started: bool