全部博文(2065)
分类: Java
2010-05-21 15:54:52
JDK内存监控之jstat
(时间:
要重点介绍下这个命令。
这是jdk命令中比较重要,也是相当实用的一个命令,可以观察到classloader,compiler,gc相关信息
具体参数如下:
-class:统计class loader行为信息
-compile:统计编译行为信息
-gc:统计jdk gc时heap信息
-gccapacity:统计不同的generations(不知道怎么翻译好,包括新生区,老年区,permanent区)相应的heap容量情况
-gccause:统计gc的情况,(同-gcutil)和引起gc的事件
-gcnew:统计gc时,新生代的情况
-gcnewcapacity:统计gc时,新生代heap容量
-gcold:统计gc时,老年区的情况
-gcoldcapacity:统计gc时,老年区heap容量
-gcpermcapacity:统计gc时,permanent区heap容量
-gcutil:统计gc时,heap情况
-printcompilation:不知道干什么的,一直没用过。
一般比较常用的几个参数是:
jstat -class 2083 1000 10 (每隔1秒监控一次,一共做10次)
输出内容含义如下:
Loaded |
Number of classes loaded.(加载的类的数量) |
Bytes |
Number of Kbytes loaded.(加载的字节数) |
Unloaded |
Number of classes unloaded. |
Bytes |
Number of Kbytes unloaded. |
Time |
Time spent performing class
load and unload operations. |
示例:jstat -class 2083 1000 10
Loaded Bytes Unloaded
Bytes Time
1207 1377.5
6 5.2 0.95
1207 1377.5
6 5.2 0.95
1207 1377.5
6 5.2
0.95
1207 1377.5
6 5.2 0.95
1207 1377.5
6 5.2 0.95
1207 1377.5
6 5.2 0.95
1207 1377.5
6 5.2 0.95
1207 1377.5
6 5.2 0.95
1207 1377.5
6 5.2
0.95
1207 1377.5
6 5.2 0.95
jstat -gc 2083 2000 20(每隔2秒监控一次,共做10)
输出内容含义如下:
S |
Current survivor(存活的) space 0 capacity (KB). |
EC |
Current |
EU |
|
OC |
Current old space capacity
(KB). |
OU |
Old space utilization (KB). |
PC |
Current permanent space
capacity (KB). |
PU |
Permanent space utilization
(KB). |
YGC |
Number of young generation
GC Events. |
YGCT |
Young generation garbage
collection time. |
FGC |
Number of full GC events. |
FGCT |
Full garbage collection
time. |
GCT |
Total garbage collection
time. |
输出内容:
监控内存使用情况 参数 (查看内存溢出相对有用)
jstat -gccause
2083 5000 (每隔5秒监控一次)
输出内容含义如下:
S0 |
Survivor space 0 utilization
as a percentage of the space's current capacity. |
S1 |
Survivor space 1 utilization
as a percentage of the space's current capacity. |
E |
|
O |
Old space utilization as a
percentage of the space's current capacity. |
P |
Permanent space utilization
as a percentage of the space's current capacity. |
YGC |
Number of young generation
GC events. |
YGCT |
Young generation garbage
collection time. |
FGC |
Number of full GC events. |
FGCT |
Full garbage collection
time. |
GCT |
Total garbage collection
time. |
LGCC |
Cause of last Garbage
Collection. |
GCC |
Cause of current Garbage
Collection. |
如果能熟练运用这些命令,尤其是在linux下,那么完全可以代替jprofile等监控工具了,谁让它收费呢。呵呵。
用命令的好处就是速度快,并且辅助于其他命令,比如grep gawk sed等,可以组装多种符合自己需求的工具。