jvm monitoring and diagnostic tool
1 Overview: There are many reasons that may cause performance problems in java applications, such as thread control, disk read and write, database access, network I/O, garbage collection, etc.
Standpoint: Use data to explain the problem, use knowledge to analyze the problem, and use the tool to deal with the problem.
2.jps view the running process
jps (Java Process Status)
package com.qf58.exec.ratelimiter;
import java.util.Scanner;
/**
* @version 1.0
* @author: Liu
* @date :2021-02-21 09:43
*/
public class JpsTest {
public static void main (String[] args) {
Scanner scanner = new Scanner(System.in );
String info = scanner.next();
}
}
Before running, cmd enter jps
After running: cmd enter jps
This 13272 is the startup process allocated by the cpu
3.jstat: view jvm statistics
jstat (JVM Statistics Monitoring Tool) is a command line tool used to monitor various operating status information of virtual machines. It can display running data such as class loading, memory, garbage collection, JIT compilation, etc.in the local or remote virtual machine process.
Linux is often used to detect garbage collection problems and memory leaks.
The parameter option option can consist of the following values.
Related to class loading:
-class: Displays related information of ClassLoader: class loading, unloading quantity, total space, time consumed for class loading, etc.
Garbage collection related:
-gc: Displays heap information related to GC. Including the capacity of Eden area, two Survivor areas, old generation, permanent generation, etc., used space, total GC time and other information.
-gccapacity: The display content is basically the same as -gc, but the output mainly focuses on the maximum and minimum space used by each area of the Java heap.
-gcutil: The display content is basically the same as -gc, but the output mainly focuses on the percentage of the used space to the total space.
-gccause: Same function as -gcutil, but will additionally output the cause of the last or currently occurring GC.
-gcnew: display the GC status of the new generation
-gcnewcapacity: the display content is basically the same as -gcnew, and the output mainly focuses on the largest and smallest space used
-geold: displays the GC status of the old generation
-gcoldcapacity: the display content is basically the same as -gcold, and the output is mainly
Pay attention to the maximum and minimum space used- gcpermcapacity: Display the maximum and minimum space used by the permanent generation.
JIT related:
-compiler: display the methods and time-consuming information
compiled by the JIT compiler -printcompilation: output the methods that have been compiled by JIT
1>Class loading statistics
jstat -class 13272
Loaded: the number of loaded classesBytes: the size of the space occupiedUnloaded: The number of unloadedBytes: Not loaded occupied spaceTime: loading time
The above unloaded is 0, indicating that the loading is complete
2>Compile statistics
jstat -compiler 13272
Compiled: The number of compilations.Failed: the number of failuresInvalid: Unavailable quantityTime: timeFailedType: Failure typeFailedMethod: failed method
97 bytes are compiled as above, the failure is 0 and the time is 0.03 seconds
3>Garbage collection statistics
jstat -gc 13272
S0C: the size of the first surviving area
S1C: the size of the second surviving area
S0U: the use size of the first surviving area
S1U: the use size of the second surviving area
EC: the size of the
Eden park EU: the use of the Eden park Size
OC: Old generation size
OU: Old generation use size
MC: Method area size
MU: Method area use size
CCSC: Compression class space size
CCSU: Compression class space use size
YGC: Number of young generation garbage collections
YGCT: Young generation garbage collection consumption Time
FGC: Number of garbage collections in the old age
FGCT: Garbage collection consumption time in the old age
GCT: Total garbage collection time consumption
jstat can also be used to determine whether there is a memory leak.
Step 1:
In a long-running Java program, we can run the jstat command to continuously obtain multiple rows of performance data, and take the minimum value of the OU column (that is, the occupied memory of the old generation) in these rows of data.
Step 2:
Then, we repeat the above operation every longer time to obtain multiple sets of OU minimums. If these values are on the rise, it means that the memory used in the old age of the Java program is on the rise, which means that the objects that cannot be recycled are on the increase, so there is a high possibility of memory leaks.
4>jinfo: View and modify JVM configuration parameters in real time
jinfo (Configuration Info for Java)
view virtual machine configuration parameter information, and can also be used to adjust virtual machine configuration parameters.
Official help document:
https://docs.oracle.com/en/java/javase/11/tools/jinfo.html
jinfo -flags 13272 View some parameters that have been assigned
Extension: java -XX:+PrintFlagsInitial View the initial value of all JVM parameter startup
java -XX:+PrintFlagsFinal View the final value of all JVM parameters
java -XX:+PrintCommandLineFlags View the names and values of the detailed XX parameters that have been set by the user or JVM
5> jmap: Export memory image file & memory usage
jmap (JVM Memory Map): On the one hand, it is used to obtain dump files (heap dump snapshot files, binary files), and it can also obtain memory-related information of the target Java process, including the usage of each area of the Java heap and the objects in the heap.Statistics, class loading information, etc.
0 Comments