Java故障分析工具


这些工具都在java安装目录的bin目录下。

命令行工具

jps

列出正在运行的虚拟机进程, 并显示虚拟机执行主类( Main Class, main()函数所在的类)名称以及这些进程的本地虚拟机唯一ID( LVMID, Local Virtual Machine Identifier)。

jps [ options ] [ hostid ]

示例:

jps -l
2388 D:\Develop\glassfish\bin\..\modules\admin-cli.jar
2764 com.sun.enterprise.glassfish.bootstrap.ASMain
3788 sun.tools.jps.Jps

options:

options说明
-q只输出LVMID,省略主类的名称
-m输出虚拟机启动时传递给主类main()函数的参赛
-l输出主类的全名,如果进程执行的是JAR包,输出JAR路径
-v输出JVM启动时的参数

jstat

监视运行时状态的命令行工具。

jstat [ option vmid [interval[s|ms] [count]] ]

示例:假设每250毫秒查询一次进程2764垃圾收集状况, 一共查询20次,命令如下

jstat -gc 2764 250 20

option:

option说明
-class监视类加载、卸载数量、总空间以及类装载耗费的时间
-gc监视堆状况,包括Eden区,两个Survivor区,老年代、永久代的容量,
已用空间,垃圾回收次数、回收耗时等信息
-gccapacity内容同-gc,关注各个区使用到的最大最小空间
-gcutil内容同-gc,关注已使用空间占总空间的百分比
-gccause功能同-gcutil,增加上次GC的原因
-gcnew关注新生代GC情况
-gcnewcapacity同-gccapacity,关注新生代
-gcold关注老年代
-gcoldcapacity同-gccapacity,关注老年代
-gcpermcapacity关注永久代的最大最小空间
-compile输出即时编译器编译过的方法、耗时等信息
-printcompilation输出即时编译过的方法

执行样例

jstat -gcutil 2764
S0      S1      E      O       P      YGC    YGCT     FGC     FGCT    GCT
0.00   0.00    6.20   41.42   47.20   16     0.105     3     0.472    0.577

jinfo

实时查看和调整JVM各项参数。
命令格式

jinfo [ option ] pid

option

optioncomment
-flag to print the value of the named VM flag
-flag [+|-]to enable or disable the named VM flag
-flag =to set the named VM flag to the given value
-flagsto print VM flags
-syspropsto print Java system properties
to print both of the above
-h-help

执行样例

jinfo -flag CMSInitiatingOccupancyFraction 1444
-XX:CMSInitiatingOccupancyFraction=85

jmap

生成堆转储快照(dump文件)。
命令格式

jmap [ option ] vmid

option

option说明
to print same info as Solaris pmap
-heapto print java heap summary
-histo[:live]to print histogram of java object heap; if the “live” suboption is specified, only count live objects
-clstatsto print class loader statistics
-finalizerinfoto print information on objects awaiting finalization
-dump:<dump-options>to dump java heap in hprof binary format
dump-options:
live : dump only live objects; if not specified, all objects in the heap are dumped.
format=b : binary format
file=<file> : dump heap to <file>
Example: jmap -dump:live,format=b,file=heap.bin <vmid>
-Fforce. Use with -dump:<dump-options> <vmid> or -histo to force a heap dump or
histogram when <vmid> does not respond.
The “live” suboption is not supported in this mode.
-h | -helpto print this help message
-J<flag>to pass directly to the runtime system

jhat

分析jmap生成的快照
比较少用,自带一个微型http服务器,生成的结果在浏览器查看。
格式

jhat <dump>

jstack

Java堆栈跟踪工具。
用于生成虚拟机当前时刻的线程快照(threaddump)。
格式

jstack [ option ] vmid

option

option说明
-Fto force a thread dump. Use when jstack <vmid> does not respond (process is hung)
-mto print both java and native frames (mixed mode)
-llong listing. Prints additional information about locks
-h or -helpto print this help message

可视化工具

JHSDB

需要命令行启动
命令参考

jhsdb hsdb --pid 11180

JConsole

直接在Java目录的bin目录下,找到jconsole双击启动。

jvisualvm

直接在Java目录的bin目录下,找到jvisualvm双击启动。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值