Forum: JRuby Profiling a Rails app

6fffdf47ba23571d98546e0e990757d0?d=identicon&s=25 Matt Hauck (Guest)
on 2012-07-18 05:11
(Received via mailing list)
Any recommendations for the best way to profile a rails app? I saw there
was a post several months ago about some troubles here that was never
responded to:

Is anybody using these profiling tools with useful results?
27598e1b77ce41fb0bd8a6fc4a3715d4?d=identicon&s=25 Patrick Mahoney (Guest)
on 2012-07-18 19:04
(Received via mailing list)
On 17.07.2012 22:10, Matt Hauck wrote:

> Any recommendations for the best way to profile a rails app? I saw
> there
> was a post several months ago about some troubles here that was never
> responded to:
> Is anybody using these profiling tools with useful results?

I've had good results with Java profilers. I have used:



Netbeans Profiler: (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
method names.

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
it compiles
you'll start to see things in the rubyjit package that will mostly
retain the
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
<in another terminal>
$ 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
$ jruby
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

Patrick Mahoney
6fffdf47ba23571d98546e0e990757d0?d=identicon&s=25 Matt Hauck (Guest)
on 2012-07-20 08:43
(Received via mailing list)
Thanks for the tips =)

Matt Hauck
6fffdf47ba23571d98546e0e990757d0?d=identicon&s=25 Matt Hauck (Guest)
on 2012-07-20 09:09
(Received via mailing list)
Wow, I started taking a look at JXinsight/Opus, and it is really easy to
use and really helpful. Thanks again!

Matt Hauck
Fe3bda5efab4f341304dee628e9a5dc2?d=identicon&s=25 Peter Lamber (Guest)
on 2012-07-20 10:20
(Received via mailing list)
This is awesome, I have no use for this ATM but I just simply love the
helpful and kind Netbeans/Ruby folks.
patrick.awesomeness += 1

2012/7/20 Matt Hauck <>
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.