1.1 cup使用率进行排序
[root@master ~]# top -c
top - 20:45:36 up 1:14, 4 users, load average: 0.45, 0.85, 0.53
Tasks: 125 total, 1 running, 124 sleeping, 0 stopped, 0 zombie
%Cpu(s): 11.2 us, 15.3 sy, 0.0 ni, 73.3 id, 0.0 wa, 0.0 hi, 0.2 si, 0.0 st
KiB Mem : 4026164 total, 2921784 free, 564604 used, 539776 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 3228744 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1324 root 20 0 1241168 15464 6860 S 2.6 0.4 0:26.05 /opt/app/node_exporter-1.8.2/node_exporter --log.level=info 1759 root 20 0 161856 6512 4788 S 2.3 0.2 0:11.19 sshd: root@pts/0,pts/1 1919 root 20 0 161856 6508 4788 S 2.3 0.2 0:10.26 sshd: root@pts/2,pts/3 2075 root 20 0 162836 3008 1548 S 1.0 0.1 0:03.18 top 1677 grafana 20 0 1497756 120168 57912 S 0.7 3.0 0:27.31 /usr/share/grafana/bin/grafana server --config=/etc/grafana/grafana.ini --pidfile=/var/run/grafana/grafana-server.pid --packaging=rpm cfg:defaul+ 1864 root 20 0 162836 3008 1548 S 0.7 0.1 0:03.25 top 14867 root 20 0 113284 1560 1316 S 0.7 0.0 0:00.02 bash -c export LANG="en_US.U
1.2 以进程号查看对应线程的cup使用
# 查看 math-game java程序的进程
[root@master ~]# ps -ef | grep java
root 5826 1761 0 20:40 pts/0 00:00:02 java -jar math-game.jar
root 16809 1935 0 20:46 pts/2 00:00:00 grep --color=auto java[root@master ~]# top -Hp 5826
top - 20:47:47 up 1:17, 4 users, load average: 0.93, 0.90, 0.59
Threads: 14 total, 0 running, 14 sleeping, 0 stopped, 0 zombie
%Cpu(s): 9.6 us, 14.2 sy, 0.0 ni, 75.8 id, 0.0 wa, 0.0 hi, 0.3 si, 0.0 st
KiB Mem : 4026164 total, 2920020 free, 565612 used, 540532 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 3227724 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 5919 root 20 0 3368920 26808 12356 S 0.3 0.7 0:00.98 VM Periodic Tas 5826 root 20 0 3368920 26808 12356 S 0.0 0.7 0:00.07 java 5867 root 20 0 3368920 26808 12356 S 0.0 0.7 0:01.51 java 5868 root 20 0 3368920 26808 12356 S 0.0 0.7 0:00.00 GC task thread# 5869 root 20 0 3368920 26808 12356 S 0.0 0.7 0:00.00 GC task thread# 5870 root 20 0 3368920 26808 12356 S 0.0 0.7 0:00.00 Gang worker#0 ( 5871 root 20 0 3368920 26808 12356 S 0.0 0.7 0:00.00 Gang worker#1 ( 5872 root 20 0 3368920 26808 12356 S 0.0 0.7 0:00.04 VM Thread 5904 root 20 0 3368920 26808 12356 S 0.0 0.7 0:00.00 Reference Handl 5908 root 20 0 3368920 26808 12356 S 0.0 0.7 0:00.00 Finalizer 5915 root 20 0 3368920 26808 12356 S 0.0 0.7 0:00.00 Signal Dispatch 5916 root 20 0 3368920 26808 12356 S 0.0 0.7 0:00.14 C2 CompilerThre 5917 root 20 0 3368920 26808 12356 S 0.0 0.7 0:00.28 C1 CompilerThre 5918 root 20 0 3368920 26808 12356 S 0.0 0.7 0:00.00 Service Thread
查看线程PID的堆栈信息 jstack 进程ID | grep 线程PID的16进制数
printf "%x\n" 线程的PID 转16进制
[root@master ~]# printf "%x\n" 5869
16ed
[root@master ~]# jstack 5826 | grep 16ed
"GC task thread#1 (ParallelGC)" os_prio=0 cpu=0.83ms elapsed=3460.53s tid=0x00007fc5a8021000 nid=0x16ed runnable
1.3 jcmd 命令查看java进程
[root@master ~]# jcmd
5826 math-game.jar
31548 sun.tools.jcmd.JCmd
1.4 jmap -heap 进程号 查看进程堆内存
[root@master ~]# jmap -heap 5826
Attaching to process ID 5826, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.412-b11using thread-local object allocation.
Parallel GC with 2 thread(s)Heap Configuration:MinHeapFreeRatio = 0MaxHeapFreeRatio = 100MaxHeapSize = 1031798784 (984.0MB)NewSize = 21495808 (20.5MB)MaxNewSize = 343932928 (328.0MB)OldSize = 43515904 (41.5MB)NewRatio = 2SurvivorRatio = 8MetaspaceSize = 21807104 (20.796875MB)CompressedClassSpaceSize = 1073741824 (1024.0MB)MaxMetaspaceSize = 17592186044415 MBG1HeapRegionSize = 0 (0.0MB)Heap Usage:
PS Young Generation
Eden Space:capacity = 16252928 (15.5MB)used = 3251320 (3.1007003784179688MB)free = 13001608 (12.399299621582031MB)20.00451857043851% used
From Space:capacity = 2621440 (2.5MB)used = 0 (0.0MB)free = 2621440 (2.5MB)0.0% used
To Space:capacity = 2621440 (2.5MB)used = 0 (0.0MB)free = 2621440 (2.5MB)0.0% used
PS Old Generationcapacity = 43515904 (41.5MB)used = 0 (0.0MB)free = 43515904 (41.5MB)0.0% used1680 interned Strings occupying 109136 bytes.