dump data: corelibs_dump_data stack trace: corelibs_stack_trace profiling, timing, etc: corelibs_debug
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
"""
|
|
Profile memory usage in Python
|
|
"""
|
|
|
|
# https://docs.python.org/3/library/tracemalloc.html
|
|
|
|
from warnings import warn, deprecated
|
|
from typing import TYPE_CHECKING
|
|
from corelibs_debug.profiling import display_top as display_top_ng, display_top_str, Profiling as CoreLibsProfiling
|
|
if TYPE_CHECKING:
|
|
from tracemalloc import Snapshot
|
|
|
|
|
|
@deprecated("Use corelibs_debug.profiling.display_top_str with data from display_top instead")
|
|
def display_top(snapshot: 'Snapshot', key_type: str = 'lineno', limit: int = 10) -> str:
|
|
"""
|
|
Print tracmalloc stats
|
|
https://docs.python.org/3/library/tracemalloc.html#pretty-top
|
|
|
|
Args:
|
|
snapshot ('Snapshot'): _description_
|
|
key_type (str, optional): _description_. Defaults to 'lineno'.
|
|
limit (int, optional): _description_. Defaults to 10.
|
|
"""
|
|
return display_top_str(
|
|
display_top_ng(
|
|
snapshot=snapshot,
|
|
key_type=key_type,
|
|
limit=limit
|
|
)
|
|
)
|
|
|
|
|
|
class Profiling(CoreLibsProfiling):
|
|
"""
|
|
Profile memory usage and elapsed time for some block
|
|
Based on: https://stackoverflow.com/a/53301648
|
|
"""
|
|
|
|
|
|
warn("Use corelibs_debug.profiling.Profiling instead", DeprecationWarning, stacklevel=2)
|
|
|
|
# __END__
|