Search in sources :

Example 1 with HISTORY

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

Example 2 with HISTORY

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();
}
Also used : SpongeImpl(org.spongepowered.common.SpongeImpl) HttpURLConnection(java.net.HttpURLConnection) JsonObject(com.google.gson.JsonObject) ConsoleSource(org.spongepowered.api.command.source.ConsoleSource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HISTORY(co.aikar.timings.TimingsManager.HISTORY) URL(java.net.URL) JsonObjectBuilder(co.aikar.util.JSONUtil.JsonObjectBuilder) IMPLEMENTATION(org.spongepowered.api.Platform.Component.IMPLEMENTATION) Platform(org.spongepowered.api.Platform) JsonElement(com.google.gson.JsonElement) InetAddress(java.net.InetAddress) Block(net.minecraft.block.Block) EntityTypes(org.spongepowered.api.entity.EntityTypes) Text(org.spongepowered.api.text.Text) RconSource(org.spongepowered.api.command.source.RconSource) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) ManagementFactory(java.lang.management.ManagementFactory) TextColors(org.spongepowered.api.text.format.TextColors) OutputStream(java.io.OutputStream) RuntimeMXBean(java.lang.management.RuntimeMXBean) TextActions(org.spongepowered.api.text.action.TextActions) CommandSource(org.spongepowered.api.command.CommandSource) Sponge(org.spongepowered.api.Sponge) Set(java.util.Set) IOException(java.io.IOException) Sets(com.google.common.collect.Sets) JSONUtil(co.aikar.util.JSONUtil) JsonArray(com.google.gson.JsonArray) BlockType(org.spongepowered.api.block.BlockType) Entry(java.util.Map.Entry) EntityType(org.spongepowered.api.entity.EntityType) GZIPOutputStream(java.util.zip.GZIPOutputStream) Joiner(com.google.common.base.Joiner) InputStream(java.io.InputStream) Platform(org.spongepowered.api.Platform) RuntimeMXBean(java.lang.management.RuntimeMXBean) EntityType(org.spongepowered.api.entity.EntityType) BlockType(org.spongepowered.api.block.BlockType) JsonObjectBuilder(co.aikar.util.JSONUtil.JsonObjectBuilder)

Example 3 with HISTORY

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();
}
Also used : HttpURLConnection(java.net.HttpURLConnection) JsonObject(com.google.gson.JsonObject) RuntimeMXBean(java.lang.management.RuntimeMXBean) PGZIPOutputStream(cn.nukkit.nbt.stream.PGZIPOutputStream) URL(java.net.URL) Date(java.util.Date) HISTORY(co.aikar.timings.TimingsManager.HISTORY) SimpleDateFormat(java.text.SimpleDateFormat) JsonUtil(cn.nukkit.timings.JsonUtil) Deflater(java.util.zip.Deflater) Server(cn.nukkit.Server) CommandSender(cn.nukkit.command.CommandSender) GsonBuilder(com.google.gson.GsonBuilder) ConsoleCommandSender(cn.nukkit.command.ConsoleCommandSender) TranslationContainer(cn.nukkit.lang.TranslationContainer) InetAddress(java.net.InetAddress) RemoteConsoleCommandSender(cn.nukkit.command.RemoteConsoleCommandSender) java.io(java.io) TextFormat(cn.nukkit.utils.TextFormat) Gson(com.google.gson.Gson) ManagementFactory(java.lang.management.ManagementFactory) JsonObject(com.google.gson.JsonObject) RuntimeMXBean(java.lang.management.RuntimeMXBean) JsonUtil(cn.nukkit.timings.JsonUtil)

Aggregations

HISTORY (co.aikar.timings.TimingsManager.HISTORY)3 JsonObject (com.google.gson.JsonObject)3 ManagementFactory (java.lang.management.ManagementFactory)3 RuntimeMXBean (java.lang.management.RuntimeMXBean)3 HttpURLConnection (java.net.HttpURLConnection)3 InetAddress (java.net.InetAddress)3 URL (java.net.URL)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 JsonArray (com.google.gson.JsonArray)2 java.io (java.io)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 GZIPOutputStream (java.util.zip.GZIPOutputStream)2 Server (cn.nukkit.Server)1 CommandSender (cn.nukkit.command.CommandSender)1 ConsoleCommandSender (cn.nukkit.command.ConsoleCommandSender)1 RemoteConsoleCommandSender (cn.nukkit.command.RemoteConsoleCommandSender)1 TranslationContainer (cn.nukkit.lang.TranslationContainer)1 PGZIPOutputStream (cn.nukkit.nbt.stream.PGZIPOutputStream)1