使用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命令列監控工具(jmap,jstack,jstat,jinfoJava命令列JS
- Java命令列監控工具(jmap,jstack,jstat,jinfo,jps)Java命令列JS
- Java 監控基礎 - 使用 JMX 監控和管理 Java 程式Java
- Java生產環境效能監控與調優—基於JDK命令列工具的監控JavaJDK命令列
- java命令--jmap命令使用Java
- 【AIX】AIX程式監控工具AI
- 使用Metrics方法級遠端監控Java程式Java
- Java程式監控指標Java指標
- 小程式日誌監控工具
- Java的jmap命令使用詳解Java
- 監控java程式啟動時的CPU使用情況Java
- JDK幾個很實用的工具 jps、jinfo、jstat、jstack、jmap、jconsoleJDKJS
- Flutter效能監控工具(3)--- Observatory使用Flutter
- Java監控神器之psi-probe監控Tomcat和應用JavaTomcat
- linux安裝Arthas監控java程式LinuxJava
- MySQL監控工具MySql
- Linux中監控磁碟分割槽和使用情況的幾個工具Linux
- Windows 2003自帶效能監控工具的使用Windows
- mytop 使用介紹 mysql實時監控工具MySql
- Linux 效能監控工具Linux
- linux監控工具auditLinux
- tomcat 監控工具probeTomcat
- 運維監控工具運維
- OceanBase 監控工具 OBAgent
- Mycat Web監控工具Web
- 服務監控工具
- 使用者領域 API 監控和程式碼注入檢測API
- Java程式碼中,如何監控Mysql的binlog?JavaMySql
- 使用 Prometheus 監控 SAP ABAP 應用程式Prometheus
- 網站監控工具有哪些,8款好用的監控工具推薦網站
- Linux 中如何使用 Htop 監控工具?【網路安全】Linux
- 如何使用 taosKeeper 做好監控工作,時序資料庫 TDengine 3.0 監控工具詳解資料庫
- Mac系統監控工具Mac
- Linux 流量監控工具 iftopLinux
- capital許可監控工具API