1
2
3#ifndef Py_PYSTATS_H
4#define Py_PYSTATS_H
5#ifdef __cplusplus
6extern "C" {
7#endif
8
9#ifdef Py_STATS
10
11#define SPECIALIZATION_FAILURE_KINDS 36
12
13/* Stats for determining who is calling PyEval_EvalFrame */
14#define EVAL_CALL_TOTAL 0
15#define EVAL_CALL_VECTOR 1
16#define EVAL_CALL_GENERATOR 2
17#define EVAL_CALL_LEGACY 3
18#define EVAL_CALL_FUNCTION_VECTORCALL 4
19#define EVAL_CALL_BUILD_CLASS 5
20#define EVAL_CALL_SLOT 6
21#define EVAL_CALL_FUNCTION_EX 7
22#define EVAL_CALL_API 8
23#define EVAL_CALL_METHOD 9
24
25#define EVAL_CALL_KINDS 10
26
27typedef struct _specialization_stats {
28 uint64_t success;
29 uint64_t failure;
30 uint64_t hit;
31 uint64_t deferred;
32 uint64_t miss;
33 uint64_t deopt;
34 uint64_t failure_kinds[SPECIALIZATION_FAILURE_KINDS];
35} SpecializationStats;
36
37typedef struct _opcode_stats {
38 SpecializationStats specialization;
39 uint64_t execution_count;
40 uint64_t pair_count[256];
41} OpcodeStats;
42
43typedef struct _call_stats {
44 uint64_t inlined_py_calls;
45 uint64_t pyeval_calls;
46 uint64_t frames_pushed;
47 uint64_t frame_objects_created;
48 uint64_t eval_calls[EVAL_CALL_KINDS];
49} CallStats;
50
51typedef struct _object_stats {
52 uint64_t increfs;
53 uint64_t decrefs;
54 uint64_t interpreter_increfs;
55 uint64_t interpreter_decrefs;
56 uint64_t allocations;
57 uint64_t allocations512;
58 uint64_t allocations4k;
59 uint64_t allocations_big;
60 uint64_t frees;
61 uint64_t to_freelist;
62 uint64_t from_freelist;
63 uint64_t new_values;
64 uint64_t dict_materialized_on_request;
65 uint64_t dict_materialized_new_key;
66 uint64_t dict_materialized_too_big;
67 uint64_t dict_materialized_str_subclass;
68 uint64_t type_cache_hits;
69 uint64_t type_cache_misses;
70 uint64_t type_cache_dunder_hits;
71 uint64_t type_cache_dunder_misses;
72 uint64_t type_cache_collisions;
73} ObjectStats;
74
75typedef struct _stats {
76 OpcodeStats opcode_stats[256];
77 CallStats call_stats;
78 ObjectStats object_stats;
79} PyStats;
80
81
82PyAPI_DATA(PyStats) _py_stats_struct;
83PyAPI_DATA(PyStats *) _py_stats;
84
85extern void _Py_StatsClear(void);
86extern void _Py_PrintSpecializationStats(int to_file);
87
88#ifdef _PY_INTERPRETER
89
90#define _Py_INCREF_STAT_INC() do { if (_py_stats) _py_stats->object_stats.interpreter_increfs++; } while (0)
91#define _Py_DECREF_STAT_INC() do { if (_py_stats) _py_stats->object_stats.interpreter_decrefs++; } while (0)
92
93#else
94
95#define _Py_INCREF_STAT_INC() do { if (_py_stats) _py_stats->object_stats.increfs++; } while (0)
96#define _Py_DECREF_STAT_INC() do { if (_py_stats) _py_stats->object_stats.decrefs++; } while (0)
97
98#endif
99
100#else
101
102#define _Py_INCREF_STAT_INC() ((void)0)
103#define _Py_DECREF_STAT_INC() ((void)0)
104
105#endif // !Py_STATS
106
107#ifdef __cplusplus
108}
109#endif
110#endif /* !Py_PYSTATs_H */
111

source code of include/python3.12/pystats.h