使用JDK工具jmap和jhat監控Java程式
Suppose you have a running Java process and you would like to inspect its running status, for example how many object instance are created or memory consumption status, you can use some standard tool provided by JDK.
This blog is written based on JDK 1.8. The sample code I am using to simulate a endless running process:
package jmap;class Tool{
private int count = 0;
public void Run() throws InterruptedException{
while(true){
System.out.println("Hello: " + this.count++);
Thread.sleep(5000);
}
}}public class JMapTest {
public static void main(String[] args) throws InterruptedException {
Tool tool = new Tool();
tool.Run();
}}
(1) First get process id found in task manager: 15392
(2) use command line jmap -dump:format=b,file=c:\temp\heapstatus.bin 15392 jmap is a standard tool provided by JDK in this folder in my laptop:
heap bin file is generated now:
(3) Use another tool jhat to parse the bin file: jhat c:\temp\heapstatus.bin
Then access localhost:7000 in browser:
Click hyperlink class jmap.Tool, now I can find out that the instance of my tool class @0x7166babd8 has member attribute count with value 49.
(4) There is a plugin in Eclipse MAT – Memory Analyzer Tool which can achieve the same.
Once plugin is installed, you can make them visible in “Show View”:
Drag your bin file into the view and the heap file will be parsed automatically. Click “Find object by address”:
Type address of object instance you want to inspect:
You can get the same result as you get previously in localhost:7000
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2722629/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 使用JDK自帶的jmap和jhat監控處於執行狀態的Java程式JDKJava
- Java JDK目錄下的jmap和jhat工具的使用方式JavaJDK
- JVM監控工具:jps、jstat、jinfo、jmap、jhat、jJVMJS
- java虛擬機器記憶體監控工具jps,jinfo,Jstack,jstat,jmap,jhat使用Java虛擬機記憶體JS
- JVM效能調優監控工具——jps、jstack、jmap、jhat、jstat、hprof使用詳解JVMJS
- Java命令列監控工具(jmap,jstack,jstat,jinfoJava命令列JS
- Java命令列監控工具(jmap,jstack,jstat,jinfo,jps)Java命令列JS
- Java 監控基礎 - 使用 JMX 監控和管理 Java 程式Java
- Java——命令jps、jstat、jmap、jstack、jhat、jinfoJavaJS
- Java生產環境效能監控與調優—基於JDK命令列工具的監控JavaJDK命令列
- 使用jvisualvm監控Java程式(本地和遠端)LVMJava
- java命令--jmap命令使用Java
- 【AIX】AIX程式監控工具AI
- 使用Metrics方法級遠端監控Java程式Java
- Java程式監控指標Java指標
- 小程式日誌監控工具
- 硬碟監控和分析工具:Smartctl硬碟
- 效能監控和分析工具--nmon
- Linux nmon 監控工具使用Linux
- Java效能監控工具:VisualVMJavaLVM
- Java的jmap命令使用詳解Java
- Flutter效能監控工具(3)--- Observatory使用Flutter
- 幾個常用監控工具的使用
- 安裝使用OSWatcher監控工具
- 使用Metrics方法級遠端監控Java程式(優化)Java優化
- 監控java程式啟動時的CPU使用情況Java
- MySQL監控工具MySql
- Redis監控工具Redis
- Ganglia監控工具
- jvm系列(四):jvm調優-命令大全(jps jstat jmap jhat jstack jinfo)JVMJS
- linux下流量監控工具 iftop使用Linux
- oracle監控工具ignite使用圖解Oracle圖解
- Mycat Web監控工具Web
- MySQL監控工具-orztopMySql
- MySQL監控工具-orzdbaMySql
- 效能監控工具YourKit
- JVM 效能監控工具JVM
- CentOS效能監控工具CentOS