您的位置:首页 > 其它

查看JVM内存状态的工具使用

2012-05-15 14:07 239 查看
只是介绍SUN JDK自带的小工具

一些工具的链接http://docs.oracle.com/javase/1.5.0/docs/tooldocs/

jps -lvm

jinfo

jstat -options查看可用的选项http://docs.oracle.com/javase/1.5.0/docs/tooldocs/share/jstat.html

jstat -gc

jstat -gcutil 统计gc时,heap情况

jmap

jmap prints shared object memory maps or heap memory details of a given process or core file or a remote debug server.

used frequently

jmap -heap:format=b <pid> to dump java heap in hprof binary format: heap.bin Dump出内存使用详情

jmap -heap <pid>

jmap [ option ] pid

jmap [ option ] executable core

jmap [ option ] [server-id@]remote-hostname-or-IP

?e.g.?(还不确定如何远程连接) step 1. jsadebugd 6664 amrndhl235 step 2. jmap -heap 6664@amrndhl235

rmiregistry -J-Xbootclasspath:$JAVA_HOME/lib/sa-jdi.jar

OPTIONS

<no option>

When no option is used jmap prints shared object mappings. For each shared object loaded in the target VM, start address, the size of the mapping, and the full path of the shared object file are printed. This is similar to the Solaris pmap utility.

-heap

Prints a heap summary. GC algorithm used, heap configuration and generation wise heap usage are printed.

-histo

Prints a histogram of the heap. For each Java class, number of objects, memory size in bytes, and fully qualified class names are printed. VM internal class names are printed with '*' prefix.

-permstat

Prints class loader wise statistics of permanent generation of Java heap. For each class loader, its name, liveness, address, parent class loader, and the number and size of classes it has loaded are printed.

-h Prints a help message.

jconsole监控 (用JMX监测JVM的运行参数)

使用时需要在启动application时加入参数

JAVA_OPTS="-Djava.rmi.server.hostname=amrndhl235 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=5000 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"

如果需要设置密码要设置authenticate=true,并且设置密码文件

JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.access.file=/home/tomcat/jmxremote.access -Dcom.sun.management.jmxremote.password.file=/home/tomcat/jmxremote.password"

密码文件内容

# jmx remote authentication password entries

admin password

support passwordSupport

在linux上需要设置它的权限chmod 600 jmxremote.password

jmxremote.access文件内容

# Access control entries:

admin readwrite

support readonly

关于JMX,可以参考

Monitoring and Management Using JMX

用JMX管理你的JVM

JConsole 运行对application是有开销的,例如:首先独自运行一个应用程序,然后在分析器下运行,并测量差异。比如JDK附带的demo SwingSet2.

先使用java -verbose:gc -Xms10m -Xmx19m -Djava.rmi.server.hostname=AMRGROLL3DK364 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=5000 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar SwingSet2.jar 运行
SwingSet2 来查看垃圾收集清理然后运行同一个应用程序并将 JConsole 分析器连接到它。当 JConsole 连接好了之后,一个稳定的 GC 清理流出现,否则不会出现。这就是分析器的性能开销。

JDK 6还带了jvisualvm (VisualVM 入门指南)

推荐安装visualvm的插件Tools->Plugins

安装后,插件位置看Help->About->Detail

Jconsole Plugin (JConsole Plug-in Wrapper Tab)

Click on 'JConsole Plugins'.

Click on 'Add JAR/Folder' JDK_HOME/demo/management/JTop/JTop.jar

重启visualvm
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: