use of co.aikar.timings.TimingsManager.HISTORY 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();
}
use of co.aikar.timings.TimingsManager.HISTORY in project SpongeCommon by SpongePowered.
the class TimingsExport method reportTimings.
/**
* Builds an XML report of the timings to be uploaded for parsing.
*
* @param sender Who to report to
*/
static void reportTimings(CommandSource sender) {
Platform platform = SpongeImpl.getGame().getPlatform();
JsonObjectBuilder builder = JSONUtil.objectBuilder().add("version", platform.getContainer(IMPLEMENTATION).getVersion().orElse(platform.getMinecraftVersion().getName() + "-DEV")).add("maxplayers", SpongeImpl.getGame().getServer().getMaxPlayers()).add("start", TimingsManager.timingStart / 1000).add("end", System.currentTimeMillis() / 1000).add("sampletime", (System.currentTimeMillis() - TimingsManager.timingStart) / 1000);
if (!TimingsManager.privacy) {
builder.add("server", getServerName()).add("motd", Sponge.getServer().getMotd().toPlain()).add("online-mode", Sponge.getServer().getOnlineMode()).add("icon", SpongeImpl.getServer().getServerStatusResponse().getFavicon());
}
final Runtime runtime = Runtime.getRuntime();
RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
builder.add("system", JSONUtil.objectBuilder().add("timingcost", getCost()).add("name", System.getProperty("os.name")).add("version", System.getProperty("os.version")).add("jvmversion", System.getProperty("java.version")).add("arch", System.getProperty("os.arch")).add("maxmem", runtime.maxMemory()).add("cpu", runtime.availableProcessors()).add("runtime", ManagementFactory.getRuntimeMXBean().getUptime()).add("flags", RUNTIME_FLAG_JOINER.join(runtimeBean.getInputArguments())).add("gc", JSONUtil.mapArrayToObject(ManagementFactory.getGarbageCollectorMXBeans(), (input) -> {
return JSONUtil.singleObjectPair(input.getName(), JSONUtil.arrayOf(input.getCollectionCount(), input.getCollectionTime()));
})));
Set<BlockType> blockTypeSet = Sets.newHashSet();
Set<EntityType> entityTypeSet = Sets.newHashSet();
int size = HISTORY.size();
TimingHistory[] history = new TimingHistory[size + 1];
int i = 0;
for (TimingHistory timingHistory : HISTORY) {
blockTypeSet.addAll(timingHistory.blockTypeSet);
entityTypeSet.addAll(timingHistory.entityTypeSet);
history[i++] = timingHistory;
}
// Current snapshot
history[i] = new TimingHistory();
blockTypeSet.addAll(history[i].blockTypeSet);
entityTypeSet.addAll(history[i].entityTypeSet);
JsonObjectBuilder handlersBuilder = JSONUtil.objectBuilder();
for (TimingIdentifier.TimingGroup group : TimingIdentifier.GROUP_MAP.values()) {
for (TimingHandler id : group.handlers) {
if (!id.timed && !id.isSpecial()) {
continue;
}
handlersBuilder.add(id.id, JSONUtil.arrayOf(group.id, id.name));
}
}
builder.add("idmap", JSONUtil.objectBuilder().add("groups", JSONUtil.mapArrayToObject(TimingIdentifier.GROUP_MAP.values(), (group) -> {
return JSONUtil.singleObjectPair(group.id, group.name);
})).add("handlers", handlersBuilder).add("worlds", JSONUtil.mapArrayToObject(TimingHistory.worldMap.entrySet(), (entry) -> {
return JSONUtil.singleObjectPair(entry.getValue(), entry.getKey());
})).add("tileentity", JSONUtil.mapArrayToObject(blockTypeSet, (blockType) -> {
return JSONUtil.singleObjectPair(Block.getIdFromBlock((Block) blockType), blockType.getId());
})).add("entity", JSONUtil.mapArrayToObject(entityTypeSet, (entityType) -> {
if (entityType == EntityTypes.UNKNOWN) {
return null;
}
return JSONUtil.singleObjectPair(TimingsPls.getEntityId(entityType), entityType.getId());
})));
// Information about loaded plugins
builder.add("plugins", JSONUtil.mapArrayToObject(SpongeImpl.getGame().getPluginManager().getPlugins(), (plugin) -> {
return JSONUtil.objectBuilder().add(plugin.getId(), JSONUtil.objectBuilder().add("version", plugin.getVersion().orElse("")).add("description", plugin.getDescription().orElse("")).add("website", plugin.getUrl().orElse("")).add("authors", AUTHOR_LIST_JOINER.join(plugin.getAuthors()))).build();
}));
// Information on the users Config
builder.add("config", JSONUtil.objectBuilder().add("sponge", serializeConfigNode(SpongeImpl.getGlobalConfig().getRootNode())));
new TimingsExport(sender, builder.build(), history).start();
}
use of co.aikar.timings.TimingsManager.HISTORY in project Nukkit by Nukkit.
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(CommandSender sender) {
JsonObject out = new JsonObject();
out.addProperty("version", Server.getInstance().getVersion());
out.addProperty("maxplayers", Server.getInstance().getMaxPlayers());
out.addProperty("start", TimingsManager.timingStart / 1000);
out.addProperty("end", System.currentTimeMillis() / 1000);
out.addProperty("sampletime", (System.currentTimeMillis() - TimingsManager.timingStart) / 1000);
if (!Timings.isPrivacy()) {
out.addProperty("server", Server.getInstance().getName());
out.addProperty("motd", Server.getInstance().getMotd());
// In MCPE we have permanent offline mode.
out.addProperty("online-mode", false);
// "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 loaded plugins
out.add("plugins", JsonUtil.mapToObject(Server.getInstance().getPluginManager().getPlugins().values(), (plugin) -> {
JsonObject jsonPlugin = new JsonObject();
jsonPlugin.addProperty("version", plugin.getDescription().getVersion());
// Sounds legit
jsonPlugin.addProperty("description", plugin.getDescription().getDescription());
jsonPlugin.addProperty("website", plugin.getDescription().getWebsite());
jsonPlugin.addProperty("authors", String.join(", ", plugin.getDescription().getAuthors()));
return new JsonUtil.JSONPair(plugin.getName(), jsonPlugin);
}));
// Information on the users Config
JsonObject config = new JsonObject();
if (!Timings.getIgnoredConfigSections().contains("all")) {
JsonObject nukkit = JsonUtil.toObject(Server.getInstance().getConfig().getRootSection());
Timings.getIgnoredConfigSections().forEach(nukkit::remove);
config.add("nukkit", nukkit);
} else {
config.add("nukkit", null);
}
out.add("config", config);
new TimingsExport(sender, out, history).start();
}
Aggregations