当前位置:   article > 正文

JVM中jstat命令和jmap命令_jmap -histo pid

jmap -histo pid

jstat(Java Virtual Machine Statistics Monitoring Tool) 用于监视虚拟机各种运行状态信息的命令行工具.可以显示虚拟机的类装载,内存,垃圾收集,JIT编译等运行数据.

远程命令模式下jstat是定位运行期JVM性能问题的首选工具.本地首选VisualVM.

使用方式可以参考官方文档.

jstat -gc <pid>: 可以显示gc的信息,查看gc的次数,及时间。

显示列名

具体描述

S0C   

年轻代中第一个survivor(幸存区)的容量 (字节)

S1C   

年轻代中第二个survivor(幸存区)的容量 (字节)

S0U   

年轻代中第一个survivor(幸存区)目前已使用空间 (字节)

S1U     

年轻代中第二个survivor(幸存区)目前已使用空间 (字节)

EC      

年轻代中Eden(伊甸园)的容量 (字节)

EU       

年轻代中Eden(伊甸园)目前已使用空间 (字节)

OC        

Old代的容量 (字节)

OU      

Old代目前已使用空间 (字节)

PC    

Perm(持久代)的容量 (字节)

PU

Perm(持久代)目前已使用空间 (字节)

YGC    

从应用程序启动到采样时年轻代中gc次数

YGCT   

从应用程序启动到采样时年轻代中gc所用时间(s)

FGC   

从应用程序启动到采样时old代(全gc)gc次数

FGCT    

从应用程序启动到采样时old代(全gc)gc所用时间(s)

GCT

从应用程序启动到采样时gc用的总时间(s)

C:\Users\rongsoft>jstat -gc 2092
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT
10752.0 10752.0  0.0    0.0   65536.0  29375.9   108032.0   21582.5   21248.0 20674.5 2560.0 2382.2      2    0.017  1      0.025

  0.042

列成表格是像下面这样:

survivor0的容量survivor1的容量survivor0已用survivor1已用Eden容量Eden已用Old代容量Old代已用MetaSpace的容量MetaSpace已用压缩类空间容量压缩类空间使用大小年轻代GC次数年轻代GC所用时间老年代GC次数老年代GC所花时间GC所用总时间
S0C    S1C    S0U    S1U      EC      EU        OC        OU      MC    MU    CCSC  CCSU  YGC    YGCT    FGC    FGCT    GCT
10752.010752.0  0.0    0.0  65536.0  29375.9  108032.0  21582.5  21248.020674.52560.02382.2      2    0.017   10.025    0.042

如果需要打印内存日志,需要增加参数:
-XX:+PrintGCDetails -XX:-UseAdaptiveSizePolicy -XX:SurvivorRatio=8 -XX:NewSize=10M -XX:MaxNewSize=10M

ps -ef |grep xxxxxx.jar

java -Xmx2048M -Xms512M -Djeesuite.configcenter.profile=pro -Djava.io.tmpdir=/home/server/microservice/xxxxx/temp/ -jar /home/server/microservice/xxxxx.jar

 

-XX:-UseAdaptiveSizePolicy 禁用动态调整,使SurvivorRatio可以起作用

-XX:SurvivorRatio=8 设置比例Eden:Survivior=8,那么2个Survivior区就是2.

 

jmap命令:可以查看堆默认配置信息

 jmap -heap 995

  1. [root@service-docker-192-168-1-91.workflow]# jmap -heap 995
  2. Attaching to process ID 995, please wait...
  3. Debugger attached successfully.
  4. Server compiler detected.
  5. JVM version is 25.111-b14
  6. using thread-local object allocation.
  7. Parallel GC with 8 thread(s)
  8. Heap Configuration:
  9. MinHeapFreeRatio = 0
  10. MaxHeapFreeRatio = 100
  11. MaxHeapSize = 1073741824 (1024.0MB)
  12. NewSize = 178782208 (170.5MB)
  13. MaxNewSize = 357564416 (341.0MB)
  14. OldSize = 358088704 (341.5MB)
  15. NewRatio = 2
  16. SurvivorRatio = 8
  17. MetaspaceSize = 21807104 (20.796875MB)
  18. CompressedClassSpaceSize = 1073741824 (1024.0MB)
  19. MaxMetaspaceSize = 17592186044415 MB
  20. G1HeapRegionSize = 0 (0.0MB)
  21. Heap Usage:
  22. PS Young Generation
  23. Eden Space:
  24. capacity = 252182528 (240.5MB)
  25. used = 184114440 (175.58521270751953MB)
  26. free = 68068088 (64.91478729248047MB)
  27. 73.00840445219107% used
  28. From Space:
  29. capacity = 7864320 (7.5MB)
  30. used = 7864320 (7.5MB)
  31. free = 0 (0.0MB)
  32. 100.0% used
  33. To Space:
  34. capacity = 15728640 (15.0MB)
  35. used = 0 (0.0MB)
  36. free = 15728640 (15.0MB)
  37. 0.0% used
  38. PS Old Generation
  39. capacity = 358088704 (341.5MB)
  40. used = 317911272 (303.1838150024414MB)
  41. free = 40177432 (38.316184997558594MB)
  42. 88.7800336756783% used
  43. 34539 interned Strings occupying 4082072 bytes.

关于JVM得参数配置,可以参考官网https://docs.oracle.com/javase/9/gctuning/toc.htm

第四节 4 Factors Affecting Garbage Collection Performance

Description of Figure 4-1 follows

其中Virtual区是供新生代和老年代使用的.堆总大小为 Eden,survivor,survivor,Old.

Table 4-1 Default Options for 64-Bit Solaris Operating System

OptionDefault Value
-XX:MinHeapFreeRatio

40

-XX:MaxHeapFreeRatio

70

-Xms

6656 KB

-Xmx

calculated

 

The Young Generation

After total available memory, the second most influential factor affecting garbage collection performance is the proportion of the heap dedicated to the young generation.

The bigger the young generation, the less often minor collections occur. However, for a bounded heap size, a larger young generation implies a smaller old generation, which will increase the frequency of major collections. The optimal choice depends on the lifetime distribution of the objects allocated by the application.

Young Generation Size Options

By default, the young generation size is controlled by the option -XX:NewRatio.

For example, setting -XX:NewRatio=3 means that the ratio between the young and old generation is 1:3. In other words, the combined size of the eden and survivor spaces will be one-fourth of the total heap size.

The options -XX:NewSize and -XX:MaxNewSize bound the young generation size from below and above. Setting these to the same value fixes the young generation, just as setting -Xms and -Xmx to the same value fixes the total heap size. This is useful for tuning the young generation at a finer granularity than the integral multiples allowed by -XX:NewRatio.

Survivor Space Sizing

You can use the option -XX:SurvivorRatio to tune the size of the survivor spaces, but often this isn't important for performance.

For example, -XX:SurvivorRatio=6 sets the ratio between eden and a survivor space to 1:6. In other words, each survivor space will be one-sixth of the size of eden, and thus one-eighth of the size of the young generation (not one-seventh, because there are two survivor spaces).

If survivor spaces are too small, then the copying collection overflows directly into the old generation. If survivor spaces are too large, then they are uselessly empty. At each garbage collection, the virtual machine chooses a threshold number, which is the number of times an object can be copied before it's old. This threshold is chosen to keep the survivors half full. You can use the log configuration -Xlog:gc,age can be used to show this threshold and the ages of objects in the new generation. It's also useful for observing the lifetime distribution of an application.

Table 4-2 provides the default values for 64-bit Solaris.

Table 4-2 Default Option Values for Survivor Space Sizing

OptionServer JVM Default Value

-XX:NewRatio

2

-XX:NewSize

1310 MB

-XX:MaxNewSize

not limited

-XX:SurvivorRatio

8

The maximum size of the young generation is calculated from the maximum size of the total heap and the value of the -XX:NewRatio parameter. The "not limited" default value for the -XX:MaxNewSize parameter means that the calculated value isn't limited by -XX:MaxNewSize unless a value for -XX:MaxNewSize is specified on the command line.

jstat查看容量大小:

jstat -gccapacity 31209

  1. [root@web-nginx-192-168-1-92.test92.ayg logs]# jstat -gccapacity 31209
  2. NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC
  3. 87040.0 174592.0 100352.0 2560.0 4608.0 79872.0 175104.0 349696.0 326656.0 326656.0 0.0 1165312.0 131624.0 0.0 1048576.0 14896.0 9779 12
  • NGCMN:年轻代(young)中初始化(最小)的大小(字节)
  • NGCMX:年轻代(young)的最大容量 (字节)
  • NGC:年轻代(young)中当前的容量 (字节)
  • S0C:年轻代中第一个survivor(幸存区)的容量 (字节)
  • S1C:年轻代中第二个survivor(幸存区)的容量 (字节)
  • EC:年轻代中Eden(伊甸园)的容量 (字节)
  • OGCMN:old代中初始化(最小)的大小 (字节)
  • OGCMX:old代的最大容量(字节)
  • OGC:old代当前新生成的容量 (字节)
  • OC:Old代的容量 (字节)
  • MCMN:metaspace(元空间)中初始化(最小)的大小 (字节)
  • MCMX:metaspace(元空间)的最大容量 (字节)
  • MC:metaspace(元空间)当前新生成的容量 (字节)
  • CCSMN:最小压缩类空间大小
  • CCSMX:最大压缩类空间大小
  • CCSC:当前压缩类空间大小
  • YGC:从应用程序启动到采样时年轻代中gc次数
  • FGC:从应用程序启动到采样时old代(全gc)gc次数

jstat使用举例:详细可以参考jvm 性能调优工具之 jstat 命令详解

  1. [root@web-nginx-192-168-1-92 logs]# jps
  2. 9348 springcloud-apigateway.jar
  3. 18117 Bootstrap
  4. 5542 Bootstrap
  5. 3880 QuorumPeerMain
  6. 31209 mypayer.jar
  7. 5322 Bootstrap
  8. 4748 springcloud-admin.jar
  9. 5709 Bootstrap
  10. 4470 configserver.jar
  11. 7734 ConsoleConsumer
  12. 12822 Jps
  13. 20375 Bootstrap
  14. 8122 ConnectStandalone
  15. 4347 Kafka
  16. 4699 springcloud-eureka.jar
  17. You have new mail in /var/spool/mail/root
  18. [root@web-nginx-192-168-1-92 logs]# jstat -gccapacity 31209
  19. NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC
  20. 87040.0 174592.0 100352.0 2560.0 4608.0 79872.0 175104.0 349696.0 326656.0 326656.0 0.0 1165312.0 131624.0 0.0 1048576.0 14896.0 9779 12
  21. [root@web-nginx-192-168-1-92 logs]# jstat -gcold 31209
  22. MC MU CCSC CCSU OC OU YGC FGC FGCT GCT
  23. 131624.0 126963.1 14896.0 13916.6 326656.0 130010.1 9813 12 4.207 190.493
  24. [root@web-nginx-192-168-1-92 logs]# jstat -gcnew 31209
  25. S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT
  26. 3072.0 3072.0 2064.0 0.0 1 15 3072.0 168448.0 109317.2 14998 273.159
  27. You have new mail in /var/spool/mail/root
  28. [root@web-nginx-192-168-1-92 logs]# jstat -gcoldcapacity 31209
  29. OGCMN OGCMX OGC OC YGC FGC FGCT GCT
  30. 175104.0 349696.0 288768.0 288768.0 15002 17 6.059 279.273
  31. [root@web-nginx-192-168-1-92 logs]# jstat -gcnewcapacity 31209
  32. NGCMN NGCMX NGC S0CMX S0C S1CMX S1C ECMX EC YGC FGC
  33. 87040.0 174592.0 168448.0 57856.0 3072.0 57856.0 2048.0 173568.0 151552.0 15003 17
  34. [root@web-nginx-192-168-1-92 logs]# jstat -gcutil 31209
  35. S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
  36. 99.22 0.00 11.10 56.16 96.39 93.46 15028 273.592 17 6.059 279.651

如果要打印GC日志,可以增加配置参数

  1. -XX:+PrintGC 输出GC日志
  2. -XX:+PrintGCDetails 输出GC的详细日志(jdk9已经废弃)
  3. -XX:+PrintGCTimeStamps 输出GC的时间戳(以基准时间的形式)
  4. -XX:+PrintGCDateStamps 输出GC的时间戳(jdk9已经移除.以日期的形式,如 2013-05-04T21:53:59.234+0800)
  5. -XX:+PrintHeapAtGC 在进行GC的前后打印出堆的信息
  6. -Xloggc:../logs/gc.log 日志文件的输出路径

 注意:已经废弃的参数配置后可能导致启动失败.

jmap导出文件

jmap -dump:format=b,live,file=jmap.dump 31209

参考:

用jvisualvm分析dump文件

jstack检测cpu高

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/653883
推荐阅读
相关标签
  

闽ICP备14008679号