@@ -199,10 +199,6 @@ print_object_stats(FILE *out, ObjectStats *stats)
199199 fprintf (out , "Object method cache collisions: %" PRIu64 "\n" , stats -> type_cache_collisions );
200200 fprintf (out , "Object method cache dunder hits: %" PRIu64 "\n" , stats -> type_cache_dunder_hits );
201201 fprintf (out , "Object method cache dunder misses: %" PRIu64 "\n" , stats -> type_cache_dunder_misses );
202- fprintf (out , "Optimization attempts: %" PRIu64 "\n" , stats -> optimization_attempts );
203- fprintf (out , "Optimization traces created: %" PRIu64 "\n" , stats -> optimization_traces_created );
204- fprintf (out , "Optimization traces executed: %" PRIu64 "\n" , stats -> optimization_traces_executed );
205- fprintf (out , "Optimization uops executed: %" PRIu64 "\n" , stats -> optimization_uops_executed );
206202}
207203
208204static void
@@ -215,13 +211,63 @@ print_gc_stats(FILE *out, GCStats *stats)
215211 }
216212}
217213
214+ static void
215+ print_histogram (FILE * out , const char * name , uint64_t hist [_Py_UOP_HIST_SIZE ])
216+ {
217+ for (int i = 0 ; i < _Py_UOP_HIST_SIZE ; i ++ ) {
218+ fprintf (out , "%s[%" PRIu64 "]: %" PRIu64 "\n" , name , (uint64_t )1 << i , hist [i ]);
219+ }
220+ }
221+
222+ static void
223+ print_optimization_stats (FILE * out , OptimizationStats * stats )
224+ {
225+ fprintf (out , "Optimization attempts: %" PRIu64 "\n" , stats -> attempts );
226+ fprintf (out , "Optimization traces created: %" PRIu64 "\n" , stats -> traces_created );
227+ fprintf (out , "Optimization traces executed: %" PRIu64 "\n" , stats -> traces_executed );
228+ fprintf (out , "Optimization uops executed: %" PRIu64 "\n" , stats -> uops_executed );
229+ fprintf (out , "Optimization trace stack overflow: %" PRIu64 "\n" , stats -> trace_stack_overflow );
230+ fprintf (out , "Optimization trace stack underflow: %" PRIu64 "\n" , stats -> trace_stack_underflow );
231+ fprintf (out , "Optimization trace too long: %" PRIu64 "\n" , stats -> trace_too_long );
232+ fprintf (out , "Optimization inner loop: %" PRIu64 "\n" , stats -> inner_loop );
233+ fprintf (out , "Optimization recursive call: %" PRIu64 "\n" , stats -> recursive_call );
234+
235+ print_histogram (out , "Trace length" , stats -> trace_length_hist );
236+ print_histogram (out , "Trace run length" , stats -> trace_run_length_hist );
237+ print_histogram (out , "Optimized trace length" , stats -> optimized_trace_length_hist );
238+
239+ const char * const * names ;
240+ for (int i = 0 ; i < 512 ; i ++ ) {
241+ if (i < 256 ) {
242+ names = _PyOpcode_OpName ;
243+ } else {
244+ names = _PyOpcode_uop_name ;
245+ }
246+ if (stats -> opcode [i ].execution_count ) {
247+ fprintf (out , "uops[%s].execution_count : %" PRIu64 "\n" , names [i ], stats -> opcode [i ].execution_count );
248+ }
249+ }
250+
251+ for (int i = 0 ; i < 256 ; i ++ ) {
252+ if (stats -> unsupported_opcode [i ]) {
253+ fprintf (
254+ out ,
255+ "unsupported_opcode[%s].count : %" PRIu64 "\n" ,
256+ _PyOpcode_OpName [i ],
257+ stats -> unsupported_opcode [i ]
258+ );
259+ }
260+ }
261+ }
262+
218263static void
219264print_stats (FILE * out , PyStats * stats )
220265{
221266 print_spec_stats (out , stats -> opcode_stats );
222267 print_call_stats (out , & stats -> call_stats );
223268 print_object_stats (out , & stats -> object_stats );
224269 print_gc_stats (out , stats -> gc_stats );
270+ print_optimization_stats (out , & stats -> optimization_stats );
225271}
226272
227273void
0 commit comments