diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-03-22 12:39:05 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-03-22 12:39:05 (GMT) |
commit | 10b73e17489048419b512f6710aecba62ff5b91a (patch) | |
tree | 091166b7bbae2f92f0993729ad6378544126dd6c /Include | |
parent | e492ae50e251c4fcd48bc37b1eaa4821894f1fdb (diff) | |
download | cpython-10b73e17489048419b512f6710aecba62ff5b91a.zip cpython-10b73e17489048419b512f6710aecba62ff5b91a.tar.gz cpython-10b73e17489048419b512f6710aecba62ff5b91a.tar.bz2 |
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')
-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 b1f06ef..941e00f 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 */ |