8000 Assorted minor fixes for specialization stats. by markshannon · Pull Request #100219 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Assorted minor fixes for specialization stats. #100219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
10000
Assorted minor fixes for specialization stats.
  • Loading branch information
markshannon committed Dec 13, 2022
commit a6db29627c91b35d69ec48e0baf76803e85a2b13
15 changes: 11 additions & 4 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ _PyCode_Quicken(PyCodeObject *code)
#define SPEC_FAIL_NOT_PY_FUNCTION 7


#define SPEC_FAIL_LOAD_GLOBAL_NON_DICT 17
#define SPEC_FAIL_LOAD_GLOBAL_NON_STRING_OR_SPLIT 18

/* Attributes */
Expand Down Expand Up @@ -702,7 +703,9 @@ _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name)
goto success;
}
}
SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_ATTR_METHOD);
else {
SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_ATTR_METHOD);
}
goto fail;
}
case PROPERTY:
Expand Down Expand Up @@ -1076,7 +1079,6 @@ PyObject *descr, DescriptorClassification kind)
*/
write_u32(cache->type_version, owner_cls->tp_version_tag);
write_obj(cache->descr, descr);
// Fall through.
return 1;
fail:
return 0;
Expand All @@ -1092,6 +1094,7 @@ _Py_Specialize_LoadGlobal(
_PyLoadGlobalCache *cache = (_PyLoadGlobalCache *)(instr + 1);
assert(PyUnicode_CheckExact(name));
if (!PyDict_CheckExact(globals)) {
SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_LOAD_GLOBAL_NON_DICT);
goto fail;
}
PyDictKeysObject * globals_keys = ((PyDictObject *)globals)->ma_keys;
Expand All @@ -1101,15 +1104,17 @@ _Py_Specialize_LoadGlobal(
}
Py_ssize_t index = _PyDictKeys_StringLookup(globals_keys, name);
if (index == DKIX_ERROR) {
SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_LOAD_GLOBAL_NON_STRING_OR_SPLIT);
SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_EXPECTED_ERROR);
goto fail;
}
if (index != DKIX_EMPTY) {
if (index != (uint16_t)index) {
SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_OUT_OF_RANGE);
goto fail;
}
uint32_t keys_version = _PyDictKeys_GetVersionForCurrentState(globals_keys);
if (keys_version == 0) {
SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_OUT_OF_VERSIONS);
goto fail;
}
cache->index = (uint16_t)index;
Expand All @@ -1118,6 +1123,7 @@ _Py_Specialize_LoadGl 10000 obal(
goto success;
}
if (!PyDict_CheckExact(builtins)) {
SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_LOAD_GLOBAL_NON_DICT);
goto fail;
}
PyDictKeysObject * builtin_keys = ((PyDictObject *)builtins)->ma_keys;
Expand All @@ -1127,10 +1133,11 @@ _Py_Specialize_LoadGlobal(
}
index = _PyDictKeys_StringLookup(builtin_keys, name);
if (index == DKIX_ERROR) {
SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_LOAD_GLOBAL_NON_STRING_OR_SPLIT);
SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_EXPECTED_ERROR);
goto fail;
}
if (index != (uint16_t)index) {
SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_OUT_OF_RANGE);
goto fail;
}
uint32_t globals_version = _PyDictKeys_GetVersionForCurrentState(globals_keys);
Expand Down
13 changes: 4 additions & 9 deletions Tools/scripts/summarize_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
opmap = {name: i for i, name in enumerate(opname)}
opmap = dict(sorted(opmap.items()))

TOTAL = "specialization.deferred", "specialization.hit", "specialization.miss", "execution_count"
TOTAL = "specialization.hit", "specialization.miss", "execution_count"

def format_ratio(num, den):
"""
Expand Down Expand Up @@ -90,7 +90,7 @@ def calculate_specialization_stats(family_stats, total):
if key in ("specialization.hit", "specialization.miss"):
label = key[len("specialization."):]
elif key == "execution_count":
label = "unquickened"
continue
elif key in ("specialization.success", "specialization.failure", "specializable"):
continue
elif key.startswith("pair"):
Expand Down Expand Up @@ -224,7 +224,7 @@ def pretty(defname):
return defname.replace("_", " ").lower()

def kind_to_text(kind, defines, opname):
if kind < 7:
if kind <= 7:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably deal with these numeric constants (this 7 here, and the 40 above) in some more flexible way, but that can be left as a follow-on PR.

return pretty(defines[kind][0])
if opname.endswith("ATTR"):
opname = "ATTR"
Expand All @@ -241,19 +241,14 @@ def categorized_counts(opcode_stats):
not_specialized = 0
specialized_instructions = {
op for op in opcode._specialized_instructions
if "__" not in op and "ADAPTIVE" not in op}
adaptive_instructions = {
op for op in opcode._specialized_instructions
if "ADAPTIVE" in op}
if "__" not in op}
for i, opcode_stat in enumerate(opcode_stats):
if "execution_count" not in opcode_stat:
continue
count = opcode_stat['execution_count']
name = opname[i]
if "specializable" in opcode_stat:
not_specialized += count
elif name in adaptive_instructions:
not_specialized += count
elif name in specialized_instructions:
miss = opcode_stat.get("specialization.miss", 0)
not_specialized += miss
Expand Down
0