File indexing completed on 2025-01-18 10:06:47
0001 #ifndef Py_INTERNAL_TRACEMALLOC_H
0002 #define Py_INTERNAL_TRACEMALLOC_H
0003 #ifdef __cplusplus
0004 extern "C" {
0005 #endif
0006
0007 #ifndef Py_BUILD_CORE
0008 # error "this header requires Py_BUILD_CORE define"
0009 #endif
0010
0011 #include "pycore_hashtable.h" // _Py_hashtable_t
0012
0013
0014
0015 #define TRACE_RAW_MALLOC
0016
0017
0018 struct _PyTraceMalloc_Config {
0019
0020
0021 enum {
0022 TRACEMALLOC_NOT_INITIALIZED,
0023 TRACEMALLOC_INITIALIZED,
0024 TRACEMALLOC_FINALIZED
0025 } initialized;
0026
0027
0028
0029 int tracing;
0030
0031
0032
0033 int max_nframe;
0034 };
0035
0036
0037
0038
0039 #if defined(_MSC_VER)
0040 #pragma pack(push, 4)
0041 #endif
0042
0043 struct
0044 #ifdef __GNUC__
0045 __attribute__((packed))
0046 #endif
0047 tracemalloc_frame {
0048
0049
0050 PyObject *filename;
0051 unsigned int lineno;
0052 };
0053 #ifdef _MSC_VER
0054 #pragma pack(pop)
0055 #endif
0056
0057 struct tracemalloc_traceback {
0058 Py_uhash_t hash;
0059
0060 uint16_t nframe;
0061
0062 uint16_t total_nframe;
0063 struct tracemalloc_frame frames[1];
0064 };
0065
0066
0067 struct _tracemalloc_runtime_state {
0068 struct _PyTraceMalloc_Config config;
0069
0070
0071 struct {
0072 PyMemAllocatorEx mem;
0073 PyMemAllocatorEx raw;
0074 PyMemAllocatorEx obj;
0075 } allocators;
0076
0077 #if defined(TRACE_RAW_MALLOC)
0078 PyThread_type_lock tables_lock;
0079 #endif
0080
0081
0082 size_t traced_memory;
0083
0084
0085 size_t peak_traced_memory;
0086
0087
0088
0089 _Py_hashtable_t *filenames;
0090
0091
0092 struct tracemalloc_traceback *traceback;
0093
0094
0095
0096 _Py_hashtable_t *tracebacks;
0097
0098
0099 _Py_hashtable_t *traces;
0100
0101
0102 _Py_hashtable_t *domains;
0103
0104 struct tracemalloc_traceback empty_traceback;
0105
0106 Py_tss_t reentrant_key;
0107 };
0108
0109 #define _tracemalloc_runtime_state_INIT \
0110 { \
0111 .config = { \
0112 .initialized = TRACEMALLOC_NOT_INITIALIZED, \
0113 .tracing = 0, \
0114 .max_nframe = 1, \
0115 }, \
0116 .reentrant_key = Py_tss_NEEDS_INIT, \
0117 }
0118
0119
0120 #ifdef __cplusplus
0121 }
0122 #endif
0123 #endif