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.

Show HN: Austin-Tui – Spy inside a running Python program at no performance cost

256 pointsby p403n1x87over 4 years ago

8 comments

jvnsover 4 years ago
Two other profilers that also let you spy on a running Python program:<p>- py-spy: <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> (written in Rust)<p>- pyflame: <a href="https:&#x2F;&#x2F;github.com&#x2F;uber-archive&#x2F;pyflame" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;uber-archive&#x2F;pyflame</a> (C++, seems to be not maintained anymore)<p>The &quot;no performance cost&quot; thing is interesting: my experience writing a similar profiler is that there are a couple of things that can affect performance a little bit:<p>1. You have to make a lot of system calls to read the memory of the target process, and if you want to sample at a high rate then that does use some CPU. This can be an issue if you only have 1 CPU.<p>2. you have two choices when reading memory from a process: you can either race with the program and hope that you read its memory to get the function stack before it changes what function it&#x27;s running (and you&#x27;re likely to win the race, because C is faster than Python), or you can pause the program briefly while taking a sample. py-spy has an option to choose which one you want to do: <a href="https:&#x2F;&#x2F;github.com&#x2F;benfred&#x2F;py-spy#how-can-i-avoid-pausing-the-python-program" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;benfred&#x2F;py-spy#how-can-i-avoid-pausing-th...</a><p>Definitely this method is a lot lower overhead than a tracing profiler that instruments every single function call, and in practice it works well.<p>One thing I think is nice about this kind of profiler is that reading memory from the target process sounds like a complicated thing, but it&#x27;s not: you can see austin&#x27;s code for reading memory here, and it&#x27;s implemented for 3 platforms in just 130 lines of C: <a href="https:&#x2F;&#x2F;github.com&#x2F;P403n1x87&#x2F;austin&#x2F;blob&#x2F;877e2ff946ea5313e4773b4ee1d01da853b5b31d&#x2F;src&#x2F;mem.h#L98" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;P403n1x87&#x2F;austin&#x2F;blob&#x2F;877e2ff946ea5313e47...</a>
评论 #24908940 未加载
评论 #24906694 未加载
评论 #24906631 未加载
评论 #24907470 未加载
评论 #24910762 未加载
emddudleyover 4 years ago
This is a TUI for the profiler Austin, whose README has a bit more detail on what it can do:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;P403n1x87&#x2F;austin" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;P403n1x87&#x2F;austin</a>
Pulcinellaover 4 years ago
What’s the difference between a TUI and a CLI?<p>(Also my preferred TUI acronym is tactile user interface).
评论 #24907579 未加载
评论 #24907491 未加载
评论 #24908910 未加载
评论 #24912521 未加载
评论 #24907550 未加载
评论 #24907399 未加载
评论 #24908568 未加载
评论 #24907401 未加载
shepardrtcover 4 years ago
Love the TUI! Which library did you use for it?
评论 #24907053 未加载
vvladymyrovover 4 years ago
Can Austin attach to python process running in the docker container from the host system? `sudo austin-tui -Cp &lt;pid&gt;` I used pyflame for that at some point.
评论 #24916250 未加载
tr33houseover 4 years ago
looks awesome. how easy is it to use this to profile a webapp written in a framework like django? Open-metrics? just curious
评论 #24906638 未加载
评论 #24906569 未加载
iwebdevfromhomeover 4 years ago
Is it possible to spy from a python script running in a virtual python 2 environment?
评论 #24908004 未加载
RantyDaveover 4 years ago
Wasn&#x27;t there lots of work around using dtrace for this?