日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

JVM-10虚拟机性能监控与故障处理工具之【JDK的命令行】

發布時間:2025/3/21 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JVM-10虚拟机性能监控与故障处理工具之【JDK的命令行】 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • 思維導圖
  • 概述
  • 命令行工具
    • jps 虛擬機進程狀況工具
      • 概述
      • 語法及使用
    • jstat 虛擬機統計信息監視工具
      • 概述
      • 語法及使用
    • jinfo Java配置信息工具
      • 概述
      • 語法及使用
    • jmap Java 內存映射工具
      • 概述
      • 語法及使用
    • jhat 虛擬機堆轉儲快照分析工具
      • 概述
      • 語法及使用
    • jstack Java堆棧跟蹤工具
      • 概述
      • 語法及使用
    • hsdis:jit生成代碼反匯編

思維導圖


概述

前面介紹了虛擬機的內存分配和回收,大致有了一些理論基礎,接下來我們從實踐的角度去了解虛擬機內存管理。定位問題的時候,知識、經驗是關鍵基礎,數據是依據,工具是運用知識處理數據的手段。

這里我們說的數據主要包括

  • 運行日志

  • 異常堆棧

  • GC日志

  • 線程快照(thread dump / javacore文件)

  • 堆轉儲快照(heapdump/hprof文件)等


命令行工具

Java安裝目錄 bin目錄下有很多官方提供的命令行程序,今天我們倆了解下虛擬機性能監控與故障處理工具

名稱英文全稱作用
jpsJVM Process Status Tool顯示指定系統內所有的HotSPot虛擬機進程
jstatJVM Statistics Monitoring Tool用于手機HotSpot虛擬機個方面的運行數據
jinfoConfiguration Info for Java顯示虛擬機配置信息
jmapMemory Map for Java生成虛擬機的內存轉儲快照(headump文件)
jhatJava Heap Analysis Tool虛擬機堆轉儲快照分析工具
jstackStack Trace For Javajava堆棧跟蹤工具,,顯示線程快照

jps 虛擬機進程狀況工具

概述

Java Virtual Machine Process Status Tool

不僅名字像unix主機的ps命令,功能也相似,可以列舉出正在運行的虛擬機進程,并顯示虛擬機執行主類(Main Class,main函數所在的類)名稱以及這些進程的本地虛擬機唯一ID(Local Virtual Machine Identifier ,LVMID)。.

使用頻率最高的JDK命令行工具,以為內其他的JDK工具大多需要輸入它查詢到LVMID來確定要監控的是哪一個虛擬機進程。 對于本地虛擬機進程來講,LVMID和操作系統的進程ID(Process Identifer ,PID) 一致。


語法及使用

usage: jps [-help]jps [-q] [-mlvV] [<hostid>]Definitions:<hostid>: <hostname>[:<port>]

jps可以通過RMI協議查看開啟了RMI服務的遠程虛擬機進程狀態。,hostid為RMI注冊表中注冊的主機名。

jps的其他常用選項

選項作用
-q只輸出LVMID,省略主類的名稱
-m輸出虛擬機進程啟動時傳遞給主類main函數的參數
-l輸出主類的全名,如果執行的是jar包,輸出jar路徑
-v 輸出虛擬機進程啟動時jvm參數

jstat 虛擬機統計信息監視工具

概述

jstat (JVM Statistics Monitoring Tool)用于監視虛擬機各種運行狀態信息的命令行工具。 它可以顯示本地或者遠程虛擬機進程中的類裝載、內存、垃圾會搜、JIT編譯等運行數據。

在沒有圖形化界面的服務器上,它將是運行期定位虛擬機性能問題的首選工具


語法及使用

Usage: jstat -help|-optionsjstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]Definitions:<option> An option reported by the -options option<vmid> Virtual Machine Identifier. A vmid takes the following form:<lvmid>[@<hostname>[:<port>]]Where <lvmid> is the local vm identifier for the targetJava virtual machine, typically a process id; <hostname> isthe name of the host running the target Java virtual machine;and <port> is the port number for the rmiregistry on thetarget host. See the jvmstat documentation for a more completedescription of the Virtual Machine Identifier.<lines> Number of samples between header lines.<interval> Sampling interval. The following forms are allowed:<n>["ms"|"s"]Where <n> is an integer and the suffix specifies the units asmilliseconds("ms") or seconds("s"). The default units are "ms".<count> Number of samples to take before terminating.-J<flag> Pass <flag> directly to the runtime system.
  • 對于命令格式中的VMID和LVMID,如果是本地虛擬機進程,兩者一致。如果是遠程虛擬機進程,則VMID的格式為
    [protocol:][//]lvmind[@hostname[:port]/servername]

  • interval : 查詢間隔

  • count:查詢次數 如果省略interval和count,則只查詢一次

假設需要250毫秒查詢一次進程3245的垃圾收集狀況,一共查詢20次

jstat -gc 3245 250 20
  • 選項option代表用戶希望查詢的虛擬機信息,主要分為3類:類裝載、垃圾收集、運行期編譯狀況。

jstat的主要選項

選項作用
-class監視類裝載、卸載數量,總空間以及類裝載鎖耗費的時間
-gc監視Java堆狀況,包括eden區、兩個Survivor區、老年代、永久代等的容量、已使用空間、GC時間合計等信息
-gccapacity監視內容與-gc基本相同,但輸出主要關注Java堆各個區域使用的最大、最小空間
-gcutil監視內容與-gc基本相同,但輸出主要關注已使用空間占總空間的百分比
-gccause與-gcutil功能一樣,但是會額外輸出導致上一次GC產生的原因
-gcnew監視新生代GC狀況
-gcnewcapacity監視內容與-gcnew 基本相同,但輸出主要關注Java堆各個區域使用的最大、最小空間
-gcold監視老年代代GC狀況
-gcoldcapacity監視內容與-gcold 基本相同,但輸出主要關注Java堆各個區域使用的最大、最小空間
-gcpermcapacity輸出永久代使用的最大、最小空間
-compiler輸出JIT編譯器編譯過的方法、耗時等信息
-printcompilation輸出已經被JIT編譯的方法

使用舉例

E:\Program Files\Java\jdk1.8.0_161\bin>jstat -gcutil 12888 1000 10 Warning: Unresolved Symbol: sun.gc.metaspace.capacity substituted NaN Warning: Unresolved Symbol: sun.gc.metaspace.used substituted NaN Warning: Unresolved Symbol: sun.gc.metaspace.capacity substituted NaN Warning: Unresolved Symbol: sun.gc.compressedclassspace.capacity substituted NaN Warning: Unresolved Symbol: sun.gc.compressedclassspace.used substituted NaN Warning: Unresolved Symbol: sun.gc.compressedclassspace.capacity substituted NaNS0 S1 E O M CCS YGC YGCT FGC FGCT GCT0.00 91.47 46.39 9.12 - - 9 0.215 0 0.000 0.2150.00 91.47 48.39 9.12 - - 9 0.215 0 0.000 0.2150.00 91.47 48.39 9.12 - - 9 0.215 0 0.000 0.2150.00 91.47 48.39 9.12 - - 9 0.215 0 0.000 0.2150.00 91.47 48.39 9.12 - - 9 0.215 0 0.000 0.2150.00 91.47 48.39 9.12 - - 9 0.215 0 0.000 0.2150.00 91.47 48.39 9.12 - - 9 0.215 0 0.000 0.2150.00 91.47 48.39 9.12 - - 9 0.215 0 0.000 0.2150.00 91.47 48.39 9.12 - - 9 0.215 0 0.000 0.2150.00 91.47 48.39 9.12 - - 9 0.215 0 0.000 0.215
  • S0: Survivor0是空的

  • S1:Survivor1使用了91.47的空間

  • E:Eden 使用了 48.39%的空間

  • O: 老年代使用了 9.12%的空間

  • M: 因為我這里是使用了JDK8 ,沒有了永久代的概念,這里是元數據區

  • YGC: Minor GC表示程序啟動以來,發生了9次Minor GC

  • YGCT:Young GC Time 耗時為0.215秒

  • FGC:Full GC 表示程序啟動以來,發生了0次Minor GC

  • FGCT:Full GC Time 耗時為0秒

  • GCT:表示GC Time ,所有的GC總耗時 0.215秒

純文本狀態下監視虛擬機的變化確實不如后面提到的VisualVM等可視化的建施工局直接用圖形的方式展現直觀,但直接在主機上使用jstat命令仍然是一種常用的監控方式。


jinfo Java配置信息工具

概述


語法及使用

Usage:jinfo [option] <pid>(to connect to running process)jinfo [option] <executable <core>(to connect to a core file)jinfo [option] [server_id@]<remote server IP or hostname>(to connect to remote debug server)where <option> is one of:-flag <name> to print the value of the named VM flag-flag [+|-]<name> to enable or disable the named VM flag-flag <name>=<value> to set the named VM flag to the given value-flags to print VM flags-sysprops to print Java system properties<no option> to print both of the above-h | -help to print this help message

使用舉例

E:\Program Files\Java\jdk1.8.0_161\bin>jinfo -flag MaxPermSize 12888 -XX:MaxPermSize=85983232

jmap Java 內存映射工具

概述


語法及使用

Usage:jmap [option] <pid>(to connect to running process)jmap [option] <executable <core>(to connect to a core file)jmap [option] [server_id@]<remote server IP or hostname>(to connect to remote debug server)where <option> is one of:<none> to print same info as Solaris pmap-heap to print java heap summary-histo[:live] to print histogram of java object heap; if the "live"suboption is specified, only count live objects-clstats to print class loader statistics-finalizerinfo to print information on objects awaiting finalization-dump:<dump-options> to dump java heap in hprof binary formatdump-options:live dump only live objects; if not specified,all objects in the heap are dumped.format=b binary formatfile=<file> dump heap to <file>Example: jmap -dump:live,format=b,file=heap.bin <pid>-F force. Use with -dump:<dump-options> <pid> or -histoto force a heap dump or histogram when <pid> does notrespond. The "live" suboption is not supportedin this mode.-h | -help to print this help message-J<flag> to pass <flag> directly to the runtime system

jmap的主要選項

選項作用
-dump生成java堆轉儲快照。 格式為 -dump:[live,] format=b,file=<filename> 其中live子參數說明是否只dump出存活的對象
-finalizeinfo顯示在F-Queue中等待Finalizer線程執行finalize方法的對象。 只在linux/solaris平臺有效
-heap只顯示Java堆詳細信息。如使用腦脹回收器、參數配置、分代狀況等。只在linux/solaris平臺有效
-histo顯示堆中對象統計信息,包括類、實例數量、合計容量
-permstat以ClassLoader為統計口徑顯示永久代內存狀態。 只在linux/solaris平臺有效
-F當虛擬機進程對-dump選項沒有響應時,可以使用這個選項強制生成dump快照。只在linux/solaris平臺有效

使用舉例, 對pid=12888的進程輸出dump信息

E:\Program Files\Java\jdk1.8.0_161\bin>jmap -dump:format=b,file=test.bin 12888 Dumping heap to E:\Program Files\Java\jdk1.8.0_161\bin\test.bin ... Heap dump file created

jhat 虛擬機堆轉儲快照分析工具

概述


語法及使用

Usage: jhat [-stack <bool>] [-refs <bool>] [-port <port>] [-baseline <file>] [-debug <int>] [-version] [-h|-help] <file>-J<flag> Pass <flag> directly to the runtime system. Forexample, -J-mx512m to use a maximum heap size of 512MB-stack false: Turn off tracking object allocation call stack.-refs false: Turn off tracking of references to objects-port <port>: Set the port for the HTTP server. Defaults to 7000-exclude <file>: Specify a file that lists data members that shouldbe excluded from the reachableFrom query.-baseline <file>: Specify a baseline object dump. Objects inboth heap dumps with the same ID and same class willbe marked as not being "new".-debug <int>: Set debug level.0: No debug output1: Debug hprof file parsing2: Debug hprof file parsing, no server-version Report version number-h|-help Print this help and exit<file> The file to readFor a dump file that contains multiple heap dumps, you may specify which dump in the file by appending "#<number>" to the file name, i.e. "foo.hprof#3".All boolean options default to "true"

用法舉例

E:\Program Files\Java\jdk1.8.0_161\bin>jmap -dump:format=b,file=test.bin 12888 Dumping heap to E:\Program Files\Java\jdk1.8.0_161\bin\test.bin ... File existsE:\Program Files\Java\jdk1.8.0_161\bin>jhat test.bin Reading from test.bin... Dump file created Mon Aug 06 20:49:25 CST 2018 Snapshot read, resolving... Resolving 244224 objects... Chasing references, expect 48 dots................................................ Eliminating duplicate references................................................ Snapshot resolved. Started HTTP server on port 7000 Server is ready.

瀏覽器輸入 http://localhost:7000/


jstack Java堆棧跟蹤工具

概述


語法及使用

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

jstack的主要選項

選項作用
-F當正常輸出的請求不被響應時,強制輸出線程堆棧
-m如果調用到本地方法的話,可以顯示C/C++的堆棧
-l除了堆棧信息,顯示關于鎖的附件信息

用法舉例

E:\Program Files\Java\jdk1.8.0_161\bin>jstack -l 12888 2018-08-06 21:01:10 Full thread dump Java HotSpot(TM) 64-Bit Server VM (24.51-b03 mixed mode):"DestroyJavaVM" prio=6 tid=0x000000000e1ab800 nid=0x2f80 waiting on condition [0x0000000000000000]java.lang.Thread.State: RUNNABLELocked ownable synchronizers:- None"DefaultQuartzScheduler_QuartzSchedulerThread" prio=6 tid=0x000000000e1a9800 nid=0xb5c in Object.wait() [0x000000000f59f000]java.lang.Thread.State: TIMED_WAITING (on object monitor)at java.lang.Object.wait(Native Method)at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:410)- locked <0x0000000762395018> (a java.lang.Object)Locked ownable synchronizers:- None ...... ....... ..........

hsdis:jit生成代碼反匯編

Sun官方推薦的HotSpot虛擬機JIT編譯代碼的反匯編插件。了解即可。


總結

以上是生活随笔為你收集整理的JVM-10虚拟机性能监控与故障处理工具之【JDK的命令行】的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。