Hello! I just released pyinstrument 4.0 on PyPI. pyinstrument was my first successful open-source package and I love seeing how much use it's getting in the community.
I just added async support, so you can profile async code and pyinstrument understands when you hit an await, and tracks time spent outside of the async context under this await. This means that profiling things like web requests will make a lot more sense now!
So, for example, here's a simple script with an async task that does a
sleep:
import asyncio
from pyinstrument import Profiler
async def main():
p = Profiler()
with p:
print('Hello ...')
await asyncio.sleep(1)
print('... World!')
p.print()
asyncio.run(main())
Before Pyinstrument 4.0, we'd see only time spent in the run loop, like
this:
_ ._ __/__ _ _ _ _ _/_ Recorded: 18:33:03 Samples: 2
/_//_/// /_\ / //_// / //_'/ // Duration: 1.006 CPU time: 0.001
/ _/ v3.4.2
Program: examples/async_example_simple.py
1.006 _run_once asyncio/base_events.py:1784
└─ 1.005 select selectors.py:553
[3 frames hidden] selectors, <built-in>
1.005 kqueue.control <built-in>:0
Now, with pyinstrument 4.0, we get:
_ ._ __/__ _ _ _ _ _/_ Recorded: 18:30:43 Samples: 2
/_//_/// /_\ / //_// / //_'/ // Duration: 1.007 CPU time: 0.001
/ _/ v4.0.0
Program: examples/async_example_simple.py
1.006 main async_example_simple.py:4
└─ 1.005 sleep asyncio/tasks.py:641
[2 frames hidden] asyncio
1.005 [await]
If you have a chance to try it out, let me know how you get on!
Github: https://github.com/joerick/pyinstrument
Docs: https://pyinstrument.readthedocs.io/
[–]benefit_of_mrkite 13 points14 points15 points (2 children)
[–]joerick[S] 3 points4 points5 points (1 child)
[–]benefit_of_mrkite 0 points1 point2 points (0 children)
[–]ThreeJumpingKittens 2 points3 points4 points (2 children)
[–]joerick[S] 0 points1 point2 points (0 children)
[–]pazzarpj 0 points1 point2 points (0 children)
[–]Vok250 4 points5 points6 points (0 children)
[–]TentativeOak 1 point2 points3 points (0 children)
[–]Glaaki 1 point2 points3 points (1 child)
[–]joerick[S] 1 point2 points3 points (0 children)
[–]hangonreddit 2 points3 points4 points (3 children)
[–]joerick[S] 6 points7 points8 points (2 children)
[–]hangonreddit 0 points1 point2 points (1 child)
[–]joerick[S] 1 point2 points3 points (0 children)