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.

How to spy on a Ruby program

229 pointsby bartbesalmost 9 years ago

13 comments

amagumorialmost 9 years ago
You know, sometimes i get slightly eye-rolly at the tone of Julia's articles, but fuck, this sort of attitude in programming is so much better than the alternative (i.e. lkml). Bringing more positivity and jolliness into programming is important. Fuck the traditional macho programmer attitude. I'm gonna try to be more like Julia.
评论 #11893144 未加载
eeZialmost 9 years ago
For Python, you can just use Pyrasite (<a href="https:&#x2F;&#x2F;github.com&#x2F;lmacken&#x2F;pyrasite" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;lmacken&#x2F;pyrasite</a>) and inject a script which prints a stack trace for all threads.<p>I&#x27;ve done this to debug OpenStack in the past and it worked very well. There are many similar projects for Python, I used this one since it&#x27;s in the RHEL repo.<p>Useful summary on StackOverflow: <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;4163964&#x2F;python-is-it-possible-to-attach-a-console-into-a-running-process" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;4163964&#x2F;python-is-it-pos...</a>
gabetaxalmost 9 years ago
If this sort of stuff is relevant to you, <a href="http:&#x2F;&#x2F;patshaughnessy.net&#x2F;ruby-under-a-microscope" rel="nofollow">http:&#x2F;&#x2F;patshaughnessy.net&#x2F;ruby-under-a-microscope</a> is an essential book to read.
lamontcgalmost 9 years ago
When I&#x27;ve needed to dump a stack trace, I&#x27;ve just included an interrupt handler which prints the call stack to a debug log.<p>That has been good enough for the problem of &quot;wtf is this ruby process doing for _minutes_ at a time?&quot; That doesn&#x27;t get you flame graphs, but you can take a few snapshots and get an idea of what is happening.<p>For more involved perf debugging I&#x27;ve used ruby-prof.
parennoobalmost 9 years ago
From the article:<p>“I&#x27;m constantly surprised by how many people don&#x27;t know you can do this. It&#x27;s amazing.”<p>I&#x27;m probably nitpicking, but sad to see this in the article. One of the things I <i>love</i> about Julia&#x27;s writing otherwise is that it is free of this sort of &#x27;I&#x27;m surprised that you don&#x27;t know this simple thing.&#x27; expressions.
评论 #11889196 未加载
评论 #11892719 未加载
Freakyalmost 9 years ago
Don&#x27;t forget if you&#x27;re on a system with DTrace, Ruby supports a nice bunch of probes for various events: <a href="http:&#x2F;&#x2F;ruby-doc.org&#x2F;core-2.3.0&#x2F;doc&#x2F;dtrace_probes_rdoc.html" rel="nofollow">http:&#x2F;&#x2F;ruby-doc.org&#x2F;core-2.3.0&#x2F;doc&#x2F;dtrace_probes_rdoc.html</a>
jon-woodalmost 9 years ago
If you&#x27;re planning ahead you can have your application load rbtrace which then allows connecting to a running process to see what it&#x27;s doing, with options to limit to slow calls, IO, of specific method calls.
campermanalmost 9 years ago
I hadn&#x27;t heard of perf - very handy indeed. It&#x27;s in the linux-tools package for distros using apt. You will need to install both the generic package and the one for your kernel version.
评论 #11895419 未加载
jzwinckalmost 9 years ago
Of course there are equivalent programs for C. On GNU&#x2F;Linux it&#x27;s pstack aka gstack. Also gcore if you want an entire core dump you can analyze later with gdb.<p><a href="http:&#x2F;&#x2F;linux.die.net&#x2F;man&#x2F;1&#x2F;pstack" rel="nofollow">http:&#x2F;&#x2F;linux.die.net&#x2F;man&#x2F;1&#x2F;pstack</a>
nxzeroalmost 9 years ago
One issue I&#x27;ve run across is spying on JRuby&#x27;s native Java classes. Anyone have a solution?
评论 #11887979 未加载
xjlin0almost 9 years ago
Nice write. The FlameGraph link in Julia&#x27;s article is broken, maybe points to this one? <a href="https:&#x2F;&#x2F;github.com&#x2F;brendangregg&#x2F;FlameGraph" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;brendangregg&#x2F;FlameGraph</a>
guptaneilalmost 9 years ago
&gt; maybe it doesn&#x27;t exist because a Linux-only Ruby debugging tool is sort of a weird thing?<p>Linux-only seems perfectly acceptable, especially as more and more development moves to Docker containers.<p>Great write up, looking forward to seeing a completed tool!
评论 #11888070 未加载
jsnkalmost 9 years ago
&quot;I was going to paste the strace output of what gdb is actually doing, but it is 20 megabytes of system calls.&quot;<p>I think this is why you shouldn&#x27;t run this on production server itself. Each call is very resource intensive on the production server.<p>I believe the right way to analyze memory is to use &quot;gcore&quot;, dump the memory, download it to the local machine&#x27;s VM instance that&#x27;s running the same OS as the production using scp. Also download the same ruby binary that production is running, and use gdb on the VM to analyze memory dump.
评论 #11888972 未加载