how to count zgc result(gc time and heap usage)

476 views Asked by At

the result of jstat -gcutil is suitable for generational garbage collection, but how can I count the zgc result?

1

There are 1 answers

5
Eugene On

afaik, every GC algorithm implements its own statistics, meaning that is a collector specific output. Yes, ZGC is not generational, as such some of the statistics will not be present, which is normal, but otherwise it simply works?

If I have a sample as :

 public class DeleteMe {

    public static void main(String[] args) {
        for(;;){
            LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(500));
            System.out.println(allocate());
        }
    }

    static int allocate() {
        int [] b = new int[10_000];
        for(int i=0;i<10_000;++i){
            b[i] = i + ThreadLocalRandom.current().nextInt();
        }
        return Arrays.hashCode(b);
    }

}

And then take some snapshots of :

jstat -gcutil <PID>

I do see numbers like:

  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT    CGC    CGCT     GCT   
   -      -      -  15.38  76.33  74.80      -        -     -        -    63    0.005    0.005

S0/S1/E are blank because they simply don't exist (there is no young generation at all). Same argument stays true for: YGC/YGCT/FGC/FGCT, simply because there is no such thing in ZGC. You can find what they mean here, for example. There is also this Q&A that explains some options that are not present in the documentation above.