Skip to content
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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion coverage/ctracer/tracer.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ CTracer_handle_call(CTracer *self, PyFrameObject *frame)
self->pcur_entry->started_context = FALSE;
}

/* Check if we should trace this line. */
/* Check if we should trace this code block. */
filename = frame->f_code->co_filename;
disposition = PyDict_GetItem(self->should_trace_cache, filename);
if (disposition == NULL) {
Expand Down Expand Up @@ -535,6 +535,9 @@ CTracer_handle_call(CTracer *self, PyFrameObject *frame)
self->pcur_entry->file_data = NULL;
self->pcur_entry->file_tracer = Py_None;
SHOWLOG(self->pdata_stack->depth, frame->f_lineno, filename, "skipped");
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 7
frame->f_trace_lines = 0;
#endif
}

self->pcur_entry->disposition = disposition;
Expand Down
6 changes: 6 additions & 0 deletions coverage/pytracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
YIELD_VALUE = chr(YIELD_VALUE)


HAS_F_TRACE_LINES = sys.version_info >= (3, 7)

Copy link
Owner

@nedbat nedbat Apr 2, 2019

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

Copy link
Contributor Author

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?

Copy link
Owner

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?

Copy link
Contributor Author

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.


class PyTracer(object):
"""Python implementation of the raw data tracer."""

Expand Down Expand Up @@ -117,6 +120,9 @@ def _trace(self, frame, event, arg_unused):
if tracename not in self.data:
self.data[tracename] = {}
self.cur_file_dict = self.data[tracename]
else:
if HAS_F_TRACE_LINES:
frame.f_trace_lines = False
# The call event is really a "start frame" event, and happens for
# function calls and re-entering generators. The f_lasti field is
# -1 for calls, and a real offset for generators. Use <0 as the
Expand Down