Collect stats for UNPACK_SEQUENCE. (GH-31105)

This commit is contained in:
Mark Shannon 2022-02-03 18:40:56 +00:00 committed by GitHub
parent da4d4ec185
commit a0401d8372
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -2792,6 +2792,12 @@ handle_eval_breaker:
TARGET(UNPACK_SEQUENCE) { TARGET(UNPACK_SEQUENCE) {
PREDICTED(UNPACK_SEQUENCE); PREDICTED(UNPACK_SEQUENCE);
PyObject *seq = POP(), *item, **items; PyObject *seq = POP(), *item, **items;
#ifdef Py_STATS
extern int _PySpecialization_ClassifySequence(PyObject *);
_py_stats.opcode_stats[UNPACK_SEQUENCE].specialization.failure++;
_py_stats.opcode_stats[UNPACK_SEQUENCE].specialization.
failure_kinds[_PySpecialization_ClassifySequence(seq)]++;
#endif
if (PyTuple_CheckExact(seq) && if (PyTuple_CheckExact(seq) &&
PyTuple_GET_SIZE(seq) == oparg) { PyTuple_GET_SIZE(seq) == oparg) {
items = ((PyTupleObject *)seq)->ob_item; items = ((PyTupleObject *)seq)->ob_item;

View File

@ -572,6 +572,10 @@ initial_counter_value(void) {
#define SPEC_FAIL_ITER_DICT_VALUES 22 #define SPEC_FAIL_ITER_DICT_VALUES 22
#define SPEC_FAIL_ITER_ENUMERATE 23 #define SPEC_FAIL_ITER_ENUMERATE 23
/* UNPACK_SEQUENCE */
#define SPEC_FAIL_TUPLE 10
#define SPEC_FAIL_LIST 11
static int static int
specialize_module_load_attr( specialize_module_load_attr(
@ -1880,7 +1884,6 @@ success:
adaptive->counter = initial_counter_value(); adaptive->counter = initial_counter_value();
} }
int int
_PySpecialization_ClassifyIterator(PyObject *iter) _PySpecialization_ClassifyIterator(PyObject *iter)
{ {
@ -1930,3 +1933,15 @@ int
} }
return SPEC_FAIL_OTHER; return SPEC_FAIL_OTHER;
} }
int
_PySpecialization_ClassifySequence(PyObject *seq)
{
if (PyTuple_CheckExact(seq)) {
return SPEC_FAIL_TUPLE;
}
if (PyList_CheckExact(seq)) {
return SPEC_FAIL_LIST;
}
return SPEC_FAIL_OTHER;
}