GH-132554: Add stats for GET_ITER by markshannon · Pull Request #132592 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Include/internal/pycore_code.h
3 changes: 3 additions & 0 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3026,6 +3026,9 @@ dummy_func(
}

inst(GET_ITER, (iterable -- iter)) {
#ifdef Py_STATS
_Py_GatherStats_GetIter(iterable);
#endif
/* before: [obj]; after [getiter(obj)] */
PyObject *iter_o = PyObject_GetIter(PyStackRef_AsPyObjectBorrow(iterable));
PyStackRef_CLOSE(iterable);
Expand Down
5 changes: 5 additions & 0 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ print_spec_stats(FILE *out, OpcodeStats *stats)
* even though we don't specialize them yet. */
fprintf(out, "opcode[BINARY_SLICE].specializable : 1\n");
fprintf(out, "opcode[STORE_SLICE].specializable : 1\n");
fprintf(out, "opcode[GET_ITER].specializable : 1\n");
for (int i = 0; i < 256; i++) {
if (_PyOpcode_Caches[i]) {
/* Ignore jumps as they cannot be specialized */
Expand Down Expand Up @@ -668,6 +669,7 @@ _PyCode_Quicken(_Py_CODEUNIT *instructions, Py_ssize_t size, int enable_counters
#define SPEC_FAIL_ITER_CALLABLE 28
#define SPEC_FAIL_ITER_ASCII_STRING 29
#define SPEC_FAIL_ITER_ASYNC_GENERATOR_SEND 30
#define SPEC_FAIL_ITER_SELF 31

// UNPACK_SEQUENCE

Expand Down Expand Up @@ -3114,6 +3116,53 @@ _Py_Specialize_ContainsOp(_PyStackRef value_st, _Py_CODEUNIT *instr)
return;
}

#ifdef Py_STATS
void
_Py_GatherStats_GetIter(_PyStackRef iterable)
{
PyTypeObject *tp = PyStackRef_TYPE(iterable);
int kind = SPEC_FAIL_OTHER;
if (tp == &PyTuple_Type) {
kind = SPEC_FAIL_ITER_TUPLE;
}
else if (tp == &PyList_Type) {
kind = SPEC_FAIL_ITER_LIST;
}
else if (tp == &PyDict_Type) {
kind = SPEC_FAIL_ITER_DICT_KEYS;
}
else if (tp == &PySet_Type) {
kind = SPEC_FAIL_ITER_SET;
}
else if (tp == &PyBytes_Type) {
kind = SPEC_FAIL_ITER_BYTES;
}
else if (tp == &PyEnum_Type) {
kind = SPEC_FAIL_ITER_ENUMERATE;
}
else if (tp == &PyUnicode_Type) {
kind = SPEC_FAIL_ITER_STRING;
}
else if (tp == &PyGen_Type) {
kind = SPEC_FAIL_ITER_GENERATOR;
}
else if (tp == &PyCoro_Type) {
kind = SPEC_FAIL_ITER_COROUTINE;
}
else if (tp == &PyAsyncGen_Type) {
kind = SPEC_FAIL_ITER_ASYNC_GENERATOR;
}
else if (tp == &_PyAsyncGenASend_Type) {
kind = SPEC_FAIL_ITER_ASYNC_GENERATOR_SEND;
}
else if (tp->tp_iter == PyObject_SelfIter) {
kind = SPEC_FAIL_ITER_SELF;
}
SPECIALIZATION_FAIL(GET_ITER, kind);
}
#endif


/* Code init cleanup.
* CALL_ALLOC_AND_ENTER_INIT will set up
* the frame to execute the EXIT_INIT_CHECK
Expand Down
2 changes: 1 addition & 1 deletion Tools/scripts/summarize_stats.py