Skip to content

Commit 4fea66d

Browse files
markshannonJelleZijlstra
authored andcommitted
pythonGH-101520: Move tracemalloc functionality into core, leaving interface in Modules. (python#104508)
1 parent 1f381f2 commit 4fea66d

11 files changed

+1625
-1549
lines changed

Include/internal/pycore_pylifecycle.h

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ PyAPI_FUNC(int) _Py_IsLocaleCoercionTarget(const char *ctype_loc);
3131

3232
extern void _Py_InitVersion(void);
3333
extern PyStatus _PyFaulthandler_Init(int enable);
34-
extern int _PyTraceMalloc_Init(int enable);
3534
extern PyObject * _PyBuiltin_Init(PyInterpreterState *interp);
3635
extern PyStatus _PySys_Create(
3736
PyThreadState *tstate,

Include/tracemalloc.h

+34
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,40 @@ PyAPI_FUNC(int) PyTraceMalloc_Untrack(
3333
PyAPI_FUNC(PyObject*) _PyTraceMalloc_GetTraceback(
3434
unsigned int domain,
3535
uintptr_t ptr);
36+
37+
/* Return non-zero if tracemalloc is tracing */
38+
PyAPI_FUNC(int) _PyTraceMalloc_IsTracing(void);
39+
40+
/* Clear the tracemalloc traces */
41+
PyAPI_FUNC(void) _PyTraceMalloc_ClearTraces(void);
42+
43+
/* Clear the tracemalloc traces */
44+
PyAPI_FUNC(PyObject *) _PyTraceMalloc_GetTraces(void);
45+
46+
/* Clear tracemalloc traceback for an object */
47+
PyAPI_FUNC(PyObject *) _PyTraceMalloc_GetObjectTraceback(PyObject *obj);
48+
49+
/* Initialize tracemalloc */
50+
PyAPI_FUNC(int) _PyTraceMalloc_Init(void);
51+
52+
/* Start tracemalloc */
53+
PyAPI_FUNC(int) _PyTraceMalloc_Start(int max_nframe);
54+
55+
/* Stop tracemalloc */
56+
PyAPI_FUNC(void) _PyTraceMalloc_Stop(void);
57+
58+
/* Get the tracemalloc traceback limit */
59+
PyAPI_FUNC(int) _PyTraceMalloc_GetTracebackLimit(void);
60+
61+
/* Get the memory usage of tracemalloc in bytes */
62+
PyAPI_FUNC(size_t) _PyTraceMalloc_GetMemory(void);
63+
64+
/* Get the current size and peak size of traced memory blocks as a 2-tuple */
65+
PyAPI_FUNC(PyObject *) _PyTraceMalloc_GetTracedMemory(void);
66+
67+
/* Set the peak size of traced memory blocks to the current size */
68+
PyAPI_FUNC(void) _PyTraceMalloc_ResetPeak(void);
69+
3670
#endif
3771

3872
#endif /* !Py_TRACEMALLOC_H */

Makefile.pre.in

+1
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ PYTHON_OBJS= \
421421
Python/sysmodule.o \
422422
Python/thread.o \
423423
Python/traceback.o \
424+
Python/tracemalloc.o \
424425
Python/getopt.o \
425426
Python/pystrcmp.o \
426427
Python/pystrtod.o \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Move the core functionality of the ``tracemalloc`` module in the ``Python/``
2+
folder, leaving just the module wrapper in ``Modules/``.

0 commit comments

Comments
 (0)