jruby/jruby — pull request #240 by kares (2012-07-31 14:15:33+00:00)
Title: Runtime profiling [dejavu]

This is my second attempt to update JRuby's profiler internals, see #96 which got closed by @BanzaiMan with an advise to retry, thus I rebased and I'm looking (once again) for feedback, here's the desc from the first pull :

This is my attempt to support "arbitrary" `Ruby` runtime profiling, as currently only profiling of the `Ruby.getGlobalRuntime` works as expected. The primary motivation for this would be profiling web applications running on top of jruby-rack https://github.com/jruby/jruby-rack/pull/62.
Besides there's some "internal" profiling related refactorings, such as `JRuby::Profiler.profile` returns the full `ProfileData` (instead of the top `Invocation`). Printers are instantiated with a `ProfileData` argument e.g.

data = JRuby::Profiler.profile do
...
end
JRuby::Profiler::FlatProfilePrinter.new(data).printProfile(System.out)

The available profile specs are passing + there's a spec that makes sure all works for (non-global) instantiated runtimes. However, I must say I did not fully understand why the runtime needs to track the profiled methods (I thought tracking the invocations `ProfileData.addProfiledMethod` as they occur would be enough but it clearly isn't). I originally thought I would also accomplish user initiated profiling working only by a `require 'jruby/profiler'` and `JRuby::Profiler.profile` (without the need for a --profile argument).

If there's anything I did wrong, did not or could have done better I would love to hear from you guys.