zoukankan      html  css  js  c++  java
  • JVM探秘:jstat查看JVM统计信息

    本系列笔记主要基于《深入理解Java虚拟机:JVM高级特性与最佳实践 第2版》,是这本书的读书笔记。

    jstat命令用来查看JVM统计信息,可以查看类加载信息、垃圾收集的信息、JIT编译信息等等,功能非常丰富。

    所有的JDK工具都可以在Oracle官网的 Java Tools Reference 文档中找到使用说明,这是主要参考,包括命令格式、参数内容、输出信息等等。

    jstat命令格式:

    jstat [ generalOption | outputOptions vmid [ interval[s|ms] [ count ] ]
    

    jstat命令的帮助信息:

    image

    jstat统计类加载信息

    jstat命令使用-class参数可以统计类加载信息,命令举例:

    jstat -class 21060 1000 10
    

    -class表示查看类加载统计信息,21060是pid,1000表示每1000毫秒打印一次,10表示打印10次。
    输出如下:

    image

    输出信息中,每一列的含义可以查阅 Java Tools Reference 文档,从左到右依次,Loaded表示加载的类的个数,Bytes表示加载了多少KB,Unloaded表示卸载的类的个数,Bytes表示卸载了多少KB,Time表示类加载和卸载花费的时间。

    jstat统计垃圾收集信息

    jstat命令中,常用的跟垃圾收集相关的统计参数有:-gc、-gccapacity、-gcutil、-gccause、-gcnew、-gcold。

    jstat -gc

    -gc参数用来查看Java堆的垃圾收集统计信息,举例如下:

    jstat -gc 21060 1000 3
    

    其中,21060是pid,1000表示每1000毫秒打印一次,3表示打印3次。
    输出如下:

    image

    同样的,输出信息中,每一列的含义可以查阅 Java Tools Reference 文档,依次如下:

    S0C: 第1个Survivor空间的容量 Current survivor space 0 capacity (kB).
    S1C: 第2个Survivor空间的容量(kB).
    S0U: 第1个Survivor空间中已经使用的容量 Survivor space 0 utilization (kB).
    S1U: 第2个Survivor空间中已经使用的容量(kB).
    EC: Eden空间的容量(kB).
    EU: Eden空间中已经使用的容量(kB).
    OC: 老年代Old空间的容量(kB).
    OU: 老年代Old空间已经使用的容量(kB).
    MC: 元空间Metaspace的容量(kB).
    MU: 元空间Metaspace已经使用的容量(kB).
    CCSC: 压缩类空间的容量 Compressed class space capacity (kB).
    CCSU: 压缩类空间已经使用的容量(kB).
    YGC: Young GC发生的次数.
    YGCT: Young GC花费的时间.
    FGC: Full GC发生的次数.
    FGCT: Full GC花费的时间.
    GCT: 所有的GC花费的总时间.
    

    jstat -gccapacity

    -gccapacity参数用来统计各个内存区域的容量使用的最大最小值,例如使用到的最大值、最小值、当前使用值等等,举例如下:

    jstat -gccapacity 21060
    

    输出如下:

    image

    输出信息中,每一列的含义可以查阅 Java Tools Reference 文档,就不再一一列举了。基本都是统计的新生代老年代使用的最小值、最大值、当前值,Survivor和Eden空间的当前值,元空间和压缩类空间的最小值、最大值、当前值。

    jstat -gcutil

    -gcutil参数统计的是各个内存区域使用率,已使用容量的百分比,举例如下:

    jstat -gcutil 21060
    

    输出如下:

    image

    输出信息中,统计的都是Survivor、Eden、老年代、元空间、压缩类空间等的使用百分比。

    jstat统计JIT编译信息

    jstat命令中,跟JIT编译相关的统计参数有:-compiler、-printcompilation。
    -compiler参数统计的是JIT编译信息,举例如下:

    jstat -compiler 21060
    

    输出如下:

    image

    输出信息中,从左到右每列依次是,Compiled表示完成了多少次JIT编译,Failed表示编译失败的次数,Invalid表示无效的编译次数,Time表示JIT编译总共花费的时间,FailedType最后一次编译失败的编译类型,FailedMethod最后一次编译失败的类名和方法名。

    jstat的其他参数

    除了上面列举的几个,jstat还有很多其他参数,使用手册参考 Java Tools Reference 文档,jstat所有统计参数列举如下:

    class: Displays statistics about the behavior of the class loader.
    compiler: Displays statistics about the behavior of the Java HotSpot VM Just-in-Time compiler.
    gc: Displays statistics about the behavior of the garbage collected heap.
    gccapacity: Displays statistics about the capacities of the generations and their corresponding spaces.
    gccause: Displays a summary about garbage collection statistics (same as -gcutil), with the cause of the last and current (when applicable) garbage collection events.
    gcnew: Displays statistics of the behavior of the new generation.
    gcnewcapacity: Displays statistics about the sizes of the new generations and its corresponding spaces.
    gcold: Displays statistics about the behavior of the old generation and metaspace statistics.
    gcoldcapacity: Displays statistics about the sizes of the old generation.
    gcmetacapacity: Displays statistics about the sizes of the metaspace.
    gcutil: Displays a summary about garbage collection statistics.
    printcompilation: Displays Java HotSpot VM compilation method statistics.
    
  • 相关阅读:
    hibernate中的配置参数详解
    js 提示框
    Caused by: java.sql.SQLException: 数字溢出
    什么是Assembly(程序集)?
    我的邮箱
    hdu 3746(KMP的循环节问题)
    hdu 1176(一道简单的dp)
    hdu 1385(求出最短路并输出最短路径)
    hdu 1003(最大连续字串)
    hdu 4512(最长公共递增子序列加强版)
  • 原文地址:https://www.cnblogs.com/cellei/p/12173952.html
Copyright © 2011-2022 走看看