|
1 | | - |
| 1 | +// Statistics on Python performance (public API). |
| 2 | +// |
| 3 | +// Define _Py_INCREF_STAT_INC() and _Py_DECREF_STAT_INC() used by Py_INCREF() |
| 4 | +// and Py_DECREF(). |
| 5 | +// |
| 6 | +// See Include/cpython/pystats.h for the full API. |
2 | 7 |
|
3 | 8 | #ifndef Py_PYSTATS_H |
4 | 9 | #define Py_PYSTATS_H |
5 | 10 | #ifdef __cplusplus |
6 | 11 | extern "C" { |
7 | 12 | #endif |
8 | 13 |
|
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 | | - |
27 | | -typedef 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 | | - |
37 | | -typedef struct _opcode_stats { |
38 | | - SpecializationStats specialization; |
39 | | - uint64_t execution_count; |
40 | | - uint64_t pair_count[256]; |
41 | | -} OpcodeStats; |
42 | | - |
43 | | -typedef 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 | | - |
51 | | -typedef 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 dict_dematerialized; |
69 | | - uint64_t type_cache_hits; |
70 | | - uint64_t type_cache_misses; |
71 | | - uint64_t type_cache_dunder_hits; |
72 | | - uint64_t type_cache_dunder_misses; |
73 | | - uint64_t type_cache_collisions; |
74 | | - uint64_t optimization_attempts; |
75 | | - uint64_t optimization_traces_created; |
76 | | - uint64_t optimization_traces_executed; |
77 | | - uint64_t optimization_uops_executed; |
78 | | - /* Temporary value used during GC */ |
79 | | - uint64_t object_visits; |
80 | | -} ObjectStats; |
81 | | - |
82 | | -typedef struct _gc_stats { |
83 | | - uint64_t collections; |
84 | | - uint64_t object_visits; |
85 | | - uint64_t objects_collected; |
86 | | -} GCStats; |
87 | | - |
88 | | -typedef struct _stats { |
89 | | - OpcodeStats opcode_stats[256]; |
90 | | - CallStats call_stats; |
91 | | - ObjectStats object_stats; |
92 | | - GCStats *gc_stats; |
93 | | -} PyStats; |
94 | | - |
95 | | - |
96 | | -PyAPI_DATA(PyStats) _py_stats_struct; |
97 | | -PyAPI_DATA(PyStats *) _py_stats; |
98 | | - |
99 | | -extern void _Py_StatsClear(void); |
100 | | -extern void _Py_PrintSpecializationStats(int to_file); |
101 | | - |
102 | | -#ifdef _PY_INTERPRETER |
103 | | - |
104 | | -#define _Py_INCREF_STAT_INC() do { if (_py_stats) _py_stats->object_stats.interpreter_increfs++; } while (0) |
105 | | -#define _Py_DECREF_STAT_INC() do { if (_py_stats) _py_stats->object_stats.interpreter_decrefs++; } while (0) |
106 | | - |
| 14 | +#if defined(Py_STATS) && !defined(Py_LIMITED_API) |
| 15 | +# define Py_CPYTHON_PYSTATS_H |
| 16 | +# include "cpython/pystats.h" |
| 17 | +# undef Py_CPYTHON_PYSTATS_H |
107 | 18 | #else |
108 | | - |
109 | | -#define _Py_INCREF_STAT_INC() do { if (_py_stats) _py_stats->object_stats.increfs++; } while (0) |
110 | | -#define _Py_DECREF_STAT_INC() do { if (_py_stats) _py_stats->object_stats.decrefs++; } while (0) |
111 | | - |
112 | | -#endif |
113 | | - |
114 | | -#else |
115 | | - |
116 | | -#define _Py_INCREF_STAT_INC() ((void)0) |
117 | | -#define _Py_DECREF_STAT_INC() ((void)0) |
118 | | - |
| 19 | +# define _Py_INCREF_STAT_INC() ((void)0) |
| 20 | +# define _Py_DECREF_STAT_INC() ((void)0) |
119 | 21 | #endif // !Py_STATS |
120 | 22 |
|
121 | 23 | #ifdef __cplusplus |
122 | 24 | } |
123 | 25 | #endif |
124 | | -#endif /* !Py_PYSTATs_H */ |
| 26 | +#endif // !Py_PYSTATS_H |
0 commit comments