tracemalloc.h 2.1 KB

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