JDK 自带工具备忘

来源:互联网 发布:sql server2005标准版 编辑:程序博客网 时间:2024/04/29 21:21

转载自:http://evenx86.github.io/2015/04/21/JDK-Tools/

简介

  • jps JVM process status 显示系统内所有的hotspot虚拟机进程。
  • jstat JVM statistics monitoring tool 收集hotspot虚拟机各方面的运行数据
  • jinfo configuration info for java 显示虚拟机配置信息
  • jmap 生成虚拟机的内存转储快照
  • jhat JVM heap dump browser 用于分析heapdump文件。
  • jstack stack trace for java 显示虚拟机上的线程快照

    jps

    参数列表

    -q Suppress the output of the class name, JAR file name, and arguments passed to the main method, producing only a list of local VM identifiers. 只显示LVMID省略主类名称
    -m Output the arguments passed to the main method. The output may be null for embedded JVMs. 显示进程启动时传递的参数
    -l Output the full package name for the application’s main class or the full path name to the application’s JAR file. 显示主类全名,jar路径
    -v Output the arguments passed to the JVM. 显示进程启动时JVM参数
    -V Output the arguments passed to the JVM through the flags file (the .hotspotrc file or the file specified by the -XX:Flags= argument).

jstat

JStat可以用来查看JVM的一些统计信息,及GC的情况等。JStat命令本身支持了定时刷新功能。
jstat-gc [pid] 2000 10

具体参数含义如下:
jstat -classpid:显示加载class的数量,及所占空间等信息。
jstat -compilerpid:显示VM实时编译的数量等信息。
jstat -gc pid:可以显示gc的信息,查看gc的次数,及时间。其中最后五项,分别是young gc的次数,younggc的时间,full gc的次数,fullgc的时间,gc的总时间。
jstat-gccapacity:可以显示,VM内存中三代(young,old,perm)对象的使用和占用大小,如:PGCMN显示的是最小perm的内存使用量,PGCMX显示的是perm的内存最大使用量,PGC是当前新生成的perm内存占用量,PC是但前perm内存占用量。其他的可以根据这个类推,OC是old内纯的占用量。
jstat -gcnewpid:new对象的信息。
jstat -gcnewcapacitypid:new对象的信息及其占用量。
jstat -gcoldpid:old对象的信息。
jstat -gcoldcapacitypid:old对象的信息及其占用量。
jstat -gcpermcapacity pid:perm对象的信息及其占用量。
jstat -utilpid:统计gc信息统计。
jstat -printcompilationpid:当前VM执行的信息。

jmap

使用JMap可以解决上面提到的问题,并通过Linux的watch命令达到实时监控的效果。
例如,通过下面命令打印堆上apache包占用内存最大的前30个对象,每一秒刷新一次: watch-n 1 -d "jmap -histo:live [pid] | grep "apache" | head -n 30"
jmap [option] vmid

  • -dump 生成Java堆转储快照
  • -heap 显示Java堆的详细信息
  • -histo 显示堆中对象统计信息,包括类实例数量合计容量

watch 是周期性的执行下个程序并全屏显示执行结果,。
-n或—interval watch缺省每2秒运行一下程序,可以用-n或-interval来指定间隔的时间。
-d或—differences 用-d或—differences 选项watch 会高亮显示变化的区域。 而-d=cumulative选项会把变动过的地方(不管最近的那次有没有变动)都高亮显示出来。
-t 或-no-title 会关闭watch命令在顶部的时间间隔,命令,当前时间的输出。

1234567891011121314151617
[root@localhost sync]# jmap -histo 27109 num     #instances         #bytes  class name----------------------------------------------   1:      30115700     2278829352  [I   2:      29118169     1620754128  [C   3:      13780299     1212666312  java.util.regex.Matcher   4:       7813981      707061400  [B   5:      20477817      655290144  java.lang.String   6:       2988315      472124848  [Ljava.lang.Object;   7:       7817628      437787168  java.util.HashMap$Entry   8:       1098010      265252184  [Ljava.util.HashMap$Entry;   9:       1973855      142117560  java.util.LinkedHashMap$Entry  10:       1010641      121276920  java.util.TreeMap$AscendingSubMap  11:       1948128      109095168  java.nio.HeapByteBuffer  12:             4       86507584  [Ljava.io.ObjectInputStream$HandleTable$HandleList;  13:       3482239       83573736  java.lang.Long

这里涉及到一个问题:

http://docs.oracle.com/javase/6/docs/api/java/lang/Class.html#getName%28%29

其中I,C等表示class文件里的class的标识。
对应关系如下:

  • B 代表byte
  • C 代表char
  • D 代表double
  • F 代表float
  • I 代表int
  • J 代表long
  • Z代表boolean
    前边有[代表数组,[I 就相当于int[]
    对象用[L+类名表示
0 0
原创粉丝点击