From 15ee55528e1cbc47ef7e9f64186393eee40a49d9 Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Mon, 14 Feb 2022 10:01:31 +0000 Subject: [PATCH] Include length in stats for UNPACK_SEQUENCE. (GH-31254) --- Python/ceval.c | 4 ++-- Python/specialize.c | 34 ++++++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Python/ceval.c b/Python/ceval.c index 5eb91502c30..ad8b05400d5 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2740,10 +2740,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr PREDICTED(UNPACK_SEQUENCE); PyObject *seq = POP(), *item, **items; #ifdef Py_STATS - extern int _PySpecialization_ClassifySequence(PyObject *); + extern int _PySpecialization_ClassifySequence(PyObject *, int); _py_stats.opcode_stats[UNPACK_SEQUENCE].specialization.failure++; _py_stats.opcode_stats[UNPACK_SEQUENCE].specialization. - failure_kinds[_PySpecialization_ClassifySequence(seq)]++; + failure_kinds[_PySpecialization_ClassifySequence(seq, oparg)]++; #endif if (PyTuple_CheckExact(seq) && PyTuple_GET_SIZE(seq) == oparg) { diff --git a/Python/specialize.c b/Python/specialize.c index 1259a3ca3ec..b54a2ecd506 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -602,8 +602,26 @@ initial_counter_value(void) { #define SPEC_FAIL_FOR_ITER_ENUMERATE 23 /* UNPACK_SEQUENCE */ -#define SPEC_FAIL_UNPACK_SEQUENCE_TUPLE 10 -#define SPEC_FAIL_UNPACK_SEQUENCE_LIST 11 +#define SPEC_FAIL_UNPACK_SEQUENCE_TUPLE_0 9 +#define SPEC_FAIL_UNPACK_SEQUENCE_TUPLE_1 10 +#define SPEC_FAIL_UNPACK_SEQUENCE_TUPLE_2 11 +#define SPEC_FAIL_UNPACK_SEQUENCE_TUPLE_3 12 +#define SPEC_FAIL_UNPACK_SEQUENCE_TUPLE_4 13 +#define SPEC_FAIL_UNPACK_SEQUENCE_TUPLE_N 14 + +#define SPEC_FAIL_UNPACK_SEQUENCE_LIST_0 15 +#define SPEC_FAIL_UNPACK_SEQUENCE_LIST_1 16 +#define SPEC_FAIL_UNPACK_SEQUENCE_LIST_2 17 +#define SPEC_FAIL_UNPACK_SEQUENCE_LIST_3 18 +#define SPEC_FAIL_UNPACK_SEQUENCE_LIST_4 19 +#define SPEC_FAIL_UNPACK_SEQUENCE_LIST_N 20 + +#define SPEC_FAIL_UNPACK_SEQUENCE_OTHER_0 21 +#define SPEC_FAIL_UNPACK_SEQUENCE_OTHER_1 22 +#define SPEC_FAIL_UNPACK_SEQUENCE_OTHER_2 23 +#define SPEC_FAIL_UNPACK_SEQUENCE_OTHER_3 24 +#define SPEC_FAIL_UNPACK_SEQUENCE_OTHER_4 25 +#define SPEC_FAIL_UNPACK_SEQUENCE_OTHER_N 26 static int @@ -1978,15 +1996,19 @@ int } int -_PySpecialization_ClassifySequence(PyObject *seq) +_PySpecialization_ClassifySequence(PyObject *seq, int n) { + assert(n >= 0); + if (n > 4) { + n = 5; + } if (PyTuple_CheckExact(seq)) { - return SPEC_FAIL_UNPACK_SEQUENCE_TUPLE; + return SPEC_FAIL_UNPACK_SEQUENCE_TUPLE_0 + n; } if (PyList_CheckExact(seq)) { - return SPEC_FAIL_UNPACK_SEQUENCE_LIST; + return SPEC_FAIL_UNPACK_SEQUENCE_LIST_0 + n; } - return SPEC_FAIL_OTHER; + return SPEC_FAIL_UNPACK_SEQUENCE_OTHER_0 + n; } int