diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2024-05-02 17:30:00 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-02 17:30:00 (GMT) |
commit | 6bcbee09df9f6fa6496fb7f68b6d655f190903a7 (patch) | |
tree | 3805da0e3cb96c9d035b14fa4c7350b3030e0e89 /Python/tracemalloc.c | |
parent | 2770d5caca42d48102f8e18210132a964c34af7c (diff) | |
download | cpython-6bcbee09df9f6fa6496fb7f68b6d655f190903a7.zip cpython-6bcbee09df9f6fa6496fb7f68b6d655f190903a7.tar.gz cpython-6bcbee09df9f6fa6496fb7f68b6d655f190903a7.tar.bz2 |
gh-93502: Add new C-API functions to trace object creation and destruction (#115945)
Diffstat (limited to 'Python/tracemalloc.c')
-rw-r--r-- | Python/tracemalloc.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Python/tracemalloc.c b/Python/tracemalloc.c index 19b64c6..e3ec720 100644 --- a/Python/tracemalloc.c +++ b/Python/tracemalloc.c @@ -906,6 +906,10 @@ _PyTraceMalloc_Start(int max_nframe) return -1; } + if (PyRefTracer_SetTracer(_PyTraceMalloc_TraceRef, NULL) < 0) { + return -1; + } + if (tracemalloc_config.tracing) { /* hook already installed: do nothing */ return 0; @@ -1352,8 +1356,12 @@ _PyTraceMalloc_Fini(void) Do nothing if tracemalloc is not tracing memory allocations or if the object memory block is not already traced. */ int -_PyTraceMalloc_NewReference(PyObject *op) +_PyTraceMalloc_TraceRef(PyObject *op, PyRefTracerEvent event, void* Py_UNUSED(ignore)) { + if (event != PyRefTracer_CREATE) { + return 0; + } + assert(PyGILState_Check()); if (!tracemalloc_config.tracing) { |