1,登陆到linux 服务器,使用top 查看进程得cpu 使用率
top
cpu 高得是pid=21412
2.使用 top -Hp 21412,查看该进程中 线程占用cpu最高得id
3.使用 jstack pid 打印信息:
可能出现 jstack command not found;
可能是因为linux 上面没有配置环境变量;需要找到jdk路径,在bin下执行 jstack;
找到完整路径:
最终打印下面线程信息:
其中nid 为十六进制得 线程id;
使用 printf "%x\n" 21412 打印出16进制id;
使用jstack 打印单条线程信息
该线程为gc 线程;频繁得gc 导致cpu 占用居高不下;
二,使用jmap 查看内存使用信息
1.jmap -heap pid:查看内存使用得总体信息:
[root@izbp10jvoyzncf92zd6b9rz bin]# jmap -heap 4635
Attaching to process ID 4635, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.171-b11
using thread-local object allocation.
Mark Sweep Compact GC
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 482344960 (460.0MB)
NewSize = 10485760 (10.0MB)
MaxNewSize = 160759808 (153.3125MB)
OldSize = 20971520 (20.0MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 21807104 (20.796875MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 17592186044415 MB
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
New Generation (Eden + 1 Survivor Space):
capacity = 10092544 (9.625MB)
used = 4667632 (4.4514007568359375MB)
free = 5424912 (5.1735992431640625MB)
46.24831955154221% used
Eden Space:
capacity = 8978432 (8.5625MB)
used = 4667104 (4.450897216796875MB)
free = 4311328 (4.111602783203125MB)
51.98128136405109% used
From Space:
capacity = 1114112 (1.0625MB)
used = 528 (5.035400390625E-4MB)
free = 1113584 (1.0619964599609375MB)
0.04739200367647059% used
To Space:
capacity = 1114112 (1.0625MB)
used = 0 (0.0MB)
free = 1114112 (1.0625MB)
0.0% used
tenured generation:
capacity = 22384640 (21.34765625MB)
used = 13429768 (12.807624816894531MB)
free = 8954872 (8.540031433105469MB)
59.99546117337603% used
12001 interned Strings occupying 1712024 bytes.
[root@izbp10jvoyzncf92zd6b9rz bin]#
2.使用 jmap -F -dump:live,format=b,file=/home/zhou/a.hprof 4635 获取内存dump 信息;
-F: 强制执行
-dump:live : 内存中存活得对象
format=b 二进制格式文件
输出:
[root@izbp10jvoyzncf92zd6b9rz bin]# jmap -F -dump:live,format=b,file=/home/zhou/a.hprof 4635
Attaching to process ID 4635, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.171-b11
Dumping heap to /home/zhou/a.hprof ...
Heap dump file created
输出得a.hprof使用jdk自带的 jvisualvm 查看