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

GH-103082: Implementation of PEP 669: Low Impact Monitoring for CPython #103083

Merged
merged 127 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
e85d910
Initial experimental implementation of PEP 669.
markshannon Nov 9, 2022
6283ee8
First draft implementing small subset of PEP 669.
markshannon Nov 18, 2022
4edb7b7
Support disabling and restarting.
markshannon Nov 28, 2022
852c40b
Support multiple tools per event.
markshannon Nov 28, 2022
416b314
Tidy up of monitoring internals
markshannon Dec 2, 2022
7971979
Fix legacy tracing.
markshannon Dec 4, 2022
9896902
Implement support for multiple tools.
markshannon Dec 8, 2022
f432a66
Get support for line tracing mostly working. Needs to wait for regist…
markshannon Dec 22, 2022
fb29b34
Merge branch 'main' into pep-669-incremental
markshannon Jan 13, 2023
15a1ccd
Fix up INSTRUMENTED_OPCODES vector.
markshannon Jan 13, 2023
9abb339
Fix instrumented branches to call instrumentation with correct target.
markshannon Jan 16, 2023
3ba6a39
Merge main and assorted fixups to handle new instruction.
markshannon Jan 17, 2023
aa09895
Add PY_THROW event handling and fix up line table.
markshannon Jan 17, 2023
9e5d87d
LINE events working for sys.setrace.
markshannon Jan 17, 2023
e52cbe6
Add lots of internal debugging for instrumentation.
markshannon Jan 18, 2023
6c8be7e
Add more tests. Get those and some other passing.
markshannon Jan 18, 2023
c9e1e21
Fix LINE instrumentation and frame.set_lineno support (mostly)
markshannon Jan 19, 2023
e52e8d3
Refining line event generation.
markshannon Jan 20, 2023
f434ec7
Get sys.settrace tests passing.
markshannon Jan 20, 2023
b680084
Monitor 'internal' StopIteration raises.
markshannon Jan 20, 2023
e6e7cf1
Check for NULLs.
markshannon Jan 20, 2023
5bbc83e
Fix up a few tests
markshannon Jan 20, 2023
7fe9a43
Turn off debugging output by default.
markshannon Jan 23, 2023
8b9f996
Remove debugging printfs
markshannon Jan 26, 2023
9b02640
Avoid refleak.
markshannon Jan 26, 2023
2cadf32
Record last traced line on frame object.
markshannon Jan 26, 2023
1f54d77
Get a couple more top-level tests passing.
markshannon Jan 30, 2023
43a3f3e
Update magic number
markshannon Jan 30, 2023
3d436cf
Remove debug print statement.
markshannon Jan 30, 2023
691bcf5
Raise SystemError if frame is missing.
markshannon Jan 30, 2023
f07be07
Restore a few tests and better handle EXTENDED_ARG.
markshannon Jan 31, 2023
8b8f67e
Make sure instrumentation respects instruction boundaries.
markshannon Feb 1, 2023
d0a2228
Fix handling of errors in jump instruments
markshannon Feb 1, 2023
2a3a85e
Fix memory leaks.
markshannon Feb 1, 2023
c3724ab
Instrument FOR_ITER.
markshannon Feb 1, 2023
d64823c
Fix legacy profiling of calls.
markshannon Feb 2, 2023
284d0b1
Fix up instrumented yield.
markshannon Feb 3, 2023
b9e1f3b
Merge branch 'main' into pep-669-incremental
markshannon Feb 8, 2023
1440473
Fix instrumentation of SEND and tidy up instrumented bytecode numbering.
markshannon Feb 9, 2023
825f42a
Handle line numbers in exception handled event.
markshannon Feb 9, 2023
ce5ddb3
Instrument END_FOR to mimic PEP 380 StopIteration and add more tests.
markshannon Feb 10, 2023
5740c47
Merge branch 'main' into pep-669-incremental
markshannon Feb 13, 2023
da83abe
Add END_SEND for instrumentation.
markshannon Feb 14, 2023
cdb2bda
Correctly set StopIteration in INSTRUMENTED_END_FOR.
markshannon Feb 14, 2023
0148fa3
Set last traced line when jumping in debugger.
markshannon Feb 14, 2023
c5fb4f4
Fix test_dis to account for END_SEND.
markshannon Feb 17, 2023
7fa431b
Add a few more tests.
markshannon Feb 17, 2023
25bbc61
delete commented out code
markshannon Feb 17, 2023
5629a3e
Fix last (known) inconsistency in sys.settrace behaviour
markshannon Feb 17, 2023
477cc53
More clearly differentiate between instrumented events and non-instru…
markshannon Feb 20, 2023
23b5f5e
Add support for sys.monitoring.MISSING
markshannon Feb 21, 2023
dfc18c5
Add support for local (per-code-object) event monitoring.
markshannon Feb 23, 2023
566adbe
Merge branch 'main' into pep-669
markshannon Feb 23, 2023
cfb17ed
Make sure that tracing/profiling thread counts are correct.
markshannon Feb 23, 2023
c535f76
Remove linearray field
markshannon Feb 23, 2023
d579d2e
Rename some fields, shortening names.
markshannon Feb 23, 2023
0982e5e
Remove out of dat comments.
markshannon Feb 23, 2023
0693423
Remove instrumentation for JUMP_IF_[FALS|TRUE]_OR_POP
markshannon Mar 22, 2023
d6453e5
Merge branch 'main' into pep-669
markshannon Mar 22, 2023
0ee2aee
Minor fixups from merge.
markshannon Mar 23, 2023
acdca93
Remove instrumentation for COMPARE_AND_BRANCH.
markshannon Mar 23, 2023
f17ef14
Merge branch 'main' into pep-669
markshannon Mar 23, 2023
e7f6c37
Group instrumented opcodes.
markshannon Mar 23, 2023
e44ebc5
Remove last references to DO_TRACING
markshannon Mar 23, 2023
ece51e6
Merge branch 'main' into pep-669
markshannon Mar 23, 2023
e88921e
Remove unused function.
markshannon Mar 23, 2023
2d9f22c
Streamline de-instrumentation a little.
markshannon Mar 23, 2023
b7579ac
Use modern API for saving and restoring exception.
markshannon Mar 23, 2023
5a089a6
Refactor instrumentation calls to reduce duplication.
markshannon Mar 24, 2023
d5fdec8
Fix refleaks
markshannon Mar 24, 2023
c88741d
Remove commented out code.
markshannon Mar 24, 2023
b6744ca
Make sure that stacktop == -1 when stack_pointer is cached.
markshannon Mar 24, 2023
6c3473a
Minor cleanups.
markshannon Mar 24, 2023
899aecd
Remove useless asserts.
markshannon Mar 24, 2023
80d2e2e
Make functions static
markshannon Mar 24, 2023
94d35d8
Update Windows build files.
markshannon Mar 24, 2023
5aa0805
Make _PyLegacyEventHandler_Type immortal
markshannon Mar 24, 2023
b39edd3
Make arrays const.
markshannon Mar 24, 2023
c9c40cb
Rename _PyFrame_GetStackPointer to _PyFrame_FetchStackPointer and mak…
markshannon Mar 24, 2023
6611c72
Fixups from code review
markshannon Mar 24, 2023
50d28f1
Improve debugging output and make a few things more robust.
markshannon Mar 24, 2023
7165f52
Fix up frame.set_lineno().
markshannon Mar 25, 2023
65c548e
Make line instrumentation able to handle multiple inits.
markshannon Mar 25, 2023
575f7d1
Add brief comments on instrumentation data structures.
markshannon Mar 25, 2023
415741d
Add symbol constant for min instrumented opcode.
markshannon Mar 25, 2023
d70a1a4
Code cleanup from review.
markshannon Mar 25, 2023
d580de6
A bit more cleanup.
markshannon Mar 25, 2023
2076d5f
Add a few more comments.
markshannon Mar 25, 2023
7b32d79
Remove unused code.
markshannon Mar 25, 2023
662c16c
Fix leak of monitoring blocks.
markshannon Mar 25, 2023
d0139e9
Merge branch 'main' into pep-669
markshannon Mar 25, 2023
51a93e7
Make function static.
markshannon Mar 25, 2023
64bf37f
Use symbolic constants in line computations.
markshannon Mar 26, 2023
5faec77
Make data static.
markshannon Mar 26, 2023
0be1562
Add extra check.
markshannon Mar 26, 2023
b32a075
Make sure that instrumentation of line and instructions at the same t…
markshannon Mar 26, 2023
85d6923
Remove incorrect assertion.
markshannon Mar 31, 2023
ebcc42f
Turn off instrumentation debugging.
markshannon Mar 31, 2023
7cfbc7e
Fix a couple of errors.
markshannon Mar 31, 2023
d366364
Add minimal news entry.
markshannon Mar 31, 2023
fdb4860
Pacify the global object checker.
markshannon Mar 31, 2023
aee722f
Minor fixups.
markshannon Apr 3, 2023
bba53b8
Fix refleak when error in RETURN instrumentation.
markshannon Apr 3, 2023
718fbc8
Merge branch 'main' into pep-669
markshannon Apr 3, 2023
97ec1c5
Fix another refleak in error handling in instrumented instruction.
markshannon Apr 3, 2023
edc6709
Remove debug code ready for final review.
markshannon Apr 3, 2023
e40a68f
Fix another (and hopefully final) refleak when handling an error in a…
markshannon Apr 3, 2023
d9f8192
Comment and rename #defines to better reflect names in PEP.
markshannon Apr 4, 2023
2d9a380
Add various IDs as defined in the PEP.
markshannon Apr 4, 2023
29f41e7
Remove _PyThreadState_UpdateTracingState.
markshannon Apr 4, 2023
38b7f43
Formatting fixes, and check error codes.
markshannon Apr 4, 2023
9a40dad
Make sure tool API function names match PEP.
markshannon Apr 4, 2023
a551d65
A bit more cleanup.
markshannon Apr 4, 2023
4951306
Tidy up imports.
markshannon Apr 4, 2023
44a031e
Use clinic return converters.
markshannon Apr 4, 2023
c2155b7
Address code review.
markshannon Apr 4, 2023
b218428
Address further review comments.
markshannon Apr 4, 2023
9c0429e
Use byte offset, to conform to the convention used in other APIs taki…
markshannon Apr 5, 2023
c6bf38e
Address code review.
markshannon Apr 5, 2023
82fe16c
Merge branch 'main' into pep-669
markshannon Apr 5, 2023
43618a9
Keep check-c-globals happy.
markshannon Apr 5, 2023
821ae52
Don't crash if locals events aren't set.
markshannon Apr 9, 2023
505a08d
Add NO_EVENTS.
markshannon Apr 9, 2023
f63da91
Flip order of LINE and INSTRUCTION events.
markshannon Apr 9, 2023
c324344
Check tool is in use when setting events.
markshannon Apr 9, 2023
168b34a
Reset last traced line number when setting frame.f_trace only if set …
markshannon Apr 12, 2023
f07a080
Tidy up test case.
markshannon Apr 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add symbol constant for min instrumented opcode.
  • Loading branch information
markshannon committed Mar 25, 2023
commit 415741d30fddb7b1c99b6b082c4f60eb81c959d4
1 change: 1 addition & 0 deletions Include/cpython/code.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extern "C" {
#define PY_MONITORING_EVENTS 16
#define PY_MONITORING_UNGROUPED_EVENTS 14

/* Table of which tools are active for each monitored event. */
typedef struct _Py_Monitors {
uint8_t tools[PY_MONITORING_UNGROUPED_EVENTS];
} _Py_Monitors;
Expand Down
1 change: 1 addition & 0 deletions Include/opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def pseudo_op(name, op, real_ops):
def_op('CALL_INTRINSIC_2', 174)

# Instrumented instructions
markshannon marked this conversation as resolved.
Show resolved Hide resolved
MIN_INSTRUMENTED_OPCODE = 238

def_op('INSTRUMENTED_POP_JUMP_IF_NONE', 238)
def_op('INSTRUMENTED_POP_JUMP_IF_NOT_NONE', 239)
Expand Down
6 changes: 2 additions & 4 deletions Lib/test/test__opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def test_stack_effect(self):
# All defined opcodes
has_arg = dis.hasarg
for name, code in filter(lambda item: item[0] not in dis.deoptmap, dis.opmap.items()):
if code >= 230:
# Opcodes 230 and up are internal for instrumentation
if code >= opcode.MIN_INSTRUMENTED_OPCODE:
continue
with self.subTest(opname=name):
if code not in has_arg:
Expand Down Expand Up @@ -50,8 +49,7 @@ def test_stack_effect_jump(self):
has_exc = dis.hasexc
has_jump = dis.hasjabs + dis.hasjrel
for name, code in filter(lambda item: item[0] not in dis.deoptmap, dis.opmap.items()):
if code >= 230:
# Opcodes 230 and up are internal for instrumentation
if code >= opcode.MIN_INSTRUMENTED_OPCODE:
continue
with self.subTest(opname=name):
if code not in has_arg:
Expand Down
16 changes: 8 additions & 8 deletions Programs/test_frozenmain.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Tools/build/generate_opcode_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def main(opcode_py, outfile='Include/opcode.h', internaloutfile='Include/interna
HAVE_ARGUMENT = opcode["HAVE_ARGUMENT"]
MIN_PSEUDO_OPCODE = opcode["MIN_PSEUDO_OPCODE"]
MAX_PSEUDO_OPCODE = opcode["MAX_PSEUDO_OPCODE"]
MIN_INSTRUMENTED_OPCODE = opcode["MIN_INSTRUMENTED_OPCODE"]

NUM_OPCODES = len(opname)
used = [ False ] * len(opname)
Expand Down Expand Up @@ -117,6 +118,8 @@ def main(opcode_py, outfile='Include/opcode.h', internaloutfile='Include/interna
fobj.write(DEFINE.format("HAVE_ARGUMENT", HAVE_ARGUMENT))
if op == MIN_PSEUDO_OPCODE:
fobj.write(DEFINE.format("MIN_PSEUDO_OPCODE", MIN_PSEUDO_OPCODE))
if op == MIN_INSTRUMENTED_OPCODE:
fobj.write(DEFINE.format("MIN_INSTRUMENTED_OPCODE", MIN_INSTRUMENTED_OPCODE))

fobj.write(DEFINE.format(name, op))

Expand Down