-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-107265: Remove all ENTER_EXECUTOR when execute _Py_Instrument #108539
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
23e1f48
Revert "gh-107265: Fix initialize/remove_tools for ENTER_EXECUTOR cas…
corona10 8820df8
gh-107265: Remove all ENTER_EXECUTOR when execute _Py_Instrument
corona10 e015f14
nit
corona10 7612b8e
Add assert
corona10 7d38c77
nit
corona10 a01354d
Address code review
corona10 9a631d7
nit
corona10 7e81bf0
Add test
corona10 162a870
Merge remote-tracking branch 'upstream/main' into gh-107265-mark
corona10 05773f9
Add test
corona10 9ddbfe7
Add space between +=
corona10 1199dfe
Return -1 if there is ENTER_EXECUTOR
corona10 1232432
Update
corona10 e051be1
Merge remote-tracking branch 'upstream/main' into gh-107265-mark
corona10 4a0be4d
fix
corona10 bc251b5
Fix
corona10 83d8829
Address Guido's review
corona10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1718,3 +1718,31 @@ def make_foo_optimized_then_set_event(): | |
make_foo_optimized_then_set_event() | ||
finally: | ||
sys.monitoring.set_events(TEST_TOOL, 0) | ||
|
||
|
||
class TestOptimizer(MonitoringTestBase, unittest.TestCase): | ||
|
||
def setUp(self): | ||
import _testinternalcapi | ||
self.old_opt = _testinternalcapi.get_optimizer() | ||
opt = _testinternalcapi.get_counter_optimizer() | ||
_testinternalcapi.set_optimizer(opt) | ||
super(TestOptimizer, self).setUp() | ||
|
||
def tearDown(self): | ||
import _testinternalcapi | ||
super(TestOptimizer, self).tearDown() | ||
_testinternalcapi.set_optimizer(self.old_opt) | ||
|
||
def test_for_loop(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like @markshannon to review this part at least. |
||
def test_func(x): | ||
i = 0 | ||
while i < x: | ||
i += 1 | ||
|
||
code = test_func.__code__ | ||
sys.monitoring.set_local_events(TEST_TOOL, code, E.PY_START) | ||
self.assertEqual(sys.monitoring.get_local_events(TEST_TOOL, code), E.PY_START) | ||
test_func(1000) | ||
sys.monitoring.set_local_events(TEST_TOOL, code, 0) | ||
self.assertEqual(sys.monitoring.get_local_events(TEST_TOOL, code), 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@markshannon cc @gvanrossum
I added a test, but not sure what you wanted :)
Without this PR, Python/instrumentation.c#L1589 will not be able to pass the assert through this test.
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.
What is this test supposed to do? When I copy this test into the main branch, it passes (in debug mode, so failing asserts would cause crashes), so I don't think this proves your fix works.
By adding some
dis.dis(test_func, adaptive=True)
calls to the test I think I see the difference -- in main, an ENTER_EXECUTOR opcode remains in the code object, whereas with this PR, the ENTER_EXECUTOR opcode appears after the function is called, but disappears again after the second set_local_events call.You could check for that ENTER_EXECUTOR (there are examples in test_capi/test_misc.py) but it would be nice if you had example code that actually crashed or triggered an assert (in debug mode) in main without your fix.
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.
Hmm,, interesting, It looks like I watched the Hallucination when I wrote the test in the first place :(
I will soon update the PR.
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.
See: #108539 (comment)