Search in sources :

Example 1 with DragonProxy

use of org.dragonet.proxy.DragonProxy in project DragonProxy by DragonetMC.

the class TimingsExport method reportTimings.

/**
 * Builds a JSON timings report and sends it to Aikar's viewer
 *
 * @param sender Sender that issued the command
 */
public static void reportTimings(UpstreamSession sender) {
    JsonObject out = new JsonObject();
    out.addProperty("version", DragonProxy.getInstance().getVersion());
    // TODO
    out.addProperty("maxplayers", 2);
    out.addProperty("start", TimingsManager.timingStart / 1000);
    out.addProperty("end", System.currentTimeMillis() / 1000);
    out.addProperty("sampletime", (System.currentTimeMillis() - TimingsManager.timingStart) / 1000);
    if (!Timings.isPrivacy()) {
        // TODO
        out.addProperty("server", "DragonProxy : name");
        out.addProperty("motd", DragonProxy.getInstance().getMotd());
        out.addProperty("online-mode", DragonProxy.getInstance().getAuthMode().equals("online"));
        // "data:image/png;base64,"
        out.addProperty("icon", "");
    }
    final Runtime runtime = Runtime.getRuntime();
    RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
    JsonObject system = new JsonObject();
    system.addProperty("timingcost", getCost());
    system.addProperty("name", System.getProperty("os.name"));
    system.addProperty("version", System.getProperty("os.version"));
    system.addProperty("jvmversion", System.getProperty("java.version"));
    system.addProperty("arch", System.getProperty("os.arch"));
    system.addProperty("maxmem", runtime.maxMemory());
    system.addProperty("cpu", runtime.availableProcessors());
    system.addProperty("runtime", ManagementFactory.getRuntimeMXBean().getUptime());
    system.addProperty("flags", String.join(" ", runtimeBean.getInputArguments()));
    system.add("gc", JsonUtil.mapToObject(ManagementFactory.getGarbageCollectorMXBeans(), (input) -> new JsonUtil.JSONPair(input.getName(), JsonUtil.toArray(input.getCollectionCount(), input.getCollectionTime()))));
    out.add("system", system);
    TimingsHistory[] history = HISTORY.toArray(new TimingsHistory[HISTORY.size() + 1]);
    // Current snapshot
    history[HISTORY.size()] = new TimingsHistory();
    JsonObject timings = new JsonObject();
    for (TimingIdentifier.TimingGroup group : TimingIdentifier.GROUP_MAP.values()) {
        for (Timing id : group.timings.stream().toArray(Timing[]::new)) {
            if (!id.timed && !id.isSpecial())
                continue;
            timings.add(String.valueOf(id.id), JsonUtil.toArray(group.id, id.name));
        }
    }
    JsonObject idmap = new JsonObject();
    idmap.add("groups", JsonUtil.mapToObject(TimingIdentifier.GROUP_MAP.values(), (group) -> new JsonUtil.JSONPair(group.id, group.name)));
    idmap.add("handlers", timings);
    idmap.add("worlds", JsonUtil.mapToObject(TimingsHistory.levelMap.entrySet(), (entry) -> new JsonUtil.JSONPair(entry.getValue(), entry.getKey())));
    idmap.add("tileentity", JsonUtil.mapToObject(TimingsHistory.blockEntityMap.entrySet(), (entry) -> new JsonUtil.JSONPair(entry.getKey(), entry.getValue())));
    idmap.add("entity", JsonUtil.mapToObject(TimingsHistory.entityMap.entrySet(), (entry) -> new JsonUtil.JSONPair(entry.getKey(), entry.getValue())));
    out.add("idmap", idmap);
    // Information about plugins, needed but empty
    out.add("plugins", new JsonArray());
    // Information on the proxy Config
    JsonObject config = new JsonObject();
    if (!Timings.getIgnoredConfigSections().contains("all")) {
        JsonObject jsonConfig = JsonUtil.toObject(DragonProxy.getInstance().getConfig());
        Timings.getIgnoredConfigSections().forEach(jsonConfig::remove);
        config.add("DragonProxy", jsonConfig);
    } else {
        config.add("DragonProxy", null);
    }
    out.add("config", config);
    new TimingsExport(sender, out, history).start();
}
Also used : HttpURLConnection(java.net.HttpURLConnection) JsonObject(com.google.gson.JsonObject) RuntimeMXBean(java.lang.management.RuntimeMXBean) URL(java.net.URL) Date(java.util.Date) HISTORY(co.aikar.timings.TimingsManager.HISTORY) SimpleDateFormat(java.text.SimpleDateFormat) UpstreamSession(org.dragonet.proxy.network.UpstreamSession) GsonBuilder(com.google.gson.GsonBuilder) InetAddress(java.net.InetAddress) JsonArray(com.google.gson.JsonArray) java.io(java.io) Gson(com.google.gson.Gson) JsonUtil(org.dragonet.common.utilities.JsonUtil) GZIPOutputStream(java.util.zip.GZIPOutputStream) DragonProxy(org.dragonet.proxy.DragonProxy) ManagementFactory(java.lang.management.ManagementFactory) JsonObject(com.google.gson.JsonObject) RuntimeMXBean(java.lang.management.RuntimeMXBean) JsonArray(com.google.gson.JsonArray)

Aggregations

HISTORY (co.aikar.timings.TimingsManager.HISTORY)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 java.io (java.io)1 ManagementFactory (java.lang.management.ManagementFactory)1 RuntimeMXBean (java.lang.management.RuntimeMXBean)1 HttpURLConnection (java.net.HttpURLConnection)1 InetAddress (java.net.InetAddress)1 URL (java.net.URL)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 JsonUtil (org.dragonet.common.utilities.JsonUtil)1 DragonProxy (org.dragonet.proxy.DragonProxy)1 UpstreamSession (org.dragonet.proxy.network.UpstreamSession)1