Skip to content
New issue

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

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

Already on GitHub? # to your account

opcode tracing #15

Open
lazka opened this issue Mar 21, 2020 · 2 comments
Open

opcode tracing #15

lazka opened this issue Mar 21, 2020 · 2 comments

Comments

@lazka
Copy link

lazka commented Mar 21, 2020

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.

@jwilk
Copy link
Owner

jwilk commented Jun 3, 2020

Sounds interesting, but I won't have time to work on this any time soon.

@lazka
Copy link
Author

lazka commented Jun 3, 2020

Thanks, maybe I will

After fixing the 1000 bugs this has found for me :P, in other words, thanks for this!

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants