diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-03-22 13:39:05 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-03-22 13:39:05 +0100 |
commit | 10b73e17489048419b512f6710aecba62ff5b91a (patch) | |
tree | 091166b7bbae2f92f0993729ad6378544126dd6c /Include/pymem.h | |
parent | tracemalloc now supports domains (diff) | |
download | cpython-10b73e17489048419b512f6710aecba62ff5b91a.tar.gz cpython-10b73e17489048419b512f6710aecba62ff5b91a.tar.bz2 cpython-10b73e17489048419b512f6710aecba62ff5b91a.zip |
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.
Diffstat (limited to 'Include/pymem.h')
-rw-r--r-- | Include/pymem.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Include/pymem.h b/Include/pymem.h index b1f06efb01f..941e00f6c2c 100644 --- a/Include/pymem.h +++ b/Include/pymem.h @@ -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 */ |