java jvm heap dump and thread dump analysis

1. Concept:

When analyzing java application failures, it is often necessary to analyze memory and cpu information, that is, the so-called heap dump and thread dump

 

heap dump:

 The heap dump file is a binary file that needs to be checked by the tool heap analyze, mainly to view the memory information that occupies too much stack space.

thread dump:

Text file, record the specific operation information, you can see that the line at that point takes the most time, such as database query, long page, etc., you can analyze multiple files to find the common points of the problem to confirm the problem point of the code .

 

2. Use JDK's own tools to obtain thread dump and heap dump

 

Tools: jmap, jstack

1. Get the heap dump file

        Switch to JDK_HOME/bin/ under windows and execute the following command: jmap -dump:format=b,file=heap.hprof 2576 

        Switch to JDK_HOME/bin/ under linux and execute the following command: ./jmap -dump:format=b,file=heap.hprof 2576

        This will generate the heap.hprof file in the current directory, which is the heap dump file.

2. Get the thread dump file

        Execute under windows: jstack 2576 > thread.txt

        Execute under linux: ./jstack 2576 > thread.txt

Windows/linux will dump the command execution result to thread.txt, which is the thread dump file. After we have the dump file, we can obtain the information in the dump file with the help of performance analysis tools.

 

3. If we only need to export the objects that survive in the dump, we can use the :live parameter

jmap -dump:live,format=b,file=heapLive.hprof 2576   

Description: 2576 in the above example is the PID of the java process I currently need to analyze

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324932823&siteId=291194637