On 17.07.2012 22:10, Matt H. wrote:
Any recommendations for the best way to profile a rails app? I saw
was a post several months ago about some troubles here that was never
Is anybody using these profiling tools with useful results?
I’ve had good results with Java profilers. I have used:
JProfiler: ej-technologies - Java APM, Java Profiler, Java Installer Builder
Netbeans Profiler: http://profiler.netbeans.org/ (part of Netbeans IDE;
not a separate program)
I generally used them in “sampling” mode which is the lightweight but
accurate profile where the profiler periodically peeks at the stacks of
running threads. It can thus miss some method calls.
I typically run with a filter to restrict profiling to Java packages
“org.jruby” and “rubyjit”, but this is not required, or some other
may be more appropriate.
I have not used Opus JRuby edition. I believe it converts the somewhat
obscured Java class and method names into normal looking Ruby class and
Opus is very nice, but won’t show a call stack; only a flat list of
(of course, you could buy more advanced versions). It tends to “just
in my experience (I think it does more than just sampling but has
tuning to avoid making your app too sluggish). Netbeans is nice since
free and open source, but I’ve had fewer problems with Opus and
One issue with digging into a call stack within Netbeans or JProfiler
that each Ruby method involves several Java method calls, so call
get very very deep. But with a little patience and a lot of clicking,
can get useful information.
Keep in mind that before JRuby compiles your Ruby code to bytecode, all
see are org.jruby methods interpreting an abstract syntax tree. Once
you’ll start to see things in the rubyjit package that will mostly
Ruby class and method names.
If you have never used a Java profiler, they all typically work by
specifying a JVM option to load some code. This code starts before any
your Java classes (JRuby etc.) are loaded so it has the chance to
instrument these classes. Typically, the profiler will wait until you
launch the profiler’s GUI and connect to it, at which point your Rails
will start up.
Example for Opus:
$ cat jxinsight.aspectj.filters.config
$ jruby -J-javaagent:/absolute/path/to/Opus/opus-aj-javaagent.jar
$ java -jar Opus/console/opencore-console.jar
if app is running on localhost, opus console should connect
or you may need to click “Console → Add Server…”. I’ve had to do
locally to connect to my 192.168.x.x address
Example for Netbeans:
There is some setup work to do in Netbeans to export the profiling pack
native code agent or whatever it’s called. This can be done via the
“Profile → Attach Profiler” dialog.
tells netbeans profiler to start and wait for a connection on port
Profiler Agent: Initializing…
Profiler Agent: Options: >/Users/pat/apps/nb-remote-mac-jdk6/lib,5140<
Profiler Agent: Initialized successfully
Profiler Agent: Waiting for connection on port 5140 (Protocol version:
Now inside Netbeans, attach the profiler, edit the filter to include
“org.jruby., rubyjit.”, let it run for a while, then click “Take