JRuby Roundup: JRuby-Prof Allows Fast Profiling, JRuby::Synchronized for Automatic Synchronization
JRuby-Prof is a new JRuby specific profiler by Daniel Lucraft. While there are many mature profilers for Java available, JRuby's mixed execution mode makes their output hard to read; some JRuby code is interpreted, some JRuby hot spots are JIT compiled to bytecode. With a Java profiler, JRuby's internal methods will show up in the profiles, hogging all the top spots in the profile output, when the user actually only wants to know how often which Ruby methods are invoked.
JRuby-prof uses JRuby's hooks to get information about events like method invocation, etc. Hooks are a more efficient way of implementing a profiler, at least compared to the simple method of
set_trace_func, where a callback function is called before a line is executed.
JRuby-prof is available as a Gem:
jruby -S gem install jruby-prof
The source code for JRuby-prof is available at GitHub.
A new addition to JRuby is the JRuby::Synchronized module. Charles Nutter explains the idea behind JRuby::Synchronized on the jruby-user list:
After talking with MenTaLguY on IRC about adding some concurrent collections to JRuby, we came up with a new feature for people to try out:
class MyClass include JRuby::Synchronized ...
the effect of including or extending this new module is that all method calls against that class's object (or against that now-singleton object) will act like they're wrapped in a Java synchronized block. No two threads will be able to execute methods against those objects at the same time (on a per-object basis, obviously).
It's an experiment with providing concurrency tools for JRuby - what others would you like to see?
Not all Java Profilers are equal
This is not entirely true. There are Java profiling (metering) solutions Ruby/JRuby aware.
Juergen Hoeller,Stéphane Nicoll Dec 18, 2014
Helen Walton Dec 17, 2014