Skip to content

Commit a0401d8

Browse files
authored
Collect stats for UNPACK_SEQUENCE. (GH-31105)
1 parent da4d4ec commit a0401d8

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Python/ceval.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2792,6 +2792,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
27922792
TARGET(UNPACK_SEQUENCE) {
27932793
PREDICTED(UNPACK_SEQUENCE);
27942794
PyObject *seq = POP(), *item, **items;
2795+
#ifdef Py_STATS
2796+
extern int _PySpecialization_ClassifySequence(PyObject *);
2797+
_py_stats.opcode_stats[UNPACK_SEQUENCE].specialization.failure++;
2798+
_py_stats.opcode_stats[UNPACK_SEQUENCE].specialization.
2799+
failure_kinds[_PySpecialization_ClassifySequence(seq)]++;
2800+
#endif
27952801
if (PyTuple_CheckExact(seq) &&
27962802
PyTuple_GET_SIZE(seq) == oparg) {
27972803
items = ((PyTupleObject *)seq)->ob_item;

Python/specialize.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,10 @@ initial_counter_value(void) {
572572
#define SPEC_FAIL_ITER_DICT_VALUES 22
573573
#define SPEC_FAIL_ITER_ENUMERATE 23
574574

575+
/* UNPACK_SEQUENCE */
576+
#define SPEC_FAIL_TUPLE 10
577+
#define SPEC_FAIL_LIST 11
578+
575579

576580
static int
577581
specialize_module_load_attr(
@@ -1880,7 +1884,6 @@ _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs,
18801884
adaptive->counter = initial_counter_value();
18811885
}
18821886

1883-
18841887
int
18851888
_PySpecialization_ClassifyIterator(PyObject *iter)
18861889
{
@@ -1930,3 +1933,15 @@ int
19301933
}
19311934
return SPEC_FAIL_OTHER;
19321935
}
1936+
1937+
int
1938+
_PySpecialization_ClassifySequence(PyObject *seq)
1939+
{
1940+
if (PyTuple_CheckExact(seq)) {
1941+
return SPEC_FAIL_TUPLE;
1942+
}
1943+
if (PyList_CheckExact(seq)) {
1944+
return SPEC_FAIL_LIST;
1945+
}
1946+
return SPEC_FAIL_OTHER;
1947+
}

0 commit comments

Comments
 (0)