首页 > 代码库 > Java自带优秀工具

Java自带优秀工具

Java自己有很多优秀的调试工具,可以帮助分析系统的漏洞,瓶颈,这里列举几个自己常用的命令:

 jps -l
 查看现有的java进程
jps -l 显示所有正在运行的java进程id
jstack 
查看Java线程
     jstack -l pid; 做thread dump,直接打印在串口
    jstack pid>> ./threaddumps  输出到指定文件分析
jmap
查看Java内存使用情况    
jmap -histo:live pid 对象占用内存排名
jmap -dump:file=memroydumps pid 把heap dump到文件
jhat 

通过查看jmap dump文件分析

jhat ./threaddumps 分析dump文件

d:\cloudlu\workspace\CustomerSecurityManagementSystem\CustomerSecurityManagementWeb>jmap -dump:file=test.map 6860
Dumping heap to D:\cloudlu\workspace\CustomerSecurityManagementSystem\CustomerSecurityManagementWeb\test.map ...
Heap dump file created

d:\cloudlu\workspace\CustomerSecurityManagementSystem\CustomerSecurityManagementWeb>jhat test.map
Reading from test.map...
Dump file created Wed Jun 04 10:49:22 CST 2014
Snapshot read, resolving...
Resolving 1982196 objects...
Chasing references, expect 396 dots.........................................................................................................
............................................................................................................................................
............................................................................................................................................
...........
Eliminating duplicate references............................................................................................................
............................................................................................................................................
............................................................................................................................................
........
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.

http://localhost:7000 查看分析结果

jstat 

查看heap内各个部分的使用量,以及加载类的数量以及GC的相关信息。

jstat -options (查看参数) / jstat -help

jstat -gcutil -t -h 3 6860 200 10
Timestamp         S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT
         2930.6   0.00   0.00  31.53  60.00  91.23  82.55     80    1.622     5    6.644    8.266
         2930.8   0.00   0.00  31.53  60.00  91.23  82.55     80    1.622     5    6.644    8.266
         2931.0   0.00   0.00  31.53  60.00  91.23  82.55     80    1.622     5    6.644    8.266
Timestamp         S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT
         2931.2   0.00   0.00  31.53  60.00  91.23  82.55     80    1.622     5    6.644    8.266
         2931.4   0.00   0.00  31.53  60.00  91.23  82.55     80    1.622     5    6.644    8.266
         2931.6   0.00   0.00  31.53  60.00  91.23  82.55     80    1.622     5    6.644    8.266
Timestamp         S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT
         2931.8   0.00   0.00  31.53  60.00  91.23  82.55     80    1.622     5    6.644    8.266
         2932.0   0.00   0.00  31.53  60.00  91.23  82.55     80    1.622     5    6.644    8.266
         2932.2   0.00   0.00  31.53  60.00  91.23  82.55     80    1.622     5    6.644    8.266
Timestamp         S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT
         2932.4   0.00   0.00  31.53  60.00  91.23  82.55     80    1.622     5    6.644    8.266


jdk自带的hprof

启动应用时带上hprof参数,查看cpu,内存使用情况

java -agentlib:hprof=cpu=times,interval=20,depth=10 -jar start.jar

http://www.cnblogs.com/linhaohong/archive/2012/07/12/2588657.html

Jconsole&Jvisualvm

下回分解