Virtual machine performance monitoring

 Java virtual machine monitoring and tuning, by means of Java comes with analysis tools.

jps: JVM Process Status Tool, to display all the HotSpot virtual machine process within the specified system

jstat: JVM Statistics Monitoring Tool, used in mobile phones HotSpot virtual machine to run all aspects of data

jinfo: Configuration Info for Java, virtual machine configuration information display

jmap: Memory Map for Java, generates a snapshot of the virtual machine memory dump (heapdump file)

jstack: Stack Trace for Java, display a snapshot of the virtual machine thread

 

1, jps: VM process status tool

usage:

usage: jps [-help]
jps [-q] [-mlvV] [<hostid>]

Definitions:
<hostid>: <hostname>[:<port>]

Option Description:

-q: Only output LVMID, the name of the main class is omitted

Parameters passed to the output of the main class virtual machine processes start () function: -m

-l: full name of the output of the main class is jar package jar package path output if the process execution

-v: output virtual machine JVM startup parameters

 

2, jstat: Virtual Machine statistics monitoring tool

Command tool for monitoring virtual machines running various status information.

usage:

Usage: jstat -help|-options
jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]

Definitions:
<the Option> Options
<vmid> Process ID
<lvmid> local virtual machine process vmid and lvmid is consistent, if it is remote virtual machine process, vmid format: [@ <hostname> [: <Port>]]
<interval The> Polling interval: support milliseconds and seconds, milliseconds default
<count> number of queries

Option Description:

-class: monitoring class loading, unloading amount of total space, and the time it takes to load the class

-gc: Java heap monitor the situation, including the Eden area, two survivor district, the old era, such as permanent-generation capacity, used space, GC total time information

-gccapacity: -gc monitor the content and the same, but the output is mainly concerned about the use of Java heap each region to the maximum, minimum space

-gcutil: -gc monitor the content and the same, but the output has been focused on the use of the percentage of total space

-gccause: -gcutil and function the same, but will cause additional output generated by the last GC

-gcnew: GC monitors the status of the new generation

-gcnewcapacity: monitor the content and -gcnew same, but the output is mainly concerned about the use to the maximum, minimum space

-gcold: old's condition monitoring GC

-gcoldcapacity: monitor the content and -gcold same, but the output is mainly concerned about the use to the maximum, minimum space

-gcpermcapacity: generation of output used to permanently maximum, minimum space

-compiler: Output JIT compiler compiled method, time-consuming and other information

-printcompilation: output has been compiled JIT methods

Note 1:

S0C: surviving size using a second zone;: size of the first region of surviving, S1C: the size of the second region of surviving, S0U: using a size of the first region of surviving, SlU
EC: Eden area size, EU : use the size of the Eden area;
OC: old's size, OU: old's use of size;
MC: method area size, MU: method area using size;
CCSC: compression class space, CCSU: compression of space use size;
YGC: the number of the young generation garbage collection, YGCT: the young generation garbage collection time-consuming, FGC: the number of garbage collection years old, FGCT: old's garbage collection time-consuming, GCT: total garbage collection time consuming.

Note 2:

Eden new generation area (E) using 40.09%, two Survivor areas (S0, S1), respectively, using 0.00% and 100.00%, year old (O) using 14.57%, generation of permanent (P) is a space after the element jdk1.8 (M) instead of using 97.55%. Since the program runs Minor GC (YGC) were 19 times, (YGCT) Total time 3.229 seconds; Full GC (FGC) did not occur, (FGCT) Total time 0 seconds; all GC (GCT) Total time 3.229 seconds .

Description:

NGCMN: minimum capacity of the new generation, NGCMX: new generation of maximum capacity, NGC: current new generation capacity;
S0C: surviving a first area size, S1C: the size of the second region of surviving;
EC: Eden area size;
OGCMN: Old s minimum capacity, OGCMX: old's maximum capacity, OGC: current old's size, OC: current old's size;
MCMN: minimum metadata capacity, MCMX: maximum metadata capacity, MC: current metadata space;
the CCSmn: minimum compression class space, CCSMX: maximum compression class space, CCSC: current compression type space;
YGC: the young generation the number of gc, FGC: GC number of years old;

 

3, jinfo: Java configuration tool

Real-time view and adjust the parameters of the virtual machine.

usage:

jinfo [option] <pid>
(to connect to running process)
jinfo [option] <executable <core>
(to connect to a core file)
jinfo [option] [server_id@]<remote server IP or hostname>
(to connect to remote debug server)

选项说明:

-flag <name> :输出指定参数值
-flag [+|-]<name> :设置指定参数是否可用
-flag <name>=<value> :设置参数和值
-flags:输出所有参数
-sysprops:输出Java参数
<no option> :输出上面的所有参数信息

 

4、jmap:Java内存映像工具

用于生成堆转储快照(一般称为heapdump或dump文件)

用法:

jmap [option] <pid>
(to connect to running process)
jmap [option] <executable <core>
(to connect to a core file)
jmap [option] [server_id@]<remote server IP or hostname>
(to connect to remote debug server)

选项说明:

-dump:生成Java堆转储快照。格式为:-dump:[live,]format=b,file=<filename>,其中live子参数说明是否只dump出存活的对象

-finalizerinfo:显示在F-Queue队列中等待Finalizer线程执行finalize方法的对象。只在Linux/Solaris平台下有效

-heap:显示Java堆详细信息,如使用哪种回收期、参数配置、分代状况等。只在Linux/Solaris平台下有效

-histo:显示对重对象统计信息,包括类、实例数量、合计容量

-permstat:以ClassLoader为统计口径显示永久代内存状态。只在Linux/Solaris平台下有效

-F:当虚拟机进程堆-dump选项没有响应时,可食用这个选项强制生成dump快照。只在Linux/Solaris平台下有效

生成Java堆转储快照:

显示Java堆详细信息:

堆配置参数说明:

MinHeapFreeRatio:最小堆空闲比率,默认40%,小于40%增加堆内存
MaxHeapFreeRatio:最大堆空闲比率,默认70%,大于70%减少堆内存
MaxHeapSize:最大堆内存
NewSize:新生代内存大小
MaxNewSize:新生代最大内存
OldSize:老年代大小
NewRatio:新生代比率,默认2
SurvivorRatio:存活区比率,默认8
MetaspaceSize:元空间内存大小
MaxMetaspaceSize:元空间最大内存
CompressedClassSpaceSize:压缩类空间大小
G1HeapRegionSize:G1垃圾收集器Region大小,取值范围从1M到32M,且是2的指数。如不设定,那么G1会根据Heap大小自动决定

 

 5、jhat:虚拟机堆转储快照分析工具

jhat命令与jmap搭配使用,来分析jmap生成的堆转储快照。jhat内置了一个微型的HTTP/HTML服务器,生产dump文件的分析结果后,可以在浏览器中查看。

实际工作很少使用,本文使用Eclipse Memory Analyzer等工具。

关于Eclipse Memory Analyzer可以查看我的另一篇文章:https://www.cnblogs.com/wangymd/p/11277583.html 

 

6、jstack:Java堆栈跟踪工具

用于生成虚拟机当前时刻的线程快照(一般称为threaddump或者javacore文件)。

线程快照就是单签虚拟机内每条线程正在习性的方法堆栈的集合,生成线程快照的主要目的是定位线程出现长时间停顿的原因,如线程死锁、死循环、请求外部资源导致的长时间等待等都是导致线程长时间停顿的常见原因。

用法:

jstack [-l] <pid>
(to connect to running process)
jstack -F [-m] [-l] <pid>
(to connect to a hung process)
jstack [-m] [-l] <executable> <core>
(to connect to a core file)
jstack [-m] [-l] [server_id@]<remote server IP or hostname>
(to connect to a remote debug server)

选项:

-F:当正常输出的请求不被响应时,强制输出线程堆栈
-m:如果调用到本地方法的话,可以显示C/C++的堆栈
-l:除堆栈外,显示关于锁的附加信息

 

Guess you like

Origin www.cnblogs.com/wangymd/p/11274808.html