Skip to content

opcode tracing #15

Open
Open
@lazka

Description

@lazka

Hey,

I was wondering if the opcode tracing added with Python 3.7 might be useful:

def wrap(frame, event, arg):
    frame.f_trace_lines = False
    frame.f_trace_opcodes = True
    code = frame.f_code
    if event == "opcode":
        filename = code.co_filename
        linenumber = frame.f_lineno
        opcode = dis.opname[code.co_code[frame.f_lasti]]
        print(level * 4 * " ", [event, filename, linenumber, opcode])
    else:
        ....
 ['call', <frame at 0x7f1dfd1cb040, file 'settrace.py', line 44, code mytestfunction>, None]
     ['opcode', 'settrace.py', 45, 'LOAD_CONST']
     ['opcode', 'settrace.py', 45, 'LOAD_FAST']
     ['opcode', 'settrace.py', 45, 'COMPARE_OP']
     ['opcode', 'settrace.py', 45, 'POP_JUMP_IF_FALSE']
     ['opcode', 'settrace.py', 45, 'LOAD_CONST']
     ['opcode', 'settrace.py', 45, 'LOAD_FAST']
     ['opcode', 'settrace.py', 45, 'COMPARE_OP']
     ['opcode', 'settrace.py', 45, 'POP_JUMP_IF_FALSE']
     ['opcode', 'settrace.py', 45, 'LOAD_CONST']
     ['opcode', 'settrace.py', 45, 'LOAD_FAST']
     ['opcode', 'settrace.py', 45, 'COMPARE_OP']
     ['opcode', 'settrace.py', 45, 'POP_JUMP_IF_FALSE']
     ['opcode', 'settrace.py', 45, 'LOAD_CONST']
     ['opcode', 'settrace.py', 45, 'RETURN_VALUE']
     ['return', <frame at 0x7f1dfd1cb040, file 'settrace.py', line 45, code mytestfunction>, None]

From what I understand it would make it easier to get coverage for multipl conditions per line like

if foo and bar and quux:
    ...

But not sure and not sure what the performance impact is.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions