JVM

12-虚拟机性能监控、故障处理工具

2021-06-17  本文已影响0人  紫荆秋雪_文

从实践的角度去认识虚拟机内存管理的世界,给一个系统定位问题的时候,知识、经验是关键基础,数据是依据,工具是运用知识处理数据(数据包括但不限于异常堆栈、虚拟机运行日志、垃圾收集器日志、线程快照(threaddump./javacore文件)、堆转储快照(heapdump/hprof文件))的手段。恰当使用虚拟机故障处理分析的工具可以提升我们分析数据、定位并解决问题的效率,但应当意识到工具永远都是知识技能的一层包装,没有什么工具是“秘密武器”,拥有了就能“包治百病”。

一、基础故障处理工具

JDK中bin目录下工具

jps : 虚拟机进程状况工具

jps  或  jps -l
jps工具主要选项.png

jstat : 虚拟机统计信息监视工具

jstat [ option vmid [interval[s|ms] [count]] ]
[protocol:][//]lvmid[@hostname[:port]/servername]
jstat -gc 2764 250 20
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT
  1.78   0.00  53.99  70.64  95.96  93.66     52    1.772     4    1.185    2.956

jinfo : Java配置信息工具

jinfo [ option ] 16330
jinfo -flag  CMSInitiatingOccupancyFraction 16330

jmap : Java内存映像工具

jmap [ option ] vmid
jmap -dump:format=b,file=raven.bin 16793
jmap工具主要选项.png

jhat : 虚拟机堆转储快照分析工具

jhat raven.bin
Reading from raven.bin...
Dump file created Tue Jun 15 14:34:23 CST 2021
Snapshot read, resolving...
Resolving 6118027 objects...
Chasing references, expect 1223 dots.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Eliminating duplicate references.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.

jstack : Java堆栈跟踪工具

jstack [ option ] vmid

基础工具总结

二、可视化故障处理工具

JDK中除了附带大量的命令行工具外,还提供了几个功能集成度更高的可视化工具,用户可以使用这些可视化工具以更加便捷的方式进行进程故障诊断和调试工作。主要包括JConsole、JHSDB、VisualVM和JMC四个。

JHSDB:基于服务性代理的调试工具

JHSDB实例测试
package com.lkty.jhsdb;


/**
 * JHSDB 测试代码
 *
 * staticObj、instanceObj、localObj 存放在哪里?
 */
public class JhsdbTest {

    private static class ObjectHolder {}

    static class Test {
        static ObjectHolder staticObj = new ObjectHolder();
        ObjectHolder instanceObj = new ObjectHolder();

        void foo() {
            ObjectHolder localObj = new ObjectHolder();
            System.out.println(" done ");
        }
    }
    public static void main(String[] args) {
        Test test = new Test();
        test.foo();
    }
}
-Xmx10m -XX:+UseSerialGC -XX:-UseCompressedOops
上一篇下一篇

猜你喜欢

热点阅读