File indexing completed on 2025-01-18 10:06:50
0001
0002
0003 #ifndef Py_PYSTATS_H
0004 #define Py_PYSTATS_H
0005 #ifdef __cplusplus
0006 extern "C" {
0007 #endif
0008
0009 #ifdef Py_STATS
0010
0011 #define SPECIALIZATION_FAILURE_KINDS 36
0012
0013
0014 #define EVAL_CALL_TOTAL 0
0015 #define EVAL_CALL_VECTOR 1
0016 #define EVAL_CALL_GENERATOR 2
0017 #define EVAL_CALL_LEGACY 3
0018 #define EVAL_CALL_FUNCTION_VECTORCALL 4
0019 #define EVAL_CALL_BUILD_CLASS 5
0020 #define EVAL_CALL_SLOT 6
0021 #define EVAL_CALL_FUNCTION_EX 7
0022 #define EVAL_CALL_API 8
0023 #define EVAL_CALL_METHOD 9
0024
0025 #define EVAL_CALL_KINDS 10
0026
0027 typedef struct _specialization_stats {
0028 uint64_t success;
0029 uint64_t failure;
0030 uint64_t hit;
0031 uint64_t deferred;
0032 uint64_t miss;
0033 uint64_t deopt;
0034 uint64_t failure_kinds[SPECIALIZATION_FAILURE_KINDS];
0035 } SpecializationStats;
0036
0037 typedef struct _opcode_stats {
0038 SpecializationStats specialization;
0039 uint64_t execution_count;
0040 uint64_t pair_count[256];
0041 } OpcodeStats;
0042
0043 typedef struct _call_stats {
0044 uint64_t inlined_py_calls;
0045 uint64_t pyeval_calls;
0046 uint64_t frames_pushed;
0047 uint64_t frame_objects_created;
0048 uint64_t eval_calls[EVAL_CALL_KINDS];
0049 } CallStats;
0050
0051 typedef struct _object_stats {
0052 uint64_t increfs;
0053 uint64_t decrefs;
0054 uint64_t interpreter_increfs;
0055 uint64_t interpreter_decrefs;
0056 uint64_t allocations;
0057 uint64_t allocations512;
0058 uint64_t allocations4k;
0059 uint64_t allocations_big;
0060 uint64_t frees;
0061 uint64_t to_freelist;
0062 uint64_t from_freelist;
0063 uint64_t new_values;
0064 uint64_t dict_materialized_on_request;
0065 uint64_t dict_materialized_new_key;
0066 uint64_t dict_materialized_too_big;
0067 uint64_t dict_materialized_str_subclass;
0068 uint64_t type_cache_hits;
0069 uint64_t type_cache_misses;
0070 uint64_t type_cache_dunder_hits;
0071 uint64_t type_cache_dunder_misses;
0072 uint64_t type_cache_collisions;
0073 } ObjectStats;
0074
0075 typedef struct _stats {
0076 OpcodeStats opcode_stats[256];
0077 CallStats call_stats;
0078 ObjectStats object_stats;
0079 } PyStats;
0080
0081
0082 PyAPI_DATA(PyStats) _py_stats_struct;
0083 PyAPI_DATA(PyStats *) _py_stats;
0084
0085 extern void _Py_StatsClear(void);
0086 extern void _Py_PrintSpecializationStats(int to_file);
0087
0088 #ifdef _PY_INTERPRETER
0089
0090 #define _Py_INCREF_STAT_INC() do { if (_py_stats) _py_stats->object_stats.interpreter_increfs++; } while (0)
0091 #define _Py_DECREF_STAT_INC() do { if (_py_stats) _py_stats->object_stats.interpreter_decrefs++; } while (0)
0092
0093 #else
0094
0095 #define _Py_INCREF_STAT_INC() do { if (_py_stats) _py_stats->object_stats.increfs++; } while (0)
0096 #define _Py_DECREF_STAT_INC() do { if (_py_stats) _py_stats->object_stats.decrefs++; } while (0)
0097
0098 #endif
0099
0100 #else
0101
0102 #define _Py_INCREF_STAT_INC() ((void)0)
0103 #define _Py_DECREF_STAT_INC() ((void)0)
0104
0105 #endif
0106
0107 #ifdef __cplusplus
0108 }
0109 #endif
0110 #endif