聊一聊GC日志,线程转储和堆转储
共 5222字,需浏览 11分钟
·
2021-04-02 15:59
聊一聊GC日志,线程转储和堆转储
•垃圾收集(Garbage collection,GC)日志•线程转储(Thread dump)•堆转储(Heap dump)
介些都是些啥东东
GC日志
线程转储
堆转储
来!出来亮个相
GC日志
2021-04-01T12:32:24.398+0800: 0.356: [GC pause (G1 Evacuation Pause) (young), 0.0215287 secs]
[Parallel Time: 20.0 ms, GC Workers: 8]
[GC Worker Start (ms): Min: 355.9, Avg: 356.3, Max: 358.4, Diff: 2.4]
[Ext Root Scanning (ms): Min: 0.0, Avg: 6.4, Max: 16.7, Diff: 16.7, Sum: 51.4]
[Update RS (ms): Min: 0.0, Avg: 1.0, Max: 2.5, Diff: 2.5, Sum: 8.2]
[Processed Buffers: Min: 0, Avg: 1.1, Max: 5, Diff: 5, Sum: 9]
[Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.1, Sum: 0.1]
[Object Copy (ms): Min: 2.9, Avg: 11.9, Max: 17.5, Diff: 14.6, Sum: 95.3]
[Termination (ms): Min: 0.0, Avg: 0.1, Max: 0.2, Diff: 0.2, Sum: 0.9]
[Termination Attempts: Min: 1, Avg: 2.5, Max: 5, Diff: 4, Sum: 20]
[GC Worker Other (ms): Min: 0.0, Avg: 0.1, Max: 0.1, Diff: 0.1, Sum: 0.5]
[GC Worker Total (ms): Min: 17.5, Avg: 19.6, Max: 19.9, Diff: 2.4, Sum: 156.5]
[GC Worker End (ms): Min: 375.8, Avg: 375.9, Max: 375.9, Diff: 0.1]
[Code Root Fixup: 0.0 ms]
[Code Root Purge: 0.0 ms]
[Clear CT: 0.5 ms]
[Other: 1.0 ms]
[Choose CSet: 0.0 ms]
[Ref Proc: 0.4 ms]
[Ref Enq: 0.0 ms]
[Redirty Cards: 0.4 ms]
[Humongous Register: 0.0 ms]
[Humongous Reclaim: 0.0 ms]
[Free CSet: 0.0 ms]
[Eden: 12.0M(12.0M)->0.0B(14.0M) Survivors: 0.0B->2048.0K Heap: 12.6M(252.0M)->7848.3K(252.0M)]
[Times: user=0.08 sys=0.00, real=0.02 secs]
线程转储
"HeavyThread" #11 prio=5 os_prio=0 tid=0x000001885e78f000 nid=0x2e3c runnable [0x0000001b443fe000]
java.lang.Thread.State: RUNNABLE
at java.io.FileOutputStream.writeBytes(Native Method)
at java.io.FileOutputStream.write(Unknown Source)
at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
at java.io.BufferedOutputStream.flush(Unknown Source)
- locked <0x00000006c1407098> (a java.io.BufferedOutputStream)
at java.io.PrintStream.write(Unknown Source)
- locked <0x00000006c1406a90> (a java.io.PrintStream)
at sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)
at sun.nio.cs.StreamEncoder.implFlushBuffer(Unknown Source)
at sun.nio.cs.StreamEncoder.flushBuffer(Unknown Source)
- locked <0x00000006c14201b0> (a java.io.OutputStreamWriter)
at java.io.OutputStreamWriter.flushBuffer(Unknown Source)
at java.io.PrintStream.newLine(Unknown Source)
- eliminated <0x00000006c1406a90> (a java.io.PrintStream)
at java.io.PrintStream.println(Unknown Source)
- locked <0x00000006c1406a90> (a java.io.PrintStream)
at com.jeremy.tech.lab.CPULoadTester$HeavyLoadTask.run(CPULoadTester.java:13)
at java.lang.Thread.run(Unknown Source)
堆转储
这些文件都用在什么场景
GC日志
线程转储
内存转储
OutOfMemoryError
问题。我怎么获取这些文件呢
GC日志
•java 8及以前版本
-XX:+PrintGCDetails
-XX:+PrintGCDateStamps
-Xloggc:<file-path>
•java 9及以后版本
-Xlog:gc*:file=<file-path>
注:<file-path>为垃圾收集日志的生成文件路径
线程转储
jstack
工具来获取线程转储, jstack
在 JDK_HOME\bin
目录下。线程转储文件可以用如下方式获取:jstack -l <pid> > <file-path>
注:<pid>为应用进程号;<file-path>为线程转储文件生成的文件路径
堆转储
jmap
工具来获取堆转储, jmap
在 JDK_HOME/bin
目录下。获取堆转储文件用以下方法即可:jmap -dump:format=b,file=<file-path> <pid>
注:<pid>为应用进程号;<file-path>为堆转储文件生成的文件路径
分析工具
GC日志
•Gceasy (https://gceasy.io/)•IBM GC & Memory visualizer (https://www.ibm.com/support/pages/java-sdk-monitoring-and-post-mortem)•HP Jmeter (https://myenterpriselicense.hpe.com/cwp-ui/free-software/HPJMETER)•Google Garbage Cat (https://code.google.com/archive/a/eclipselabs.org/p/garbagecat)
线程转储
•fastThread (https://fastthread.io/)•Samurai (https://github.com/yusuke/samurai)•IBM Thread & Monitor analyzer (https://www.ibm.com/support/pages/java-sdk-monitoring-and-post-mortem)•Visual VM (https://visualvm.github.io/)
堆转储
•Eclipse MAT (https://www.eclipse.org/mat/)•HeapHero (https://heaphero.io/)•JVisualVM (https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jvisualvm.html)
最后
欢迎关注我的公众号“须弥零一”,原创技术文章第一时间推送。