One: jstack finds the thread that consumes the most CPU and locates the code
1.ps -ef|grep java or jps -l
get process pid
2. Find the thread that consumes the most CPU in the process, I usually use:
top -Hp pid
3. The longest CPU time is the thread whose pid is 21742, printf "x%\n" 21742, and get hexadecimal, which is a
4. Use jstack pid | grep a to print the stack information of the process
Two: Linux historical indicator data
sar -A: report all information
sar -u: cpu utilization
sar 2 5: display 5 times every 2s, cpu usage
Regarding the problem of cpu consumption, it can generally be solved by these two methods. If it is complicated, you need to use perf.
Three: jstat and gc logs
jstat -gc pid 1000: print heap usage every 1s
jstat -gcutil pid
Some people are used to looking at the gc log:
-XX:+PrintGC output GC log
-XX:+PrintGCDetails output detailed GC log
-XX:+PrintGCTimeStamps Print GC timestamps (in the form of base time)
-XX:+PrintGCDateStamps Print the timestamp of the GC (in the form of a date, such as 2013-05-04T21:53:59.234+0800)
-XX:+PrintHeapAtGC Print out heap information before and after GC
-Xloggc:../logs/gc.log Output path to log file
I usually do the following settings
-XX:+PrintGCDetails -Xloggc:../logs/gc.log -XX:+PrintGCTimeStamps
Four: the use of jmap
jmap -dump:format=b,file=a.bin pid : When you need to dump memory for viewing, after the memory is dumped,
使用eclipse memory analyzer
jmap -histo:live pid : when fgc needs to be enforced
Some people like to use gcore, but some jdk versions don't support it very well.
Five: The use of the btrace tool, there is no specific research, and it will be posted later
Check when using:
http://www.jianshu.com/p/dbb3a8b5c92f