tracemalloc.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #ifndef Py_TRACEMALLOC_H
  2. #define Py_TRACEMALLOC_H
  3. #ifndef Py_LIMITED_API
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. /* Track an allocated memory block in the tracemalloc module.
  8. Return 0 on success, return -1 on error (failed to allocate memory to store
  9. the trace).
  10. Return -2 if tracemalloc is disabled.
  11. If memory block is already tracked, update the existing trace. */
  12. PyAPI_FUNC(int) PyTraceMalloc_Track(
  13. unsigned int domain,
  14. uintptr_t ptr,
  15. size_t size);
  16. /* Untrack an allocated memory block in the tracemalloc module.
  17. Do nothing if the block was not tracked.
  18. Return -2 if tracemalloc is disabled, otherwise return 0. */
  19. PyAPI_FUNC(int) PyTraceMalloc_Untrack(
  20. unsigned int domain,
  21. uintptr_t ptr);
  22. /* Get the traceback where a memory block was allocated.
  23. Return a tuple of (filename: str, lineno: int) tuples.
  24. Return None if the tracemalloc module is disabled or if the memory block
  25. is not tracked by tracemalloc.
  26. Raise an exception and return NULL on error. */
  27. PyAPI_FUNC(PyObject*) _PyTraceMalloc_GetTraceback(
  28. unsigned int domain,
  29. uintptr_t ptr);
  30. /* Return non-zero if tracemalloc is tracing */
  31. PyAPI_FUNC(int) _PyTraceMalloc_IsTracing(void);
  32. /* Clear the tracemalloc traces */
  33. PyAPI_FUNC(void) _PyTraceMalloc_ClearTraces(void);
  34. /* Clear the tracemalloc traces */
  35. PyAPI_FUNC(PyObject *) _PyTraceMalloc_GetTraces(void);
  36. /* Clear tracemalloc traceback for an object */
  37. PyAPI_FUNC(PyObject *) _PyTraceMalloc_GetObjectTraceback(PyObject *obj);
  38. /* Initialize tracemalloc */
  39. PyAPI_FUNC(PyStatus) _PyTraceMalloc_Init(void);
  40. /* Start tracemalloc */
  41. PyAPI_FUNC(int) _PyTraceMalloc_Start(int max_nframe);
  42. /* Stop tracemalloc */
  43. PyAPI_FUNC(void) _PyTraceMalloc_Stop(void);
  44. /* Get the tracemalloc traceback limit */
  45. PyAPI_FUNC(int) _PyTraceMalloc_GetTracebackLimit(void);
  46. /* Get the memory usage of tracemalloc in bytes */
  47. PyAPI_FUNC(size_t) _PyTraceMalloc_GetMemory(void);
  48. /* Get the current size and peak size of traced memory blocks as a 2-tuple */
  49. PyAPI_FUNC(PyObject *) _PyTraceMalloc_GetTracedMemory(void);
  50. /* Set the peak size of traced memory blocks to the current size */
  51. PyAPI_FUNC(void) _PyTraceMalloc_ResetPeak(void);
  52. #ifdef __cplusplus
  53. }
  54. #endif
  55. #endif /* !Py_LIMITED_API */
  56. #endif /* !Py_TRACEMALLOC_H */