Add hooks for calling arbitrary code around each benchmark#193
Merged
Add hooks for calling arbitrary code around each benchmark#193
Conversation
vstinner
reviewed
Jun 25, 2024
Member
vstinner
left a comment
There was a problem hiding this comment.
I like the concept of hooks.
Would it be possible to use importlib.metadata instead of setuptools pkg_resources? See: https://docs.python.org/dev/library/importlib.metadata.html#entry-points
Collaborator
Author
Sure -- I've never used entry points before -- I hadn't realized that's the new canonical way. |
vstinner
approved these changes
Jul 8, 2024
corona10
approved these changes
Jul 28, 2024
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This change adds a concept of "hooks" to pyperf for running arbitrary code before and after the actual internal benchmarking code. These are implemented with entry points, so it should be possible to write an external plugin to add new integrations and functionality.
There are a few real use cases that the Faster CPython team already needs this for:
sys.monitoringhooks around benchmarks to do custom analysis of which specific bytecodes are run during benchmarkingThe
pystatsintegration that already exists in pyperf also should have, in hindsight, been implemented this way, so this PR also refactors things to do that, and it serves as a proof-of-concept of the new hook functionality.This PR needs tests but I thought I would submit a draft first to ensure this seems like the right direction first.