JStack 工具
top
使用 top 命令获取占用内存/CPU 最高进程的 pid
输入大写的 M 按照内存排序,大写的 P按照 CPU排序
top -Hp pid
使用top -Hp pid 可以查看该进程下,各个线程的cpu使用情况
jstack pid
通过top命令定位到cpu占用率较高的线程之后,接着使用jstack pid命令来查看当前java进程的堆栈状态
jstack -l PID >log.txt
把堆栈信息输出到文件中
分析堆栈信息
我们把占用cpu资源较高的线程pid(本例子是21350),将该pid转成16进制的值(5366)
在thread dump中,每个线程都有一个nid,我们找到对应的nid(5366),发现一直在跑(24行)
jmap 工具
查看堆heap占用情况
jmap -heap 90099
Attaching to process ID 90099, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.71-b01
using thread-local object allocation.
Parallel GC with 4 thread(s) #垃圾回收的方式
Heap Configuration: #堆配置信息
MinHeapFreeRatio = 0
MaxHeapFreeRatio = 100
MaxHeapSize = 2147483648 (2048.0MB)
NewSize = 1310720 (1.25MB)
MaxNewSize = 17592186044415 MB
OldSize = 5439488 (5.1875MB)
NewRatio = 2
SurvivorRatio = 8
PermSize = 21757952 (20.75MB)
MaxPermSize = 85983232 (82.0MB)
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity = 34603008 (33.0MB)
used = 9773032 (9.320289611816406MB)
free = 24829976 (23.679710388183594MB)
28.24330185398911% used
From Space:
capacity = 5242880 (5.0MB)
used = 0 (0.0MB)
free = 5242880 (5.0MB)
0.0% used
To Space:
capacity = 5242880 (5.0MB)
used = 0 (0.0MB)
free = 5242880 (5.0MB)
0.0% used
PS Old Generation
capacity = 89128960 (85.0MB)
used = 0 (0.0MB)
free = 89128960 (85.0MB)
0.0% used
PS Perm Generation
capacity = 22020096 (21.0MB)
used = 2666808 (2.5432662963867188MB)
free = 19353288 (18.45673370361328MB)
12.110791887555804% used
677 interned Strings occupying 44048 bytes.
查看对象占用内存情况
jmap -histo:live 96176
num #instances #bytes class name
----------------------------------------------
1: 5948 766656 <methodKlass>
2: 5948 679168 <constMethodKlass>
3: 401 474448 <constantPoolKlass>
4: 365 289664 <constantPoolCacheKlass>
5: 401 276112 <instanceKlassKlass>
6: 562 93176 [B
7: 900 86256 [C
8: 463 45328 java.lang.Class
9: 653 43216 [[I
10: 608 37144 [S
11: 45 24480 <objArrayKlassKlass>
其中 :
C is a char[]
S is a short[]
I is a int[]
B is a byte[]
I is a int[]
导出堆信息
可以使用jmap把堆信息导出。导出的命令如下:
jmap -dump:format=b,file=a.dmp 96185
Dumping heap to /Users/canglong/dev/test/a.dmp ...
Heap dump file created
dump 分析工具有很多,选择顺手的即可
标签:used,Java,MB,pid,free,Debug,capacity,思路,jmap From: https://www.cnblogs.com/jietang64/p/18081302