【问题标题】:How to pass JRUBY_OPTS to JRuby war/jar packed with Warbler?如何将 JRUBY_OPTS 传递给装有 Warbler 的 JRuby 战争/jar?
【发布时间】:2015-10-31 04:07:09
【问题描述】:

我不知道如何在 Tomcat 中分析 JRuby On Rails 应用程序。实际上,当 ruby​​ 代码不是通过jruby 命令运行,而是通过java 运行时,我不知道如何将--profile 选项传递给JRuby。

调查我创建文件的问题:

$ 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

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

并获得了适当的分析器输出。

然后我用warbler打包跑了

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

得到一个错误:

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

如您所见,JRUBY_OPTS 环境变量已进入进程,但对 JRuby 没有影响。

如何解决?

【问题讨论】:

    标签: jar profiling jruby jrubyonrails warbler


    【解决方案1】:
    java -Djruby.cli.profiling.mode=API -jar profile.jar
    

    我应该澄清一下,JRUBY_OPTS 要么由 jruby shell 脚本处理,要么由 CLI 处理,当使用 warbler 时,两者都不可用,因此您需要查找相应的属性并像这样传递它。上面的一个启用 API 分析。

    来自 jruby --properties

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

    【讨论】:

      猜你喜欢
      • 2012-02-03
      • 2012-01-17
      • 2013-06-10
      • 2017-01-21
      • 1970-01-01
      • 1970-01-01
      • 2014-05-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多