-
-
Notifications
You must be signed in to change notification settings - Fork 32k
Behavior change for opcode trace after PEP 669 #103615
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
Comments
Cc: @markshannon |
Hi @markshannon , any idea on this issue? |
Yeah, but this is globally enabling a more expensive mechanism, forever. No thanks. ;)
This (enabling opcode tracing for a single code object via a descriptor on the frame) definitely seems like the right approach. It's a shame that we probably can't disable it locally too when the descriptor is set to false (or the frame dies) without a counter somewhere (maybe we can aggressively disable events for each instruction somehow?), but I think that this approach seems much better than enabling super-expensive opcode tracing globally forever just because one function somewhere got clever. :) |
Can we check whether tracing is enabled in |
Feel free to try it, but my understanding is that enabling these events globally is incredibly expensive (in terms of the work that needs to be done/undone for every code object that is currently executing or will be executed, as well as wiping out all specializations, allocating arrays for instruction-level metadata, etc.). Toggling it per-code object and then checking if the frame has opcode tracing enabled in the callback seems a lot slicker to me, but you also seem to have a better idea of how all of the different pieces fit together. I could definitely be missing something. :) |
FTR, I consider adding |
* Use local monitoring for opcode trace * Remove f_opcode_trace_set * Add test for setting f_trace_opcodes after settrace
* Use local monitoring for opcode trace * Remove f_opcode_trace_set * Add test for setting f_trace_opcodes after settrace
* Use local monitoring for opcode trace * Remove f_opcode_trace_set * Add test for setting f_trace_opcodes after settrace
Before PEP 669, the opcode trace is togglable after trace function being set. So something like
would work.
After PEP 669, the opcode event is set on
sys.settrace()
so it's impossible to enable it after enabling the trace.kind of works but it's super intuitive.
For the current implementation, if we enabled opcode before we do
sys.settrace()
, it would be "enabled" forever. Meaning the event will be always on, the callback will be always triggered, butframe.f_trace_opcode
will be checked in the callback function. Can we always have opcode callback on? It would be a performance hit(extra call for each opcode), but that happens if we want any opcode event at all, and I think that's basically how the old tracing system does it.Another option would be making
f_trace_opcode
a descriptor and toggle(actually, probable just enable) opcode events there.If we don't want to do that at all and just want to break the backward-compatibility because no one is doing insturction trace anyway (I only realized this when syncing #103050 to the lastest change), we should probably document it - make sure the current frame's
f_trace_opcode
is set before callingsys.settrace()
if you want opcode events.BTW we would've caught this if we already had the instruction level debugging :)
Linked PRs
The text was updated successfully, but these errors were encountered: