3939*/
4040
4141Py_ssize_t _Py_QuickenedCount = 0 ;
42- #if COLLECT_SPECIALIZATION_STATS
42+ #ifdef Py_STATS
4343SpecializationStats _specialization_stats [256 ] = { 0 };
4444
4545#define ADD_STAT_TO_DICT (res , field ) \
@@ -71,7 +71,6 @@ stats_to_dict(SpecializationStats *stats)
7171 ADD_STAT_TO_DICT (res , miss );
7272 ADD_STAT_TO_DICT (res , deopt );
7373 ADD_STAT_TO_DICT (res , unquickened );
74- #if COLLECT_SPECIALIZATION_STATS_DETAILED
7574 PyObject * failure_kinds = PyTuple_New (SPECIALIZATION_FAILURE_KINDS );
7675 if (failure_kinds == NULL ) {
7776 Py_DECREF (res );
@@ -92,7 +91,6 @@ stats_to_dict(SpecializationStats *stats)
9291 return NULL ;
9392 }
9493 Py_DECREF (failure_kinds );
95- #endif
9694 return res ;
9795}
9896#undef ADD_STAT_TO_DICT
@@ -113,7 +111,7 @@ add_stat_dict(
113111 return err ;
114112}
115113
116- #if COLLECT_SPECIALIZATION_STATS
114+ #ifdef Py_STATS
117115PyObject *
118116_Py_GetSpecializationStats (void ) {
119117 PyObject * stats = PyDict_New ();
@@ -151,35 +149,34 @@ print_stats(FILE *out, SpecializationStats *stats, const char *name)
151149 PRINT_STAT (name , miss );
152150 PRINT_STAT (name , deopt );
153151 PRINT_STAT (name , unquickened );
154- #if PRINT_SPECIALIZATION_STATS_DETAILED
155152 for (int i = 0 ; i < SPECIALIZATION_FAILURE_KINDS ; i ++ ) {
156153 fprintf (out , " %s.specialization_failure_kinds[%d] : %" PRIu64 "\n" ,
157154 name , i , stats -> specialization_failure_kinds [i ]);
158155 }
159- #endif
160156}
161157#undef PRINT_STAT
162158
163159void
164- _Py_PrintSpecializationStats (void )
160+ _Py_PrintSpecializationStats (int to_file )
165161{
166162 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. */
169165# ifdef MS_WINDOWS
170- const char * dirname = "c:\\temp\\py_stats\\" ;
166+ const char * dirname = "c:\\temp\\py_stats\\" ;
171167# else
172- const char * dirname = "/tmp/py_stats/" ;
168+ const char * dirname = "/tmp/py_stats/" ;
173169# 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+ }
183180 print_stats (out , & _specialization_stats [LOAD_ATTR ], "load_attr" );
184181 print_stats (out , & _specialization_stats [LOAD_GLOBAL ], "load_global" );
185182 print_stats (out , & _specialization_stats [LOAD_METHOD ], "load_method" );
@@ -194,7 +191,7 @@ _Py_PrintSpecializationStats(void)
194191 }
195192}
196193
197- #if COLLECT_SPECIALIZATION_STATS_DETAILED
194+ #ifdef Py_STATS
198195
199196#define SPECIALIZATION_FAIL (opcode , kind ) _specialization_stats[opcode].specialization_failure_kinds[kind]++
200197
@@ -860,7 +857,7 @@ _Py_Specialize_StoreAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name, S
860857}
861858
862859
863- #if COLLECT_SPECIALIZATION_STATS_DETAILED
860+ #ifdef Py_STATS
864861static int
865862load_method_fail_kind (DesciptorClassification kind )
866863{
@@ -1086,7 +1083,7 @@ _Py_Specialize_LoadGlobal(
10861083 return 0 ;
10871084}
10881085
1089- #if COLLECT_SPECIALIZATION_STATS_DETAILED
1086+ #ifdef Py_STATS
10901087static int
10911088binary_subscr_fail_kind (PyTypeObject * container_type , PyObject * sub )
10921089{
@@ -1380,7 +1377,7 @@ specialize_py_call(
13801377 return 0 ;
13811378}
13821379
1383- #if COLLECT_SPECIALIZATION_STATS_DETAILED
1380+ #ifdef Py_STATS
13841381static int
13851382builtin_call_fail_kind (int ml_flags )
13861383{
@@ -1459,7 +1456,7 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
14591456 }
14601457}
14611458
1462- #if COLLECT_SPECIALIZATION_STATS_DETAILED
1459+ #ifdef Py_STATS
14631460static int
14641461call_fail_kind (PyObject * callable )
14651462{
0 commit comments