作用
JVM statistics Monitoring,用于监视虚拟机运行时状态信息的命令,它可以显示出虚拟机进程中的类装载、内存、垃圾收集、JIT编译等运行数据。
使用
依旧先看一下使用帮助
~ ᐅ jstat -help
Usage: jstat -help|-options
jstat - [-t] [-h
] [ []]
Definitions:
An option reported by the -options option
Virtual Machine Identifier. A vmid takes the following form:
[@[:
]]
Where is the local vm identifier for the target
Java virtual machine, typically a process id; is
the name of the host running the target Java virtual machine;
and
is the port number for the rmiregistry on the
target host. See the jvmstat documentation for a more complete
description of the Virtual Machine Identifier.
Number of samples between header lines.
Sampling interval. The following forms are allowed:
["ms"|"s"]
Where is an integer and the suffix specifies the units as
milliseconds("ms") or seconds("s"). The default units are "ms".
Number of samples to take before terminating.
-J Pass directly to the runtime system.
这里首先介绍一下 jstat - pid 后面跟0、1、2个参数的差别,举例说明:
~ ᐅ jps
30054 Jps
29529 Launcher
28953
29530 SearchBusiestCPU
29295 RemoteMavenServer
~ ᐅ jstat -gcutil 29530 # 0个参数的时候直接输出一次当前情况
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
0.00 0.00 20.59 0.00 17.27 19.75 0 0.000 0 0.000 0.000
~ ᐅ jstat -gcutil 29530 1000 # 1个参数时这个参数代表间隔时间,一直输出
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
0.00 0.00 20.59 0.00 17.27 19.75 0 0.000 0 0.000 0.000
0.00 0.00 20.59 0.00 17.27 19.75 0 0.000 0 0.000 0.000
0.00 0.00 20.59 0.00 17.27 19.75 0 0.000 0 0.000 0.000
0.00 0.00 20.59 0.00 17.27 19.75 0 0.000 0 0.000 0.000
^C% ~ ᐅ jstat -gcutil 29530 1000 2 # 2个参数时第一个参数参数代表间隔时间,后一个参数代表输出的总次数
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
0.00 0.00 20.59 0.00 17.27 19.75 0 0.000 0 0.000 0.000
0.00 0.00 20.59 0.00 17.27 19.75 0 0.000 0 0.000 0.000
当然也支持-t,-h,直接看一下效果即可,不是特别的重要:
~ ᐅ jstat -gcutil -t -h5 29530 1000
Timestamp S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
428.5 0.00 0.00 20.59 0.00 17.27 19.75 0 0.000 0 0.000 0.000
429.5 0.00 0.00 20.59 0.00 17.27 19.75 0 0.000 0 0.000 0.000
430.5 0.00 0.00 20.59 0.00 17.27 19.75 0 0.000 0 0.000 0.000
431.5 0.00 0.00 20.59 0.00 17.27 19.75 0 0.000 0 0.000 0.000
432.5 0.00 0.00 20.59 0.00 17.27 19.75 0 0.000 0 0.000 0.000
Timestamp S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
433.5 0.00 0.00 20.59 0.00 17.27 19.75 0 0.000 0 0.000 0.000
434.5 0.00 0.00 20.59 0.00 17.27 19.75 0 0.000 0 0.000 0.000
435.5 0.00 0.00 20.59 0.00 17.27 19.75 0 0.000 0 0.000 0.000
436.5 0.00 0.00 20.59 0.00 17.27 19.75 0 0.000 0 0.000 0.000
437.5 0.00 0.00 20.59 0.00 17.27 19.75 0 0.000 0 0.000 0.000
Timestamp S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
438.5 0.00 0.00 20.59 0.00 17.27 19.75 0 0.000 0 0.000 0.000
439.5 0.00 0.00 20.59 0.00 17.27 19.75 0 0.000 0 0.000 0.000
不同参数详细解释
jstat -options
可以列出当前JVM版本支持的选项,常见的有
l class (类加载器)
l compiler (JIT)
l gc (GC堆状态)
l gccapacity (各区大小)
l gccause (最近一次GC统计和原因)
l gcnew (新区统计)
l gcnewcapacity (新区大小)
l gcold (老区统计)
l gcoldcapacity (老区大小)
l gcpermcapacity (永久区大小)
l gcutil (GC统计汇总)
l printcompilation (HotSpot编译统计)
1、jstat –class
: 显示加载class的数量,及所占空间等信息。
2、jstat -compiler
:显示VM实时编译的数量等信息。
3、jstat -gc
: 可以显示gc的信息,查看gc的次数,及时间。
不同的版本有一定的差别,比如jdk8之后会有MC、MU等,代表Metaspace的容量(C)和已使用空间(U),下面其他参数也有相同的问题,注意识别对应的后缀即可。
4、jstat -gccapacity
:可以显示,VM内存中三代(young,old,perm)对象的使用和占用大小
5、jstat -gcutil
:统计gc信息
6、jstat -gcnew
:年轻代对象的信息。
7、jstat -gcnewcapacity
: 年轻代对象的信息及其占用量。
8、jstat -gcold
:old代对象的信息。
9、jstat -gcoldcapacity
:old代对象的信息及其占用量。
10、jstat -gcpermcapacity
: perm对象的信息及其占用量。
11、jstat -printcompilation
:当前VM执行的信息。
关于jstat就主要介绍到这里,这个命令相对容易一些,关键是对结果的解读。这些结果也不需要刻意去背,能清楚的理解分代,找到缩写规律,自己单独看也是很容易的。
其他jvm命令就不做单独讲解了,看看找机会把零散的再收拾一下。
其他文章推荐
Java并发编程与高并发解决方案:
https://coding.imooc.com/class/195.html
Java开发企业级权限管理系统:
https://coding.imooc.com/class/149.html
欢迎转载和收藏,别忘了关注我哦~
领取专属 10元无门槛券
私享最新 技术干货