美文网首页
JVM相关信息查看

JVM相关信息查看

作者: 某某程序员_ | 来源:发表于2019-10-12 15:19 被阅读0次

    1. jps,查看jvm实例

    [root@test_back-1~]# jps -help
    usage: jps [-help]
           jps [-q] [-mlvV] [<hostid>]
    
    Definitions:
        <hostid>:      <hostname>[:<port>]
    [root@test_back-1~]# jps -q
    30262
    28666
    20794
    30109
    [root@test_back-1~]# jps -m
    20806 Jps -m
    30262 Bootstrap start
    28666 jar
    30109 Bootstrap start
    
    

    2. jstat,jvm统计信息,包含内存信息及GC信息

    [root@test_back-1~]# jstat -help
    Usage: jstat -help|-options
           jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]
    
    Definitions:
      <option>      An option reported by the -options option
      <vmid>        Virtual Machine Identifier. A vmid takes the following form:
                         <lvmid>[@<hostname>[:<port>]]
                    Where <lvmid> is the local vm identifier for the target
                    Java virtual machine, typically a process id; <hostname> is
                    the name of the host running the target Java virtual machine;
                    and <port> is the port number for the rmiregistry on the
                    target host. See the jvmstat documentation for a more complete
                    description of the Virtual Machine Identifier.
      <lines>       Number of samples between header lines.
      <interval>    Sampling interval. The following forms are allowed:
                        <n>["ms"|"s"]
                    Where <n> is an integer and the suffix specifies the units as 
                    milliseconds("ms") or seconds("s"). The default units are "ms".
      <count>       Number of samples to take before terminating.
      -J<flag>      Pass <flag> directly to the runtime system.
    [root@test_back-1~]# jstat -options
    -class
    -compiler
    -gc
    -gccapacity
    -gccause
    -gcmetacapacity
    -gcnew
    -gcnewcapacity
    -gcold
    -gcoldcapacity
    -gcutil
    -printcompilation
    [root@test_back-1~]# 
    [root@test_back-1~]# jstat -gc -t -h10 30109 1500ms 3
    Timestamp        S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT   
            89872.2 17024.0 17024.0 560.1   0.0   136320.0 112080.7  878208.0   48104.2   82732.0 79226.9 9772.0 9139.9   1258   10.912   6      0.271   11.183
            89873.7 17024.0 17024.0 560.1   0.0   136320.0 115375.3  878208.0   48104.2   82732.0 79226.9 9772.0 9139.9   1258   10.912   6      0.271   11.183
            89875.2 17024.0 17024.0 560.1   0.0   136320.0 117665.7  878208.0   48104.2   82732.0 79226.9 9772.0 9139.9   1258   10.912   6      0.271   11.183
    
    

    3. jmap,查看JVM内存相关信息

    [root@test_back-1~]# 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
    [root@test_back-1~]# jmap -heap 30109
    Attaching to process ID 30109, please wait...
    Debugger attached successfully.
    Server compiler detected.
    JVM version is 25.74-b02
    
    using parallel threads in the new generation.
    using thread-local object allocation.
    Concurrent Mark-Sweep GC
    
    Heap Configuration:
       MinHeapFreeRatio         = 40
       MaxHeapFreeRatio         = 70
       MaxHeapSize              = 1073741824 (1024.0MB)
       NewSize                  = 174456832 (166.375MB)
       MaxNewSize               = 174456832 (166.375MB)
       OldSize                  = 899284992 (857.625MB)
       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 = 157024256 (149.75MB)
       used     = 46988880 (44.81208801269531MB)
       free     = 110035376 (104.93791198730469MB)
       29.924599674587856% used
    Eden Space:
       capacity = 139591680 (133.125MB)
       used     = 46461032 (44.308692932128906MB)
       free     = 93130648 (88.8163070678711MB)
       33.283525207232984% used
    From Space:
       capacity = 17432576 (16.625MB)
       used     = 527848 (0.5033950805664062MB)
       free     = 16904728 (16.121604919433594MB)
       3.0279403342340228% used
    To Space:
       capacity = 17432576 (16.625MB)
       used     = 0 (0.0MB)
       free     = 17432576 (16.625MB)
       0.0% used
    concurrent mark-sweep generation:
       capacity = 899284992 (857.625MB)
       used     = 49281872 (46.99885559082031MB)
       free     = 850003120 (810.6261444091797MB)
       5.480117252974239% used
    
    29566 interned Strings occupying 3583576 bytes.
    
    

    4. jstack,查看java栈及本地方法栈信息

    [root@test_back-1~]# jstack -help
    Usage:
        jstack [-l] <pid>
            (to connect to running process)
        jstack -F [-m] [-l] <pid>
            (to connect to a hung process)
        jstack [-m] [-l] <executable> <core>
            (to connect to a core file)
        jstack [-m] [-l] [server_id@]<remote server IP or hostname>
            (to connect to a remote debug server)
    
    Options:
        -F  to force a thread dump. Use when jstack <pid> does not respond (process is hung)
        -m  to print both java and native frames (mixed mode)
        -l  long listing. Prints additional information about locks
        -h or -help to print this help message
    [root@test_back-1~]# jstack -l 30109
    "Reference Handler" #2 daemon prio=10 os_prio=0 tid=0x00007f1e80120000 nid=0x75a5 in Object.wait() [0x00007f1e84a61000]
       java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        at java.lang.Object.wait(Object.java:502)
        at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
        - locked <0x00000000ca967f48> (a java.lang.ref.Reference$Lock)
        at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)
    
       Locked ownable synchronizers:
        - None
    
    "main" #1 prio=5 os_prio=0 tid=0x00007f1e8000a000 nid=0x759f runnable [0x00007f1e87d70000]
       java.lang.Thread.State: RUNNABLE
        at java.net.PlainSocketImpl.socketAccept(Native Method)
        at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409)
        at java.net.ServerSocket.implAccept(ServerSocket.java:545)
        at java.net.ServerSocket.accept(ServerSocket.java:513)
        at org.apache.catalina.core.StandardServer.await(StandardServer.java:466)
        at org.apache.catalina.startup.Catalina.await(Catalina.java:743)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:689)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:355)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:495)
    
       Locked ownable synchronizers:
        - None
    
    "VM Thread" os_prio=0 tid=0x00007f1e80118800 nid=0x75a4 runnable 
    
    "Gang worker#0 (Parallel GC Threads)" os_prio=0 tid=0x00007f1e8001b000 nid=0x75a0 runnable 
    
    "Gang worker#1 (Parallel GC Threads)" os_prio=0 tid=0x00007f1e8001c800 nid=0x75a1 runnable 
    
    "Concurrent Mark-Sweep GC Thread" os_prio=0 tid=0x00007f1e8004a000 nid=0x75a2 runnable 
    
    "VM Periodic Task Thread" os_prio=0 tid=0x00007f1e80756000 nid=0x75b6 waiting on condition 
    
    JNI global references: 689
    
    

    5. jinfo,查看jvm配置信息

    [root@test_back-1~]# jinfo -help
    Usage:
        jinfo [option] <pid>
            (to connect to running process)
        jinfo [option] <executable <core>
            (to connect to a core file)
        jinfo [option] [server_id@]<remote server IP or hostname>
            (to connect to remote debug server)
    
    where <option> is one of:
        -flag <name>         to print the value of the named VM flag
        -flag [+|-]<name>    to enable or disable the named VM flag
        -flag <name>=<value> to set the named VM flag to the given value
        -flags               to print VM flags
        -sysprops            to print Java system properties
        <no option>          to print both of the above
        -h | -help           to print this help message
    [root@test_back-1~]# jinfo 30109
    Attaching to process ID 30109, please wait...
    Debugger attached successfully.
    Server compiler detected.
    JVM version is 25.74-b02
    Java System Properties:
    
    java.vendor = Oracle Corporation
    rocketmq.client.logFileName = ons.log
    sun.java.launcher = SUN_STANDARD
    catalina.base = /wdzj/java/tomcat_8080
    ...
    
    java.vm.name = Java HotSpot(TM) 64-Bit Server VM
    file.encoding = UTF-8
    java.specification.version = 1.8
    
    VM Flags:
    Non-default VM flags: -XX:CICompilerCount=2 -XX:InitialHeapSize=1073741824 -XX:MaxHeapSize=1073741824 -XX:MaxNewSize=174456832 -XX:MaxTenuringThreshold=6 -XX:MinHeapDeltaBytes=196608 -XX:NewSize=174456832 -XX:OldPLABSize=16 -XX:OldSize=899284992 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -
    

    示例:查看指定进程栈信息

    [root@test_back-1 ~]# top -Hp 30109   #查看这个JVM进程里面的进程运行情况
    top - 15:01:01 up 123 days,  8:43,  3 users,  load average: 0.20, 0.13, 0.05
    Tasks: 246 total,   0 running, 246 sleeping,   0 stopped,   0 zombie
    Cpu(s):  1.5%us,  0.7%sy,  0.0%ni, 97.0%id,  0.8%wa,  0.0%hi,  0.0%si,  0.0%st
    Mem:   3924700k total,  3654884k used,   269816k free,   160024k buffers
    Swap:  3989496k total,   120700k used,  3868796k free,  1181444k cached
     Unknown command - try 'h' for help 
      PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                                                                  
    30126 root      20   0 3980m 762m  15m S  0.7 19.9   0:59.70 java                                                                                                                                                      
    ...                                                                                                                                                  
    [root@test_back-1 ~]# printf "%x \n" 30126   #转换进程id为16进制
    75ae 
    [root@test_back-1 ~]# jstack 30109|grep 75ae --color -C 5  #查看进程里面的栈信息
        at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
    
    "DataCarrier.DEFAULT.Consumser.0.Thread" #10 daemon prio=5 os_prio=0 tid=0x00007f1e8070f000 nid=0x75ae sleeping[0x00007f1e84295000]
       java.lang.Thread.State: TIMED_WAITING (sleeping)
        at java.lang.Thread.sleep(Native Method)
        at org.apache.skywalking.apm.commons.datacarrier.consumer.ConsumerThread.run(ConsumerThread.java:72)
    
    "Thread-3" #9 daemon prio=5 os_prio=0 tid=0x00007f1e8026e000 nid=0x75aa waiting on condition [0x00007f1e84413000]
    
    

    每一个使用之前都下查看帮助信息(-help)

    相关文章

      网友评论

          本文标题:JVM相关信息查看

          本文链接:https://www.haomeiwen.com/subject/epfbyctx.html