设为首页收藏本站

数码鹭岛论坛

 找回密码
 注-册

QQ登录

只需一步,快速开始

搜索
查看: 1644|回复: 0
打印 上一主题 下一主题

How to setup VisualVM and jstatd to take heap dump and thread dump in linux

[复制链接]
跳转到指定楼层
1#
发表于 2014-11-19 09:24:52 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
How to setup JVisualVM

jvisualvm comes installed with JDK and is available in bin directory. File name is jvisualvm.exe
How to setup jstatd in linux

In order to do remote profiling, jstatd must be running on remote host. jstatd setup needs to complete in 6 steps

    Create a jstatd.sh file at any path

    #!/bin/sh
    policy=${HOME}/jstatd.all.policy
    [ -r ${policy} ] || cat >${policy} <<'POLICY'
    grant codebase "file:/usr/lib/jvm/jre-1.6.0-openjdk.x86_64/lib/tools.jar" {
      permission java.security.AllPermission;
    };
    POLICY
    echo ${policy}
    jstatd -J-Djava.security.policy=${policy} -J-Djava.rmi.server.hostname=192.169.31.224&

    Replace 192.169.31.224 with the IP address of the remote host
    Replace "/usr/lib/jvm/jre-1.6.0-openjdk.x86_64/lib/tools.jar" with the actual path of tools.jar
    To find actual path of tools.jar, if you have multiple jvm installed in linux, run following commands
        Check Java using following command

        [root@31224 ~]# /usr/sbin/alternatives --config java

        There are 2 programs which provide 'java'.

          Selection    Command
        -----------------------------------------------
           1           /usr/lib/jvm/jre-1.4.2-gcj/bin/java
        *+ 2           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java

        Enter to keep the current selection[+], or type selection number:

        Here current JVM path is "/usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java" so enter this path in jstatd.sh
        Check the path to tools.jar. Here tools.jar is available at multiple locations

        [root@31224 ~]# locate tools.jar
        /usr/java/jdk1.7.0_45/db/lib/derbytools.jar
        /usr/java/jdk1.7.0_45/lib/tools.jar
        /usr/java/jdk1.7.0_45/lib/visualvm/visualvm/modules/com-sun-tools-visualvm-tools.jar
        /usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/lib/tools.jar
        /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/lib/tools.jar

        Use chmod 777 -R /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/lib
        To find running jstatd use following commands:-

        [root@App31224 ~]# which jstatd
        /usr/bin/jstatd
        [root@App31224 ~]# ls -lart /usr/bin/jstatd
        lrwxrwxrwx 1 root root 24 Oct 16  2010 /usr/bin/jstatd -> /etc/alternatives/jstatd
        [root@App31224 ~]# ll /etc/alternatives/jstatd
        lrwxrwxrwx 1 root root 49 Oct 15  2010 /etc/alternatives/jstatd -> /usr/lib/jvm/java-1.6.0-openjdk.x86_64/bin/jstatd

    use chmod a+x jstatd.sh to make it executable
    Finally run ./jstatd.sh

How to setup jstatd in windows

    Run the "jstatd" command in a command window:

    C:\Program Files\Java\jdk1.7.0_45\bin>jstatd.exe
    Could not create remote object
    access denied ("java.util.PropertyPermission" "java.rmi.server.ignoreSubClasses"
     "write")
    java.security.AccessControlException: access denied ("java.util.PropertyPermissi
    on" "java.rmi.server.ignoreSubClasses" "write")
            at java.security.AccessControlContext.checkPermission(AccessControlConte
    xt.java:372)
            at java.security.AccessController.checkPermission(AccessController.java:
    559)
            at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
            at java.lang.System.setProperty(System.java:783)
            at sun.tools.jstatd.Jstatd.main(Jstatd.java:139)

    The "access denied" error is expected, because "jstatd" requires a security policy file specified with the "java.security.policy" system property, if there is no security manager running on my machine.
    Create the security policy file, jstatd.all.policy, that grants permissions to run "jstatd" and other tools in the tools.jar:

    grant codebase "file:C:/Program Files/Java/jdk1.7.0_45/lib/tools.jar" {
       permission java.security.AllPermission;
    };

    Run "jstatd" with the security policy file, tools.policy specified to the "java.security.policy" system property:

    C:\Program Files\Java\jdk1.7.0_45\bin>jstatd.exe -J-Djava.rmi.server.hostname=127.0.0.1 -J-Djava.security.policy=jstatd.all.policy

    jVisualVM will autodetect all running java processes

    File:Jstatd-local.png

How to setup and use jhat
How to check time taken during full GC

    Setup following JCATALINA_OPTS to enable full GC in setenv.sh

    export CATALINA_OPTS="$CATALINA_OPTS -verbose:gc -XX:+HeapDumpOnOutOfMemoryError  -XX:+PrintTenuringDistribution -XX:+PrintGCTimeStamps
    -XX:+PrintGCDetails -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCApplicationConcurrentTime -XX:+PrintHeapAtGC -Xloggc:logs/gc.log"

    Use following tail command tail -f logs/gc.log | grep 'threads were stopped'
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享
您需要登录后才可以回帖 登录 | 注-册

本版积分规则

小黑屋|手机版|Archiver|数码鹭岛 ( 闽ICP备20006246号 )  

counter

GMT+8, 2025-12-3 19:20 , Processed in 0.077163 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表