Alexey
Alexey

Reputation: 9457

How to pass JRUBY_OPTS to JRuby war/jar packed with Warbler?

I cannot figure out how to profile JRuby On Rails application within Tomcat. Actually, I don't know how to pass --profile option to JRuby when ruby code ran not by jruby command, but from java.

To investigate the issue I created file:

$ cat bin/profile_puts.rb

require 'yaml'
puts ENV['JRUBY_OPTS']

require 'jruby/profiler'
def profile(&block)
  JRuby::Profiler::GraphProfilePrinter.new(JRuby::Profiler.profile(&block)).printProfile(STDOUT)
end
profile do
  puts "hi"
end

ran

$ jruby --profile.api bin/profile_puts.rb

And got a proper profiler output.

Then I packaged it with warbler and ran

$ gem install warbler
$ warble jar    
$ JRUBY_OPTS=--profile.api java -jar profile.jar JarMain

And got an error:

--profile.api
RuntimeError: Profiling not enabled in runtime

As you can see the JRUBY_OPTS environment variable got to the process, but had no effect for JRuby.

How can this be addressed?

Upvotes: 0

Views: 556

Answers (1)

Andrew Smith
Andrew Smith

Reputation: 91

java -Djruby.cli.profiling.mode=API -jar profile.jar

I should clarify this, JRUBY_OPTS are either processed by the jruby shell script or by the CLI, when using warbler neither is available so you need to look for a corresponding property and pass it like this. The one above enables API profiling.

From jruby --properties

# Enable instrumented profiling modes.
# Options: [OFF, API, FLAT, GRAPH, HTML, JSON, SERVICE], Default: OFF.

#cli.profiling.mode=OFF

Upvotes: 1

Related Questions