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

bpo-31344: Per-frame control of trace events #3417

Merged
merged 7 commits into from
Sep 8, 2017

Conversation

ncoghlan
Copy link
Contributor

@ncoghlan ncoghlan commented Sep 7, 2017

f_trace_lines: enable/disable line trace events
f_trace_opcodes: enable/disable opcode trace events

These are intended primarily for testing of the interpreter
itself, as they make it much easier to emulate signals
arriving at unfortunate times.

https://bugs.python.org/issue31344

@zooba
Copy link
Member

zooba commented Sep 7, 2017

Ping @int19h - any thoughts? :)

Copy link
Member

@zooba zooba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me (with a post-8pm caveat)

@int19h
Copy link

int19h commented Sep 7, 2017

This would potentially come in handy for debuggers; e.g. we could implement per-statement (rather than per-line) stepping with this.

f_trace_lines: enable/disable line trace events
f_trace_opcodes: enable/disable opcode trace events

These are intended primarily for testing of the interpreter
itself, as they make it much easier to emulate signals
arriving at unfortunate times.
@ncoghlan ncoghlan force-pushed the bpo-31344-per-opcode-trace-events branch from 494f6e7 to 8c9fcba Compare September 7, 2017 17:14
Copy link
Member

@gpshead gpshead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall good, some comments to address.


Implementations *may* allow per-opcode events to be requested by setting
:attr:`f_trace_opcodes` to :const:`True`. This is intended specifically
for interpreter signal safety testing, and may have surprising results
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps change the wording to:

and may result in surprising undefined behavior if an exception escapes the trace function.

i'm trying to make it more explicit that we do not guarantee any behavior when exceptions are allowed to escape during opcode tracing. changing "are raised by" to something involving "escape" makes it clear that exceptions can be raised and handled. the important thing is that they are resolved before the function exits.

/* The following values are used for 'what' for tracefunc functions: */
/* The following values are used for 'what' for tracefunc functions
*
* To add a new kind of trace event, also update "trace_init" in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna guess you learned this the hard way. thanks for the comment! :)

self.events = []
def _reconfigure_frame(self, frame):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style nit, leave a blank line between methods

@@ -257,6 +266,10 @@ def tearDown(self):
if self.using_gc:
gc.enable()

@staticmethod
def make_tracer():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment mentioning why is this needed at all. (letting subclasses such as XYZ override it)

def compare_events(self, line_offset, events, expected_events):
skip_opcode_events = [e for e in events if e[1] != 'opcode']
if len(events) > 1:
self.assertLess(len(skip_opcode_events), len(events))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a msg= parameter describing why this is a problem if this were to fail.

disabled by setting :attr:`f_trace_lines` to :const:`False`.

Implementations *may* allow per-opcode events to be requested by setting
:attr:`f_trace_opcodes` to :const:`True`. This is intended specifically
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets not describe what it is intended for here. that we happen to use it for interpreter signal exception safety testing isn't relevant to someone reading about the API. It'll gain other uses.

@ncoghlan
Copy link
Contributor Author

ncoghlan commented Sep 8, 2017

Merging as the previous Appveyor run already passed: https://ci.appveyor.com/project/python/cpython/build/3.7.0a0.6126

@ncoghlan ncoghlan merged commit 5a85167 into python:master Sep 8, 2017
@ncoghlan ncoghlan deleted the bpo-31344-per-opcode-trace-events branch March 30, 2018 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants