pooltool.utils¶
Utilities¶
Overview¶
Decorator for a class property |
|
Small wrapper for pprofile that accepts a filepath and outputs cachegrind file |
|
Save an object x to filepath path |
|
|
|
Get the total memory, including children |
|
A pretty-print for the tracemalloc memory usage module |
|
Convert memory usage data from tracemalloc into a pandas DataFrame. |
Classes¶
Functions¶
- pooltool.utils.get_total_memory_usage(keep_raw=False)[source]¶
Get the total memory, including children
- Parameters:
keep_raw (bool, False) -- A human readable format is returned, e.g. “1.41 GB”. If keep_raw, the raw number is returned, e.g. 1515601920
- pooltool.utils.display_top_memory_usage(snapshot, key_type='lineno', limit=10)[source]¶
A pretty-print for the tracemalloc memory usage module
Modified from https://docs.python.org/3/library/tracemalloc.html
Examples
>>> import tracemalloc >>> import pooltool.utils as utils >>> tracemalloc.start() >>> snap = tracemalloc.take_snapshot >>> utils.display_top_memory_usage(snap) Top 10 lines #1: anvio/bamops.py:160: 4671.3 KiB constants.cigar_consumption, #2: anvio/bamops.py:96: 2571.6 KiB self.cigartuples = np.array(read.cigartuples) #3: python3.6/linecache.py:137: 1100.0 KiB lines = fp.readlines() #4: <frozen importlib._bootstrap_external>:487: 961.4 KiB #5: typing/templates.py:627: 334.3 KiB return type(base)(name, (base,), dct) #6: typing/templates.py:923: 315.7 KiB class Template(cls): #7: python3.6/_weakrefset.py:84: 225.2 KiB self.data.add(ref(item, self._remove)) #8: targets/npyimpl.py:411: 143.2 KiB class _KernelImpl(_Kernel): #9: _vendor/pyparsing.py:3349: 139.7 KiB self.errmsg = "Expected " + _ustr(self) #10: typing/context.py:456: 105.1 KiB def on_disposal(wr, pop=self._globals.pop): 3212 other: 4611.9 KiB Total allocated size: 15179.4 KiB
- pooltool.utils.memory_usage_to_dataframe(snapshot, key_type='lineno', limit=10)[source]¶
Convert memory usage data from tracemalloc into a pandas DataFrame.
Args: snapshot (tracemalloc.Snapshot): The snapshot of memory allocation. key_type (str): The type of key to categorize memory usage. limit (int): The number of top entries to include.
Returns: pd.DataFrame: DataFrame containing memory usage information.