Back to home page

EIC code displayed by LXR

 
 

    


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 /* Trace memory blocks allocated by PyMem_RawMalloc() */
0015 #define TRACE_RAW_MALLOC
0016 
0017 
0018 struct _PyTraceMalloc_Config {
0019     /* Module initialized?
0020        Variable protected by the GIL */
0021     enum {
0022         TRACEMALLOC_NOT_INITIALIZED,
0023         TRACEMALLOC_INITIALIZED,
0024         TRACEMALLOC_FINALIZED
0025     } initialized;
0026 
0027     /* Is tracemalloc tracing memory allocations?
0028        Variable protected by the GIL */
0029     int tracing;
0030 
0031     /* limit of the number of frames in a traceback, 1 by default.
0032        Variable protected by the GIL. */
0033     int max_nframe;
0034 };
0035 
0036 
0037 /* Pack the frame_t structure to reduce the memory footprint on 64-bit
0038    architectures: 12 bytes instead of 16. */
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     /* filename cannot be NULL: "<unknown>" is used if the Python frame
0049        filename is NULL */
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     /* Number of frames stored */
0060     uint16_t nframe;
0061     /* Total number of frames the traceback had */
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     /* Protected by the GIL */
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     /* Size in bytes of currently traced memory.
0081        Protected by TABLES_LOCK(). */
0082     size_t traced_memory;
0083     /* Peak size in bytes of traced memory.
0084        Protected by TABLES_LOCK(). */
0085     size_t peak_traced_memory;
0086     /* Hash table used as a set to intern filenames:
0087        PyObject* => PyObject*.
0088        Protected by the GIL */
0089     _Py_hashtable_t *filenames;
0090     /* Buffer to store a new traceback in traceback_new().
0091        Protected by the GIL. */
0092     struct tracemalloc_traceback *traceback;
0093     /* Hash table used as a set to intern tracebacks:
0094        traceback_t* => traceback_t*
0095        Protected by the GIL */
0096     _Py_hashtable_t *tracebacks;
0097     /* pointer (void*) => trace (trace_t*).
0098        Protected by TABLES_LOCK(). */
0099     _Py_hashtable_t *traces;
0100     /* domain (unsigned int) => traces (_Py_hashtable_t).
0101        Protected by TABLES_LOCK(). */
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  // !Py_INTERNAL_TRACEMALLOC_H