您好,登錄后才能下訂單哦!
本篇內容介紹了“有哪些常用性能分析命令與工具”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
查看:/usr/bin/jstack -l 11400
導出:/usr/bin/jstack 11400 > thread.txt
統計:/usr/bin/jstack -l 11400 | grep 'Apollo-RemoteConfigRepository-1' | wc -l
查看cpu占用高進程:
輸出:1
輸出:
"SimplePauseDetectorThread_0" #78 daemon prio=9 os_prio=0 tid=0x00007f664c07c800 nid=0x2efd sleeping[0x00007f662aa37000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at java.lang.Thread.sleep(Thread.java:340)
at java.util.concurrent.TimeUnit.sleep(TimeUnit.java:386)
at org.LatencyUtils.TimeServices.sleepNanos(TimeServices.java:62)
at org.LatencyUtils.SimplePauseDetector$SimplePauseDetectorThread.run(SimplePauseDetector.java:116)
"Thread-32" #77 daemon prio=9 os_prio=0 tid=0x00007f664c074800 nid=0x2efc waiting on condition [0x00007f662aa78000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000ed80df78> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at org.LatencyUtils.PauseDetector$PauseDetectorThread.run(PauseDetector.java:85)
"RxIoScheduler-1 (Evictor)" #76 daemon prio=5 os_prio=0 tid=0x00007f66a8735800 nid=0x2eed waiting on condition [0x00007f662acb9000]
java.lang.Thread.State: TIMED_WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000ed51a578> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
"Connection evictor" #75 daemon prio=5 os_prio=0 tid=0x00007f66a8659000 nid=0x2eec waiting on condition [0x00007f662acfa000]
2efd
輸出:PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
12029 root 20 0 4396512 813692 8668 S 6.2 10.2 0:05.74 java
12527 root 20 0 4396512 813692 8668 S 6.2 10.2 0:41.19 java
top -H -p 11400
printf '%x\n' 12029
jstack 11400 | grep 2efd -A 30
jstack
Usage: jstack [-l] <pid> (to connect to running process) jstack -F [-m] [-l] <pid> (to connect to a hung process) jstack [-m] [-l] <executable> <core> (to connect to a core file) jstack [-m] [-l] [server_id@]<remote server IP or hostname> (to connect to a remote debug server) Options: -F to force a thread dump. Use when jstack <pid> does not respond (process is hung) -m to print both java and native frames (mixed mode) -l long listing. Prints additional information about locks -h or -help to print this help message |
值得關注的線程狀態有:
死鎖,Deadlock(重點關注)
執行中,Runnable
等待資源,Waiting on condition(重點關注)
等待獲取監視器,Waiting on monitor entry(重點關注)
暫停,Suspended
對象等待中,Object.wait() 或 TIMED_WAITING
阻塞,Blocked(重點關注)
停止,Parked
jstack能得到運行java程序的java stack和native stack的信息。可以輕松得知當前線程的運行情況。
查看進程的內存映像信息:jmap 11400
顯示Java堆詳細信息:jmap -heap 11400
顯示堆中對象的統計信息:/usr/bin/jmap -histo:live 11400 | head -20
生成堆轉儲快照dump文件: jmap -dump:live,format=b,file=/tmp/heap.hprof 11400
輸出:Attaching to process ID 11400, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.121-b13
0x0000000000400000 7K /usr/java/jdk1.8.0_121/jre/bin/java
0x00007f664832e000 250K /usr/java/jdk1.8.0_121/jre/lib/amd64/libsunec.so
0x00007f6684bfe000 66K /usr/lib64/libbz2.so.1.0.6
0x00007f6684e0e000 153K /usr/lib64/liblzma.so.5.2.2
0x00007f6685034000 88K /usr/lib64/libz.so.1.2.7
0x00007f668524a000 97K /usr/lib64/libelf-0.166.so
0x00007f6685462000 19K /usr/lib64/libattr.so.1.1.0
0x00007f6685667000 86K /usr/lib64/libgcc_s-4.8.5-20150702.so.1
0x00007f668587d000 294K /usr/lib64/libdw-0.166.so
0x00007f6685ac5000 19K /usr/lib64/libcap.so.2.22
0x00007f6685cca000 107K /usr/lib64/libresolv-2.17.so
0x00007f6685ee4000 30K /usr/lib64/libnss_dns-2.17.so
0x00007f66862eb000 90K /usr/java/jdk1.8.0_121/jre/lib/amd64/libnio.so
0x00007f6687be0000 113K /usr/java/jdk1.8.0_121/jre/lib/amd64/libnet.so
0x00007f6687df7000 49K /usr/java/jdk1.8.0_121/jre/lib/amd64/libmanagement.so
0x00007f66c8000000 64K /usr/lib64/libnss_myhostname.so.2
0x00007f66c9bc1000 121K /usr/java/jdk1.8.0_121/jre/lib/amd64/libzip.so
0x00007f66c9ddc000 60K /usr/lib64/libnss_files-2.17.so
0x00007f66c9fef000 48K /usr/java/jdk1.8.0_121/jre/lib/amd64/libinstrument.so
0x00007f66ca1f9000 220K /usr/java/jdk1.8.0_121/jre/lib/amd64/libjava.so
0x00007f66ca425000 64K /usr/java/jdk1.8.0_121/jre/lib/amd64/libverify.so
0x00007f66ca633000 42K /usr/lib64/librt-2.17.so
0x00007f66ca83b000 1110K /usr/lib64/libm-2.17.so
0x00007f66cab3d000 16591K /usr/java/jdk1.8.0_121/jre/lib/amd64/server/libjvm.so
0x00007f66cbb2f000 2105K /usr/lib64/libc-2.17.so
0x00007f66cbefd000 18K /usr/lib64/libdl-2.17.so
0x00007f66cc101000 99K /usr/java/jdk1.8.0_121/jre/lib/amd64/jli/libjli.so
0x00007f66cc317000 138K /usr/lib64/libpthread-2.17.so
0x00007f66cc533000 159K /usr/lib64/ld-2.17.so
輸出:Attaching to process ID 11400, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.121-b13
using parallel threads in the new generation.
using thread-local object allocation.
Concurrent Mark-Sweep GC
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 536870912 (512.0MB)
NewSize = 134217728 (128.0MB)
MaxNewSize = 134217728 (128.0MB)
OldSize = 402653184 (384.0MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 21807104 (20.796875MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 268435456 (256.0MB)
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
New Generation (Eden + 1 Survivor Space):
capacity = 120848384 (115.25MB)
used = 66229472 (63.161346435546875MB)
free = 54618912 (52.088653564453125MB)
54.80377131066974% used
Eden Space:
capacity = 107479040 (102.5MB)
used = 63536296 (60.592933654785156MB)
free = 43942744 (41.907066345214844MB)
59.11505722418064% used
From Space:
capacity = 13369344 (12.75MB)
used = 2693176 (2.5684127807617188MB)
free = 10676168 (10.181587219238281MB)
20.144413966758577% used
To Space:
capacity = 13369344 (12.75MB)
used = 0 (0.0MB)
free = 13369344 (12.75MB)
0.0% used
concurrent mark-sweep generation:
capacity = 402653184 (384.0MB)
used = 176729160 (168.54206085205078MB)
free = 225924024 (215.45793914794922MB)
43.89116168022156% used
輸出:
num #instances #bytes class name
----------------------------------------------
1: 273268 29359760 [C
2: 337511 10800352 java.util.concurrent.ConcurrentHashMap$Node
3: 217704 10449792 org.aspectj.weaver.reflect.ShadowMatchImpl
4: 116214 10226832 java.lang.reflect.Method
5: 217712 6966784 org.aspectj.weaver.patterns.ExposedState
6: 69225 6647552 [Ljava.lang.Object;
7: 271133 6507192 java.lang.String
8: 12598 6112856 [B
9: 1479 3026296 [Ljava.util.concurrent.ConcurrentHashMap$Node;
10: 50114 2806384 java.util.LinkedHashMap
11: 24799 2751976 java.lang.Class
12: 66869 2674760 java.util.LinkedHashMap$Entry
13: 34280 2507280 [Ljava.util.HashMap$Node;
14: 11273 2043680 [I
15: 78910 1932576 [Z
16: 60015 1920480 java.util.HashMap$Node
17: 78497 1883920 [Lorg.aspectj.weaver.ast.Var;
輸出:Dumping heap to /tmp/heap.hprof ...
Heap dump file created
jmap
|
得到運行java程序的內存分配的詳細情況,可以生成 java 程序的 dump 文件, 也可以查看堆內對象示例的統計信息、查看 ClassLoader 的信息以及 finalizer 隊列。
查看垃圾回收:jstat -gcutil 11400 1000 5
O:老年代使用比例
M:元數據區使用比例
CCS:壓縮使用比例
YGC:年輕代垃圾回收次數
FGCT:老年代垃圾回收消耗時間(單位:s秒)
GCT:垃圾回收消耗總時間(單位:s秒)
輸出:
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
0.00 16.15 33.06 35.11 94.91 92.76 507 11.471 10 2.549 14.019
0.00 16.15 34.19 35.11 94.91 92.76 507 11.471 10 2.549 14.019
0.00 16.15 34.30 35.11 94.91 92.76 507 11.471 10 2.549 14.019
0.00 16.15 34.51 35.11 94.91 92.76 507 11.471 10 2.549 14.019
0.00 16.15 35.63 35.11 94.91 92.76 507 11.471 10 2.549 14.019
jstat
|
監視虛擬機各種運行狀態信息的命令行工具,查看堆內存各部分的使用量,以及加載類的數量
顯示網卡列表:netstat -i
顯示網絡統計:netstat -lntup
統計機器中網絡連接各個狀態個數:netstat -anc | grep 9092
找出程序運行的端口:netstat -ap | grep 11400
輸出:
Kernel Interface table
Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0 1500 127092481 0 2325462 0 90637447 0 0 0 BMRU
lo 65536 275564 0 0 0 275564 0 0 0 LRU
輸出:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:9039 0.0.0.0:* LISTEN 11400/java
tcp 0 0 0.0.0.0:9999 0.0.0.0:* LISTEN 11400/java
tcp 0 0 0.0.0.0:9071 0.0.0.0:* LISTEN 15250/java
tcp 0 0 0.0.0.0:9072 0.0.0.0:* LISTEN 4078/java
tcp 0 0 0.0.0.0:9073 0.0.0.0:* LISTEN 4586/java
tcp 0 0 0.0.0.0:50001 0.0.0.0:* LISTEN 4586/java
tcp 0 0 0.0.0.0:9078 0.0.0.0:* LISTEN 13131/java
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 815/sshd
tcp 0 0 0.0.0.0:8087 0.0.0.0:* LISTEN 28760/java
tcp 0 0 0.0.0.0:10072 0.0.0.0:* LISTEN 4078/java
tcp 0 0 0.0.0.0:7071 0.0.0.0:* LISTEN 1453/java
tcp 0 0 0.0.0.0:7072 0.0.0.0:* LISTEN 32059/java
tcp 0 0 0.0.0.0:9088 0.0.0.0:* LISTEN 24501/java
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 795/zabbix_agentd
tcp 0 0 0.0.0.0:16869 0.0.0.0:* LISTEN 1453/java
tcp6 0 0 :::22 :::* LISTEN 815/sshd
tcp6 0 0 :::10050 :::* LISTEN 795/zabbix_agentd
udp 0 0 127.0.0.1:323 0.0.0.0:* 499/chronyd
udp6 0 0 ::1:323 :::* 499/chronyd
輸出:
tcp 0 0 172.16.20.142:40464 172.16.20.60:9092 ESTABLISHED
tcp 0 0 172.16.20.142:52536 172.16.20.60:9092 ESTABLISHED
tcp 0 0 172.16.20.142:58202 172.16.20.60:9092 ESTABLISHED
tcp 0 0 172.16.20.142:41314 172.16.20.60:9092 ESTABLISHED
tcp 0 0 172.16.20.142:40826 172.16.20.60:9092 ESTABLISHED
tcp 0 0 172.16.20.142:41150 172.16.20.60:9092 ESTABLISHED
tcp 0 0 172.16.20.142:54978 172.16.20.60:9092 ESTABLISHED
輸出:
tcp 0 0 0.0.0.0:9039 0.0.0.0:* LISTEN 11400/java
tcp 0 0 0.0.0.0:distinct 0.0.0.0:* LISTEN 11400/java
tcp 0 0 ext-spring-md-sho:55364 work-arch-lb-1:6379 ESTABLISHED 11400/java
tcp 0 0 ext-spring-md-sho:54114 db-work-01:ms-sql-s ESTABLISHED 11400/java
tcp 0 0 ext-spring-md-sho:45768 172.16.20.1:amqp ESTABLISHED 11400/java
tcp 0 0 ext-spring-md-sho:49960 172.16.20.1:ms-sql-s ESTABLISHED 11400/java
tcp 0 0 ext-spring-md-sho:49932 172.16.20.1:ms-sql-s ESTABLISHED 11400/java
tcp 0 0 ext-spring-md-sho:49954 172.16.20.1:ms-sql-s ESTABLISHED 11400/java
tcp 0 0 ext-spring-md-sho:47498 172.16.20.38:eforward ESTABLISHED 11400/java
tcp 0 0 ext-spring-md-sho:49946 172.16.20.1:ms-sql-s ESTABLISHED 11400/java
tcp 0 0 ext-spring-md-sho:49970 172.16.20.1:ms-sql-s ESTABLISHED 11400/java
tcp 0 0 ext-spring-md-sho:54616 st-arch-polari:webcache ESTABLISHED 11400/java
tcp 0 0 ext-spring-md-sho:49964 172.16.20.1:ms-sql-s ESTABLISHED 11400/java
tcp 0 0 ext-spring-md-sho:49968 172.16.20.1:ms-sql-s ESTABLISHED 11400/java
tcp 0 0 ext-spring-md-sho:54144 db-work-01:ms-sql-s ESTABLISHED 11400/java
tcp 0 0 ext-spring-md-sho:54112 db-work-01:ms-sql-s ESTABLISHED 11400/java
tcp 0 0 ext-spring-md-sho:54096 db-work-01:ms-sql-s ESTABLISHED 11400/java
tcp 0 0 ext-spring-md-sho:40826 172.16.20.:XmlIpcRegSvc ESTABLISHED 11400/java
tcp 1 0 ext-spring-md-sho:41072 172.16.20.168:mysql CLOSE_WAIT 11400/java
tcp 0 0 ext-spring-md-sho:49956 172.16.20.1:ms-sql-s ESTABLISHED 11400/java
tcp 0 0 ext-spring-md-sho:49966 172.16.20.1:ms-sql-s ESTABLISHED 11400/java
tcp 0 0 ext-spring-md-sho:54098 db-work-01:ms-sql-s ESTABLISHED 11400/java
netstat
|
用于顯示與IP、TCP、UDP和ICMP協議相關的統計數據,一般用于檢驗本機各端口的網絡連接情況
應用啟動參數:-Djava.rmi.server.hostname=xxxxx -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=12345
點擊JDK/bin 目錄下面的jconsole.exe
即可啟動
通過圖型列出最大的Object
列出線程的樹結構,及線程下面對象占用內存的空間
自動分析內存內存泄漏的原因,可以直接定位到Class,且行數
Class Name : 類名稱,java類名
Objects : 類的對象的數量,這個對象被創建了多少個
Shallow Heap :一個對象內存的消耗大小,不包含對其他對象的引用
Retained Heap :是shallow Heap的總和,也就是該對象被GC之后所能回收到內存的總和
在某一項上右鍵打開菜單選擇 list objects ->with incoming refs 將列出該類的實例
快速找出某個實例沒被釋放的原因,可以右健 Path to GC Roots–>exclue all phantom/weak/soft etc. reference :
在被分析的jvm 的啟動參數增加下面內容:-agentpath:/opt/jprofiler11/bin/linux-x64/libjprofilerti.so=port=8849
點擊jprofiler.exe
執行菜單Session–Integr ation Wizards–New Server Integration
選擇JDK
選擇Web容器是否和Jprofiler一起運行
輸入服務器地址,在服務器上執行jpenable
/usr/local/bin/jpenable
Select a JVM:
ext-service-md-car-check-analysis.jar [10125] [1]
Please select the profiling mode:
GUI mode (attach with JProfiler GUI) [1, Enter]
Offline mode (use config file to set profiling settings) [2]
Please enter a profiling port
[45763]
8849
You can now use the JProfiler GUI to connect on port 8849
選擇安裝目錄
端口號指定
接入
overview:
cpu views:可錄像回放
https://github.com/oldratlee/useful-scripts/blob/master/docs/java.md#-show-busy-java-threads
https://arthas.aliyun.com/doc/
https://docs.oracle.com/javase/8/docs/technotes/guides/visualvm/index.html
創建一個包含了你自己配置的JFR模板文件。運行jmc, 然后Window->Flight Recording Template Manage菜單。準備好檔案后,就可以導出文件,并移動到要排查問題的環境中。
一分鐘后可查看記錄數據,通過這些數據,可以清楚的了解到這一分鐘時間內,整個
“有哪些常用性能分析命令與工具”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。