-
-
Notifications
You must be signed in to change notification settings - Fork 433
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
[postponed] Set f_trace_lines = 0/False on ignored frames #791
Conversation
This is meant for optimization, so that the trace handler is not called for lines in blocks that are not traced.
This is not much of a gain for the CTracer, but for PyTracer. With this patch CTracer: 20.5s without this patch, 20.0s with it (but just run once, it is likely due to a function call being less of an overhead in C). |
This appears to be py37+ only. And pdb/bdb would need to be fixed to set it to True explicitly (https://bugs.python.org/issue36494). |
Added to cpython in python/cpython@5a85167 (bpo-31344). There also |
Codecov Report
@@ Coverage Diff @@
## master #791 +/- ##
==========================================
- Coverage 90.24% 90.22% -0.02%
==========================================
Files 78 78
Lines 10884 10887 +3
Branches 1127 1128 +1
==========================================
+ Hits 9822 9823 +1
- Misses 939 941 +2
Partials 123 123
Continue to review full report at Codecov.
|
We should be returning None for the trace function if we don't want to trace the frame, and that should be enough. But I don't see where we're returning None. Or is this the decade-old bug? Yep, it is: https://bugs.python.org/issue11992 sigh |
I've tried returning None also before, but stopped when noticing that several tests were failing due to it, and assumed coverage.py needs to trace everything still internally. (I've also tried (quickly) to not add to |
pypy2 failure (https://travis-ci.com/nedbat/coveragepy/jobs/189126179) might be unrelated?! |
I tried restarting the pypy2 failure: https://travis-ci.com/nedbat/coveragepy/jobs/189126179 (oops, same URL...) |
@@ -15,6 +15,9 @@ | |||
YIELD_VALUE = chr(YIELD_VALUE) | |||
|
|||
|
|||
HAS_F_TRACE_LINES = sys.version_info >= (3, 7) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather add a constant to PYBEHAVIOR in env.py, perhaps using hasattr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it require to get a frame object first? (i.e. sys._getframe()
) to inspect it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, though that should be easy. Though come to think of it, why not just do the hasattr where you try to set the attribute?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea was to have as less overhead as possible in the tracing function itself.
The bug about pdb: it affects people trying to stop in the debugger when using coverage? I guess that could happen if you are running a test suite, and want to break on failures? |
The problem/bug with pdb is "just" that coverage.py relies on its trace function being called, which is not the case anymore after |
@blueyed Are you saying we shouldn't merge this until pdb is changed? Or just that they will want to eventually change? |
The discussion above is not related to this PR really, which should just improve performance. I was replying to the "bug about pdb" - which is more a conceptual problem due to only having a single trace function only. pdb could restore any previous one (i.e. coverage.py's), instead of setting it to |
Oh, sorry - I forgot about #791 (comment) / python/cpython#12640. |
I haven't dug super deep into this PR, but maybe it's easier to restart this now that coverage only supports 3.7 upwards? |
0c14f1a
to
82169a6
Compare
This same change was made in #1381 |
This is meant for optimization, so that the trace handler is not called
for lines in blocks that are not traced.
TODO: