Пример #1
0
  /**
   * 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()
            // Get some basic system details about the server
            .add(
                "version",
                platform
                    .getImplementation()
                    .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", SpongeImpl.getGame().getServer().getMotd().toPlain())
          .add("online-mode", SpongeImpl.getGame().getServer().getOnlineMode())
          .add("icon", MinecraftServer.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;
    }

    history[i] = new TimingHistory(); // Current snapshot
    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) -> {
                      return JSONUtil.singleObjectPair(
                          ((SpongeEntityType) entityType).entityTypeId, 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();
  }
Пример #2
0
  static long getCost() {
    // Benchmark the users System.nanotime() for cost basis
    int passes = 200;
    TimingHandler SAMPLER1 = SpongeTimingsFactory.ofSafe("Timings Sampler 1");
    TimingHandler SAMPLER2 = SpongeTimingsFactory.ofSafe("Timings Sampler 2");
    TimingHandler SAMPLER3 = SpongeTimingsFactory.ofSafe("Timings Sampler 3");
    TimingHandler SAMPLER4 = SpongeTimingsFactory.ofSafe("Timings Sampler 4");
    TimingHandler SAMPLER5 = SpongeTimingsFactory.ofSafe("Timings Sampler 5");
    TimingHandler SAMPLER6 = SpongeTimingsFactory.ofSafe("Timings Sampler 6");

    long start = System.nanoTime();
    for (int i = 0; i < passes; i++) {
      SAMPLER1.startTiming();
      SAMPLER2.startTiming();
      SAMPLER3.startTiming();
      SAMPLER3.stopTiming();
      SAMPLER4.startTiming();
      SAMPLER5.startTiming();
      SAMPLER6.startTiming();
      SAMPLER6.stopTiming();
      SAMPLER5.stopTiming();
      SAMPLER4.stopTiming();
      SAMPLER2.stopTiming();
      SAMPLER1.stopTiming();
    }
    long timingsCost = (System.nanoTime() - start) / passes / 6;
    SAMPLER1.reset(true);
    SAMPLER2.reset(true);
    SAMPLER3.reset(true);
    SAMPLER4.reset(true);
    SAMPLER5.reset(true);
    SAMPLER6.reset(true);
    return timingsCost;
  }