如何在SmartOS上使用HotSpot DTrace探针? [英] How do I use the HotSpot DTrace probes on SmartOS?

查看:116
本文介绍了如何在SmartOS上使用HotSpot DTrace探针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Mac OS X上,我可以通过运行以下命令找到运行Java程序的HotSpot探针:

On Mac OS X, I can find the HotSpot probes of running Java programs by running:

cody.mello@ashur ~ (1) % sudo dtrace -ln 'hotspot*:::'
Password:
Invalid connection: com.apple.coresymbolicationd
   ID   PROVIDER            MODULE                          FUNCTION NAME
165084  hotspot46      libjvm.dylib _ZN13instanceKlass15initialize_implE19instanceKlassHandleP6Thread [instanceKlass::initialize_impl(instanceKlassHandle, Thread*)] class-initialization-clinit
165085  hotspot46      libjvm.dylib _ZN13instanceKlass15initialize_implE19instanceKlassHandleP6Thread [instanceKlass::initialize_impl(instanceKlassHandle, Thread*)] class-initialization-concurrent
165086  hotspot46      libjvm.dylib _ZN13instanceKlass15initialize_implE19instanceKlassHandleP6Thread [instanceKlass::initialize_impl(instanceKlassHandle, Thread*)] class-initialization-end
165087  hotspot46      libjvm.dylib _ZN13instanceKlass15initialize_implE19instanceKlassHandleP6Thread [instanceKlass::initialize_impl(instanceKlassHandle, Thread*)] class-initialization-erroneous
165088  hotspot46      libjvm.dylib _ZN13instanceKlass15initialize_implE19instanceKlassHandleP6Thread [instanceKlass::initialize_impl(instanceKlassHandle, Thread*)] class-initialization-error
165089  hotspot46      libjvm.dylib _ZN13instanceKlass15initialize_implE19instanceKlassHandleP6Thread [instanceKlass::initialize_impl(instanceKlassHandle, Thread*)] class-initialization-recursive
...

但是,如果我创建一个简单的Java程序并在SmartOS上运行它:

But if I create a simple Java program and run it on SmartOS:

cody@101901c9-6d66-ea32-fe42-f1fbebd4bf99 ~ % cat Loop.java 
class Loop {

    public static void main(String[] args) throws InterruptedException {
        while (true) {
                Thread.sleep(5000);
        }
    }
}
cody@101901c9-6d66-ea32-fe42-f1fbebd4bf99 ~ % javac Loop.java 
cody@101901c9-6d66-ea32-fe42-f1fbebd4bf99 ~ % java Loop

我找不到任何探针:

cody@101901c9-6d66-ea32-fe42-f1fbebd4bf99 ~ (255) % pfexec dtrace -ln 'hotspot*:::'
   ID   PROVIDER            MODULE                          FUNCTION NAME
dtrace: failed to match hotspot*:::: No probe matches description

要看他们有什么特别的事情吗?

Is there anything special that I need to do to see them?

推荐答案

这里的问题是,在SmartOS(以及其他illumos变体以及它们的专有Solaris表亲)上,JVM中的DTrace模块很懒惰.已加载(也就是说,DOF是使用-x lazyload编译的).因此,只有明确启用后,DTrace探针才会加载.有两种方法可以解决此问题.首先,您可以告诉DTrace自身启用有问题的特定探针,从而迫使目标进程加载其探针.这至少需要目标进程的ID.要在问题中提供的示例中解决这个问题,它将类似于:

The problem here is that on SmartOS (and other illumos variants -- as well as their proprietary Solaris cousins) the DTrace module in the JVM is lazily loaded (that is, the DOF was compiled with -x lazyload). As a result, the DTrace probes are not loaded until explicitly enabled. There are two ways to deal with this. The first is that you can tell DTrace itself to enable the specific probes in question, forcing the target process to load its probes. This requires (at least) the ID of the target process; to couch this in the example provided in the question, it would be something like:

% pfexec dtrace -ln 'hotspot*$target:::' -p `pgrep -fn "java Loop"`

这将拾取hotspot(和hotspot_jni)USDT探针,但在充满毫无疑问的Java进程的机器上,使用jstack()操作仍然很困难. (也就是说,当您要在已知进程上使用USDT探针,而不是在所有Java进程上使用ustack helper概要文件时,此方法才起作用.)如果这是您关心的问题,请使用illumos变体(SmartOS, OmniOS等),则可以使用为任务设计的审核库有效地撤消DTrace探针(和堆栈帮助程序)的延迟加载.该库-/usr/lib/dtrace/libdtrace_forceload.so及其64位变体/usr/lib/dtrace/64/libdtrace_forceload.so-将在进程启动时有效地强制DTrace探针加载,从而为所有此类进程提供USDT探针和jstack()操作.要针对32位JVM执行此操作,请在设置了LD_AUDIT_32环境变量的情况下启动java:

This will pick up the hotspot (and hotspot_jni) USDT probes, but it still leaves using the jstack() action difficult on a machine filled with unsuspecting Java processes. (That is, this works when you want to use the USDT probes on a known process, not when you want to use the ustack helper profile all Java processes.) If this is a problem that you care about, on illumos variants (SmartOS, OmniOS, etc.) you can effectively undo the lazy loading of the DTrace probes (and stack helper) by using an audit library designed for the task. This library -- /usr/lib/dtrace/libdtrace_forceload.so and its 64-bit variant, /usr/lib/dtrace/64/libdtrace_forceload.so -- will effectively force the DTrace probes to be loaded when the process starts, giving you USDT probes and the jstack() action for all such processes. To do this for 32-bit JVMs, launch java with the LD_AUDIT_32 environment variable set:

export LD_AUDIT_32=/usr/lib/dtrace/libdtrace_forceload.so

对于64位JVM:

export LD_AUDIT_64=/usr/lib/dtrace/64/libdtrace_forceload.so

这篇关于如何在SmartOS上使用HotSpot DTrace探针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆