Ejemplo n.º 1
0
 JsonObject export() {
   return JSONUtil.objectBuilder()
       .add("s", this.startTime)
       .add("e", this.endTime)
       .add("tk", this.totalTicks)
       .add("tm", this.totalTime)
       .add("w", this.worlds)
       .add(
           "h",
           JSONUtil.mapArray(
               this.entries, (entry) -> entry.data.count == 0 ? null : entry.export()))
       .add("mp", JSONUtil.mapArray(this.minuteReports, MinuteReport::export))
       .build();
 }
Ejemplo n.º 2
0
  @Override
  public void run() {
    this.sender.sendMessage(Text.of(TextColors.GREEN, "Preparing Timings Report..."));

    this.out.add("data", JSONUtil.mapArray(this.history, TimingHistory::export));

    String response = null;
    try {
      HttpURLConnection con =
          (HttpURLConnection) new URL("http://timings.aikar.co/post").openConnection();
      con.setDoOutput(true);
      con.setRequestProperty(
          "User-Agent",
          "Sponge/" + getServerName() + "/" + InetAddress.getLocalHost().getHostName());
      con.setRequestMethod("POST");
      con.setInstanceFollowRedirects(false);

      OutputStream request =
          new GZIPOutputStream(con.getOutputStream()) {

            {
              this.def.setLevel(7);
            }
          };

      request.write(JSONUtil.toString(this.out).getBytes("UTF-8"));
      request.close();

      response = getResponse(con);

      if (con.getResponseCode() != 302) {
        this.sender.sendMessage(
            Text.of(
                TextColors.RED,
                "Upload Error: " + con.getResponseCode() + ": " + con.getResponseMessage()));
        this.sender.sendMessage(Text.of(TextColors.RED, "Check your logs for more information"));
        if (response != null) {
          SpongeImpl.getLogger().fatal(response);
        }
        return;
      }

      String location = con.getHeaderField("Location");
      this.sender.sendMessage(
          Text.of(
              TextColors.GREEN,
              "View Timings Report: ",
              TextActions.openUrl(new URL(location)),
              location));
      if (!(this.sender instanceof ConsoleSource)) {
        SpongeImpl.getLogger().info("View Timings Report: " + location);
      }

      if (response != null && !response.isEmpty()) {
        SpongeImpl.getLogger().info("Timing Response: " + response);
      }
    } catch (IOException ex) {
      this.sender.sendMessage(
          Text.of(TextColors.RED, "Error uploading timings, check your logs for more information"));
      if (response != null) {
        SpongeImpl.getLogger().fatal(response);
      }
      SpongeImpl.getLogger().fatal("Could not paste timings", ex);
    }
  }
Ejemplo n.º 3
0
  TimingHistory() {
    this.endTime = System.currentTimeMillis() / 1000;
    this.startTime = TimingsManager.historyStart / 1000;
    if (timedTicks % 1200 != 0 || MINUTE_REPORTS.isEmpty()) {
      this.minuteReports = MINUTE_REPORTS.toArray(new MinuteReport[MINUTE_REPORTS.size() + 1]);
      this.minuteReports[this.minuteReports.length - 1] = new MinuteReport();
    } else {
      this.minuteReports = MINUTE_REPORTS.toArray(new MinuteReport[MINUTE_REPORTS.size()]);
    }
    long ticks = 0;
    for (MinuteReport mp : this.minuteReports) {
      ticks += mp.ticksRecord.timed;
    }
    this.totalTicks = ticks;
    this.totalTime = FULL_SERVER_TICK.record.totalTime;
    this.entries = new TimingHistoryEntry[TimingsManager.HANDLERS.size()];

    int i = 0;
    for (TimingHandler handler : TimingsManager.HANDLERS) {
      this.entries[i++] = new TimingHistoryEntry(handler);
    }

    final Map<EntityType, Counter> entityCounts =
        MRUMapCache.of(LoadingMap.of(Maps.newHashMap(), Counter.loader()));
    final Map<BlockType, Counter> tileEntityCounts =
        MRUMapCache.of(LoadingMap.of(Maps.newHashMap(), Counter.loader()));
    // Information about all loaded chunks/entities
    this.worlds =
        JSONUtil.mapArrayToObject(
            SpongeImpl.getGame().getServer().getWorlds(),
            (world) -> {
              return JSONUtil.singleObjectPair(
                  String.valueOf(worldMap.get(world.getName())),
                  JSONUtil.mapArray(
                      world.getLoadedChunks(),
                      (chunk) -> {
                        entityCounts.clear();
                        tileEntityCounts.clear();

                        for (Entity entity : chunk.getEntities()) {
                          if (entity.getType() == null) {
                            SpongeImpl.getLogger().error("Entity is not registered {}", entity);
                            continue;
                          }
                          entityCounts.get(entity.getType()).increment();
                        }

                        for (TileEntity tileEntity : chunk.getTileEntities()) {
                          tileEntityCounts.get(tileEntity.getBlock().getType()).increment();
                        }

                        if (tileEntityCounts.isEmpty() && entityCounts.isEmpty()) {
                          return null;
                        }
                        return JSONUtil.arrayOf(
                            chunk.getPosition().getX(),
                            chunk.getPosition().getZ(),
                            JSONUtil.mapArrayToObject(
                                entityCounts.entrySet(),
                                (entry) -> {
                                  if (entry.getKey() == EntityTypes.UNKNOWN) {
                                    return null;
                                  }
                                  this.entityTypeSet.add(entry.getKey());
                                  return JSONUtil.singleObjectPair(
                                      ((SpongeEntityType) entry.getKey()).entityTypeId,
                                      entry.getValue().count());
                                }),
                            JSONUtil.mapArrayToObject(
                                tileEntityCounts.entrySet(),
                                (entry) -> {
                                  this.blockTypeSet.add(entry.getKey());
                                  return JSONUtil.singleObjectPair(
                                      Block.getIdFromBlock((Block) entry.getKey()),
                                      entry.getValue().count());
                                }));
                      }));
            });
  }