summaryrefslogtreecommitdiffstats
path: root/Python/specialize.c
diff options
context:
space:
mode:
authorMichael Droettboom <mdboom@gmail.com>2023-10-04 21:52:28 (GMT)
committerGitHub <noreply@github.com>2023-10-04 21:52:28 (GMT)
commite561e9805854980a61967d07869b4ec4205b32c8 (patch)
tree4cf341fc0bf0091ad1b3e7eb034699b23a4ae851 /Python/specialize.c
parentf7860295b16a402621e209871c8eaeeea16f464e (diff)
downloadcpython-e561e9805854980a61967d07869b4ec4205b32c8.zip
cpython-e561e9805854980a61967d07869b4ec4205b32c8.tar.gz
cpython-e561e9805854980a61967d07869b4ec4205b32c8.tar.bz2
GH-109329: Add tier 2 stats (GH-109913)
Diffstat (limited to 'Python/specialize.c')
-rw-r--r--Python/specialize.c54
1 files changed, 50 insertions, 4 deletions
diff --git a/Python/specialize.c b/Python/specialize.c
index d9b748c..ff732eb 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -199,10 +199,6 @@ print_object_stats(FILE *out, ObjectStats *stats)
fprintf(out, "Object method cache collisions: %" PRIu64 "\n", stats->type_cache_collisions);
fprintf(out, "Object method cache dunder hits: %" PRIu64 "\n", stats->type_cache_dunder_hits);
fprintf(out, "Object method cache dunder misses: %" PRIu64 "\n", stats->type_cache_dunder_misses);
- fprintf(out, "Optimization attempts: %" PRIu64 "\n", stats->optimization_attempts);
- fprintf(out, "Optimization traces created: %" PRIu64 "\n", stats->optimization_traces_created);
- fprintf(out, "Optimization traces executed: %" PRIu64 "\n", stats->optimization_traces_executed);
- fprintf(out, "Optimization uops executed: %" PRIu64 "\n", stats->optimization_uops_executed);
}
static void
@@ -216,12 +212,62 @@ print_gc_stats(FILE *out, GCStats *stats)
}
static void
+print_histogram(FILE *out, const char *name, uint64_t hist[_Py_UOP_HIST_SIZE])
+{
+ for (int i = 0; i < _Py_UOP_HIST_SIZE; i++) {
+ fprintf(out, "%s[%" PRIu64"]: %" PRIu64 "\n", name, (uint64_t)1 << i, hist[i]);
+ }
+}
+
+static void
+print_optimization_stats(FILE *out, OptimizationStats *stats)
+{
+ fprintf(out, "Optimization attempts: %" PRIu64 "\n", stats->attempts);
+ fprintf(out, "Optimization traces created: %" PRIu64 "\n", stats->traces_created);
+ fprintf(out, "Optimization traces executed: %" PRIu64 "\n", stats->traces_executed);
+ fprintf(out, "Optimization uops executed: %" PRIu64 "\n", stats->uops_executed);
+ fprintf(out, "Optimization trace stack overflow: %" PRIu64 "\n", stats->trace_stack_overflow);
+ fprintf(out, "Optimization trace stack underflow: %" PRIu64 "\n", stats->trace_stack_underflow);
+ fprintf(out, "Optimization trace too long: %" PRIu64 "\n", stats->trace_too_long);
+ fprintf(out, "Optimization inner loop: %" PRIu64 "\n", stats->inner_loop);
+ fprintf(out, "Optimization recursive call: %" PRIu64 "\n", stats->recursive_call);
+
+ print_histogram(out, "Trace length", stats->trace_length_hist);
+ print_histogram(out, "Trace run length", stats->trace_run_length_hist);
+ print_histogram(out, "Optimized trace length", stats->optimized_trace_length_hist);
+
+ const char* const* names;
+ for (int i = 0; i < 512; i++) {
+ if (i < 256) {
+ names = _PyOpcode_OpName;
+ } else {
+ names = _PyOpcode_uop_name;
+ }
+ if (stats->opcode[i].execution_count) {
+ fprintf(out, "uops[%s].execution_count : %" PRIu64 "\n", names[i], stats->opcode[i].execution_count);
+ }
+ }
+
+ for (int i = 0; i < 256; i++) {
+ if (stats->unsupported_opcode[i]) {
+ fprintf(
+ out,
+ "unsupported_opcode[%s].count : %" PRIu64 "\n",
+ _PyOpcode_OpName[i],
+ stats->unsupported_opcode[i]
+ );
+ }
+ }
+}
+
+static void
print_stats(FILE *out, PyStats *stats)
{
print_spec_stats(out, stats->opcode_stats);
print_call_stats(out, &stats->call_stats);
print_object_stats(out, &stats->object_stats);
print_gc_stats(out, stats->gc_stats);
+ print_optimization_stats(out, &stats->optimization_stats);
}
void