jvm性能分析工具

1.jconsole

public class TestGC {
    public static void main(String[] args) throws InterruptedException {
        int size = 1024 * 1024;
        byte[] data = new byte[size];
        data = null;
        System.gc();
        while (true){
            System.out.println("true");
            Thread.sleep(1000);
        }
    }
}

编译及运行

[root@dev1 java]# javac TestGC.java 
[root@dev1 java]# java -Dcom.sun.management.jmxremote.port=9890 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=192.168.1.100 TestGC

输入目标主机域名及上述端口,用户名/口令,点击连接即可
image.png

2.visualvm

下载visualvm到本地,打开visualvm
image.png

输入主机名
image.png

输入用户名及密码,端口号
image.png

即可查看jvm信息
image.png

3.jinfo工具

查看jvm进程参数等信息

[root@dev1 ~]# jps
13507 -- process information unavailable
3492 TestGC
13398 -- process information unavailable
13642 -- process information unavailable
3851 Jps
[root@dev1 ~]# jinfo 3492
Java System Properties:
#Fri Aug 07 01:37:04 CST 2020
awt.toolkit=sun.awt.X11.XToolkit
java.specification.version=11
sun.cpu.isalist=
sun.jnu.encoding=UTF-8
com.sun.management.jmxremote.authenticate=false
java.class.path=.
java.vm.vendor=Oracle Corporation
sun.arch.data.model=64
java.vendor.url=http\://java.oracle.com/
user.timezone=
java.vm.specification.version=11
os.name=Linux
sun.java.launcher=SUN_STANDARD
user.country=CN
sun.boot.library.path=/usr/lib/jvm/java-11-openjdk-11.0.7.10-4.el7_8.x86_64/lib
com.sun.management.jmxremote.ssl=false
sun.java.command=TestGC
jdk.debug=release
sun.cpu.endian=little
user.home=/root
user.language=zh
java.specification.vendor=Oracle Corporation
java.version.date=2020-04-14
java.home=/usr/lib/jvm/java-11-openjdk-11.0.7.10-4.el7_8.x86_64
file.separator=/
java.vm.compressedOopsMode=32-bit
line.separator=\n
java.specification.name=Java Platform API Specification
java.vm.specification.vendor=Oracle Corporation
java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment
sun.management.compiler=HotSpot 64-Bit Tiered Compilers
java.runtime.version=11.0.7+10-LTS
user.name=root
path.separator=\:
os.version=3.10.0-1062.el7.x86_64
java.runtime.name=OpenJDK Runtime Environment
file.encoding=UTF-8
java.vm.name=OpenJDK 64-Bit Server VM
java.vendor.version=18.9
java.vendor.url.bug=http\://bugreport.java.com/bugreport/
java.io.tmpdir=/tmp
java.version=11.0.7
com.sun.management.jmxremote.port=9890
user.dir=/data/java
os.arch=amd64
java.vm.specification.name=Java Virtual Machine Specification
java.awt.printerjob=sun.print.PSPrinterJob
sun.os.patch.level=unknown
java.library.path=/usr/java/packages/lib\:/usr/lib64\:/lib64\:/lib\:/usr/lib
java.vendor=Oracle Corporation
java.vm.info=mixed mode, sharing
java.vm.version=11.0.7+10-LTS
java.rmi.server.hostname=192.168.1.100
java.rmi.server.randomIDs=true
sun.io.unicode.encoding=UnicodeLittle
java.class.version=55.0
VM Flags:
-XX:CICompilerCount=2 -XX:ConcGCThreads=1 -XX:G1ConcRefinementThreads=2 -XX:G1HeapRegionSize=1048576 -XX:GCDrainStackTargetSize=64 -XX:InitialHeapSize=62914560 -XX:+ManagementServer -XX:MarkStackSize=4194304 -XX:MaxHeapSize=994050048 -XX:MaxNewSize=595591168 -XX:MinHeapDeltaBytes=1048576 -XX:NonNMethodCodeHeapSize=5825164 -XX:NonProfiledCodeHeapSize=122916538 -XX:ProfiledCodeHeapSize=122916538 -XX:ReservedCodeCacheSize=251658240 -XX:+SegmentedCodeCache -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:+UseG1GC 
VM Arguments:
jvm_args: -Dcom.sun.management.jmxremote.port=9890 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=192.168.1.100 
java_command: TestGC
java_class_path (initial): .
Launcher Type: SUN_STANDARD
[root@dev1 ~]

4.查看进程中线程堆栈信息

[root@dev1 ~]# jstack 3492
2020-08-07 01:38:30
Full thread dump OpenJDK 64-Bit Server VM (11.0.7+10-LTS mixed mode, sharing):
Threads class SMR info:
_java_thread_list=0x00007fe12c0030c0, length=13, elements={
0x00007fe174015000, 0x00007fe1740b3800, 0x00007fe1740b5800, 0x00007fe1740bb000,
0x00007fe1740bd000, 0x00007fe1740bf800, 0x00007fe1740c1800, 0x00007fe1740df000,
0x00007fe17410c800, 0x00007fe17423a800, 0x00007fe174241800, 0x00007fe174255800,
0x00007fe12c001800
}
"main" #1 prio=5 os_prio=0 cpu=480.16ms elapsed=106.98s tid=0x00007fe174015000 nid=0xda5 waiting on condition  [0x00007fe17d14a000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
        at java.lang.Thread.sleep([email protected]/Native Method)
        at TestGC.main(TestGC.java:9)
"Reference Handler" #2 daemon prio=10 os_prio=0 cpu=0.64ms elapsed=106.97s tid=0x00007fe1740b3800 nid=0xdac waiting on condition  [0x00007fe15c78b000]
   java.lang.Thread.State: RUNNABLE
        at java.lang.ref.Reference.waitForReferencePendingList([email protected]/Native Method)
        at java.lang.ref.Reference.processPendingReferences([email protected]/Reference.java:241)
        at java.lang.ref.Reference$ReferenceHandler.run([email protected]/Reference.java:213)
"Finalizer" #3 daemon prio=8 os_prio=0 cpu=0.26ms elapsed=106.97s tid=0x00007fe1740b5800 nid=0xdad in Object.wait()  [0x00007fe15c68a000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait([email protected]/Native Method)
        - waiting on <0x00000000c4c7ccc8> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove([email protected]/ReferenceQueue.java:155)
        - waiting to re-lock in wait() <0x00000000c4c7ccc8> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove([email protected]/ReferenceQueue.java:176)
        at java.lang.ref.Finalizer$FinalizerThread.run([email protected]/Finalizer.java:170)
"Signal Dispatcher" #4 daemon prio=9 os_prio=0 cpu=0.24ms elapsed=106.96s tid=0x00007fe1740bb000 nid=0xdae runnable  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
"C2 CompilerThread0" #5 daemon prio=9 os_prio=0 cpu=288.06ms elapsed=106.96s tid=0x00007fe1740bd000 nid=0xdaf waiting on condition  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
   No compile task
"C1 CompilerThread0" #6 daemon prio=9 os_prio=0 cpu=243.13ms elapsed=106.96s tid=0x00007fe1740bf800 nid=0xdb0 waiting on condition  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
   No compile task
"Sweeper thread" #7 daemon prio=9 os_prio=0 cpu=2.62ms elapsed=106.96s tid=0x00007fe1740c1800 nid=0xdb1 runnable  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
"Common-Cleaner" #8 daemon prio=8 os_prio=0 cpu=0.56ms elapsed=106.93s tid=0x00007fe1740df000 nid=0xdb2 in Object.wait()  [0x00007fe15c185000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
        at java.lang.Object.wait([email protected]/Native Method)
        - waiting on <0x00000000c4cafc78> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove([email protected]/ReferenceQueue.java:155)
        - waiting to re-lock in wait() <0x00000000c4cafc78> (a java.lang.ref.ReferenceQueue$Lock)
        at jdk.internal.ref.CleanerImpl.run([email protected]/CleanerImpl.java:148)
        at java.lang.Thread.run([email protected]/Thread.java:834)
        at jdk.internal.misc.InnocuousThread.run([email protected]/InnocuousThread.java:134)
"Service Thread" #9 daemon prio=9 os_prio=0 cpu=0.16ms elapsed=106.89s tid=0x00007fe17410c800 nid=0xdb3 runnable  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
"RMI TCP Accept-0" #11 daemon prio=5 os_prio=0 cpu=0.48ms elapsed=106.52s tid=0x00007fe17423a800 nid=0xdce runnable  [0x00007fe15415d000]
   java.lang.Thread.State: RUNNABLE
        at java.net.PlainSocketImpl.socketAccept([email protected]/Native Method)
        at java.net.AbstractPlainSocketImpl.accept([email protected]/AbstractPlainSocketImpl.java:458)
        at java.net.ServerSocket.implAccept([email protected]/ServerSocket.java:565)
        at java.net.ServerSocket.accept([email protected]/ServerSocket.java:533)
        at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop([email protected]/TCPTransport.java:394)
        at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run([email protected]/TCPTransport.java:366)
        at java.lang.Thread.run([email protected]/Thread.java:834)
"RMI TCP Accept-9890" #12 daemon prio=5 os_prio=0 cpu=0.11ms elapsed=106.51s tid=0x00007fe174241800 nid=0xdcf runnable  [0x00007fe131082000]
   java.lang.Thread.State: RUNNABLE
        at java.net.PlainSocketImpl.socketAccept([email protected]/Native Method)
        at java.net.AbstractPlainSocketImpl.accept([email protected]/AbstractPlainSocketImpl.java:458)
        at java.net.ServerSocket.implAccept([email protected]/ServerSocket.java:565)
        at java.net.ServerSocket.accept([email protected]/ServerSocket.java:533)
        at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop([email protected]/TCPTransport.java:394)
        at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run([email protected]/TCPTransport.java:366)
        at java.lang.Thread.run([email protected]/Thread.java:834)
"RMI TCP Accept-0" #13 daemon prio=5 os_prio=0 cpu=0.21ms elapsed=106.46s tid=0x00007fe174255800 nid=0xdd0 runnable  [0x00007fe130f81000]
   java.lang.Thread.State: RUNNABLE
        at java.net.PlainSocketImpl.socketAccept([email protected]/Native Method)
        at java.net.AbstractPlainSocketImpl.accept([email protected]/AbstractPlainSocketImpl.java:458)
        at java.net.ServerSocket.implAccept([email protected]/ServerSocket.java:565)
        at java.net.ServerSocket.accept([email protected]/ServerSocket.java:533)
        at sun.management.jmxremote.LocalRMIServerSocketFactory$1.accept([email protected]/LocalRMIServerSocketFactory.java:52)
        at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop([email protected]/TCPTransport.java:394)
        at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run([email protected]/TCPTransport.java:366)
        at java.lang.Thread.run([email protected]/Thread.java:834)
"Attach Listener" #14 daemon prio=9 os_prio=0 cpu=26.57ms elapsed=86.00s tid=0x00007fe12c001800 nid=0x1067 waiting on condition  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
"VM Thread" os_prio=0 cpu=11.22ms elapsed=106.97s tid=0x00007fe1740b0800 nid=0xdab runnable  
"GC Thread#0" os_prio=0 cpu=11.52ms elapsed=106.98s tid=0x00007fe17402d000 nid=0xda6 runnable  
"GC Thread#1" os_prio=0 cpu=8.66ms elapsed=106.44s tid=0x00007fe144001000 nid=0xdd2 runnable  
"G1 Main Marker" os_prio=0 cpu=0.36ms elapsed=106.98s tid=0x00007fe174047000 nid=0xda7 runnable  
"G1 Conc#0" os_prio=0 cpu=0.07ms elapsed=106.98s tid=0x00007fe174049000 nid=0xda8 runnable  
"G1 Refine#0" os_prio=0 cpu=0.23ms elapsed=106.98s tid=0x00007fe174082800 nid=0xda9 runnable  
"G1 Young RemSet Sampling" os_prio=0 cpu=16.03ms elapsed=106.98s tid=0x00007fe174084800 nid=0xdaa runnable  
"VM Periodic Task Thread" os_prio=0 cpu=81.97ms elapsed=106.45s tid=0x00007fe174258000 nid=0xdd1 waiting on condition  
JNI global refs: 15, weak refs: 0
[root@dev1]

你可能感兴趣的:(jvm,工具)