summaryrefslogtreecommitdiffstats
path: root/Include/pymem.h
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-10-25 11:31:16 (GMT)
committerGitHub <noreply@github.com>2018-10-25 11:31:16 (GMT)
commit9e00e80e213ebc37eff89ce72102c1f928ebc133 (patch)
tree50b24d69615a7994aeb4d776adc8666fcec5aafd /Include/pymem.h
parentd7c3e5f0e89cb807093e33165815c8bbd3c00f4b (diff)
downloadcpython-9e00e80e213ebc37eff89ce72102c1f928ebc133.zip
cpython-9e00e80e213ebc37eff89ce72102c1f928ebc133.tar.gz
cpython-9e00e80e213ebc37eff89ce72102c1f928ebc133.tar.bz2
bpo-35053: Enhance tracemalloc to trace free lists (GH-10063)
tracemalloc now tries to update the traceback when an object is reused from a "free list" (optimization for faster object creation, used by the builtin list type for example). Changes: * Add _PyTraceMalloc_NewReference() function which tries to update the Python traceback of a Python object. * _Py_NewReference() now calls _PyTraceMalloc_NewReference(). * Add an unit test.
Diffstat (limited to 'Include/pymem.h')
-rw-r--r--Include/pymem.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/Include/pymem.h b/Include/pymem.h
index ef6e0bb..6299ab4 100644
--- a/Include/pymem.h
+++ b/Include/pymem.h
@@ -36,6 +36,10 @@ PyAPI_FUNC(int) PyTraceMalloc_Track(
uintptr_t ptr,
size_t size);
+/* Update the Python traceback of an object.
+ This function can be used when a memory block is reused from a free list. */
+PyAPI_FUNC(int) _PyTraceMalloc_NewReference(PyObject *op);
+
/* Untrack an allocated memory block in the tracemalloc module.
Do nothing if the block was not tracked.
@@ -239,6 +243,40 @@ PyAPI_FUNC(int) _PyMem_SetDefaultAllocator(
PyMemAllocatorEx *old_alloc);
#endif
+
+/* bpo-35053: expose _Py_tracemalloc_config for performance:
+ _Py_NewReference() needs an efficient check to test if tracemalloc is
+ tracing. */
+struct _PyTraceMalloc_Config {
+ /* Module initialized?
+ Variable protected by the GIL */
+ enum {
+ TRACEMALLOC_NOT_INITIALIZED,
+ TRACEMALLOC_INITIALIZED,
+ TRACEMALLOC_FINALIZED
+ } initialized;
+
+ /* Is tracemalloc tracing memory allocations?
+ Variable protected by the GIL */
+ int tracing;
+
+ /* limit of the number of frames in a traceback, 1 by default.
+ Variable protected by the GIL. */
+ int max_nframe;
+
+ /* use domain in trace key?
+ Variable protected by the GIL. */
+ int use_domain;
+};
+
+PyAPI_DATA(struct _PyTraceMalloc_Config) _Py_tracemalloc_config;
+
+#define _PyTraceMalloc_Config_INIT \
+ {.initialized = TRACEMALLOC_NOT_INITIALIZED, \
+ .tracing = 0, \
+ .max_nframe = 1, \
+ .use_domain = 0}
+
#ifdef __cplusplus
}
#endif