.. _jgdv.debugging.malloc_tool: ========================== jgdv.debugging.malloc_tool ========================== .. py:module:: jgdv.debugging.malloc_tool .. autoapi-nested-parse:: See EOF for license/metadata/notes as applicable Functions --------- .. autoapisummary:: jgdv.debugging.malloc_tool.must_be_started Classes ------- .. autoapisummary:: jgdv.debugging.malloc_tool.MallocTool Module Contents =============== .. py:function:: must_be_started(fn) -> .. _jgdv.debugging.malloc_tool.MallocTool: .. py:class:: MallocTool(*, frame_count = 5, logger = None) 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") .. py:method:: _check_file_pat(file_pat, file_name) -> .. py:method:: _get_snapshot(val, *, filter = True) -> Retrieve a snapshot, with control of whether it is filtered or not .. py:method:: _get_top_n(stats, count = 10) -> :abstractmethod: Get the top {count} sized objects of a difference .. py:method:: _human(num, *, sign = False) -> Format a sized number in a human readable way. optionally with a sign prefix .. py:method:: _print_diff_frames(stat, *, idx = None, fullpath = False) -> Print a diff, with stacktrace .. py:method:: _print_diff_noframes(stat, *, idx = None, fullpath = False) -> Print a diff without showing the stacktrace .. py:method:: _print_obj_stat_frames(stat, *, idx = None, fullpath = False) -> Print a stacktrace for a a given object diff .. py:method:: blacklist(file_pat, *, lineno = None, all_frames = True) -> Blacklist a file pattern .. py:method:: compare(val1, val2, *, form = 'traceback', filter = True, fullpath = False, count = 10) -> Compare two snapshots, with control over filtering, output formatting, and the number of objects to report about .. py:method:: current(val = None) -> Print a brief report about the current memory state .. py:method:: inspect(val, *, form = 'traceback', filter = True, fullpath = False) -> Inspect a single snapshot of the memory state .. py:method:: snapshot(name = None) -> Take a snapshot of the current memory state .. py:method:: whitelist(file_pat, *, lineno = None, all_frames = True) -> Add a filter to whitelist a file pattern .. py:attribute:: _allocation_loc_msg :type: str .. py:attribute:: _change_msg :type: str .. py:attribute:: _cmp_enter_msg :type: str .. py:attribute:: _curr_mem_msg :type: str .. py:attribute:: _diff_msg :type: str .. py:attribute:: _enter_msg :type: str .. py:attribute:: _exit_msg :type: str .. py:attribute:: _gen_exit_msg :value: '[TraceMalloc]: -- %s --' .. py:attribute:: _inspect_msg :type: str .. py:attribute:: _logger :type: logging.Logger .. py:attribute:: _stat_line_msg :type: str .. py:attribute:: _stat_line_no_frames_msg :value: '[TraceMalloc]: (obj:%s) %-15s : %-50s (%s:%s)' .. py:attribute:: _take_snap_msg :type: str .. py:attribute:: filters :type: list[tracemalloc.Filter] .. py:attribute:: frame_count :type: int .. py:attribute:: named_snapshots :type: dict[str, tracemalloc.Snapshot] .. py:attribute:: snapshots :type: list[tracemalloc.Snapshot] .. py:attribute:: started :type: bool