Step1、找出所查java应用的进程编号
jps -mlv | grep 应用名称 # 或者 ps -ef | grep 应用名称
20848 com.lqz.test.Main -Dprogram=APP_/home/lqz/test/bin/.. -Xms4G -Xmx4G
Step2、查看应用的gc概况
- $ jstat -gcutil 20848 250 10
- S0 S1 E O P YGC YGCT FGC FGCT GCT
- 56.25 0.00 52.10 34.51 39.51 469204 5176.817 549 111.738 5288.555
- 56.25 0.00 52.10 34.51 39.51 469204 5176.817 549 111.738 5288.555
- 56.25 0.00 52.10 34.51 39.51 469204 5176.817 549 111.738 5288.555
- 56.25 0.00 52.10 34.51 39.51 469204 5176.817 549 111.738 5288.555
- 56.25 0.00 52.10 34.51 39.51 469204 5176.817 549 111.738 5288.555
- 56.25 0.00 52.10 34.51 39.51 469204 5176.817 549 111.738 5288.555
- 56.25 0.00 52.10 34.51 39.51 469204 5176.817 549 111.738 5288.555
- 56.25 0.00 52.10 34.51 39.51 469204 5176.817 549 111.738 5288.555
- 56.25 0.00 54.10 34.51 39.51 469204 5176.817 549 111.738 5288.555
- 56.25 0.00 56.11 34.51 39.51 469204 5176.817 549 111.738 5288.555
- $
jstat 详细用法:jstat - Java Virtual Machine Statistics Monitoring Tool,更多的java工具:JDK Tools and Utilities,更多jdk文档,请进入传送门。
jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]
- -gcutil Option
- Summary of Garbage Collection Statistics
- Column Description
- 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 Eden space utilization as a percentage of the space's current capacity.
- 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.
Step3、查看应用的运行时间
- $ ps -p 20848 -o etime
- ELAPSED
- 7-12:41:04
- $
ps -p pid -o etime
- CODE HEADER DESCRIPTION
- etime ELAPSED elapsed time since the process was started, in the form [[dd-]hh:]mm:ss.
Step4、计算ygc的平均耗时和时间间隔
ygc平均耗时=YGCT/YGC(s)=5176.81/469204=0.011s=11ms
ygc时间间隔=YGC/程序的运行时间=469204/(7*24*60*60 + 12*60*60 + 41*60 + 4 )=0.72s