欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jvm信息jmap使用的基本方法教程

程序员文章站 2024-02-19 19:53:58
前言 大家都知道有很多开源的监控工具,本次只使用了jmap,了解简单使用,谢谢,下面话不多说了,来一起看看详细的介绍吧 使用方法如下: 开始了,922是我的tom...

前言

大家都知道有很多开源的监控工具,本次只使用了jmap,了解简单使用,谢谢,下面话不多说了,来一起看看详细的介绍吧

使用方法如下:

开始了,922是我的tomcat进程

帮助命令查看,有哪些命令可以使用。

[root@bogon /]# jmap -help
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 format
       dump-options:
       live   dump only live objects; if not specified,
          all objects in the heap are dumped.
       format=b  binary format
       file=<file> dump heap to <file>
       example: jmap -dump:live,format=b,file=heap.bin <pid>
 -f     force. use with -dump:<dump-options> <pid> or -histo
       to force a heap dump or histogram when <pid> does not
       respond. the "live" suboption is not supported
       in this mode.
 -h | -help   to print this help message
 -j<flag>    to pass <flag> directly to the runtime system

使用1:jmap pid 查看基本信息

[root@bogon /]# jmap 922
attaching to process id 922, please wait...
debugger attached successfully.
server compiler detected.
jvm version is 25.111-b14
0x0000000000400000 7k /usr/local/software/java/bin/java
0x0000003ddde00000 153k /lib64/ld-2.12.so
0x0000003dde200000 22k /lib64/libdl-2.12.so
0x0000003dde600000 1881k /lib64/libc-2.12.so
0x0000003ddea00000 142k /lib64/libpthread-2.12.so
0x0000003ddee00000 45k /lib64/librt-2.12.so
0x0000003ddf200000 585k /lib64/libm-2.12.so
0x0000003de0e00000 111k /lib64/libresolv-2.12.so
0x0000003de9e00000 91k /lib64/libgcc_s-4.4.7-20120601.so.1
0x00007f90de586000 26k /lib64/libnss_dns-2.12.so
0x00007f913c39d000 250k /usr/local/software/java/jre/lib/amd64/libsunec.so
0x00007f913cbf2000 90k /usr/local/software/java/jre/lib/amd64/libnio.so
0x00007f913d103000 113k /usr/local/software/java/jre/lib/amd64/libnet.so
0x00007f913d31a000 49k /usr/local/software/java/jre/lib/amd64/libmanagement.so
0x00007f919a43b000 121k /usr/local/software/java/jre/lib/amd64/libzip.so
0x00007f919a656000 64k /lib64/libnss_files-2.12.so
0x00007f919a874000 220k /usr/local/software/java/jre/lib/amd64/libjava.so
0x00007f919aaa0000 64k /usr/local/software/java/jre/lib/amd64/libverify.so
0x00007f919acef000 16584k /usr/local/software/java/jre/lib/amd64/server/libjvm.so
0x00007f919bce2000 100k /usr/local/software/java/lib/amd64/jli/libjli.so

使用2 :查看堆信息,jmap -heap pid

[root@bogon /]# jmap -heap 922
attaching to process id 922, please wait...
debugger attached successfully.
server compiler detected.
jvm version is 25.111-b14

using parallel threads in the new generation. 
using thread-local object allocation.
concurrent mark-sweep gc

heap configuration:
 minheapfreeratio   = 40
 maxheapfreeratio   = 70
 maxheapsize    = 4294967296 (4096.0mb) 最大堆大小
 newsize     = 3221225472 (3072.0mb) 新生代大小
 maxnewsize    = 3221225472 (3072.0mb) 最大分配新生代内存
 oldsize     = 1073741824 (1024.0mb) 老年代大小
 newratio     = 2 
 survivorratio   = 8 新生代与老年代的比例
 metaspacesize   = 21807104 (20.796875mb) 
 compressedclassspacesize = 1073741824 (1024.0mb)
 maxmetaspacesize   = 17592186044415 mb
 g1heapregionsize   = 0 (0.0mb)

heap usage: 堆的使用情况
new generation (eden + 1 survivor space): 新生代
 capacity = 2899116032 (2764.8125mb)
 used  = 384206560 (366.4079284667969mb)
 free  = 2514909472 (2398.404571533203mb)
 13.25254166301682% used
eden space: 新生代 eden区空间
 capacity = 2577006592 (2457.625mb)
 used  = 378654344 (361.11292266845703mb)
 free  = 2198352248 (2096.512077331543mb)
 14.693572968555294% used
from space: 2个survivor区域 其中一个就是这个from区
 capacity = 322109440 (307.1875mb)
 used  = 5552216 (5.295005798339844mb)
 free  = 316557224 (301.89249420166016mb)
 1.723704837709817% used
to space:2个survivor区域 其中一个就是这个to区
 capacity = 322109440 (307.1875mb)
 used  = 0 (0.0mb)
 free  = 322109440 (307.1875mb)
 0.0% used
concurrent mark-sweep generation: 老年代 eden区空间
 capacity = 1073741824 (1024.0mb)
 used  = 846734040 (807.5085067749023mb)
 free  = 227007784 (216.49149322509766mb)
 78.85825261473656% used

使用3:jmap -histo pid 查看一些class的使用情况,

jmap -histo 922
由于里面比较多内容,所以放弃了,可以自己使用一下,如果电脑展示不了一屏呢,可以这样。

jmap -histo 922 >dump.txt 导出文件,可以自己看了
下面是我自己导出的文件信息
 num  #instances(实例数量)   #bytes(字节) class name 
----------------------------------------------
 1:  174069  1579369600 [c
 2:   4403  122732640 [i
 3:   9571  16889072 [b
 4:  157680  3784320 java.lang.string
 5:   38279  3674784 java.util.jar.jarfile$jarfileentry
 6:   70982  2271424 java.util.hashmap$node
 7:   13235  1164680 java.lang.reflect.method
 8:   6001  1028952 [ljava.util.hashmap$node;

又或者可以过滤信息,命令:jmap -histo 922 |grep dubbo 过滤一下,就过滤你想要的信息

使用4:jmap -histo:live pid >dump.txt

这个和使用3差不多,都是在统计,只不过这个是在统计正在使用的对象,然后dump对象信息。

这种命令都是结合其它的命令一起使用的,以后会有文章结合一起分析,同学有什么好的工具也分享出来,一起学习,本篇只介绍jmap

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对的支持。