39
39
*/
40
40
41
41
Py_ssize_t _Py_QuickenedCount = 0 ;
42
- #if COLLECT_SPECIALIZATION_STATS
42
+ #ifdef Py_STATS
43
43
SpecializationStats _specialization_stats [256 ] = { 0 };
44
44
45
45
#define ADD_STAT_TO_DICT (res , field ) \
@@ -71,7 +71,6 @@ stats_to_dict(SpecializationStats *stats)
71
71
ADD_STAT_TO_DICT (res , miss );
72
72
ADD_STAT_TO_DICT (res , deopt );
73
73
ADD_STAT_TO_DICT (res , unquickened );
74
- #if COLLECT_SPECIALIZATION_STATS_DETAILED
75
74
PyObject * failure_kinds = PyTuple_New (SPECIALIZATION_FAILURE_KINDS );
76
75
if (failure_kinds == NULL ) {
77
76
Py_DECREF (res );
@@ -92,7 +91,6 @@ stats_to_dict(SpecializationStats *stats)
92
91
return NULL ;
93
92
}
94
93
Py_DECREF (failure_kinds );
95
- #endif
96
94
return res ;
97
95
}
98
96
#undef ADD_STAT_TO_DICT
@@ -113,7 +111,7 @@ add_stat_dict(
113
111
return err ;
114
112
}
115
113
116
- #if COLLECT_SPECIALIZATION_STATS
114
+ #ifdef Py_STATS
117
115
PyObject *
118
116
_Py_GetSpecializationStats (void ) {
119
117
PyObject * stats = PyDict_New ();
@@ -151,35 +149,34 @@ print_stats(FILE *out, SpecializationStats *stats, const char *name)
151
149
PRINT_STAT (name , miss );
152
150
PRINT_STAT (name , deopt );
153
151
PRINT_STAT (name , unquickened );
154
- #if PRINT_SPECIALIZATION_STATS_DETAILED
155
152
for (int i = 0 ; i < SPECIALIZATION_FAILURE_KINDS ; i ++ ) {
156
153
fprintf (out , " %s.specialization_failure_kinds[%d] : %" PRIu64 "\n" ,
157
154
name , i , stats -> specialization_failure_kinds [i ]);
158
155
}
159
- #endif
160
156
}
161
157
#undef PRINT_STAT
162
158
163
159
void
164
- _Py_PrintSpecializationStats (void )
160
+ _Py_PrintSpecializationStats (int to_file )
165
161
{
166
162
FILE * out = stderr ;
167
- # if PRINT_SPECIALIZATION_STATS_TO_FILE
168
- /* Write to a file instead of stderr. */
163
+ if ( to_file ) {
164
+ /* Write to a file instead of stderr. */
169
165
# ifdef MS_WINDOWS
170
- const char * dirname = "c:\\temp\\py_stats\\" ;
166
+ const char * dirname = "c:\\temp\\py_stats\\" ;
171
167
# else
172
- const char * dirname = "/tmp/py_stats/" ;
168
+ const char * dirname = "/tmp/py_stats/" ;
173
169
# endif
174
- char buf [48 ];
175
- sprintf (buf , "%s%u_%u.txt" , dirname , (unsigned )clock (), (unsigned )rand ());
176
- FILE * fout = fopen (buf , "w" );
177
- if (fout ) {
178
- out = fout ;
179
- }
180
- #else
181
- fprintf (out , "Specialization stats:\n" );
182
- #endif
170
+ char buf [48 ];
171
+ sprintf (buf , "%s%u_%u.txt" , dirname , (unsigned )clock (), (unsigned )rand ());
172
+ FILE * fout = fopen (buf , "w" );
173
+ if (fout ) {
174
+ out = fout ;
175
+ }
176
+ }
177
+ else {
178
+ fprintf (out , "Specialization stats:\n" );
179
+ }
183
180
print_stats (out , & _specialization_stats [LOAD_ATTR ], "load_attr" );
184
181
print_stats (out , & _specialization_stats [LOAD_GLOBAL ], "load_global" );
185
182
print_stats (out , & _specialization_stats [LOAD_METHOD ], "load_method" );
@@ -194,7 +191,7 @@ _Py_PrintSpecializationStats(void)
194
191
}
195
192
}
196
193
197
- #if COLLECT_SPECIALIZATION_STATS_DETAILED
194
+ #ifdef Py_STATS
198
195
199
196
#define SPECIALIZATION_FAIL (opcode , kind ) _specialization_stats[opcode].specialization_failure_kinds[kind]++
200
197
@@ -860,7 +857,7 @@ _Py_Specialize_StoreAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name, S
860
857
}
861
858
862
859
863
- #if COLLECT_SPECIALIZATION_STATS_DETAILED
860
+ #ifdef Py_STATS
864
861
static int
865
862
load_method_fail_kind (DesciptorClassification kind )
866
863
{
@@ -1086,7 +1083,7 @@ _Py_Specialize_LoadGlobal(
1086
1083
return 0 ;
1087
1084
}
1088
1085
1089
- #if COLLECT_SPECIALIZATION_STATS_DETAILED
1086
+ #ifdef Py_STATS
1090
1087
static int
1091
1088
binary_subscr_fail_kind (PyTypeObject * container_type , PyObject * sub )
1092
1089
{
@@ -1380,7 +1377,7 @@ specialize_py_call(
1380
1377
return 0 ;
1381
1378
}
1382
1379
1383
- #if COLLECT_SPECIALIZATION_STATS_DETAILED
1380
+ #ifdef Py_STATS
1384
1381
static int
1385
1382
builtin_call_fail_kind (int ml_flags )
1386
1383
{
@@ -1459,7 +1456,7 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
1459
1456
}
1460
1457
}
1461
1458
1462
- #if COLLECT_SPECIALIZATION_STATS_DETAILED
1459
+ #ifdef Py_STATS
1463
1460
static int
1464
1461
call_fail_kind (PyObject * callable )
1465
1462
{
0 commit comments