Skip to content

Commit 55404ae

Browse files
committed
Python: CG trace: Experiment with disabling some opcodes
Currently not supported in the QL code, so no reason to pay performance to record them right now :P
1 parent 14c51eb commit 55404ae

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

python/tools/recorded-call-graph-metrics/src/cg_trace/bytecode_reconstructor.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ def expr_from_instruction(instructions: List[Instruction], index: int) -> Byteco
186186
if inst.opname in ["LOAD_GLOBAL", "LOAD_FAST", "LOAD_NAME", "LOAD_DEREF"]:
187187
return BytecodeVariableName(inst.argval)
188188

189-
elif inst.opname in ["LOAD_CONST"]:
190-
return BytecodeConst(inst.argval)
189+
# elif inst.opname in ["LOAD_CONST"]:
190+
# return BytecodeConst(inst.argval)
191191

192192
# https://docs.python.org/3/library/dis.html#opcode-LOAD_METHOD
193193
# https://docs.python.org/3/library/dis.html#opcode-LOAD_ATTR
@@ -196,19 +196,19 @@ def expr_from_instruction(instructions: List[Instruction], index: int) -> Byteco
196196
obj_expr = expr_that_added_elem_to_stack(instructions, index - 1, 0)
197197
return BytecodeAttribute(attr_name=attr_name, object=obj_expr)
198198

199-
elif inst.opname in ["BINARY_SUBSCR"]:
200-
key_expr = expr_that_added_elem_to_stack(instructions, index - 1, 0)
201-
obj_expr = expr_that_added_elem_to_stack(instructions, index - 1, 1)
202-
return BytecodeSubscript(key=key_expr, object=obj_expr)
199+
# elif inst.opname in ["BINARY_SUBSCR"]:
200+
# key_expr = expr_that_added_elem_to_stack(instructions, index - 1, 0)
201+
# obj_expr = expr_that_added_elem_to_stack(instructions, index - 1, 1)
202+
# return BytecodeSubscript(key=key_expr, object=obj_expr)
203203

204-
elif inst.opname in ["BUILD_TUPLE", "BUILD_LIST"]:
205-
elements = []
206-
for i in range(inst.arg):
207-
element_expr = expr_that_added_elem_to_stack(instructions, index - 1, i)
208-
elements.append(element_expr)
209-
elements.reverse()
210-
klass = {"BUILD_TUPLE": BytecodeTuple, "BUILD_LIST": BytecodeList}[inst.opname]
211-
return klass(elements=elements)
204+
# elif inst.opname in ["BUILD_TUPLE", "BUILD_LIST"]:
205+
# elements = []
206+
# for i in range(inst.arg):
207+
# element_expr = expr_that_added_elem_to_stack(instructions, index - 1, i)
208+
# elements.append(element_expr)
209+
# elements.reverse()
210+
# klass = {"BUILD_TUPLE": BytecodeTuple, "BUILD_LIST": BytecodeList}[inst.opname]
211+
# return klass(elements=elements)
212212

213213
# https://docs.python.org/3/library/dis.html#opcode-CALL_FUNCTION
214214
elif inst.opname in [
@@ -234,10 +234,10 @@ def expr_from_instruction(instructions: List[Instruction], index: int) -> Byteco
234234
)
235235
return BytecodeCall(function=func_expr)
236236

237-
elif inst.opname in ["MAKE_FUNCTION"]:
238-
name_expr = expr_that_added_elem_to_stack(instructions, index - 1, 0)
239-
assert isinstance(name_expr, BytecodeConst)
240-
return BytecodeMakeFunction(qualified_name=name_expr)
237+
# elif inst.opname in ["MAKE_FUNCTION"]:
238+
# name_expr = expr_that_added_elem_to_stack(instructions, index - 1, 0)
239+
# assert isinstance(name_expr, BytecodeConst)
240+
# return BytecodeMakeFunction(qualified_name=name_expr)
241241

242242
# TODO: handle with statements (https://docs.python.org/3/library/dis.html#opcode-SETUP_WITH)
243243
WITH_OPNAMES = ["SETUP_WITH", "WITH_CLEANUP_START", "WITH_CLEANUP_FINISH"]
@@ -248,7 +248,9 @@ def expr_from_instruction(instructions: List[Instruction], index: int) -> Byteco
248248
# - IMPORT_NAME: Observed to result in a call to filename='<frozen
249249
# importlib._bootstrap>', linenum=389, funcname='parent'
250250
if inst.opname not in ["LOAD_BUILD_CLASS", "IMPORT_NAME"] + WITH_OPNAMES:
251-
LOGGER.warning(f"Don't know how to handle this type of instruction: {inst}")
251+
LOGGER.warning(
252+
f"Don't know how to handle this type of instruction: {inst.opname}"
253+
)
252254
# Uncomment to stop execution when encountering non-ignored unknown instruction
253255
# class MyBytecodeException(BaseException):
254256
# pass

0 commit comments

Comments
 (0)