-
Notifications
You must be signed in to change notification settings - Fork 19
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
Support 3.12 using the new monitoring API. #47
Comments
Hi @markshannon ! Thanks for the kind offer! We have been following the discussion of this feature for some time (which I'd like to think we had some role in getting adopted :) , and indeed we have already experimented with it; @jaltmayerpizzorno is working on incorporating it. |
Hi @markshannon, thank you for reaching out, and sorry for taking a while to respond. I put some effort towards supporting 3.12 with the new API, but had to shift focus... I realize 3.12 is essentially out, but here are my thoughts so far on it:
What I would love to be able to do is to be able to insert callbacks at the branch destinations (see for example Figure 4 on our paper) indicating the branch taken (source and destination lines). These could then individually disabled as soon as they are reached. Can you think of some way to accomplish that using (or extending) the API? SlipCover does that (for 3.8-3.11) by going back to the AST (which has some downsides). For 3.12, I started exploring adding statements whose line numbers really encode a branch, in order to get a |
If I understand correctly, you want to record the branch out of
Would filtering out branches that do not go to the start of a line be sufficient?
There is only ever two ways a branch can go, so it can be done with a single dictionary mapping source to destination.
How does that work for branches where control flow merges?
There is an edge from |
Right... generally, as we record bytecode-based coverage, we need a way to map that back to source code, as that is how developers think about it. For branches, certainly just using the line information isn't enough. Perhaps if we used the new column information in addition, and mapped it to AST portions... I haven't tried that. Or if the compiler were to save meta-information. In any case, it is much simpler (and thus less error prone) to insert these in the AST and recompile.
Not in general, given same-line branches like
Yes, the application can keep track of branch status and disable when possible, but the branch keeps costing cycles for the destination that has already been seen. Ideally we'd want callbacks that can be disabled on a per destination basis... that's why SlipCover inserts probes within the blocks (see below). I think you meant bytecode branches above... in terms of the source code,
It's on our paper... we split such "critical" edges, turning that into
You know, maybe we should be promoting clause coverage as an option... I wonder if we'd see adoption. Anyway, I think support for inserting |
If you really think the cost of checking repeated checking branches is too high, and if you are willing to modify the AST and insert probes, as you do for 3.11, you could insert def probe(code, src, dst):
if dst - src == 2:
# do probe stuff
return DISABLE Or, if you are willing to do some up front analysis, you only need to check branches where the destination is the destination of more than one branch, and use |
I get it that might require its own PEP, given that it'd be AST-, and thus language-based. But it would a way to support more custom, high-performance dynamic analysis.
You mean modify the bytecode, right? Or is there a way to add something in the AST that compiles to
I haven't measured, but I think that using Ugh, so, in summary, no easy way to use the new APIs for branch coverage? |
Using
It depends on what you mean by a branch. If you mean a regular branch in the control flow, then the easy way is to use If branches are more limited so that in the code |
I think it only makes sense for a tool to report branches in terms of the source code... no matter what branch or other instructions the compiler generates. |
Done in #48, more or less. |
Short sales pitch 🙂
sys.monitoring
offers support for the sort of instrumentation that SlipCover uses, but built into the VM, giving even better performance without the need for import hooks, rewriting bytecode and otherhacksinelegant approaches.The ability to disable each point of instrumentation means that cold code remains instrumented, while hot code runs at full speed, even in the same function.
Feel free to ping me if you have any questions. I'm sure that the docs could be improved, but they should be enough to get you started.
The text was updated successfully, but these errors were encountered: