使用JMX(jconsole)监视JVM GC.how以获取年轻的GC信息和完整的GC信息?

时间:2015-04-23 06:45:50

标签: garbage-collection jvm

我可以获得“PS Scavenge,PS MarkSweep”属性:CollectionCount,CollectionTime通过JMX。但我的问题是:“ 哪一个是年轻的gc信息?哪一个是完整的gc信息? “我怎样才能获得有关GC的更多细节。

1 个答案:

答案 0 :(得分:0)

jstat是jstat GC信息。这两个是不同的。

以下bean:

import java.io.Serializable;

public class PerformanceBean implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = -6021047939070147624L;

    /*
     * Survivor space 0 utilization as a percentage of the space's current
     * capacity.
     */
    public final long jstatS0;

    /*
     * Survivor space 1 utilization as a percentage of the space's current
     * capacity.
     */
    public final long jstatS1;

    /*
     * Eden space utilization as a percentage of the space's current capacity.
     */

    public final long jstatE;

    /*
     * Old space utilization as a percentage of the space's current capacity.
     */

    public final long jstatO;
    /*
     * Permanent space utilization as a percentage of the space's current
     * capacity.
     */
    public final long jstatP;

    /* Number of young generation GC events. */
    public final long jstatYGC;

    /* Young generation garbage collection time. */
    public final long jstatYGCT;

    /* Number of full GC events. */
    public final long jstatFGC;

    /* Full garbage collection time. */
    public final long jstatFGCT;

    /* Total garbage collection time. */

    public final long jstatGCT;

    /* Operation System info */

    public final int availableProcessors;
    public final double systemLoadAverage;
    public final String osName;
    public final String arch;

    /*
     * 
     * Below is a picture showing an example of a memory pool:
     *<p>
     *<pre>
     *     +----------------------------------------------+
     *     +////////////////           |                  +
     *     +////////////////           |                  +
     *     +----------------------------------------------+
     *
     *     |--------|
     *            init
     *     |---------------|
     *            used
     *     |---------------------------|
     *               committed 
     *     |----------------------------------------------|
     *                           max
     *<pre>
     */

    /*
     * Memory Usage--heapMemoryUsage
     */
    public final long initHeap;
    public final long usedHeap;
    public final long committedHeap;
    public final long maxHeap;

    /* Memory Usage--nonHeapMemoryUsage */
    public final long initNonHeap;
    public final long usedNonHeap;
    public final long committedNonHeap;
    public final long maxNonHeap;

    public static class Builder {
        // Optional parameters - initialized to default values
        private long jstatS0 = 0;
        private long jstatS1 = 0;
        private long jstatE = 0;
        private long jstatO = 0;
        private long jstatP = 0;
        private long jstatYGC = 0;
        private long jstatYGCT = 0;
        private long jstatFGC = 0;
        private long jstatFGCT = 0;
        private long jstatGCT = 0;
        public int availableProcessors = 0;
        public double systemLoadAverage = 0;
        public String osName = "";
        public String arch = "";
        private long initHeap = 0;
        private long usedHeap = 0;
        private long committedHeap = 0;
        private long maxHeap = 0;
        private long initNonHeap = 0;
        private long usedNonHeap = 0;
        private long committedNonHeap = 0;
        private long maxNonHeap = 0;

        public Builder jstatS0(long val) {
            jstatS0 = val;
            return this;
        }

        public Builder jstatS1(long val) {
            jstatS1 = val;
            return this;
        }

        public Builder jstatE(long val) {
            jstatE = val;
            return this;
        }

        public Builder jstatO(long val) {
            jstatO = val;
            return this;
        }

        public Builder jstatP(long val) {
            jstatP = val;
            return this;
        }

        public Builder jstatYGC(long val) {
            jstatYGC = val;
            return this;
        }

        public Builder jstatYGCT(long val) {
            jstatYGCT = val;
            return this;
        }

        public Builder jstatFGC(long val) {
            jstatFGC = val;
            return this;
        }

        public Builder jstatFGCT(long val) {
            jstatFGCT = val;
            return this;
        }
        public Builder jstatGCT(long val) {
            jstatGCT = val;
            return this;
        }

        public Builder availableProcessors(int val) {
            availableProcessors = val;
            return this;
        }

        public Builder systemLoadAverage(double val) {
            systemLoadAverage = val;
            return this;
        }

        public Builder arch(String val) {
            arch = val;
            return this;
        }

        public Builder osName(String val) {
            osName = val;
            return this;
        }

        public Builder initHeap(long val) {
            initHeap = val;
            return this;
        }

        public Builder usedHeap(long val) {
            usedHeap = val;
            return this;
        }

        public Builder committedHeap(long val) {
            committedHeap = val;
            return this;
        }

        public Builder maxHeap(long val) {
            maxHeap = val;
            return this;
        }

        public Builder initNonHeap(long val) {
            initNonHeap = val;
            return this;
        }

        public Builder usedNonHeap(long val) {
            usedNonHeap = val;
            return this;
        }

        public Builder committedNonHeap(long val) {
            committedNonHeap = val;
            return this;
        }

        public Builder maxNonHeap(long val) {
            maxNonHeap = val;
            return this;
        }
        public PerformanceBean build(){
            return new PerformanceBean(this);
        }

    } 

    private PerformanceBean(Builder builder) {
        jstatS0 = builder.jstatS0;
        jstatS1 = builder.jstatS1;
        jstatE = builder.jstatE;
        jstatO = builder.jstatO;
        jstatP = builder.jstatP;
        jstatYGC = builder.jstatYGC;
        jstatYGCT = builder.jstatYGCT;
        jstatFGC = builder.jstatFGC;
        jstatFGCT = builder.jstatFGCT;
        jstatGCT = builder.jstatGCT;
        availableProcessors = builder.availableProcessors;
        systemLoadAverage = builder.systemLoadAverage;
        osName = builder.osName;
        arch = builder.arch;
        initHeap = builder.initHeap;
        usedHeap = builder.usedHeap;
        committedHeap = builder.committedHeap;
        maxHeap = builder.maxHeap;
        initNonHeap = builder.initNonHeap;
        usedNonHeap = builder.usedNonHeap;
        committedNonHeap = builder.committedNonHeap;
        maxNonHeap = builder.maxNonHeap;

    } 
//  public static long getSerialversionuid() {
//      return serialVersionUID;
//  }
//  public long getJstatS0() {
//      return jstatS0;
//  }
//  public long getJstatS1() {
//      return jstatS1;
//  }
//  public long getJstatE() {
//      return jstatE;
//  }
//  public long getJstatO() {
//      return jstatO;
//  }
//  public long getJstatP() {
//      return jstatP;
//  }
//  public long getJstatYGC() {
//      return jstatYGC;
//  }
//  public long getJstatYGCT() {
//      return jstatYGCT;
//  }
//  public long getJstatFGC() {
//      return jstatFGC;
//  }
//  public long getJstatFGCT() {
//      return jstatFGCT;
//  }
//  public long getJstatGCT() {
//      return jstatGCT;
//  }
//  public double getSystemLoadAverage() {
//      return systemLoadAverage;
//  }
//  public String getOsName() {
//      return osName;
//  }
//  public String getArch() {
//      return arch;
//  }
//  public long getInitHeap() {
//      return initHeap;
//  }
//  public long getUsedHeap() {
//      return usedHeap;
//  }
//  public long getCommittedHeap() {
//      return committedHeap;
//  }
//  public long getMaxHeap() {
//      return maxHeap;
//  }
//  public long getInitNonHeap() {
//      return initNonHeap;
//  }
//  public long getUsedNonHeap() {
//      return usedNonHeap;
//  }
//  public long getCommittedNonHeap() {
//      return committedNonHeap;
//  }
//  public long getMaxNonHeap() {
//      return maxNonHeap;
//  }

}