Skip to content

Conversation

@mdboom
Copy link
Contributor

@mdboommdboom commented Oct 9, 2023

This records the number of times a specific uop causes a DEOPT (in the same way this is already done for Tier 1). The summarize_stats.py script already supports the display, by virtue of reusing the code from Tier 1.

Marked as draft because it is necessarily built on #110398 which should be merged first.

@mdboommdboomforce-pushed the count-tier2-miss-opcodes branch from 22212fb to a08a127CompareOctober 24, 2023 17:31
@mdboommdboom marked this pull request as ready for review October 24, 2023 17:33
@markshannon
Copy link
Member

Looks like a useful feature. Do you have example output for this?

Copy link
Member

@gvanrossumgvanrossum left a comment

Choose a reason for hiding this comment

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

Mark put in a question, I can merge once you've answered that.

#define GC_STAT_ADD(gen, name, n) do{if (_Py_stats) _Py_stats->gc_stats[(gen)].name += (n)} while (0)
#define OPT_STAT_INC(name) do{if (_Py_stats) _Py_stats->optimization_stats.name++} while (0)
#define UOP_EXE_INC(opname) do{if (_Py_stats) _Py_stats->optimization_stats.opcode[opname].execution_count++} while (0)
#define UOP_STAT_INC(opname, name) do{if (_Py_stats) {assert(opname < 512); _Py_stats->optimization_stats.opcode[opname].name++; } } while (0)
Copy link
Member

Choose a reason for hiding this comment

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

I would have named this arg opcode (or OPCODE, per recent Discourse thread), since to me opname is a variable of type char * giving the opcode's name; opcode is the (named) constant representing the opcode, which it is. (I did a small double take when I saw assert(opname < 512). :-) But it's too late, and opname is used in several places above as well, so let's keep it this way.

@mdboom
Copy link
ContributorAuthor

mdboom commented Oct 30, 2023

Looks like a useful feature. Do you have example output for this?

Here's an example from the raytrace benchmark:

NameCountSelfCumulativeMiss ratio
_SET_IP487,881,60022.3%22.3%
_GUARD_TYPE_VERSION184,373,7608.4%30.7%2.2%
LOAD_FAST153,382,9807.0%37.7%
_CHECK_MANAGED_OBJECT_HAS_VALUES100,250,8804.6%42.3%
_LOAD_ATTR_INSTANCE_VALUE100,250,8804.6%46.8%
_GUARD_DORV_VALUES_INST_ATTR_FROM_DICT60,593,2802.8%49.6%
_GUARD_KEYS_VERSION60,593,2802.8%52.4%
_LOAD_ATTR_METHOD_WITH_VALUES60,593,2802.8%55.1%
RESUME_CHECK60,407,0402.8%57.9%
_CHECK_PEP_52360,407,0402.8%60.6%
_CHECK_FUNCTION_EXACT_ARGS60,407,0402.8%63.4%
_CHECK_STACK_SPACE60,407,0402.8%66.2%
_INIT_CALL_PY_EXACT_ARGS60,407,0402.8%68.9%
_PUSH_FRAME60,407,0402.8%71.7%
_SAVE_RETURN_OFFSET60,407,0402.8%74.4%
_POP_FRAME58,813,4402.7%77.1%
COMPARE_OP_INT40,684,8001.9%79.0%
_POP_JUMP_IF_FALSE40,308,4801.8%80.8%
_GUARD_GLOBALS_VERSION40,120,3201.8%82.6%
_LOAD_GLOBAL_MODULE40,120,3201.8%84.5%
_CHECK_ATTR_CLASS39,548,1601.8%86.3%
_LOAD_ATTR_CLASS39,548,1601.8%88.1%
_POP_JUMP_IF_TRUE31,681,9201.4%89.5%
_ITER_CHECK_LIST28,510,0801.3%90.8%
_IS_ITER_EXHAUSTED_LIST28,510,0801.3%92.1%
STORE_FAST27,071,9401.2%93.4%
_ITER_NEXT_LIST25,484,1601.2%94.5%
POP_TOP22,312,3801.0%95.5%
LOAD_CONST21,757,4401.0%96.5%
_JUMP_TO_TOP20,192,6400.9%97.5%
_GUARD_DORV_VALUES19,459,2000.9%98.3%
_STORE_ATTR_INSTANCE_VALUE19,459,2000.9%99.2%
_EXIT_TRACE5,406,7200.2%99.5%
COMPARE_OP1,758,7200.1%99.6%
LOAD_ATTR1,543,6800.1%99.6%
CALL_METHOD_DESCRIPTOR_FAST1,353,6000.1%99.7%
_ITER_CHECK_RANGE1,036,8000.0%99.7%
_IS_ITER_EXHAUSTED_RANGE1,036,8000.0%99.8%
_ITER_NEXT_RANGE1,019,4600.0%99.8%
TO_BOOL_BOOL768,0000.0%99.9%
_GUARD_BOTH_INT752,6400.0%99.9%
BINARY_OP382,0800.0%99.9%
BINARY_SUBSCR376,3200.0%99.9%
_BINARY_OP_MULTIPLY_INT376,3200.0%100.0%
_BINARY_OP_ADD_INT376,3200.0%100.0%
GET_ITER259,2000.0%100.0%
_CHECK_CALL_BOUND_METHOD_EXACT_ARGS190,0800.0%100.0%
_INIT_CALL_BOUND_METHOD_EXACT_ARGS190,0800.0%100.0%
PUSH_NULL1,8600.0%100.0%

@gvanrossumgvanrossum merged commit 84b4533 into python:mainOct 31, 2023
FullteaR pushed a commit to FullteaR/cpython that referenced this pull request Nov 3, 2023
This keeps a separate 'miss' counter for each micro-opcode, incremented whenever a guard uop takes a deoptimization side exit.
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
This keeps a separate 'miss' counter for each micro-opcode, incremented whenever a guard uop takes a deoptimization side exit.
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
This keeps a separate 'miss' counter for each micro-opcode, incremented whenever a guard uop takes a deoptimization side exit.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@mdboom@markshannon@gvanrossum