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();
}
Aggregations