TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

PyInstrument – A statistical Python profile that focuses on the slow parts

81 pointsby galacticdessertover 4 years ago

8 comments

abuckenheimerover 4 years ago
Very cool, py-spy[1] has been an invaluable tool in my development process since jvns blogged[2] about it. The power of being able to visualize where your code is spending its time is so obvious and I&#x27;m glad people are building tools to make that easier.<p>As a quick compare and contrast between py-spy and pyinstrument it looks like py-spy has the advantage of being able to attach to an already running process which is super useful when your program is stuck and you don&#x27;t know why. I haven&#x27;t used pyinstrument yet but I do like the fact that it can do its flame graph in the console, sometimes I find saving down an svg file and opening up the browser a bit arduous. Excited to give it a try.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;benfred&#x2F;py-spy" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;benfred&#x2F;py-spy</a><p>[2] <a href="https:&#x2F;&#x2F;jvns.ca&#x2F;blog&#x2F;2018&#x2F;09&#x2F;08&#x2F;an-awesome-new-python-profiler--py-spy-&#x2F;" rel="nofollow">https:&#x2F;&#x2F;jvns.ca&#x2F;blog&#x2F;2018&#x2F;09&#x2F;08&#x2F;an-awesome-new-python-profil...</a>
评论 #24837886 未加载
评论 #24841091 未加载
评论 #24838014 未加载
评论 #24837756 未加载
评论 #24837897 未加载
oefrhaover 4 years ago
&gt; The standard Python profilers profile and cProfile show you a big list of functions, ordered by the time spent in each function. This is great, but it can be difficult to interpret why those functions are getting called. It&#x27;s more helpful to know why those functions are called, and which parts of user code were involved.<p>Note that you can use something like gprof2dot to convert pstats dump from cProfile to a visual callgraph: <a href="https:&#x2F;&#x2F;github.com&#x2F;jrfonseca&#x2F;gprof2dot#python-cprofile-formerly-known-as-lsprof" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jrfonseca&#x2F;gprof2dot#python-cprofile-forme...</a><p>Not saying that solution’s better than pyinstrument — I haven’t use this one before so I’ll have to evaluate. Also, the lower overhead is undeniable.<p>---<p>Edit: Another thing I noticed in &quot;How is it different to profile or cProfile?&quot;:<p>&gt; &#x27;Wall-clock&#x27; time (not CPU time)<p>&gt; Pyinstrument records duration using &#x27;wall-clock&#x27; time. ...<p>Seems misleading as cProfile uses time.perf_counter unless you supply your own timer, and time.perf_counter does measure wall clock time. See<p><a href="https:&#x2F;&#x2F;github.com&#x2F;python&#x2F;cpython&#x2F;blob&#x2F;ec42789e6e14f6b6ac13569aeadc13798d7173a8&#x2F;Modules&#x2F;_lsprof.c#L106-L115" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;python&#x2F;cpython&#x2F;blob&#x2F;ec42789e6e14f6b6ac135...</a><p><a href="https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;time.html#time.perf_counter" rel="nofollow">https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;time.html#time.perf_counte...</a>
评论 #24840027 未加载
评论 #24838025 未加载
MikeTheGreatover 4 years ago
The title for this post has a typo - it should be &quot;profileR&quot;, not &quot;profile&quot; (er, without the capitalization on the R :) )<p>I could guess from context, but thought it might be good to point out.<p>Source: From the repo: &quot;Pyinstrument is a Python profiler&quot;<p>(Feel free to delete this comment after fixing the typo, or not :) )
jrichardshawover 4 years ago
I&#x27;m a big fan of pyinstrument. Many of the newer profilers, (e.g. py-spy) attach to a process externally via SYS_PTRACE and though that seems great in many ways, it is very much a no-go when you&#x27;re running code on an HPC cluster and you don&#x27;t have root access.
评论 #24846109 未加载
评论 #24843615 未加载
theptipover 4 years ago
I like how easy this is to wire up to a Django API, took me a few seconds to this hooked up on my local machine.<p>This gives nicer summarization&#x2F;presentation than Django Debug Toolbar&#x27;s profiler, so seems like a good one to have in the toolbox.
david_dracoover 4 years ago
Does this also track time spent in cython modules and function calls through ctypes?
alexeizover 4 years ago
How does it compare with yappi[1]?<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;sumerc&#x2F;yappi" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;sumerc&#x2F;yappi</a>
pansa2over 4 years ago
&gt; Shows you why your code is slow!<p>Because you wrote it in Python.<p>Seriously, Python is probably the slowest mainstream language of all. If you’re building something where performance matters, you should be using a different language.
评论 #24837798 未加载
评论 #24840048 未加载
评论 #24837737 未加载
评论 #24837779 未加载