All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ajjpj.asysmon.servlet.memgc.AMemGcPageDefinition Maven / Gradle / Ivy

There is a newer version: 1.0-pre28
Show newest version
package com.ajjpj.asysmon.servlet.memgc;

import com.ajjpj.abase.io.AJsonSerHelper;
import com.ajjpj.asysmon.ASysMonApi;
import com.ajjpj.asysmon.impl.ASysMonConfigurer;
import com.ajjpj.asysmon.config.presentation.APresentationPageDefinition;

import java.io.IOException;
import java.util.List;


/**
 * @author arno
 */
public class AMemGcPageDefinition implements APresentationPageDefinition {
    private final int bufferSize;

    public AMemGcPageDefinition(int bufferSize) {
        this.bufferSize = bufferSize;
    }

    private volatile GcDataSink gcDataSink;

    @Override public String getId() {
        return "memgc";
    }

    @Override public String getShortLabel() {
        return "GC View";
    }

    @Override public String getFullLabel() {
        return "Garbage Collection History";
    }

    @Override public String getHtmlFileName() {
        return "memgc.html";
    }

    @Override public String getControllerName() {
        return "CtrlMemGc";
    }

    @Override public void init(ASysMonApi sysMon) {
        gcDataSink = new GcDataSink(bufferSize);
        ASysMonConfigurer.addDataSink(sysMon, gcDataSink);
    }

    @Override public boolean handleRestCall(String service, List params, AJsonSerHelper json) throws IOException {
        if("getData".equals(service)) {
            serveData(json);
            return true;
        }

        return false;
    }

    private void serveData(AJsonSerHelper json) throws IOException {
        json.startObject();

        json.writeKey("gcs");
        json.startArray();
        for(GcDetails gc: gcDataSink.getData()) {
            serveGcDetails(json, gc);
        }
        json.endArray();

        json.endObject();

    }

    private void serveGcDetails(AJsonSerHelper json, GcDetails gc) throws IOException {
        json.startObject();

        json.writeKey("type");
        json.writeStringLiteral(gc.gcType);

        json.writeKey("algorithm");
        json.writeStringLiteral(gc.algorithm);

        json.writeKey("cause");
        json.writeStringLiteral(gc.cause);

        json.writeKey("startMillis");
        json.writeNumberLiteral(gc.startMillis, 0);

        json.writeKey("durationNanos");
        json.writeNumberLiteral(gc.durationNanos, 0);

        json.writeKey("mem");
        serveMemDetails(json, gc.memDetails);

        json.endObject();
    }

    private void serveMemDetails(AJsonSerHelper json, List memDetails) throws IOException {
        json.startObject();

        for(GcMemDetails mem: memDetails) {
            json.writeKey(mem.memKind);
            json.startObject();

            json.writeKey("usedBefore");
            json.writeNumberLiteral(mem.usedBefore, 0);

            json.writeKey("usedAfter");
            json.writeNumberLiteral(mem.usedAfter, 0);

            json.writeKey("committedBefore");
            json.writeNumberLiteral(mem.committedBefore, 0);

            json.writeKey("committedAfter");
            json.writeNumberLiteral(mem.committedAfter, 0);

            json.endObject();
        }

        json.endObject();
    }

    //TODO getMostRecentTimestamp
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy