一、jps
dbq@mac:~$ jps 50053 TIS_FullGC_Problem01 48599 Jps 92253
二、jinfo
列出当前jvm的详细信息
jinfo 50053
dbq@mac:~$ jinfo 50053 Attaching to process ID 50053, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.131-b11 Java System Properties: java.runtime.name = Java(TM) SE Runtime Environment java.vm.version = 25.131-b11 sun.boot.library.path = /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib gopherProxySet = false java.vendor.url = http://java.oracle.com/ java.vm.vendor = Oracle Corporation path.separator = : file.encoding.pkg = sun.io java.vm.name = Java HotSpot(TM) 64-Bit Server VM sun.os.patch.level = unknown sun.java.launcher = SUN_STANDARD user.country = CN user.dir = /Users/dbq/Documents/git/GCTest/out/production/GCTest java.vm.specification.name = Java Virtual Machine Specification java.runtime.version = 1.8.0_131-b11 java.awt.graphicsenv = sun.awt.CGraphicsEnvironment os.arch = x86_64 java.endorsed.dirs = /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/endorsed line.separator = java.io.tmpdir = /var/folders/fg/7tr0w_412q7ffqmyhy48jnn40000gn/T/ java.vm.specification.vendor = Oracle Corporation os.name = Mac OS X sun.jnu.encoding = UTF-8 java.library.path = /Users/dbq/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:. java.specification.name = Java Platform API Specification java.class.version = 52.0 sun.management.compiler = HotSpot 64-Bit Tiered Compilers os.version = 10.13.1 http.nonProxyHosts = local„ÄÅ169.254/16|*.local„ÄÅ169.254/16 user.home = /Users/dbq user.timezone = java.awt.printerjob = sun.lwawt.macosx.CPrinterJob file.encoding = UTF-8 java.specification.version = 1.8 user.name = dbq java.class.path = . java.vm.specification.version = 1.8 sun.arch.data.model = 64 sun.java.command = com.mashibing.jvm.gc.TIS_FullGC_Problem01 java.home = /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre user.language = zh java.specification.vendor = Oracle Corporation user.language.format = en awt.toolkit = sun.lwawt.macosx.LWCToolkit java.vm.info = mixed mode java.version = 1.8.0_131 java.ext.dirs = /Users/dbq/Library/Java/Extensions:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/ext:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java sun.boot.class.path = /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/sunrsasign.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/classes java.vendor = Oracle Corporation file.separator = / java.vendor.url.bug = http://bugreport.sun.com/bugreport/ sun.io.unicode.encoding = UnicodeBig sun.cpu.endian = little socksNonProxyHosts = local„ÄÅ169.254/16|*.local„ÄÅ169.254/16 ftp.nonProxyHosts = local„ÄÅ169.254/16|*.local„ÄÅ169.254/16 sun.cpu.isalist = VM Flags: Non-default VM flags: -XX:CICompilerCount=3 -XX:InitialHeapSize=209715200 -XX:MaxHeapSize=209715200 -XX:MaxNewSize=69730304 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=69730304 -XX:OldSize=139984896 -XX:+PrintGC -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:+UseParallelGC Command line: -Xms200M -Xmx200M -XX:+PrintGC
VM Flags:jvm参数信息
三、jstat
打印java的统计信息
jstat -gc pid 打印gc的统计信息
dbq@mac:~$ jstat -gc 50053 S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT 8192.0 8192.0 0.0 8180.3 50688.0 39484.0 136704.0 78432.0 4864.0 4024.3 512.0 441.3 5 0.184 0 0.000 0.184
也可以动态的统计
jstat -gc 48369 500 每500ms打印一次统计信息
dbq@mac:~$ jstat -gc 50053 500 S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT 22528.0 22528.0 0.0 15684.3 23040.0 17325.8 136704.0 97600.1 4864.0 4024.3 512.0 441.3 7 0.266 0 0.000 0.266 22528.0 22528.0 0.0 15684.3 23040.0 17478.7 136704.0 97600.1 4864.0 4024.3 512.0 441.3 7 0.266 0 0.000 0.266 22528.0 22528.0 0.0 15684.3 23040.0 17936.7 136704.0 97600.1 4864.0 4024.3 512.0 441.3 7 0.266 0 0.000 0.266 22528.0 22528.0 0.0 15684.3 23040.0 18456.8 136704.0 97600.1 4864.0 4024.3 512.0 441.3 7 0.266 0 0.000 0.266 22528.0 22528.0 0.0 15684.3 23040.0 18784.2 136704.0 97600.1 4864.0 4024.3 512.0 441.3 7 0.266 0 0.000 0.266 22528.0 22528.0 0.0 15684.3 23040.0 18784.2 136704.0 97600.1 4864.0 4024.3 512.0 441.3 7 0.266 0 0.000 0.266 22528.0 22528.0 0.0 15684.3 23040.0 19020.5 136704.0 97600.1 4864.0 4024.3 512.0 441.3 7 0.266 0 0.000 0.266
查看GC频率
ps -eo pid,tty,user,comm,lstart,etime | grep 24019
dbq@mac:$ ps -eo pid,tty,user,comm,lstart,etime | grep 40536 40536 ttys001 dbq java 一 3/ 1 08:30:05 2021 02:20
GC频率 = 进程运行时间/GC次数
四、垃圾回收信息的解释
之前由于添加了printGC,所以会打印gc回收信息,一般循环打印,并指定大小
GC指的是YGC,从多少k回收到多少k,相减就是回收的内存大小
FullGC
dbq@mac:~/Documents/git/GCTest/out/production/GCTest$ java -Xms200M -Xmx200M -XX:+PrintGC com.mashibing.jvm.gc.TIS_FullGC_Problem01 [GC (Allocation Failure) 51712K->1256K(196608K), 0.0023883 secs] [GC (Allocation Failure) 52968K->23238K(196608K), 0.0523418 secs] [GC (Allocation Failure) 74950K->44536K(196608K), 0.0491664 secs] [GC (Allocation Failure) 96248K->67248K(196608K), 0.0435336 secs] [GC (Allocation Failure) 118960K->86612K(195584K), 0.0364209 secs] [GC (Allocation Failure) 137300K->105244K(167936K), 0.0478008 secs] [GC (Allocation Failure) 128284K->113284K(182272K), 0.0342078 secs] [GC (Allocation Failure) 136324K->120780K(182272K), 0.0440687 secs] [GC (Allocation Failure) 143820K->131652K(182272K), 0.0488463 secs] [Full GC (Ergonomics) 131652K->126984K(182272K), 0.9244073 secs] [Full GC (Ergonomics) 150024K->135637K(182272K), 0.4714047 secs] [Full GC (Ergonomics) 158677K->143194K(182272K), 0.5033654 secs] [Full GC (Ergonomics) 159727K->147805K(182272K), 0.5497019 secs] [Full GC (Ergonomics) 159727K->151623K(182272K), 0.5586325 secs] [Full GC (Ergonomics) 159727K->154162K(182272K), 0.5261450 secs] [Full GC (Ergonomics) 159727K->155930K(182272K), 0.5602670 secs] [Full GC (Ergonomics) 159727K->157209K(182272K), 0.5733866 secs]
五、top
top命令可以查看哪些进程占用资源比较多
六、top -Hp pid
top命令可以查看进程中线程占用资源情况
由于mac下 -Hp不支持,这是linux下其他进程的线程信息
top - 15:30:44 up 117 days, 14 min, 1 user, load average: 0.00, 0.00, 0.00 Threads: 52 total, 0 running, 52 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.3 us, 0.2 sy, 0.0 ni, 99.3 id, 0.0 wa, 0.2 hi, 0.0 si, 0.0 st MiB Mem : 3637.6 total, 327.2 free, 993.9 used, 2316.5 buff/cache MiB Swap: 0.0 total, 0.0 free, 0.0 used. 2387.5 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 3489 root 20 0 3497204 535276 18008 S 0.7 14.4 606:02.57 System Clock 3464 root 20 0 3497204 535276 18008 S 0.0 14.4 0:00.00 java 3467 root 20 0 3497204 535276 18008 S 0.0 14.4 0:07.24 java 3469 root 20 0 3497204 535276 18008 S 0.0 14.4 0:09.84 java 3470 root 20 0 3497204 535276 18008 S 0.0 14.4 0:09.88 java 3471 root 20 0 3497204 535276 18008 S 0.0 14.4 1:20.66 VM Thread 3472 root 20 0 3497204 535276 18008 S 0.0 14.4 0:00.03 Reference Handl 3473 root 20 0 3497204 535276 18008 S 0.0 14.4 0:00.01 Finalizer 3474 root 20 0 3497204 535276 18008 S 0.0 14.4 0:00.00 Signal Dispatch 3475 root 20 0 3497204 535276 18008 S 0.0 14.4 0:42.07 C2 CompilerThre 3476 root 20 0 3497204 535276 18008 S 0.0 14.4 0:19.02 C1 CompilerThre 3477 root 20 0 3497204 535276 18008 S 0.0 14.4 0:00.00 Service Thread 3478 root 20 0 3497204 535276 18008 S 0.0 14.4 25:44.90 VM Periodic Tas 3481 root 20 0 3497204 535276 18008 S 0.0 14.4 2:17.25 Catalina-utilit 3482 root 20 0 3497204 535276 18008 S 0.0 14.4 2:18.40 Catalina-utilit