mirror of
https://github.com/python/cpython.git
synced 2025-12-10 11:00:14 +00:00
Add C functions _PyTraceMalloc_Track()
Issue #26530: * Add C functions _PyTraceMalloc_Track() and _PyTraceMalloc_Untrack() to track memory blocks using the tracemalloc module. * Add _PyTraceMalloc_GetTraceback() to get the traceback of an object.
This commit is contained in:
parent
e492ae50e2
commit
10b73e1748
5 changed files with 300 additions and 11 deletions
|
|
@ -25,6 +25,40 @@ PyAPI_FUNC(int) _PyMem_SetupAllocators(const char *opt);
|
|||
PyAPI_FUNC(int) _PyMem_PymallocEnabled(void);
|
||||
#endif
|
||||
|
||||
/* Identifier of an address space (domain) in tracemalloc */
|
||||
typedef unsigned int _PyTraceMalloc_domain_t;
|
||||
|
||||
/* Track an allocated memory block in the tracemalloc module.
|
||||
Return 0 on success, return -1 on error (failed to allocate memory to store
|
||||
the trace).
|
||||
|
||||
Return -2 if tracemalloc is disabled.
|
||||
|
||||
If memory block was already tracked, begin by removing the old trace. */
|
||||
PyAPI_FUNC(int) _PyTraceMalloc_Track(
|
||||
_PyTraceMalloc_domain_t domain,
|
||||
Py_uintptr_t ptr,
|
||||
size_t size);
|
||||
|
||||
/* Untrack an allocated memory block in the tracemalloc module.
|
||||
Do nothing if the block was not tracked.
|
||||
|
||||
Return -2 if tracemalloc is disabled, otherwise return 0. */
|
||||
PyAPI_FUNC(int) _PyTraceMalloc_Untrack(
|
||||
_PyTraceMalloc_domain_t domain,
|
||||
Py_uintptr_t ptr);
|
||||
|
||||
/* Get the traceback where a memory block was allocated.
|
||||
|
||||
Return a tuple of (filename: str, lineno: int) tuples.
|
||||
|
||||
Return None if the tracemalloc module is disabled or if the memory block
|
||||
is not tracked by tracemalloc.
|
||||
|
||||
Raise an exception and return NULL on error. */
|
||||
PyAPI_FUNC(PyObject*) _PyTraceMalloc_GetTraceback(
|
||||
_PyTraceMalloc_domain_t domain,
|
||||
Py_uintptr_t ptr);
|
||||
#endif /* !Py_LIMITED_API */
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue