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

Automatically profile newly spawned threads #17

Merged
merged 8 commits into from
Dec 28, 2024

Conversation

lucamuscat
Copy link
Owner

This PR implements #10.

The implementation makes use of a hack where sys.settrace is (ab)used detect the start and end of the execution of threads. Since the pyinstrument profiler requires active profilers to be stopped in the same thread that started them, we needed to stop the profiler inside of sys.settrace once we have detected that the thread being profiled has finished executing its target.

Hopefully, pyinstrument will natively support profiling multiple threads in the near future, allowing us to get rid of this sys.settrace hack. There seems to be an issue in pyinstrument's issue board tracking this feature, but the issue (and the repo itself) seems pretty inactive.

@lucamuscat lucamuscat marked this pull request as ready for review December 28, 2024 11:06
@lucamuscat lucamuscat changed the title Multithreaded support Automatically profile newly spawned threads Dec 28, 2024
@lucamuscat lucamuscat force-pushed the multithreaded-support branch from 4cb03bd to f089062 Compare December 28, 2024 11:09
@lucamuscat lucamuscat merged commit 2c7c134 into master Dec 28, 2024
@lucamuscat lucamuscat deleted the multithreaded-support branch December 28, 2024 11:12
This was referenced Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant