mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-29 19:52:55 +01:00
2331 lines
110 KiB
Diff
2331 lines
110 KiB
Diff
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||
|
From: Aikar <aikar@aikar.co>
|
||
|
Date: Thu, 3 Mar 2016 04:00:11 -0600
|
||
|
Subject: [PATCH] Timings v2
|
||
|
|
||
|
|
||
|
diff --git a/src/main/java/SpigotTimings.java b/src/main/java/SpigotTimings.java
|
||
|
new file mode 100644
|
||
|
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
|
||
|
diff --git a/src/main/java/co/aikar/timings/MinecraftTimings.java b/src/main/java/co/aikar/timings/MinecraftTimings.java
|
||
|
new file mode 100644
|
||
|
index 0000000000000000000000000000000000000000..be3a62f543a5fec4739c14821fe5a443c1fa3f5b
|
||
|
--- /dev/null
|
||
|
+++ b/src/main/java/co/aikar/timings/MinecraftTimings.java
|
||
|
@@ -0,0 +1,152 @@
|
||
|
+package co.aikar.timings;
|
||
|
+
|
||
|
+import Timing;
|
||
|
+import com.google.common.collect.MapMaker;
|
||
|
+import net.minecraft.commands.CommandFunction;
|
||
|
+import net.minecraft.network.protocol.Packet;
|
||
|
+import net.minecraft.world.level.block.Block;
|
||
|
+import net.minecraft.world.level.block.entity.BlockEntity;
|
||
|
+import org.bukkit.plugin.Plugin;
|
||
|
+import org.bukkit.scheduler.BukkitTask;
|
||
|
+
|
||
|
+import org.bukkit.craftbukkit.scheduler.CraftTask;
|
||
|
+
|
||
|
+import java.util.Map;
|
||
|
+
|
||
|
+// TODO: Re-implement missing timers
|
||
|
+public final class MinecraftTimings {
|
||
|
+
|
||
|
+ public static final Timing serverOversleep = Timings.ofSafe("Server Oversleep");
|
||
|
+ public static final Timing playerListTimer = Timings.ofSafe("Player List");
|
||
|
+ public static final Timing commandFunctionsTimer = Timings.ofSafe("Command Functions");
|
||
|
+ public static final Timing connectionTimer = Timings.ofSafe("Connection Handler");
|
||
|
+ public static final Timing tickablesTimer = Timings.ofSafe("Tickables");
|
||
|
+ public static final Timing minecraftSchedulerTimer = Timings.ofSafe("Minecraft Scheduler");
|
||
|
+ public static final Timing bukkitSchedulerTimer = Timings.ofSafe("Bukkit Scheduler");
|
||
|
+ public static final Timing bukkitSchedulerPendingTimer = Timings.ofSafe("Bukkit Scheduler - Pending");
|
||
|
+ public static final Timing bukkitSchedulerFinishTimer = Timings.ofSafe("Bukkit Scheduler - Finishing");
|
||
|
+ public static final Timing chunkIOTickTimer = Timings.ofSafe("ChunkIOTick");
|
||
|
+ public static final Timing timeUpdateTimer = Timings.ofSafe("Time Update");
|
||
|
+ public static final Timing serverCommandTimer = Timings.ofSafe("Server Command");
|
||
|
+ public static final Timing savePlayers = Timings.ofSafe("Save Players");
|
||
|
+
|
||
|
+ public static final Timing tickEntityTimer = Timings.ofSafe("## tickEntity");
|
||
|
+ public static final Timing tickTileEntityTimer = Timings.ofSafe("## tickTileEntity");
|
||
|
+ public static final Timing packetProcessTimer = Timings.ofSafe("## Packet Processing");
|
||
|
+ public static final Timing scheduledBlocksTimer = Timings.ofSafe("## Scheduled Blocks");
|
||
|
+ public static final Timing structureGenerationTimer = Timings.ofSafe("Structure Generation");
|
||
|
+
|
||
|
+ public static final Timing processQueueTimer = Timings.ofSafe("processQueue");
|
||
|
+ public static final Timing processTasksTimer = Timings.ofSafe("processTasks");
|
||
|
+
|
||
|
+ public static final Timing playerCommandTimer = Timings.ofSafe("playerCommand");
|
||
|
+
|
||
|
+ public static final Timing entityActivationCheckTimer = Timings.ofSafe("entityActivationCheck");
|
||
|
+
|
||
|
+ public static final Timing antiXrayUpdateTimer = Timings.ofSafe("anti-xray - update");
|
||
|
+ public static final Timing antiXrayObfuscateTimer = Timings.ofSafe("anti-xray - obfuscate");
|
||
|
+
|
||
|
+ private static final Map<Class<?>, String> taskNameCache = new MapMaker().weakKeys().makeMap();
|
||
|
+
|
||
|
+ private MinecraftTimings() {}
|
||
|
+
|
||
|
+ public static Timing getInternalTaskName(String taskName) {
|
||
|
+ return Timings.ofSafe(taskName);
|
||
|
+ }
|
||
|
+
|
||
|
+ /**
|
||
|
+ * Gets a timer associated with a plugins tasks.
|
||
|
+ * @param bukkitTask
|
||
|
+ * @param period
|
||
|
+ * @return
|
||
|
+ */
|
||
|
+ public static Timing getPluginTaskTimings(BukkitTask bukkitTask, long period) {
|
||
|
+ if (!bukkitTask.isSync()) {
|
||
|
+ return NullTimingHandler.NULL;
|
||
|
+ }
|
||
|
+ Plugin plugin;
|
||
|
+
|
||
|
+ CraftTask craftTask = (CraftTask) bukkitTask;
|
||
|
+
|
||
|
+ final Class<?> taskClass = craftTask.getTaskClass();
|
||
|
+ if (bukkitTask.getOwner() != null) {
|
||
|
+ plugin = bukkitTask.getOwner();
|
||
|
+ } else {
|
||
|
+ plugin = TimingsManager.getPluginByClassloader(taskClass);
|
||
|
+ }
|
||
|
+
|
||
|
+ final String taskname = taskNameCache.computeIfAbsent(taskClass, clazz -> {
|
||
|
+ try {
|
||
|
+ String clsName = !clazz.isMemberClass()
|
||
|
+ ? clazz.getName()
|
||
|
+ : clazz.getCanonicalName();
|
||
|
+ if (clsName != null && clsName.contains("$Lambda$")) {
|
||
|
+ clsName = clsName.replaceAll("(Lambda\\$.*?)/.*", "$1");
|
||
|
+ }
|
||
|
+ return clsName != null ? clsName : "UnknownTask";
|
||
|
+ } catch (Throwable ex) {
|
||
|
+ new Exception("Error occurred detecting class name", ex).printStackTrace();
|
||
|
+ return "MangledClassFile";
|
||
|
+ }
|
||
|
+ });
|
||
|
+
|
||
|
+ StringBuilder name = new StringBuilder(64);
|
||
|
+ name.append("Task: ").append(taskname);
|
||
|
+ if (period > 0) {
|
||
|
+ name.append(" (interval:").append(period).append(")");
|
||
|
+ } else {
|
||
|
+ name.append(" (Single)");
|
||
|
+ }
|
||
|
+
|
||
|
+ if (plugin == null) {
|
||
|
+ return Timings.ofSafe(null, name.toString());
|
||
|
+ }
|
||
|
+
|
||
|
+ return Timings.ofSafe(plugin, name.toString());
|
||
|
+ }
|
||
|
+
|
||
|
+ /**
|
||
|
+ * Get a named timer for the specified entity type to track type specific timings.
|
||
|
+ * @param entityType
|
||
|
+ * @return
|
||
|
+ */
|
||
|
+ public static Timing getEntityTimings(String entityType, String type) {
|
||
|
+ return Timings.ofSafe("Minecraft", "## tickEntity - " + entityType + " - " + type, tickEntityTimer);
|
||
|
+ }
|
||
|
+
|
||
|
+ /**
|
||
|
+ * Get a named timer for the specified tile entity type to track type specific timings.
|
||
|
+ * @param entity
|
||
|
+ * @return
|
||
|
+ */
|
||
|
+ public static Timing getTileEntityTimings(BlockEntity entity) {
|
||
|
+ String entityType = entity.getClass().getName();
|
||
|
+ return Timings.ofSafe("Minecraft", "## tickTileEntity - " + entityType, tickTileEntityTimer);
|
||
|
+ }
|
||
|
+ public static Timing getCancelTasksTimer() {
|
||
|
+ return Timings.ofSafe("Cancel Tasks");
|
||
|
+ }
|
||
|
+ public static Timing getCancelTasksTimer(Plugin plugin) {
|
||
|
+ return Timings.ofSafe(plugin, "Cancel Tasks");
|
||
|
+ }
|
||
|
+
|
||
|
+ public static void stopServer() {
|
||
|
+ TimingsManager.stopServer();
|
||
|
+ }
|
||
|
+
|
||
|
+ public static Timing getBlockTiming(Block block) {
|
||
|
+ return Timings.ofSafe("## Scheduled Block: " + block.toString(), scheduledBlocksTimer);
|
||
|
+ }
|
||
|
+/*
|
||
|
+ public static Timing getStructureTiming(StructureGenerator structureGenerator) {
|
||
|
+ return Timings.ofSafe("Structure Generator - " + structureGenerator.getName(), structureGenerationTimer);
|
||
|
+ }*/
|
||
|
+
|
||
|
+ public static Timing getPacketTiming(Packet packet) {
|
||
|
+ return Timings.ofSafe("## Packet - " + packet.getClass().getName(), packetProcessTimer);
|
||
|
+ }
|
||
|
+
|
||
|
+ public static Timing getCommandFunctionTiming(CommandFunction function) {
|
||
|
+ return Timings.ofSafe("Command Function - " + function.getMinecraftKey().toString());
|
||
|
+ }
|
||
|
+}
|
||
|
diff --git a/src/main/java/co/aikar/timings/TimingsExport.java b/src/main/java/co/aikar/timings/TimingsExport.java
|
||
|
new file mode 100644
|
||
|
index 0000000000000000000000000000000000000000..94adf0275a2e7093c152cc3b8b0a5747b3a13a86
|
||
|
--- /dev/null
|
||
|
+++ b/src/main/java/co/aikar/timings/TimingsExport.java
|
||
|
@@ -0,0 +1,380 @@
|
||
|
+/*
|
||
|
+ * This file is licensed under the MIT License (MIT).
|
||
|
+ *
|
||
|
+ * Copyright (c) 2014 Daniel Ennis <http://aikar.co>
|
||
|
+ *
|
||
|
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||
|
+ * of this software and associated documentation files (the "Software"), to deal
|
||
|
+ * in the Software without restriction, including without limitation the rights
|
||
|
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||
|
+ * copies of the Software, and to permit persons to whom the Software is
|
||
|
+ * furnished to do so, subject to the following conditions:
|
||
|
+ *
|
||
|
+ * The above copyright notice and this permission notice shall be included in
|
||
|
+ * all copies or substantial portions of the Software.
|
||
|
+ *
|
||
|
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||
|
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||
|
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||
|
+ * THE SOFTWARE.
|
||
|
+ */
|
||
|
+package co.aikar.timings;
|
||
|
+
|
||
|
+import com.google.common.collect.Sets;
|
||
|
+import net.minecraft.server.MinecraftServer;
|
||
|
+import org.apache.commons.lang.StringUtils;
|
||
|
+import org.bukkit.Bukkit;
|
||
|
+import org.bukkit.ChatColor;
|
||
|
+import org.bukkit.Material;
|
||
|
+import org.bukkit.configuration.ConfigurationSection;
|
||
|
+import org.bukkit.configuration.MemorySection;
|
||
|
+import org.bukkit.craftbukkit.util.CraftChatMessage;
|
||
|
+import org.bukkit.entity.EntityType;
|
||
|
+import org.json.simple.JSONObject;
|
||
|
+import org.json.simple.JSONValue;
|
||
|
+
|
||
|
+import java.io.ByteArrayOutputStream;
|
||
|
+import java.io.IOException;
|
||
|
+import java.io.InputStream;
|
||
|
+import java.io.OutputStream;
|
||
|
+import java.lang.management.ManagementFactory;
|
||
|
+import java.lang.management.OperatingSystemMXBean;
|
||
|
+import java.lang.management.RuntimeMXBean;
|
||
|
+import java.net.HttpURLConnection;
|
||
|
+import java.net.InetAddress;
|
||
|
+import java.net.URL;
|
||
|
+import java.util.List;
|
||
|
+import java.util.Map;
|
||
|
+import java.util.Set;
|
||
|
+import java.util.logging.Level;
|
||
|
+import java.util.zip.GZIPOutputStream;
|
||
|
+
|
||
|
+import static co.aikar.timings.TimingsManager.HISTORY;
|
||
|
+import static co.aikar.util.JSONUtil.appendObjectData;
|
||
|
+import static co.aikar.util.JSONUtil.createObject;
|
||
|
+import static co.aikar.util.JSONUtil.pair;
|
||
|
+import static co.aikar.util.JSONUtil.toArray;
|
||
|
+import static co.aikar.util.JSONUtil.toArrayMapper;
|
||
|
+import static co.aikar.util.JSONUtil.toObjectMapper;
|
||
|
+
|
||
|
+import TimingHistory;
|
||
|
+import TimingsReportListener;
|
||
|
+
|
||
|
+@SuppressWarnings({"rawtypes", "SuppressionAnnotation"})
|
||
|
+public class TimingsExport extends Thread {
|
||
|
+
|
||
|
+ private final TimingsReportListener listeners;
|
||
|
+ private final Map out;
|
||
|
+ private final TimingHistory[] history;
|
||
|
+ private static long lastReport = 0;
|
||
|
+
|
||
|
+ private TimingsExport(TimingsReportListener listeners, Map out, TimingHistory[] history) {
|
||
|
+ super("Timings paste thread");
|
||
|
+ this.listeners = listeners;
|
||
|
+ this.out = out;
|
||
|
+ this.history = history;
|
||
|
+ }
|
||
|
+
|
||
|
+ /**
|
||
|
+ * Checks if any pending reports are being requested, and builds one if needed.
|
||
|
+ */
|
||
|
+ public static void reportTimings() {
|
||
|
+ if (Timings.requestingReport.isEmpty()) {
|
||
|
+ return;
|
||
|
+ }
|
||
|
+ TimingsReportListener listeners = new TimingsReportListener(Timings.requestingReport);
|
||
|
+ listeners.addConsoleIfNeeded();
|
||
|
+
|
||
|
+ Timings.requestingReport.clear();
|
||
|
+ long now = System.currentTimeMillis();
|
||
|
+ final long lastReportDiff = now - lastReport;
|
||
|
+ if (lastReportDiff < 60000) {
|
||
|
+ listeners.sendMessage(ChatColor.RED + "Please wait at least 1 minute in between Timings reports. (" + (int)((60000 - lastReportDiff) / 1000) + " seconds)");
|
||
|
+ listeners.done();
|
||
|
+ return;
|
||
|
+ }
|
||
|
+ final long lastStartDiff = now - TimingsManager.timingStart;
|
||
|
+ if (lastStartDiff < 180000) {
|
||
|
+ listeners.sendMessage(ChatColor.RED + "Please wait at least 3 minutes before generating a Timings report. Unlike Timings v1, v2 benefits from longer timings and is not as useful with short timings. (" + (int)((180000 - lastStartDiff) / 1000) + " seconds)");
|
||
|
+ listeners.done();
|
||
|
+ return;
|
||
|
+ }
|
||
|
+ listeners.sendMessage(ChatColor.GREEN + "Preparing Timings Report...");
|
||
|
+ lastReport = now;
|
||
|
+ Map parent = createObject(
|
||
|
+ // Get some basic system details about the server
|
||
|
+ pair("version", Bukkit.getVersion()),
|
||
|
+ pair("maxplayers", Bukkit.getMaxPlayers()),
|
||
|
+ pair("start", TimingsManager.timingStart / 1000),
|
||
|
+ pair("end", System.currentTimeMillis() / 1000),
|
||
|
+ pair("online-mode", Bukkit.getServer().getOnlineMode()),
|
||
|
+ pair("sampletime", (System.currentTimeMillis() - TimingsManager.timingStart) / 1000),
|
||
|
+ pair("datapacks", toArrayMapper(MinecraftServer.getServer().getPackRepository().getSelectedIds(), pack -> {
|
||
|
+ // Don't feel like obf helper'ing these, non fatal if its temp missed.
|
||
|
+ return ChatColor.stripColor(CraftChatMessage.fromComponent(pack.a(true)));
|
||
|
+ }))
|
||
|
+ );
|
||
|
+ if (!TimingsManager.privacy) {
|
||
|
+ appendObjectData(parent,
|
||
|
+ pair("server", Bukkit.getUnsafe().getTimingsServerName()),
|
||
|
+ pair("motd", Bukkit.getServer().getMotd()),
|
||
|
+ pair("icon", Bukkit.getServer().getServerIcon().getData())
|
||
|
+ );
|
||
|
+ }
|
||
|
+
|
||
|
+ final Runtime runtime = Runtime.getRuntime();
|
||
|
+ RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
|
||
|
+
|
||
|
+ OperatingSystemMXBean osInfo = ManagementFactory.getOperatingSystemMXBean();
|
||
|
+
|
||
|
+ parent.put("system", createObject(
|
||
|
+ pair("timingcost", getCost()),
|
||
|
+ pair("loadavg", osInfo.getSystemLoadAverage()),
|
||
|
+ pair("name", System.getProperty("os.name")),
|
||
|
+ pair("version", System.getProperty("os.version")),
|
||
|
+ pair("jvmversion", System.getProperty("java.version")),
|
||
|
+ pair("arch", System.getProperty("os.arch")),
|
||
|
+ pair("maxmem", runtime.maxMemory()),
|
||
|
+ pair("memory", createObject(
|
||
|
+ pair("heap", ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().toString()),
|
||
|
+ pair("nonheap", ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().toString()),
|
||
|
+ pair("finalizing", ManagementFactory.getMemoryMXBean().getObjectPendingFinalizationCount())
|
||
|
+ )),
|
||
|
+ pair("cpu", runtime.availableProcessors()),
|
||
|
+ pair("runtime", runtimeBean.getUptime()),
|
||
|
+ pair("flags", StringUtils.join(runtimeBean.getInputArguments(), " ")),
|
||
|
+ pair("gc", toObjectMapper(ManagementFactory.getGarbageCollectorMXBeans(), input -> pair(input.getName(), toArray(input.getCollectionCount(), input.getCollectionTime()))))
|
||
|
+ )
|
||
|
+ );
|
||
|
+
|
||
|
+ parent.put("worlds", toObjectMapper(MinecraftServer.getServer().getAllLevels(), world -> {
|
||
|
+ if (world.getWorldData().getName().equals("worldeditregentempworld")) return null;
|
||
|
+ return pair(world.getWorldData().getName(), createObject(
|
||
|
+ pair("gamerules", toObjectMapper(world.getWorld().getGameRules(), rule -> {
|
||
|
+ return pair(rule, world.getWorld().getGameRuleValue(rule));
|
||
|
+ })),
|
||
|
+ pair("ticking-distance", world.getChunkProvider().playerChunkMap.getEffectiveViewDistance())
|
||
|
+ ));
|
||
|
+ }));
|
||
|
+
|
||
|
+ Set<Material> tileEntityTypeSet = Sets.newHashSet();
|
||
|
+ Set<EntityType> entityTypeSet = Sets.newHashSet();
|
||
|
+
|
||
|
+ int size = HISTORY.size();
|
||
|
+ TimingHistory[] history = new TimingHistory[size + 1];
|
||
|
+ int i = 0;
|
||
|
+ for (TimingHistory timingHistory : HISTORY) {
|
||
|
+ tileEntityTypeSet.addAll(timingHistory.tileEntityTypeSet);
|
||
|
+ entityTypeSet.addAll(timingHistory.entityTypeSet);
|
||
|
+ history[i++] = timingHistory;
|
||
|
+ }
|
||
|
+
|
||
|
+ history[i] = new TimingHistory(); // Current snapshot
|
||
|
+ tileEntityTypeSet.addAll(history[i].tileEntityTypeSet);
|
||
|
+ entityTypeSet.addAll(history[i].entityTypeSet);
|
||
|
+
|
||
|
+
|
||
|
+ Map handlers = createObject();
|
||
|
+ Map groupData;
|
||
|
+ synchronized (TimingIdentifier.GROUP_MAP) {
|
||
|
+ for (TimingIdentifier.TimingGroup group : TimingIdentifier.GROUP_MAP.values()) {
|
||
|
+ synchronized (group.handlers) {
|
||
|
+ for (TimingHandler id : group.handlers) {
|
||
|
+
|
||
|
+ if (!id.isTimed() && !id.isSpecial()) {
|
||
|
+ continue;
|
||
|
+ }
|
||
|
+
|
||
|
+ String name = id.identifier.name;
|
||
|
+ if (name.startsWith("##")) {
|
||
|
+ name = name.substring(3);
|
||
|
+ }
|
||
|
+ handlers.put(id.id, toArray(
|
||
|
+ group.id,
|
||
|
+ name
|
||
|
+ ));
|
||
|
+ }
|
||
|
+ }
|
||
|
+ }
|
||
|
+
|
||
|
+ groupData = toObjectMapper(
|
||
|
+ TimingIdentifier.GROUP_MAP.values(), group -> pair(group.id, group.name));
|
||
|
+ }
|
||
|
+
|
||
|
+ parent.put("idmap", createObject(
|
||
|
+ pair("groups", groupData),
|
||
|
+ pair("handlers", handlers),
|
||
|
+ pair("worlds", toObjectMapper(TimingHistory.worldMap.entrySet(), input -> pair(input.getValue(), input.getKey()))),
|
||
|
+ pair("tileentity",
|
||
|
+ toObjectMapper(tileEntityTypeSet, input -> pair(input.ordinal(), input.name()))),
|
||
|
+ pair("entity",
|
||
|
+ toObjectMapper(entityTypeSet, input -> pair(input.ordinal(), input.name())))
|
||
|
+ ));
|
||
|
+
|
||
|
+ // Information about loaded plugins
|
||
|
+
|
||
|
+ parent.put("plugins", toObjectMapper(Bukkit.getPluginManager().getPlugins(),
|
||
|
+ plugin -> pair(plugin.getName(), createObject(
|
||
|
+ pair("version", plugin.getDescription().getVersion()),
|
||
|
+ pair("description", String.valueOf(plugin.getDescription().getDescription()).trim()),
|
||
|
+ pair("website", plugin.getDescription().getWebsite()),
|
||
|
+ pair("authors", StringUtils.join(plugin.getDescription().getAuthors(), ", "))
|
||
|
+ ))));
|
||
|
+
|
||
|
+
|
||
|
+
|
||
|
+ // Information on the users Config
|
||
|
+
|
||
|
+ parent.put("config", createObject(
|
||
|
+ pair("spigot", mapAsJSON(Bukkit.spigot().getSpigotConfig(), null)),
|
||
|
+ pair("bukkit", mapAsJSON(Bukkit.spigot().getBukkitConfig(), null)),
|
||
|
+ pair("paper", mapAsJSON(Bukkit.spigot().getPaperConfig(), null))
|
||
|
+ ));
|
||
|
+
|
||
|
+ new TimingsExport(listeners, parent, history).start();
|
||
|
+ }
|
||
|
+
|
||
|
+ static long getCost() {
|
||
|
+ // Benchmark the users System.nanotime() for cost basis
|
||
|
+ int passes = 100;
|
||
|
+ TimingHandler SAMPLER1 = Timings.ofSafe("Timings Sampler 1");
|
||
|
+ TimingHandler SAMPLER2 = Timings.ofSafe("Timings Sampler 2");
|
||
|
+ TimingHandler SAMPLER3 = Timings.ofSafe("Timings Sampler 3");
|
||
|
+ TimingHandler SAMPLER4 = Timings.ofSafe("Timings Sampler 4");
|
||
|
+ TimingHandler SAMPLER5 = Timings.ofSafe("Timings Sampler 5");
|
||
|
+ TimingHandler SAMPLER6 = Timings.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;
|
||
|
+ }
|
||
|
+
|
||
|
+ private static JSONObject mapAsJSON(ConfigurationSection config, String parentKey) {
|
||
|
+
|
||
|
+ JSONObject object = new JSONObject();
|
||
|
+ for (String key : config.getKeys(false)) {
|
||
|
+ String fullKey = (parentKey != null ? parentKey + "." + key : key);
|
||
|
+ if (fullKey.equals("database") || fullKey.equals("settings.bungeecord-addresses") || TimingsManager.hiddenConfigs.contains(fullKey) || key.startsWith("seed-") || key.equals("worldeditregentempworld")) {
|
||
|
+ continue;
|
||
|
+ }
|
||
|
+ final Object val = config.get(key);
|
||
|
+
|
||
|
+ object.put(key, valAsJSON(val, fullKey));
|
||
|
+ }
|
||
|
+ return object;
|
||
|
+ }
|
||
|
+
|
||
|
+ private static Object valAsJSON(Object val, final String parentKey) {
|
||
|
+ if (!(val instanceof MemorySection)) {
|
||
|
+ if (val instanceof List) {
|
||
|
+ Iterable<Object> v = (Iterable<Object>) val;
|
||
|
+ return toArrayMapper(v, input -> valAsJSON(input, parentKey));
|
||
|
+ } else {
|
||
|
+ return String.valueOf(val);
|
||
|
+ }
|
||
|
+ } else {
|
||
|
+ return mapAsJSON((ConfigurationSection) val, parentKey);
|
||
|
+ }
|
||
|
+ }
|
||
|
+
|
||
|
+ @Override
|
||
|
+ public void run() {
|
||
|
+ out.put("data", toArrayMapper(history, TimingHistory::export));
|
||
|
+
|
||
|
+
|
||
|
+ String response = null;
|
||
|
+ String timingsURL = null;
|
||
|
+ try {
|
||
|
+ HttpURLConnection con = (HttpURLConnection) new URL("http://timings.aikar.co/post").openConnection();
|
||
|
+ con.setDoOutput(true);
|
||
|
+ String hostName = "BrokenHost";
|
||
|
+ try {
|
||
|
+ hostName = InetAddress.getLocalHost().getHostName();
|
||
|
+ } catch (Exception ignored) {}
|
||
|
+ con.setRequestProperty("User-Agent", "Paper/" + Bukkit.getUnsafe().getTimingsServerName() + "/" + hostName);
|
||
|
+ con.setRequestMethod("POST");
|
||
|
+ con.setInstanceFollowRedirects(false);
|
||
|
+
|
||
|
+ OutputStream request = new GZIPOutputStream(con.getOutputStream()) {{
|
||
|
+ this.def.setLevel(7);
|
||
|
+ }};
|
||
|
+
|
||
|
+ request.write(JSONValue.toJSONString(out).getBytes("UTF-8"));
|
||
|
+ request.close();
|
||
|
+
|
||
|
+ response = getResponse(con);
|
||
|
+
|
||
|
+ if (con.getResponseCode() != 302) {
|
||
|
+ listeners.sendMessage(
|
||
|
+ ChatColor.RED + "Upload Error: " + con.getResponseCode() + ": " + con.getResponseMessage());
|
||
|
+ listeners.sendMessage(ChatColor.RED + "Check your logs for more information");
|
||
|
+ if (response != null) {
|
||
|
+ Bukkit.getLogger().log(Level.SEVERE, response);
|
||
|
+ }
|
||
|
+ return;
|
||
|
+ }
|
||
|
+
|
||
|
+ timingsURL = con.getHeaderField("Location");
|
||
|
+ listeners.sendMessage(ChatColor.GREEN + "View Timings Report: " + timingsURL);
|
||
|
+
|
||
|
+ if (response != null && !response.isEmpty()) {
|
||
|
+ Bukkit.getLogger().log(Level.INFO, "Timing Response: " + response);
|
||
|
+ }
|
||
|
+ } catch (IOException ex) {
|
||
|
+ listeners.sendMessage(ChatColor.RED + "Error uploading timings, check your logs for more information");
|
||
|
+ if (response != null) {
|
||
|
+ Bukkit.getLogger().log(Level.SEVERE, response);
|
||
|
+ }
|
||
|
+ Bukkit.getLogger().log(Level.SEVERE, "Could not paste timings", ex);
|
||
|
+ } finally {
|
||
|
+ this.listeners.done(timingsURL);
|
||
|
+ }
|
||
|
+ }
|
||
|
+
|
||
|
+ private String getResponse(HttpURLConnection con) throws IOException {
|
||
|
+ InputStream is = null;
|
||
|
+ try {
|
||
|
+ is = con.getInputStream();
|
||
|
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||
|
+
|
||
|
+ byte[] b = new byte[1024];
|
||
|
+ int bytesRead;
|
||
|
+ while ((bytesRead = is.read(b)) != -1) {
|
||
|
+ bos.write(b, 0, bytesRead);
|
||
|
+ }
|
||
|
+ return bos.toString();
|
||
|
+
|
||
|
+ } catch (IOException ex) {
|
||
|
+ listeners.sendMessage(ChatColor.RED + "Error uploading timings, check your logs for more information");
|
||
|
+ Bukkit.getLogger().log(Level.WARNING, con.getResponseMessage(), ex);
|
||
|
+ return null;
|
||
|
+ } finally {
|
||
|
+ if (is != null) {
|
||
|
+ is.close();
|
||
|
+ }
|
||
|
+ }
|
||
|
+ }
|
||
|
+}
|
||
|
diff --git a/src/main/java/co/aikar/timings/WorldTimingsHandler.java b/src/main/java/co/aikar/timings/WorldTimingsHandler.java
|
||
|
new file mode 100644
|
||
|
index 0000000000000000000000000000000000000000..79ede25e4fe7a648b1d29c49d876482a2158f892
|
||
|
--- /dev/null
|
||
|
+++ b/src/main/java/co/aikar/timings/WorldTimingsHandler.java
|
||
|
@@ -0,0 +1,120 @@
|
||
|
+package co.aikar.timings;
|
||
|
+
|
||
|
+import Timing;
|
||
|
+import net.minecraft.server.level.ServerLevel;
|
||
|
+import net.minecraft.world.level.Level;
|
||
|
+import net.minecraft.world.level.storage.PrimaryLevelData;
|
||
|
+
|
||
|
+/**
|
||
|
+ * Set of timers per world, to track world specific timings.
|
||
|
+ */
|
||
|
+// TODO: Re-implement missing timers
|
||
|
+public class WorldTimingsHandler {
|
||
|
+ public final Timing mobSpawn;
|
||
|
+ public final Timing doChunkUnload;
|
||
|
+ public final Timing doPortalForcer;
|
||
|
+ public final Timing scheduledBlocks;
|
||
|
+ public final Timing scheduledBlocksCleanup;
|
||
|
+ public final Timing scheduledBlocksTicking;
|
||
|
+ public final Timing chunkTicks;
|
||
|
+ public final Timing lightChunk;
|
||
|
+ public final Timing chunkTicksBlocks;
|
||
|
+ public final Timing doVillages;
|
||
|
+ public final Timing doChunkMap;
|
||
|
+ public final Timing doChunkMapUpdate;
|
||
|
+ public final Timing doChunkMapToUpdate;
|
||
|
+ public final Timing doChunkMapSortMissing;
|
||
|
+ public final Timing doChunkMapSortSendToPlayers;
|
||
|
+ public final Timing doChunkMapPlayersNeedingChunks;
|
||
|
+ public final Timing doChunkMapPendingSendToPlayers;
|
||
|
+ public final Timing doChunkMapUnloadChunks;
|
||
|
+ public final Timing doChunkGC;
|
||
|
+ public final Timing doSounds;
|
||
|
+ public final Timing entityRemoval;
|
||
|
+ public final Timing entityTick;
|
||
|
+ public final Timing tileEntityTick;
|
||
|
+ public final Timing tileEntityPending;
|
||
|
+ public final Timing tracker1;
|
||
|
+ public final Timing tracker2;
|
||
|
+ public final Timing doTick;
|
||
|
+ public final Timing tickEntities;
|
||
|
+ public final Timing chunks;
|
||
|
+ public final Timing newEntities;
|
||
|
+ public final Timing raids;
|
||
|
+ public final Timing chunkProviderTick;
|
||
|
+ public final Timing broadcastChunkUpdates;
|
||
|
+ public final Timing countNaturalMobs;
|
||
|
+
|
||
|
+ public final Timing chunkLoad;
|
||
|
+ public final Timing chunkLoadPopulate;
|
||
|
+ public final Timing syncChunkLoad;
|
||
|
+ public final Timing chunkLoadLevelTimer;
|
||
|
+ public final Timing chunkIO;
|
||
|
+ public final Timing chunkPostLoad;
|
||
|
+ public final Timing worldSave;
|
||
|
+ public final Timing worldSaveChunks;
|
||
|
+ public final Timing worldSaveLevel;
|
||
|
+ public final Timing chunkSaveData;
|
||
|
+
|
||
|
+
|
||
|
+ public final Timing miscMobSpawning;
|
||
|
+
|
||
|
+ public WorldTimingsHandler(Level server) {
|
||
|
+ String name = ((PrimaryLevelData) server.getLevelData()).getLevelName() + " - ";
|
||
|
+
|
||
|
+ mobSpawn = Timings.ofSafe(name + "mobSpawn");
|
||
|
+ doChunkUnload = Timings.ofSafe(name + "doChunkUnload");
|
||
|
+ scheduledBlocks = Timings.ofSafe(name + "Scheduled Blocks");
|
||
|
+ scheduledBlocksCleanup = Timings.ofSafe(name + "Scheduled Blocks - Cleanup");
|
||
|
+ scheduledBlocksTicking = Timings.ofSafe(name + "Scheduled Blocks - Ticking");
|
||
|
+ chunkTicks = Timings.ofSafe(name + "Chunk Ticks");
|
||
|
+ lightChunk = Timings.ofSafe(name + "Light Chunk");
|
||
|
+ chunkTicksBlocks = Timings.ofSafe(name + "Chunk Ticks - Blocks");
|
||
|
+ doVillages = Timings.ofSafe(name + "doVillages");
|
||
|
+ doChunkMap = Timings.ofSafe(name + "doChunkMap");
|
||
|
+ doChunkMapUpdate = Timings.ofSafe(name + "doChunkMap - Update");
|
||
|
+ doChunkMapToUpdate = Timings.ofSafe(name + "doChunkMap - To Update");
|
||
|
+ doChunkMapSortMissing = Timings.ofSafe(name + "doChunkMap - Sort Missing");
|
||
|
+ doChunkMapSortSendToPlayers = Timings.ofSafe(name + "doChunkMap - Sort Send To Players");
|
||
|
+ doChunkMapPlayersNeedingChunks = Timings.ofSafe(name + "doChunkMap - Players Needing Chunks");
|
||
|
+ doChunkMapPendingSendToPlayers = Timings.ofSafe(name + "doChunkMap - Pending Send To Players");
|
||
|
+ doChunkMapUnloadChunks = Timings.ofSafe(name + "doChunkMap - Unload Chunks");
|
||
|
+ doSounds = Timings.ofSafe(name + "doSounds");
|
||
|
+ doChunkGC = Timings.ofSafe(name + "doChunkGC");
|
||
|
+ doPortalForcer = Timings.ofSafe(name + "doPortalForcer");
|
||
|
+ entityTick = Timings.ofSafe(name + "entityTick");
|
||
|
+ entityRemoval = Timings.ofSafe(name + "entityRemoval");
|
||
|
+ tileEntityTick = Timings.ofSafe(name + "tileEntityTick");
|
||
|
+ tileEntityPending = Timings.ofSafe(name + "tileEntityPending");
|
||
|
+
|
||
|
+ chunkLoad = Timings.ofSafe(name + "Chunk Load");
|
||
|
+ chunkLoadPopulate = Timings.ofSafe(name + "Chunk Load - Populate");
|
||
|
+ syncChunkLoad = Timings.ofSafe(name + "Sync Chunk Load");
|
||
|
+ chunkLoadLevelTimer = Timings.ofSafe(name + "Chunk Load - Load Level");
|
||
|
+ chunkIO = Timings.ofSafe(name + "Chunk Load - DiskIO");
|
||
|
+ chunkPostLoad = Timings.ofSafe(name + "Chunk Load - Post Load");
|
||
|
+ worldSave = Timings.ofSafe(name + "World Save");
|
||
|
+ worldSaveLevel = Timings.ofSafe(name + "World Save - Level");
|
||
|
+ worldSaveChunks = Timings.ofSafe(name + "World Save - Chunks");
|
||
|
+ chunkSaveData = Timings.ofSafe(name + "Chunk Save - Data");
|
||
|
+
|
||
|
+ tracker1 = Timings.ofSafe(name + "tracker stage 1");
|
||
|
+ tracker2 = Timings.ofSafe(name + "tracker stage 2");
|
||
|
+ doTick = Timings.ofSafe(name + "doTick");
|
||
|
+ tickEntities = Timings.ofSafe(name + "tickEntities");
|
||
|
+
|
||
|
+ chunks = Timings.ofSafe(name + "Chunks");
|
||
|
+ newEntities = Timings.ofSafe(name + "New entity registration");
|
||
|
+ raids = Timings.ofSafe(name + "Raids");
|
||
|
+ chunkProviderTick = Timings.ofSafe(name + "Chunk provider tick");
|
||
|
+ broadcastChunkUpdates = Timings.ofSafe(name + "Broadcast chunk updates");
|
||
|
+ countNaturalMobs = Timings.ofSafe(name + "Count natural mobs");
|
||
|
+
|
||
|
+
|
||
|
+ miscMobSpawning = Timings.ofSafe(name + "Mob spawning - Misc");
|
||
|
+ }
|
||
|
+
|
||
|
+ public static Timing getTickList(ServerLevel worldserver, String timingsType) {
|
||
|
+ return Timings.ofSafe(((PrimaryLevelData) worldserver.getLevelData()).getLevelName() + " - Scheduled " + timingsType);
|
||
|
+ }
|
||
|
+}
|
||
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
||
|
index da922f395f0fff0881ead893c900c5b2623f48f0..1d03a79e9010bc514b72a81ba0ad4a62aeff1bb7 100644
|
||
|
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
||
|
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
||
|
@@ -14,12 +14,15 @@ import java.util.concurrent.TimeUnit;
|
||
|
import java.util.logging.Level;
|
||
|
import java.util.regex.Pattern;
|
||
|
|
||
|
+import com.google.common.collect.Lists;
|
||
|
import net.minecraft.server.MinecraftServer;
|
||
|
import org.bukkit.Bukkit;
|
||
|
import org.bukkit.command.Command;
|
||
|
import org.bukkit.configuration.ConfigurationSection;
|
||
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||
|
+import co.aikar.timings.Timings;
|
||
|
+import co.aikar.timings.TimingsManager;
|
||
|
|
||
|
public class PaperConfig {
|
||
|
|
||
|
@@ -188,4 +191,30 @@ public class PaperConfig {
|
||
|
config.addDefault(path, def);
|
||
|
return config.getString(path, config.getString(path));
|
||
|
}
|
||
|
+
|
||
|
+ public static String timingsServerName;
|
||
|
+ private static void timings() {
|
||
|
+ boolean timings = getBoolean("timings.enabled", true);
|
||
|
+ boolean verboseTimings = getBoolean("timings.verbose", true);
|
||
|
+ TimingsManager.privacy = getBoolean("timings.server-name-privacy", false);
|
||
|
+ TimingsManager.hiddenConfigs = getList("timings.hidden-config-entries", Lists.newArrayList("database", "settings.bungeecord-addresses", "settings.velocity-support.secret"));
|
||
|
+ if (!TimingsManager.hiddenConfigs.contains("settings.velocity-support.secret")) {
|
||
|
+ TimingsManager.hiddenConfigs.add("settings.velocity-support.secret");
|
||
|
+ }
|
||
|
+ int timingHistoryInterval = getInt("timings.history-interval", 300);
|
||
|
+ int timingHistoryLength = getInt("timings.history-length", 3600);
|
||
|
+ timingsServerName = getString("timings.server-name", "Unknown Server");
|
||
|
+
|
||
|
+
|
||
|
+ Timings.setVerboseTimingsEnabled(verboseTimings);
|
||
|
+ Timings.setTimingsEnabled(timings);
|
||
|
+ Timings.setHistoryInterval(timingHistoryInterval * 20);
|
||
|
+ Timings.setHistoryLength(timingHistoryLength * 20);
|
||
|
+
|
||
|
+ log("Timings: " + timings +
|
||
|
+ " - Verbose: " + verboseTimings +
|
||
|
+ " - Interval: " + timeSummary(Timings.getHistoryInterval() / 20) +
|
||
|
+ " - Length: " + timeSummary(Timings.getHistoryLength() / 20) +
|
||
|
+ " - Server Name: " + timingsServerName);
|
||
|
+ }
|
||
|
}
|
||
|
diff --git a/src/main/java/net/minecraft/commands/CommandFunction.java b/src/main/java/net/minecraft/commands/CommandFunction.java
|
||
|
index cf57de0e791a9362fe95b65134d9fe4f4e95adf4..07b891075191161a8a903876b02caa75d4db1366 100644
|
||
|
--- a/src/main/java/net/minecraft/commands/CommandFunction.java
|
||
|
+++ b/src/main/java/net/minecraft/commands/CommandFunction.java
|
||
|
@@ -15,12 +15,22 @@ public class CommandFunction {
|
||
|
|
||
|
private final CommandFunction.Entry[] entries;
|
||
|
private final ResourceLocation id;
|
||
|
+ // Paper start
|
||
|
+ public co.aikar.timings.Timing timing;
|
||
|
+ public co.aikar.timings.Timing getTiming() {
|
||
|
+ if (timing == null) {
|
||
|
+ timing = co.aikar.timings.MinecraftTimings.getCommandFunctionTiming(this);
|
||
|
+ }
|
||
|
+ return timing;
|
||
|
+ }
|
||
|
+ // Paper end
|
||
|
|
||
|
public CommandFunction(ResourceLocation id, CommandFunction.Entry[] elements) {
|
||
|
this.id = id;
|
||
|
this.entries = elements;
|
||
|
}
|
||
|
|
||
|
+ public final ResourceLocation getMinecraftKey() { return this.getId(); } // Paper - OBFHELPER
|
||
|
public ResourceLocation getId() {
|
||
|
return this.id;
|
||
|
}
|
||
|
diff --git a/src/main/java/net/minecraft/network/protocol/PacketUtils.java b/src/main/java/net/minecraft/network/protocol/PacketUtils.java
|
||
|
index 23ccd095ad99fe90a6f2a16bcca368804b16101a..4ae8201d7dcffeb3298a4e593f978e15ffc5ac15 100644
|
||
|
--- a/src/main/java/net/minecraft/network/protocol/PacketUtils.java
|
||
|
+++ b/src/main/java/net/minecraft/network/protocol/PacketUtils.java
|
||
|
@@ -3,6 +3,8 @@ package net.minecraft.network.protocol;
|
||
|
import net.minecraft.network.PacketListener;
|
||
|
import org.apache.logging.log4j.LogManager;
|
||
|
import org.apache.logging.log4j.Logger;
|
||
|
+import co.aikar.timings.MinecraftTimings; // Paper
|
||
|
+import co.aikar.timings.Timing; // Paper
|
||
|
|
||
|
// CraftBukkit start
|
||
|
import net.minecraft.server.MinecraftServer;
|
||
|
@@ -21,10 +23,13 @@ public class PacketUtils {
|
||
|
|
||
|
public static <T extends PacketListener> void ensureRunningOnSameThread(Packet<T> packet, T listener, BlockableEventLoop<?> engine) throws RunningOnDifferentThreadException {
|
||
|
if (!engine.isSameThread()) {
|
||
|
+ Timing timing = MinecraftTimings.getPacketTiming(packet); // Paper - timings
|
||
|
engine.execute(() -> {
|
||
|
if (MinecraftServer.getServer().hasStopped() || (listener instanceof ServerGamePacketListenerImpl && ((ServerGamePacketListenerImpl) listener).processedDisconnect)) return; // CraftBukkit, MC-142590
|
||
|
if (listener.a().isConnected()) {
|
||
|
+ try (Timing ignored = timing.startTiming()) { // Paper - timings
|
||
|
packet.handle(listener);
|
||
|
+ } // Paper - timings
|
||
|
} else {
|
||
|
PacketUtils.LOGGER.debug("Ignoring packet due to disconnection: " + packet);
|
||
|
}
|
||
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||
|
index 2406879e76a110e96a4753e66366432a4bc52d9b..a456b9cbf0e5eea4e888e0e3d07ed17558650371 100644
|
||
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||
|
@@ -172,7 +172,7 @@ import org.bukkit.craftbukkit.Main;
|
||
|
import org.bukkit.event.server.ServerLoadEvent;
|
||
|
// CraftBukkit end
|
||
|
|
||
|
-import org.bukkit.craftbukkit.SpigotTimings; // Spigot
|
||
|
+import co.aikar.timings.MinecraftTimings; // Paper
|
||
|
import org.spigotmc.SlackActivityAccountant; // Spigot
|
||
|
|
||
|
public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTask> implements SnooperPopulator, CommandSource, AutoCloseable {
|
||
|
@@ -226,8 +226,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||
|
private long lastServerStatus;
|
||
|
public final Thread serverThread;
|
||
|
private long nextTickTime;
|
||
|
- private long delayedTasksMaxNextTickTime;
|
||
|
- private boolean mayHaveDelayedTasks;
|
||
|
+ private long delayedTasksMaxNextTickTime; final long getTickOversleepMaxTime() { return this.delayedTasksMaxNextTickTime; } // Paper - OBFHELPER
|
||
|
+ private boolean mayHaveDelayedTasks; final boolean hasExecutedTask() { return this.mayHaveDelayedTasks; } // Paper - OBFHELPER
|
||
|
private final PackRepository packRepository;
|
||
|
private final ServerScoreboard scoreboard;
|
||
|
@Nullable
|
||
|
@@ -828,6 +828,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||
|
}
|
||
|
// CraftBukkit end
|
||
|
MinecraftServer.LOGGER.info("Stopping server");
|
||
|
+ MinecraftTimings.stopServer(); // Paper
|
||
|
// CraftBukkit start
|
||
|
if (this.server != null) {
|
||
|
this.server.disablePlugins();
|
||
|
@@ -1025,9 +1026,21 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||
|
|
||
|
private boolean haveTime() {
|
||
|
// CraftBukkit start
|
||
|
+ if (isOversleep) return canOversleep();// Paper - because of our changes, this logic is broken
|
||
|
return this.forceTicks || this.runningTask() || Util.getMillis() < (this.mayHaveDelayedTasks ? this.delayedTasksMaxNextTickTime : this.nextTickTime);
|
||
|
}
|
||
|
|
||
|
+ // Paper start
|
||
|
+ boolean isOversleep = false;
|
||
|
+ private boolean canOversleep() {
|
||
|
+ return this.hasExecutedTask() && Util.getMillis() < this.getTickOversleepMaxTime();
|
||
|
+ }
|
||
|
+
|
||
|
+ private boolean canSleepForTickNoOversleep() {
|
||
|
+ return this.forceTicks || this.runningTask() || Util.getMillis() < this.nextTickTime;
|
||
|
+ }
|
||
|
+ // Paper end
|
||
|
+
|
||
|
private void executeModerately() {
|
||
|
this.runAllTasks();
|
||
|
java.util.concurrent.locks.LockSupport.parkNanos("executing tasks", 1000L);
|
||
|
@@ -1035,9 +1048,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||
|
// CraftBukkit end
|
||
|
|
||
|
protected void waitUntilNextTick() {
|
||
|
- this.runAllTasks();
|
||
|
+ //this.executeAll(); // Paper - move this into the tick method for timings
|
||
|
this.managedBlock(() -> {
|
||
|
- return !this.haveTime();
|
||
|
+ return !this.canSleepForTickNoOversleep(); // Paper - move oversleep into full server tick
|
||
|
});
|
||
|
}
|
||
|
|
||
|
@@ -1120,10 +1133,18 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||
|
protected void onServerExit() {}
|
||
|
|
||
|
protected void tickServer(BooleanSupplier shouldKeepTicking) {
|
||
|
- SpigotTimings.serverTickTimer.startTiming(); // Spigot
|
||
|
+ co.aikar.timings.TimingsManager.FULL_SERVER_TICK.startTiming(); // Paper
|
||
|
this.slackActivityAccountant.tickStarted(); // Spigot
|
||
|
long i = Util.getNanos();
|
||
|
|
||
|
+ // Paper start - move oversleep into full server tick
|
||
|
+ isOversleep = true;MinecraftTimings.serverOversleep.startTiming();
|
||
|
+ this.managedBlock(() -> {
|
||
|
+ return !this.canOversleep();
|
||
|
+ });
|
||
|
+ isOversleep = false;MinecraftTimings.serverOversleep.stopTiming();
|
||
|
+ // Paper end
|
||
|
+
|
||
|
++this.tickCount;
|
||
|
this.tickChildren(shouldKeepTicking);
|
||
|
if (i - this.lastServerStatus >= 5000000000L) {
|
||
|
@@ -1141,14 +1162,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||
|
}
|
||
|
|
||
|
if (autosavePeriod > 0 && this.tickCount % autosavePeriod == 0) { // CraftBukkit
|
||
|
- SpigotTimings.worldSaveTimer.startTiming(); // Spigot
|
||
|
MinecraftServer.LOGGER.debug("Autosave started");
|
||
|
this.profiler.push("save");
|
||
|
this.playerList.saveAll();
|
||
|
this.saveAllChunks(true, false, false);
|
||
|
this.profiler.pop();
|
||
|
MinecraftServer.LOGGER.debug("Autosave finished");
|
||
|
- SpigotTimings.worldSaveTimer.stopTiming(); // Spigot
|
||
|
}
|
||
|
|
||
|
this.profiler.push("snooper");
|
||
|
@@ -1161,6 +1180,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||
|
}
|
||
|
|
||
|
this.profiler.pop();
|
||
|
+
|
||
|
+ // Paper start - move executeAll() into full server tick timing
|
||
|
+ try (co.aikar.timings.Timing ignored = MinecraftTimings.processTasksTimer.startTiming()) {
|
||
|
+ this.runAllTasks();
|
||
|
+ }
|
||
|
+ // Paper end
|
||
|
+
|
||
|
this.profiler.push("tallying");
|
||
|
long l = this.tickTimes[this.tickCount % 100] = Util.getNanos() - i;
|
||
|
|
||
|
@@ -1171,30 +1197,29 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||
|
this.profiler.pop();
|
||
|
org.spigotmc.WatchdogThread.tick(); // Spigot
|
||
|
this.slackActivityAccountant.tickEnded(l); // Spigot
|
||
|
- SpigotTimings.serverTickTimer.stopTiming(); // Spigot
|
||
|
- org.spigotmc.CustomTimingsHandler.tick(); // Spigot
|
||
|
+ co.aikar.timings.TimingsManager.FULL_SERVER_TICK.stopTiming(); // Paper
|
||
|
}
|
||
|
|
||
|
protected void tickChildren(BooleanSupplier shouldKeepTicking) {
|
||
|
- SpigotTimings.schedulerTimer.startTiming(); // Spigot
|
||
|
+ MinecraftTimings.bukkitSchedulerTimer.startTiming(); // Spigot // Paper
|
||
|
this.server.getScheduler().mainThreadHeartbeat(this.tickCount); // CraftBukkit
|
||
|
- SpigotTimings.schedulerTimer.stopTiming(); // Spigot
|
||
|
+ MinecraftTimings.bukkitSchedulerTimer.stopTiming(); // Spigot // Paper
|
||
|
this.profiler.push("commandFunctions");
|
||
|
- SpigotTimings.commandFunctionsTimer.startTiming(); // Spigot
|
||
|
+ MinecraftTimings.commandFunctionsTimer.startTiming(); // Spigot // Paper
|
||
|
this.getFunctions().tick();
|
||
|
- SpigotTimings.commandFunctionsTimer.stopTiming(); // Spigot
|
||
|
+ MinecraftTimings.commandFunctionsTimer.stopTiming(); // Spigot // Paper
|
||
|
this.profiler.popPush("levels");
|
||
|
Iterator iterator = this.getAllLevels().iterator();
|
||
|
|
||
|
// CraftBukkit start
|
||
|
// Run tasks that are waiting on processing
|
||
|
- SpigotTimings.processQueueTimer.startTiming(); // Spigot
|
||
|
+ MinecraftTimings.processQueueTimer.startTiming(); // Spigot
|
||
|
while (!processQueue.isEmpty()) {
|
||
|
processQueue.remove().run();
|
||
|
}
|
||
|
- SpigotTimings.processQueueTimer.stopTiming(); // Spigot
|
||
|
+ MinecraftTimings.processQueueTimer.stopTiming(); // Spigot
|
||
|
|
||
|
- SpigotTimings.timeUpdateTimer.startTiming(); // Spigot
|
||
|
+ MinecraftTimings.timeUpdateTimer.startTiming(); // Spigot // Paper
|
||
|
// Send time updates to everyone, it will get the right time from the world the player is in.
|
||
|
if (this.tickCount % 20 == 0) {
|
||
|
for (int i = 0; i < this.getPlayerList().players.size(); ++i) {
|
||
|
@@ -1202,7 +1227,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||
|
entityplayer.connection.send(new ClientboundSetTimePacket(entityplayer.level.getGameTime(), entityplayer.getPlayerTime(), entityplayer.level.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT))); // Add support for per player time
|
||
|
}
|
||
|
}
|
||
|
- SpigotTimings.timeUpdateTimer.stopTiming(); // Spigot
|
||
|
+ MinecraftTimings.timeUpdateTimer.stopTiming(); // Spigot // Paper
|
||
|
|
||
|
while (iterator.hasNext()) {
|
||
|
ServerLevel worldserver = (ServerLevel) iterator.next();
|
||
|
@@ -1243,24 +1268,24 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||
|
}
|
||
|
|
||
|
this.profiler.popPush("connection");
|
||
|
- SpigotTimings.connectionTimer.startTiming(); // Spigot
|
||
|
+ MinecraftTimings.connectionTimer.startTiming(); // Spigot
|
||
|
this.getConnection().tick();
|
||
|
- SpigotTimings.connectionTimer.stopTiming(); // Spigot
|
||
|
+ MinecraftTimings.connectionTimer.stopTiming(); // Spigot
|
||
|
this.profiler.popPush("players");
|
||
|
- SpigotTimings.playerListTimer.startTiming(); // Spigot
|
||
|
+ MinecraftTimings.playerListTimer.startTiming(); // Spigot // Paper
|
||
|
this.playerList.tick();
|
||
|
- SpigotTimings.playerListTimer.stopTiming(); // Spigot
|
||
|
+ MinecraftTimings.playerListTimer.stopTiming(); // Spigot // Paper
|
||
|
if (SharedConstants.IS_RUNNING_IN_IDE) {
|
||
|
GameTestTicker.singleton.tick();
|
||
|
}
|
||
|
|
||
|
this.profiler.popPush("server gui refresh");
|
||
|
|
||
|
- SpigotTimings.tickablesTimer.startTiming(); // Spigot
|
||
|
+ MinecraftTimings.tickablesTimer.startTiming(); // Spigot // Paper
|
||
|
for (int i = 0; i < this.tickables.size(); ++i) {
|
||
|
((Runnable) this.tickables.get(i)).run();
|
||
|
}
|
||
|
- SpigotTimings.tickablesTimer.stopTiming(); // Spigot
|
||
|
+ MinecraftTimings.tickablesTimer.stopTiming(); // Spigot // Paper
|
||
|
|
||
|
this.profiler.pop();
|
||
|
}
|
||
|
diff --git a/src/main/java/net/minecraft/server/ServerFunctionManager.java b/src/main/java/net/minecraft/server/ServerFunctionManager.java
|
||
|
index 9a9680c50adf3afee5bf58b33425be25bd5933d9..14e6bdbbe368706ee17eda98bfbf35a9bb337016 100644
|
||
|
--- a/src/main/java/net/minecraft/server/ServerFunctionManager.java
|
||
|
+++ b/src/main/java/net/minecraft/server/ServerFunctionManager.java
|
||
|
@@ -75,7 +75,7 @@ public class ServerFunctionManager {
|
||
|
} else {
|
||
|
int j;
|
||
|
|
||
|
- try {
|
||
|
+ try (co.aikar.timings.Timing timing = function.getTiming().startTiming()) { // Paper
|
||
|
this.isInFunction = true;
|
||
|
int k = 0;
|
||
|
CommandFunction.Entry[] acustomfunction_c = function.getEntries();
|
||
|
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
||
|
index 23d6f803eafa78fd51ea4cdc4ca25c78661bc80b..40fe03c844c8bf6a9c4c5ae028b259f01a81eead 100644
|
||
|
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
||
|
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
||
|
@@ -62,8 +62,9 @@ import org.apache.logging.log4j.Logger;
|
||
|
import org.apache.logging.log4j.Level;
|
||
|
import org.apache.logging.log4j.io.IoBuilder;
|
||
|
import org.bukkit.command.CommandSender;
|
||
|
-import org.bukkit.craftbukkit.SpigotTimings; // Spigot
|
||
|
+import co.aikar.timings.MinecraftTimings; // Paper
|
||
|
import org.bukkit.event.server.ServerCommandEvent;
|
||
|
+import org.bukkit.craftbukkit.util.Waitable;
|
||
|
import org.bukkit.event.server.RemoteServerCommandEvent;
|
||
|
// CraftBukkit end
|
||
|
|
||
|
@@ -418,7 +419,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
||
|
}
|
||
|
|
||
|
public void handleConsoleInputs() {
|
||
|
- SpigotTimings.serverCommandTimer.startTiming(); // Spigot
|
||
|
+ MinecraftTimings.serverCommandTimer.startTiming(); // Spigot
|
||
|
while (!this.consoleInput.isEmpty()) {
|
||
|
ConsoleInput servercommand = (ConsoleInput) this.consoleInput.remove(0);
|
||
|
|
||
|
@@ -433,7 +434,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
||
|
// CraftBukkit end
|
||
|
}
|
||
|
|
||
|
- SpigotTimings.serverCommandTimer.stopTiming(); // Spigot
|
||
|
+ MinecraftTimings.serverCommandTimer.stopTiming(); // Spigot
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
@@ -669,6 +670,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
||
|
|
||
|
@Override
|
||
|
public String runCommand(String command) {
|
||
|
+ Waitable[] waitableArray = new Waitable[1];
|
||
|
this.rconConsoleSource.prepareForCommand();
|
||
|
this.executeBlocking(() -> {
|
||
|
// CraftBukkit start - fire RemoteServerCommandEvent
|
||
|
@@ -677,10 +679,39 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
||
|
if (event.isCancelled()) {
|
||
|
return;
|
||
|
}
|
||
|
+ // Paper start
|
||
|
+ if (command.toLowerCase().startsWith("timings") && command.toLowerCase().matches("timings (report|paste|get|merged|seperate)")) {
|
||
|
+ org.bukkit.command.BufferedCommandSender sender = new org.bukkit.command.BufferedCommandSender();
|
||
|
+ Waitable<String> waitable = new Waitable<String>() {
|
||
|
+ @Override
|
||
|
+ protected String evaluate() {
|
||
|
+ return sender.getBuffer();
|
||
|
+ }
|
||
|
+ };
|
||
|
+ waitableArray[0] = waitable;
|
||
|
+ co.aikar.timings.Timings.generateReport(new co.aikar.timings.TimingsReportListener(sender, waitable));
|
||
|
+ } else {
|
||
|
+ // Paper end
|
||
|
ConsoleInput serverCommand = new ConsoleInput(event.getCommand(), rconConsoleSource.createCommandSourceStack());
|
||
|
server.dispatchServerCommand(remoteConsole, serverCommand);
|
||
|
+ } // Paper
|
||
|
// CraftBukkit end
|
||
|
});
|
||
|
+ // Paper start
|
||
|
+ if (waitableArray[0] != null) {
|
||
|
+ //noinspection unchecked
|
||
|
+ Waitable<String> waitable = waitableArray[0];
|
||
|
+ try {
|
||
|
+ return waitable.get();
|
||
|
+ } catch (java.util.concurrent.ExecutionException e) {
|
||
|
+ throw new RuntimeException("Exception processing rcon command " + command, e.getCause());
|
||
|
+ } catch (InterruptedException e) {
|
||
|
+ Thread.currentThread().interrupt(); // Maintain interrupted state
|
||
|
+ throw new RuntimeException("Interrupted processing rcon command " + command, e);
|
||
|
+ }
|
||
|
+
|
||
|
+ }
|
||
|
+ // Paper end
|
||
|
return this.rconConsoleSource.getCommandResponse();
|
||
|
}
|
||
|
|
||
|
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
||
|
index d9d76d2ee43adc2b46d49f7fc3d9aef6af95e465..59a5f82c9f57d760ba4959a040ce8cbf0f49e4aa 100644
|
||
|
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
|
||
|
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
||
|
@@ -1,7 +1,9 @@
|
||
|
package net.minecraft.server.level;
|
||
|
|
||
|
+import co.aikar.timings.Timing; // Paper
|
||
|
import com.google.common.collect.ImmutableList;
|
||
|
import com.google.common.collect.Iterables;
|
||
|
+import com.google.common.collect.ComparisonChain; // Paper
|
||
|
import com.google.common.collect.Lists;
|
||
|
import com.google.common.collect.Queues;
|
||
|
import com.google.common.collect.Sets;
|
||
|
@@ -552,11 +554,14 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
||
|
|
||
|
private CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> scheduleChunkLoad(ChunkPos pos) {
|
||
|
return CompletableFuture.supplyAsync(() -> {
|
||
|
- try {
|
||
|
+ try (Timing ignored = this.level.timings.chunkLoad.startTimingIfSync()) { // Paper
|
||
|
this.level.getProfiler().incrementCounter("chunkLoad");
|
||
|
- CompoundTag nbttagcompound = this.readChunk(pos);
|
||
|
+ CompoundTag nbttagcompound; // Paper
|
||
|
+ try (Timing ignored2 = this.level.timings.chunkIO.startTimingIfSync()) { // Paper start - timings
|
||
|
+ nbttagcompound = this.readChunk(pos);
|
||
|
+ } // Paper end
|
||
|
|
||
|
- if (nbttagcompound != null) {
|
||
|
+ if (nbttagcompound != null) {try (Timing ignored2 = this.level.timings.chunkLoadLevelTimer.startTimingIfSync()) { // Paper start - timings
|
||
|
boolean flag = nbttagcompound.contains("Level", 10) && nbttagcompound.getCompound("Level").contains("Status", 8);
|
||
|
|
||
|
if (flag) {
|
||
|
@@ -568,7 +573,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
||
|
}
|
||
|
|
||
|
ChunkMap.LOGGER.error("Chunk file at {} is missing level data, skipping", pos);
|
||
|
- }
|
||
|
+ }} // Paper
|
||
|
} catch (ReportedException reportedexception) {
|
||
|
Throwable throwable = reportedexception.getCause();
|
||
|
|
||
|
@@ -605,7 +610,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
||
|
return "chunkGenerate " + requiredStatus.getName();
|
||
|
});
|
||
|
return completablefuture.thenComposeAsync((either) -> {
|
||
|
- return (CompletableFuture) either.map((list) -> {
|
||
|
+ return either.map((list) -> { // Paper - Shut up.
|
||
|
try {
|
||
|
CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> completablefuture1 = requiredStatus.generate(this.level, this.generator, this.structureManager, this.lightEngine, (ichunkaccess) -> {
|
||
|
return this.protoChunkToFullChunk(holder);
|
||
|
@@ -658,6 +663,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
||
|
ChunkStatus chunkstatus = ChunkHolder.getStatus(playerchunk.getTicketLevel());
|
||
|
|
||
|
return !chunkstatus.isOrAfter(ChunkStatus.FULL) ? ChunkHolder.UNLOADED_CHUNK : either.mapLeft((ichunkaccess) -> {
|
||
|
+ try (Timing ignored = level.timings.chunkPostLoad.startTimingIfSync()) { // Paper
|
||
|
ChunkPos chunkcoordintpair = playerchunk.getPos();
|
||
|
LevelChunk chunk;
|
||
|
|
||
|
@@ -717,6 +723,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
||
|
}
|
||
|
|
||
|
return chunk;
|
||
|
+ } // Paper
|
||
|
});
|
||
|
}, (runnable) -> {
|
||
|
ProcessorHandle mailbox = this.mainThreadMailbox;
|
||
|
@@ -1175,6 +1182,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
||
|
|
||
|
ChunkMap.TrackedEntity playerchunkmap_entitytracker;
|
||
|
ObjectIterator objectiterator;
|
||
|
+ level.timings.tracker1.startTiming(); // Paper
|
||
|
|
||
|
for (objectiterator = this.entityMap.values().iterator(); objectiterator.hasNext(); playerchunkmap_entitytracker.serverEntity.sendChanges()) {
|
||
|
playerchunkmap_entitytracker = (ChunkMap.TrackedEntity) objectiterator.next();
|
||
|
@@ -1192,16 +1200,20 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
||
|
playerchunkmap_entitytracker.lastSectionPos = sectionposition1;
|
||
|
}
|
||
|
}
|
||
|
+ level.timings.tracker1.stopTiming(); // Paper
|
||
|
|
||
|
if (!list.isEmpty()) {
|
||
|
objectiterator = this.entityMap.values().iterator();
|
||
|
|
||
|
+ level.timings.tracker2.startTiming(); // Paper
|
||
|
while (objectiterator.hasNext()) {
|
||
|
playerchunkmap_entitytracker = (ChunkMap.TrackedEntity) objectiterator.next();
|
||
|
playerchunkmap_entitytracker.updatePlayers(list);
|
||
|
}
|
||
|
+ level.timings.tracker2.stopTiming(); // Paper
|
||
|
}
|
||
|
|
||
|
+
|
||
|
}
|
||
|
|
||
|
protected void broadcast(Entity entity, Packet<?> packet) {
|
||
|
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||
|
index ef336645f3bd7a86129ad1dff7e1a15dc93d1e3e..d0b0fdaf5451bcc7f7ac7dab28aa59ef77e6dd97 100644
|
||
|
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||
|
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||
|
@@ -344,11 +344,13 @@ public class ServerChunkCache extends ChunkSource {
|
||
|
}
|
||
|
|
||
|
gameprofilerfiller.incrementCounter("getChunkCacheMiss");
|
||
|
- level.timings.syncChunkLoadTimer.startTiming(); // Spigot
|
||
|
CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> completablefuture = this.getChunkFutureMainThread(x, z, leastStatus, create);
|
||
|
|
||
|
+ if (!completablefuture.isDone()) { // Paper
|
||
|
+ this.level.timings.syncChunkLoad.startTiming(); // Paper
|
||
|
this.mainThreadProcessor.managedBlock(completablefuture::isDone);
|
||
|
- level.timings.syncChunkLoadTimer.stopTiming(); // Spigot
|
||
|
+ this.level.timings.syncChunkLoad.stopTiming(); // Paper
|
||
|
+ } // Paper
|
||
|
ichunkaccess = (ChunkAccess) ((Either) completablefuture.join()).map((ichunkaccess1) -> {
|
||
|
return ichunkaccess1;
|
||
|
}, (playerchunk_failure) -> {
|
||
|
@@ -536,7 +538,9 @@ public class ServerChunkCache extends ChunkSource {
|
||
|
|
||
|
public void save(boolean flush) {
|
||
|
this.runDistanceManagerUpdates();
|
||
|
+ try (co.aikar.timings.Timing timed = level.timings.chunkSaveData.startTiming()) { // Paper - Timings
|
||
|
this.chunkMap.saveAllChunks(flush);
|
||
|
+ } // Paper - Timings
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
@@ -573,7 +577,9 @@ public class ServerChunkCache extends ChunkSource {
|
||
|
this.runDistanceManagerUpdates();
|
||
|
this.level.timings.doChunkMap.stopTiming(); // Spigot
|
||
|
this.level.getProfiler().popPush("chunks");
|
||
|
+ this.level.timings.chunks.startTiming(); // Paper - timings
|
||
|
this.tickChunks();
|
||
|
+ this.level.timings.chunks.stopTiming(); // Paper - timings
|
||
|
this.level.timings.doChunkUnload.startTiming(); // Spigot
|
||
|
this.level.getProfiler().popPush("unload");
|
||
|
this.chunkMap.tick(shouldKeepTicking);
|
||
|
@@ -597,19 +603,24 @@ public class ServerChunkCache extends ChunkSource {
|
||
|
boolean flag2 = level.ticksPerAnimalSpawns != 0L && worlddata.getGameTime() % level.ticksPerAnimalSpawns == 0L; // CraftBukkit
|
||
|
|
||
|
this.level.getProfiler().push("naturalSpawnCount");
|
||
|
+ this.level.timings.countNaturalMobs.startTiming(); // Paper - timings
|
||
|
int l = this.distanceManager.getNaturalSpawnChunkCount();
|
||
|
NaturalSpawner.SpawnState spawnercreature_d = NaturalSpawner.createState(l, this.level.getAllEntities(), this::getFullChunk);
|
||
|
+ this.level.timings.countNaturalMobs.stopTiming(); // Paper - timings
|
||
|
|
||
|
this.lastSpawnState = spawnercreature_d;
|
||
|
this.level.getProfiler().pop();
|
||
|
//List<PlayerChunk> list = Lists.newArrayList(this.playerChunkMap.f()); // Paper
|
||
|
//Collections.shuffle(list); // Paper
|
||
|
+ this.level.timings.chunkTicks.startTiming(); // Paper
|
||
|
this.chunkMap.getChunks().forEach((playerchunk) -> { // Paper - no... just no...
|
||
|
Optional<LevelChunk> optional = ((Either) playerchunk.getTickingChunkFuture().getNow(ChunkHolder.UNLOADED_LEVEL_CHUNK)).left();
|
||
|
|
||
|
if (optional.isPresent()) {
|
||
|
this.level.getProfiler().push("broadcast");
|
||
|
+ this.level.timings.broadcastChunkUpdates.startTiming(); // Paper - timings
|
||
|
playerchunk.broadcastChanges((LevelChunk) optional.get());
|
||
|
+ this.level.timings.broadcastChunkUpdates.stopTiming(); // Paper - timings
|
||
|
this.level.getProfiler().pop();
|
||
|
Optional<LevelChunk> optional1 = ((Either) playerchunk.getEntityTickingChunkFuture().getNow(ChunkHolder.UNLOADED_LEVEL_CHUNK)).left();
|
||
|
|
||
|
@@ -623,25 +634,26 @@ public class ServerChunkCache extends ChunkSource {
|
||
|
NaturalSpawner.spawnForChunk(this.level, chunk, spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag2);
|
||
|
}
|
||
|
|
||
|
- this.level.timings.doTickTiles.startTiming(); // Spigot
|
||
|
+ //this.world.timings.chunkTicks.startTiming(); // Spigot // Paper
|
||
|
this.level.tickChunk(chunk, k);
|
||
|
- this.level.timings.doTickTiles.stopTiming(); // Spigot
|
||
|
+ //this.world.timings.chunkTicks.stopTiming(); // Spigot // Paper
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
+ this.level.timings.chunkTicks.stopTiming(); // Paper
|
||
|
this.level.getProfiler().push("customSpawners");
|
||
|
if (flag1) {
|
||
|
+ try (co.aikar.timings.Timing ignored = this.level.timings.miscMobSpawning.startTiming()) { // Paper - timings
|
||
|
this.level.tickCustomSpawners(this.spawnEnemies, this.spawnFriendlies);
|
||
|
+ } // Paper - timings
|
||
|
}
|
||
|
|
||
|
this.level.getProfiler().pop();
|
||
|
this.level.getProfiler().pop();
|
||
|
}
|
||
|
|
||
|
- this.level.timings.tracker.startTiming(); // Spigot
|
||
|
this.chunkMap.tick();
|
||
|
- this.level.timings.tracker.stopTiming(); // Spigot
|
||
|
}
|
||
|
|
||
|
private void getFullChunk(long pos, Consumer<LevelChunk> chunkConsumer) {
|
||
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||
|
index 34ed8f0d348e7bc2339660ebc6490057ba9ef214..0cc86ca4ea4a2e1b5acc3c0507397eef85dec0c1 100644
|
||
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||
|
@@ -2,6 +2,8 @@ package net.minecraft.server.level;
|
||
|
|
||
|
import com.google.common.annotations.VisibleForTesting;
|
||
|
import com.google.common.collect.Iterables;
|
||
|
+import co.aikar.timings.TimingHistory; // Paper
|
||
|
+import co.aikar.timings.Timings; // Paper
|
||
|
import com.google.common.collect.Lists;
|
||
|
import com.google.common.collect.Maps;
|
||
|
import com.google.common.collect.Queues;
|
||
|
@@ -147,7 +149,6 @@ import org.apache.logging.log4j.Logger;
|
||
|
import java.util.logging.Level;
|
||
|
import org.bukkit.Bukkit;
|
||
|
import org.bukkit.WeatherType;
|
||
|
-import org.bukkit.craftbukkit.SpigotTimings; // Spigot
|
||
|
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
||
|
import org.bukkit.craftbukkit.util.WorldUUID;
|
||
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||
|
@@ -203,10 +204,10 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
|
||
|
// CraftBukkit end
|
||
|
this.blockTicks = new ServerTickList<>(this, (block) -> {
|
||
|
return block == null || block.defaultBlockState().isAir();
|
||
|
- }, Registry.BLOCK::getKey, this::tickBlock);
|
||
|
+ }, Registry.BLOCK::getKey, this::tickBlock, "Blocks"); // Paper - Timings
|
||
|
this.liquidTicks = new ServerTickList<>(this, (fluidtype) -> {
|
||
|
return fluidtype == null || fluidtype == Fluids.EMPTY;
|
||
|
- }, Registry.FLUID::getKey, this::tickLiquid);
|
||
|
+ }, Registry.FLUID::getKey, this::tickLiquid, "Fluids"); // Paper - Timings
|
||
|
this.navigations = Sets.newHashSet();
|
||
|
this.blockEvents = new ObjectLinkedOpenHashSet();
|
||
|
this.tickTime = flag1;
|
||
|
@@ -436,17 +437,21 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
|
||
|
this.updateSkyBrightness();
|
||
|
this.tickTime();
|
||
|
gameprofilerfiller.popPush("chunkSource");
|
||
|
+ this.timings.chunkProviderTick.startTiming(); // Paper - timings
|
||
|
this.getChunkSource().tick(shouldKeepTicking);
|
||
|
+ this.timings.chunkProviderTick.stopTiming(); // Paper - timings
|
||
|
gameprofilerfiller.popPush("tickPending");
|
||
|
- timings.doTickPending.startTiming(); // Spigot
|
||
|
+ timings.scheduledBlocks.startTiming(); // Paper
|
||
|
if (!this.isDebug()) {
|
||
|
this.blockTicks.tick();
|
||
|
this.liquidTicks.tick();
|
||
|
}
|
||
|
- timings.doTickPending.stopTiming(); // Spigot
|
||
|
+ timings.scheduledBlocks.stopTiming(); // Paper
|
||
|
|
||
|
gameprofilerfiller.popPush("raid");
|
||
|
+ this.timings.raids.startTiming(); // Paper - timings
|
||
|
this.raids.tick();
|
||
|
+ this.timings.raids.stopTiming(); // Paper - timings
|
||
|
gameprofilerfiller.popPush("blockEvents");
|
||
|
timings.doSounds.startTiming(); // Spigot
|
||
|
this.runBlockEvents();
|
||
|
@@ -618,6 +623,7 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
|
||
|
}
|
||
|
|
||
|
gameprofilerfiller.popPush("tickBlocks");
|
||
|
+ timings.chunkTicksBlocks.startTiming(); // Paper
|
||
|
if (randomTickSpeed > 0) {
|
||
|
LevelChunkSection[] achunksection = chunk.getSections();
|
||
|
int l = achunksection.length;
|
||
|
@@ -649,7 +655,7 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
-
|
||
|
+ timings.chunkTicksBlocks.stopTiming(); // Paper
|
||
|
gameprofilerfiller.pop();
|
||
|
}
|
||
|
|
||
|
@@ -747,14 +753,22 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
|
||
|
if (!(entity instanceof Player) && !this.getChunkSource().isEntityTickingChunk(entity)) {
|
||
|
this.updateChunkPos(entity);
|
||
|
} else {
|
||
|
+ ++TimingHistory.entityTicks; // Paper - timings
|
||
|
// Spigot start
|
||
|
+ co.aikar.timings.Timing timer; // Paper
|
||
|
if (!org.spigotmc.ActivationRange.checkIfActive(entity)) {
|
||
|
entity.tickCount++;
|
||
|
+ timer = entity.getType().inactiveTickTimer.startTiming(); try { // Paper - timings
|
||
|
entity.inactiveTick();
|
||
|
+ } finally { timer.stopTiming(); } // Paper
|
||
|
return;
|
||
|
}
|
||
|
// Spigot end
|
||
|
- entity.tickTimer.startTiming(); // Spigot
|
||
|
+ // Paper start- timings
|
||
|
+ TimingHistory.activatedEntityTicks++;
|
||
|
+ timer = entity.getVehicle() != null ? entity.getType().passengerTickTimer.startTiming() : entity.getType().tickTimer.startTiming();
|
||
|
+ try {
|
||
|
+ // Paper end - timings
|
||
|
entity.setPosAndOldPos(entity.getX(), entity.getY(), entity.getZ());
|
||
|
entity.yRotO = entity.yRot;
|
||
|
entity.xRotO = entity.xRot;
|
||
|
@@ -781,7 +795,7 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
|
||
|
this.tickPassenger(entity, entity1);
|
||
|
}
|
||
|
}
|
||
|
- entity.tickTimer.stopTiming(); // Spigot
|
||
|
+ } finally { timer.stopTiming(); } // Paper - timings
|
||
|
|
||
|
}
|
||
|
}
|
||
|
@@ -859,6 +873,7 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
|
||
|
|
||
|
if (!flag1) {
|
||
|
org.bukkit.Bukkit.getPluginManager().callEvent(new org.bukkit.event.world.WorldSaveEvent(getWorld())); // CraftBukkit
|
||
|
+ try (co.aikar.timings.Timing ignored = timings.worldSave.startTiming()) { // Paper
|
||
|
if (progressListener != null) {
|
||
|
progressListener.progressStartNoAbort(new TranslatableComponent("menu.savingLevel"));
|
||
|
}
|
||
|
@@ -868,7 +883,10 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
|
||
|
progressListener.progressStage(new TranslatableComponent("menu.savingChunks"));
|
||
|
}
|
||
|
|
||
|
+ timings.worldSaveChunks.startTiming(); // Paper
|
||
|
chunkproviderserver.save(flush);
|
||
|
+ timings.worldSaveChunks.stopTiming(); // Paper
|
||
|
+ } // Paper
|
||
|
}
|
||
|
|
||
|
// CraftBukkit start - moved from MinecraftServer.saveChunks
|
||
|
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||
|
index 35f3940cebb00ee29da54b1ee148ee931fa11636..466c4322803bedf1fa61be281b954bf94fb8ff02 100644
|
||
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||
|
@@ -209,6 +209,7 @@ import org.bukkit.inventory.EquipmentSlot;
|
||
|
import org.bukkit.inventory.InventoryView;
|
||
|
import org.bukkit.inventory.SmithingInventory;
|
||
|
import org.bukkit.util.NumberConversions;
|
||
|
+import co.aikar.timings.MinecraftTimings; // Paper
|
||
|
// CraftBukkit end
|
||
|
|
||
|
public class ServerGamePacketListenerImpl implements ServerGamePacketListener {
|
||
|
@@ -291,7 +292,6 @@ public class ServerGamePacketListenerImpl implements ServerGamePacketListener {
|
||
|
// CraftBukkit end
|
||
|
|
||
|
public void tick() {
|
||
|
- org.bukkit.craftbukkit.SpigotTimings.playerConnectionTimer.startTiming(); // Spigot
|
||
|
this.resetPosition();
|
||
|
this.player.xo = this.player.getX();
|
||
|
this.player.yo = this.player.getY();
|
||
|
@@ -367,7 +367,6 @@ public class ServerGamePacketListenerImpl implements ServerGamePacketListener {
|
||
|
this.player.resetLastActionTime(); // CraftBukkit - SPIGOT-854
|
||
|
this.disconnect(new TranslatableComponent("multiplayer.disconnect.idling"));
|
||
|
}
|
||
|
- org.bukkit.craftbukkit.SpigotTimings.playerConnectionTimer.stopTiming(); // Spigot
|
||
|
|
||
|
}
|
||
|
|
||
|
@@ -1915,7 +1914,7 @@ public class ServerGamePacketListenerImpl implements ServerGamePacketListener {
|
||
|
// CraftBukkit end
|
||
|
|
||
|
private void handleCommand(String input) {
|
||
|
- org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.startTiming(); // Spigot
|
||
|
+ MinecraftTimings.playerCommandTimer.startTiming(); // Paper
|
||
|
// CraftBukkit start - whole method
|
||
|
if ( org.spigotmc.SpigotConfig.logCommands ) // Spigot
|
||
|
this.LOGGER.info(this.player.getScoreboardName() + " issued server command: " + input);
|
||
|
@@ -1926,7 +1925,7 @@ public class ServerGamePacketListenerImpl implements ServerGamePacketListener {
|
||
|
this.craftServer.getPluginManager().callEvent(event);
|
||
|
|
||
|
if (event.isCancelled()) {
|
||
|
- org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.stopTiming(); // Spigot
|
||
|
+ MinecraftTimings.playerCommandTimer.stopTiming(); // Paper
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
@@ -1939,7 +1938,7 @@ public class ServerGamePacketListenerImpl implements ServerGamePacketListener {
|
||
|
java.util.logging.Logger.getLogger(ServerGamePacketListenerImpl.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||
|
return;
|
||
|
} finally {
|
||
|
- org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.stopTiming(); // Spigot
|
||
|
+ MinecraftTimings.playerCommandTimer.stopTiming(); // Paper
|
||
|
}
|
||
|
// this.minecraftServer.getCommandDispatcher().a(this.player.getCommandListener(), s);
|
||
|
// CraftBukkit end
|
||
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
||
|
index 28121e2fee9d862057042261d25360f0d4ee4530..88af57699d7f9e45ad1366243049e4f3565703ff 100644
|
||
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
||
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
||
|
@@ -1,5 +1,6 @@
|
||
|
package net.minecraft.server.players;
|
||
|
|
||
|
+import co.aikar.timings.MinecraftTimings;
|
||
|
import com.google.common.collect.Lists;
|
||
|
import com.google.common.collect.Maps;
|
||
|
import com.google.common.collect.Sets;
|
||
|
@@ -1018,10 +1019,11 @@ public abstract class PlayerList {
|
||
|
}
|
||
|
|
||
|
public void saveAll() {
|
||
|
+ MinecraftTimings.savePlayers.startTiming(); // Paper
|
||
|
for (int i = 0; i < this.players.size(); ++i) {
|
||
|
this.save((ServerPlayer) this.players.get(i));
|
||
|
}
|
||
|
-
|
||
|
+ MinecraftTimings.savePlayers.stopTiming(); // Paper
|
||
|
}
|
||
|
|
||
|
public UserWhiteList getWhiteList() {
|
||
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
||
|
index b633f6b3a36b793e6dbc1b8b554bfba74c719570..2a7f587e19fcdd6d01b360d6b47d9eadd9df92cc 100644
|
||
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
||
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
||
|
@@ -115,7 +115,6 @@ import org.bukkit.craftbukkit.event.CraftPortalEvent;
|
||
|
import org.bukkit.entity.Hanging;
|
||
|
import org.bukkit.entity.LivingEntity;
|
||
|
import org.bukkit.entity.Vehicle;
|
||
|
-import org.spigotmc.CustomTimingsHandler; // Spigot
|
||
|
import org.bukkit.event.entity.EntityCombustByEntityEvent;
|
||
|
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
||
|
import org.bukkit.event.vehicle.VehicleBlockCollisionEvent;
|
||
|
@@ -247,7 +246,6 @@ public abstract class Entity implements Nameable, CommandSource, net.minecraft.s
|
||
|
public org.bukkit.projectiles.ProjectileSource projectileSource; // For projectiles only
|
||
|
public boolean forceExplosionKnockback; // SPIGOT-949
|
||
|
public boolean persistentInvisibility = false;
|
||
|
- public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getEntityTimings(this); // Spigot
|
||
|
// Spigot start
|
||
|
public final org.spigotmc.ActivationRange.ActivationType activationType = org.spigotmc.ActivationRange.initializeEntityActivationType(this);
|
||
|
public final boolean defaultActivationState;
|
||
|
@@ -616,7 +614,6 @@ public abstract class Entity implements Nameable, CommandSource, net.minecraft.s
|
||
|
}
|
||
|
|
||
|
public void move(MoverType type, Vec3 movement) {
|
||
|
- org.bukkit.craftbukkit.SpigotTimings.entityMoveTimer.startTiming(); // Spigot
|
||
|
if (this.noPhysics) {
|
||
|
this.setBoundingBox(this.getBoundingBox().move(movement));
|
||
|
this.setLocationFromBoundingbox();
|
||
|
@@ -752,7 +749,6 @@ public abstract class Entity implements Nameable, CommandSource, net.minecraft.s
|
||
|
|
||
|
this.level.getProfiler().pop();
|
||
|
}
|
||
|
- org.bukkit.craftbukkit.SpigotTimings.entityMoveTimer.stopTiming(); // Spigot
|
||
|
}
|
||
|
|
||
|
protected BlockPos getOnPos() {
|
||
|
diff --git a/src/main/java/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java
|
||
|
index 2cb86de4bfc87a709f0cfa2c4e550d8e7928a3f0..e3d92d1d35911b2960a7ca82bd4f324d285d0533 100644
|
||
|
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
|
||
|
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
|
||
|
@@ -281,17 +281,27 @@ public class EntityType<T extends Entity> {
|
||
|
return Registry.ENTITY_TYPE.getOptional(ResourceLocation.tryParse(id));
|
||
|
}
|
||
|
|
||
|
- public EntityType(EntityType.EntityFactory<T> factory, MobCategory spawnGroup, boolean saveable, boolean summonable, boolean fireImmune, boolean spawnableFarFromPlayer, ImmutableSet<Block> immutableset, EntityDimensions entitysize, int i, int j) {
|
||
|
- this.factory = factory;
|
||
|
- this.category = spawnGroup;
|
||
|
- this.canSpawnFarFromPlayer = spawnableFarFromPlayer;
|
||
|
- this.serialize = saveable;
|
||
|
- this.summon = summonable;
|
||
|
- this.fireImmune = fireImmune;
|
||
|
+ public final String id;
|
||
|
+ public EntityType(EntityType.EntityFactory<T> factory, MobCategory spawnGroup, boolean saveable, boolean summonable, boolean fireImmune, boolean spawnableFarFromPlayer, ImmutableSet<Block> immutableset, EntityDimensions entitysize, int i, int j) { this(factory, spawnGroup, saveable, summonable, fireImmune, spawnableFarFromPlayer, immutableset, entitysize, i, j, "custom"); } // Paper - old signature
|
||
|
+ public EntityType(EntityType.EntityFactory<T> entitytypes_b, MobCategory enumcreaturetype, boolean flag, boolean flag1, boolean flag2, boolean flag3, ImmutableSet<Block> immutableset, EntityDimensions entitysize, int i, int j, String id) { // Paper - add id
|
||
|
+ this.factory = entitytypes_b;
|
||
|
+ this.category = enumcreaturetype;
|
||
|
+ this.canSpawnFarFromPlayer = flag3;
|
||
|
+ this.serialize = flag;
|
||
|
+ this.summon = flag1;
|
||
|
+ this.fireImmune = flag2;
|
||
|
this.immuneTo = immutableset;
|
||
|
this.dimensions = entitysize;
|
||
|
this.clientTrackingRange = i;
|
||
|
this.updateInterval = j;
|
||
|
+
|
||
|
+ // Paper start - timings
|
||
|
+ this.id = id;
|
||
|
+ this.tickTimer = co.aikar.timings.MinecraftTimings.getEntityTimings(id, "tick");
|
||
|
+ this.inactiveTickTimer = co.aikar.timings.MinecraftTimings.getEntityTimings(id, "inactiveTick");
|
||
|
+ this.passengerTickTimer = co.aikar.timings.MinecraftTimings.getEntityTimings(id, "passengerTick");
|
||
|
+ this.passengerInactiveTickTimer = co.aikar.timings.MinecraftTimings.getEntityTimings(id, "passengerInactiveTick");
|
||
|
+ // Paper end
|
||
|
}
|
||
|
|
||
|
@Nullable
|
||
|
@@ -512,6 +522,12 @@ public class EntityType<T extends Entity> {
|
||
|
return this.updateInterval;
|
||
|
}
|
||
|
|
||
|
+ // Paper start - timings
|
||
|
+ public final co.aikar.timings.Timing tickTimer;
|
||
|
+ public final co.aikar.timings.Timing inactiveTickTimer;
|
||
|
+ public final co.aikar.timings.Timing passengerTickTimer;
|
||
|
+ public final co.aikar.timings.Timing passengerInactiveTickTimer;
|
||
|
+ // Paper end
|
||
|
public boolean trackDeltas() {
|
||
|
return this != EntityType.PLAYER && this != EntityType.LLAMA_SPIT && this != EntityType.WITHER && this != EntityType.BAT && this != EntityType.ITEM_FRAME && this != EntityType.LEASH_KNOT && this != EntityType.PAINTING && this != EntityType.END_CRYSTAL && this != EntityType.EVOKER_FANGS;
|
||
|
}
|
||
|
@@ -599,7 +615,7 @@ public class EntityType<T extends Entity> {
|
||
|
Util.fetchChoiceType(References.ENTITY_TREE, id);
|
||
|
}
|
||
|
|
||
|
- return new EntityType<>(this.factory, this.category, this.serialize, this.summon, this.fireImmune, this.canSpawnFarFromPlayer, this.immuneTo, this.dimensions, this.clientTrackingRange, this.updateInterval);
|
||
|
+ return new EntityType<>(this.factory, this.category, this.serialize, this.summon, this.fireImmune, this.canSpawnFarFromPlayer, this.immuneTo, this.dimensions, this.clientTrackingRange, this.updateInterval, id); // Paper - add id
|
||
|
}
|
||
|
}
|
||
|
|
||
|
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||
|
index 9e5dde73bd65bf4e51352c628fba024c36e29ef1..e5f8cee6726ea9a90c540bb10fd8594a35bb5e40 100644
|
||
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||
|
@@ -132,7 +132,7 @@ import org.bukkit.event.entity.EntityTeleportEvent;
|
||
|
import org.bukkit.event.player.PlayerItemConsumeEvent;
|
||
|
// CraftBukkit end
|
||
|
|
||
|
-import org.bukkit.craftbukkit.SpigotTimings; // Spigot
|
||
|
+import co.aikar.timings.MinecraftTimings; // Paper
|
||
|
|
||
|
public abstract class LivingEntity extends Entity {
|
||
|
|
||
|
@@ -2455,7 +2455,6 @@ public abstract class LivingEntity extends Entity {
|
||
|
|
||
|
@Override
|
||
|
public void tick() {
|
||
|
- SpigotTimings.timerEntityBaseTick.startTiming(); // Spigot
|
||
|
super.tick();
|
||
|
this.updatingUsingItem();
|
||
|
this.updateSwimAmount();
|
||
|
@@ -2504,9 +2503,7 @@ public abstract class LivingEntity extends Entity {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- SpigotTimings.timerEntityBaseTick.stopTiming(); // Spigot
|
||
|
this.aiStep();
|
||
|
- SpigotTimings.timerEntityTickRest.startTiming(); // Spigot
|
||
|
double d0 = this.getX() - this.xo;
|
||
|
double d1 = this.getZ() - this.zo;
|
||
|
float f = (float) (d0 * d0 + d1 * d1);
|
||
|
@@ -2586,8 +2583,6 @@ public abstract class LivingEntity extends Entity {
|
||
|
if (this.isSleeping()) {
|
||
|
this.xRot = 0.0F;
|
||
|
}
|
||
|
-
|
||
|
- SpigotTimings.timerEntityTickRest.stopTiming(); // Spigot
|
||
|
}
|
||
|
|
||
|
public void detectEquipmentUpdates() {
|
||
|
@@ -2769,7 +2764,6 @@ public abstract class LivingEntity extends Entity {
|
||
|
|
||
|
this.setDeltaMovement(d4, d5, d6);
|
||
|
this.level.getProfiler().push("ai");
|
||
|
- SpigotTimings.timerEntityAI.startTiming(); // Spigot
|
||
|
if (this.isImmobile()) {
|
||
|
this.jumping = false;
|
||
|
this.xxa = 0.0F;
|
||
|
@@ -2779,7 +2773,6 @@ public abstract class LivingEntity extends Entity {
|
||
|
this.serverAiStep();
|
||
|
this.level.getProfiler().pop();
|
||
|
}
|
||
|
- SpigotTimings.timerEntityAI.stopTiming(); // Spigot
|
||
|
|
||
|
this.level.getProfiler().pop();
|
||
|
this.level.getProfiler().push("jump");
|
||
|
@@ -2814,9 +2807,9 @@ public abstract class LivingEntity extends Entity {
|
||
|
this.updateFallFlying();
|
||
|
AABB axisalignedbb = this.getBoundingBox();
|
||
|
|
||
|
- SpigotTimings.timerEntityAIMove.startTiming(); // Spigot
|
||
|
+ // SpigotTimings.timerEntityAIMove.startTiming(); // Spigot // Paper
|
||
|
this.travel(new Vec3((double) this.xxa, (double) this.yya, (double) this.zza));
|
||
|
- SpigotTimings.timerEntityAIMove.stopTiming(); // Spigot
|
||
|
+ // SpigotTimings.timerEntityAIMove.stopTiming(); // Spigot // Paper
|
||
|
this.level.getProfiler().pop();
|
||
|
this.level.getProfiler().push("push");
|
||
|
if (this.autoSpinAttackTicks > 0) {
|
||
|
@@ -2824,9 +2817,7 @@ public abstract class LivingEntity extends Entity {
|
||
|
this.checkAutoSpinAttack(axisalignedbb, this.getBoundingBox());
|
||
|
}
|
||
|
|
||
|
- SpigotTimings.timerEntityAICollision.startTiming(); // Spigot
|
||
|
this.pushEntities();
|
||
|
- SpigotTimings.timerEntityAICollision.stopTiming(); // Spigot
|
||
|
this.level.getProfiler().pop();
|
||
|
if (!this.level.isClientSide && this.isSensitiveToWater() && this.isInWaterRainOrBubble()) {
|
||
|
this.hurt(DamageSource.DROWN, 1.0F);
|
||
|
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
|
||
|
index 5cc4c2668df72f83fb1526f4586b71d2ae0103dc..c153df1f4dea3dc0ae744bde01e334b3bd3b50af 100644
|
||
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
||
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
||
|
@@ -70,7 +70,6 @@ import org.apache.logging.log4j.Logger;
|
||
|
import java.util.HashMap;
|
||
|
import java.util.Map;
|
||
|
import org.bukkit.Bukkit;
|
||
|
-import org.bukkit.craftbukkit.SpigotTimings; // Spigot
|
||
|
import org.bukkit.craftbukkit.CraftServer;
|
||
|
import org.bukkit.craftbukkit.CraftWorld;
|
||
|
import org.bukkit.craftbukkit.block.CapturedBlockState;
|
||
|
@@ -132,7 +131,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
||
|
|
||
|
public final com.destroystokyo.paper.PaperWorldConfig paperConfig; // Paper
|
||
|
|
||
|
- public final SpigotTimings.WorldTimingsHandler timings; // Spigot
|
||
|
+ public final co.aikar.timings.WorldTimingsHandler timings; // Paper
|
||
|
public static BlockPos lastPhysicsProblem; // Spigot
|
||
|
private org.spigotmc.TickLimiter entityLimiter;
|
||
|
private org.spigotmc.TickLimiter tileLimiter;
|
||
|
@@ -217,7 +216,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
||
|
public void onBorderSetDamageSafeZOne(WorldBorder border, double safeZoneRadius) {}
|
||
|
});
|
||
|
// CraftBukkit end
|
||
|
- timings = new SpigotTimings.WorldTimingsHandler(this); // Spigot - code below can generate new world and access timings
|
||
|
+ timings = new co.aikar.timings.WorldTimingsHandler(this); // Paper - code below can generate new world and access timings
|
||
|
this.entityLimiter = new org.spigotmc.TickLimiter(spigotConfig.entityMaxTickTime);
|
||
|
this.tileLimiter = new org.spigotmc.TickLimiter(spigotConfig.tileMaxTickTime);
|
||
|
}
|
||
|
@@ -797,15 +796,14 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
||
|
}
|
||
|
|
||
|
timings.tileEntityPending.stopTiming(); // Spigot
|
||
|
+ co.aikar.timings.TimingHistory.tileEntityTicks += this.tickableBlockEntities.size(); // Paper
|
||
|
gameprofilerfiller.pop();
|
||
|
spigotConfig.currentPrimedTnt = 0; // Spigot
|
||
|
}
|
||
|
|
||
|
public void guardEntityTick(Consumer<Entity> tickConsumer, Entity entity) {
|
||
|
try {
|
||
|
- SpigotTimings.tickEntityTimer.startTiming(); // Spigot
|
||
|
tickConsumer.accept(entity);
|
||
|
- SpigotTimings.tickEntityTimer.stopTiming(); // Spigot
|
||
|
} catch (Throwable throwable) {
|
||
|
CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking entity");
|
||
|
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being ticked");
|
||
|
diff --git a/src/main/java/net/minecraft/world/level/ServerTickList.java b/src/main/java/net/minecraft/world/level/ServerTickList.java
|
||
|
index 0519d5adf392dd46b4a93c5c1b977c8355163c2e..10ac1ba0a3d192486f22c2127d5bc30353f0edb6 100644
|
||
|
--- a/src/main/java/net/minecraft/world/level/ServerTickList.java
|
||
|
+++ b/src/main/java/net/minecraft/world/level/ServerTickList.java
|
||
|
@@ -38,12 +38,17 @@ public class ServerTickList<T> implements TickList<T> {
|
||
|
private final List<TickNextTickData<T>> alreadyTicked = Lists.newArrayList();
|
||
|
private final Consumer<TickNextTickData<T>> ticker;
|
||
|
|
||
|
- public ServerTickList(ServerLevel world, Predicate<T> invalidObjPredicate, Function<T, ResourceLocation> idToName, Consumer<TickNextTickData<T>> consumer) {
|
||
|
- this.ignore = invalidObjPredicate;
|
||
|
- this.toId = idToName;
|
||
|
- this.level = world;
|
||
|
+ public ServerTickList(ServerLevel worldserver, Predicate<T> predicate, Function<T, ResourceLocation> function, Consumer<TickNextTickData<T>> consumer, String timingsType) { // Paper
|
||
|
+ this.ignore = predicate;
|
||
|
+ this.toId = function;
|
||
|
+ this.level = worldserver;
|
||
|
this.ticker = consumer;
|
||
|
+ this.timingCleanup = co.aikar.timings.WorldTimingsHandler.getTickList(worldserver, timingsType + " - Cleanup");
|
||
|
+ this.timingTicking = co.aikar.timings.WorldTimingsHandler.getTickList(worldserver, timingsType + " - Ticking");
|
||
|
}
|
||
|
+ private final co.aikar.timings.Timing timingCleanup; // Paper
|
||
|
+ private final co.aikar.timings.Timing timingTicking; // Paper
|
||
|
+ // Paper end
|
||
|
|
||
|
public void tick() {
|
||
|
int i = this.tickNextTickList.size();
|
||
|
@@ -66,6 +71,7 @@ public class ServerTickList<T> implements TickList<T> {
|
||
|
|
||
|
this.level.getProfiler().push("cleaning");
|
||
|
|
||
|
+ this.timingCleanup.startTiming(); // Paper
|
||
|
TickNextTickData nextticklistentry;
|
||
|
|
||
|
while (i > 0 && iterator.hasNext()) {
|
||
|
@@ -81,7 +87,9 @@ public class ServerTickList<T> implements TickList<T> {
|
||
|
--i;
|
||
|
}
|
||
|
}
|
||
|
+ this.timingCleanup.stopTiming(); // Paper
|
||
|
|
||
|
+ this.timingTicking.startTiming(); // Paper
|
||
|
this.level.getProfiler().popPush("ticking");
|
||
|
|
||
|
while ((nextticklistentry = (TickNextTickData) this.currentlyTicking.poll()) != null) {
|
||
|
@@ -101,6 +109,7 @@ public class ServerTickList<T> implements TickList<T> {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
+ this.timingTicking.stopTiming(); // Paper
|
||
|
this.level.getProfiler().pop();
|
||
|
this.alreadyTicked.clear();
|
||
|
this.currentlyTicking.clear();
|
||
|
diff --git a/src/main/java/net/minecraft/world/level/block/Block.java b/src/main/java/net/minecraft/world/level/block/Block.java
|
||
|
index 73a271a1fccd6f82dac8d33c0d378f0d84ceb5e5..2ae786b8fc6da19ca2a40252b0606f9e06d31ded 100644
|
||
|
--- a/src/main/java/net/minecraft/world/level/block/Block.java
|
||
|
+++ b/src/main/java/net/minecraft/world/level/block/Block.java
|
||
|
@@ -61,6 +61,15 @@ public class Block extends BlockBehaviour implements ItemLike {
|
||
|
});
|
||
|
protected final StateDefinition<Block, BlockState> stateDefinition;
|
||
|
private BlockState defaultBlockState;
|
||
|
+ // Paper start
|
||
|
+ public co.aikar.timings.Timing timing;
|
||
|
+ public co.aikar.timings.Timing getTiming() {
|
||
|
+ if (timing == null) {
|
||
|
+ timing = co.aikar.timings.MinecraftTimings.getBlockTiming(this);
|
||
|
+ }
|
||
|
+ return timing;
|
||
|
+ }
|
||
|
+ // Paper end
|
||
|
@Nullable
|
||
|
private String descriptionId;
|
||
|
@Nullable
|
||
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java
|
||
|
index bb60c9da9f3ba0d5c5bad22512675ccb841a60e5..d445a1b7b7605eed66923789c5d8e2199c31c5ac 100644
|
||
|
--- a/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java
|
||
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java
|
||
|
@@ -23,10 +23,12 @@ import org.bukkit.inventory.InventoryHolder;
|
||
|
// CraftBukkit end
|
||
|
|
||
|
import org.spigotmc.CustomTimingsHandler; // Spigot
|
||
|
+import co.aikar.timings.MinecraftTimings; // Paper
|
||
|
+import co.aikar.timings.Timing; // Paper
|
||
|
|
||
|
public abstract class BlockEntity implements net.minecraft.server.KeyedObject { // Paper
|
||
|
|
||
|
- public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getTileEntityTimings(this); // Spigot
|
||
|
+ public Timing tickTimer = MinecraftTimings.getTileEntityTimings(this); // Paper
|
||
|
// CraftBukkit start - data containers
|
||
|
private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry();
|
||
|
public CraftPersistentDataContainer persistentDataContainer;
|
||
|
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
|
||
|
index 00ce55c17980da87a3834f952475a766543506b0..f30793b81dfd9018b4879d655c7c18a9f9c25267 100644
|
||
|
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
|
||
|
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
|
||
|
@@ -732,6 +732,7 @@ public class LevelChunk implements ChunkAccess {
|
||
|
server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkLoadEvent(this.bukkitChunk, this.needsDecoration));
|
||
|
|
||
|
if (this.needsDecoration) {
|
||
|
+ try (co.aikar.timings.Timing ignored = this.world.timings.chunkLoadPopulate.startTiming()) { // Paper
|
||
|
this.needsDecoration = false;
|
||
|
java.util.Random random = new java.util.Random();
|
||
|
random.setSeed(world.getSeed());
|
||
|
@@ -751,6 +752,7 @@ public class LevelChunk implements ChunkAccess {
|
||
|
}
|
||
|
}
|
||
|
server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkPopulateEvent(bukkitChunk));
|
||
|
+ } // Paper
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java
|
||
|
index 7e13a438bd80ab5452eacf107d418c42c2e5c727..0efaf4d0f58bcf38b427e76bf09b96e354294159 100644
|
||
|
--- a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java
|
||
|
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java
|
||
|
@@ -1,5 +1,6 @@
|
||
|
package net.minecraft.world.level.chunk.storage;
|
||
|
|
||
|
+import co.aikar.timings.Timings;
|
||
|
import com.google.common.collect.Maps;
|
||
|
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
||
|
import it.unimi.dsi.fastutil.longs.LongSet;
|
||
|
@@ -446,7 +447,6 @@ public class ChunkSerializer {
|
||
|
private static void postLoadChunk(CompoundTag tag, LevelChunk chunk) {
|
||
|
ListTag nbttaglist = tag.getList("Entities", 10);
|
||
|
Level world = chunk.getLevel();
|
||
|
- world.timings.syncChunkLoadEntitiesTimer.startTiming(); // Spigot
|
||
|
|
||
|
for (int i = 0; i < nbttaglist.size(); ++i) {
|
||
|
CompoundTag nbttagcompound1 = nbttaglist.getCompound(i);
|
||
|
@@ -458,8 +458,6 @@ public class ChunkSerializer {
|
||
|
chunk.setLastSaveHadEntities(true);
|
||
|
}
|
||
|
|
||
|
- world.timings.syncChunkLoadEntitiesTimer.stopTiming(); // Spigot
|
||
|
- world.timings.syncChunkLoadTileEntitiesTimer.startTiming(); // Spigot
|
||
|
ListTag nbttaglist1 = tag.getList("TileEntities", 10);
|
||
|
|
||
|
for (int j = 0; j < nbttaglist1.size(); ++j) {
|
||
|
@@ -477,8 +475,6 @@ public class ChunkSerializer {
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
- world.timings.syncChunkLoadTileEntitiesTimer.stopTiming(); // Spigot
|
||
|
-
|
||
|
}
|
||
|
|
||
|
private static CompoundTag packStructureData(ChunkPos pos, Map<StructureFeature<?>, StructureStart<?>> structureStarts, Map<StructureFeature<?>, LongSet> structureReferences) {
|
||
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||
|
index 328d1e2b128b62f24917719c79823c9fb64a0dcf..c4cf1394fe4c2782b1fea8b3653a817157d857eb 100644
|
||
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||
|
@@ -2073,12 +2073,31 @@ public final class CraftServer implements Server {
|
||
|
private final org.bukkit.Server.Spigot spigot = new org.bukkit.Server.Spigot()
|
||
|
{
|
||
|
|
||
|
+ @Deprecated
|
||
|
@Override
|
||
|
public YamlConfiguration getConfig()
|
||
|
{
|
||
|
return org.spigotmc.SpigotConfig.config;
|
||
|
}
|
||
|
|
||
|
+ @Override
|
||
|
+ public YamlConfiguration getBukkitConfig()
|
||
|
+ {
|
||
|
+ return configuration;
|
||
|
+ }
|
||
|
+
|
||
|
+ @Override
|
||
|
+ public YamlConfiguration getSpigotConfig()
|
||
|
+ {
|
||
|
+ return org.spigotmc.SpigotConfig.config;
|
||
|
+ }
|
||
|
+
|
||
|
+ @Override
|
||
|
+ public YamlConfiguration getPaperConfig()
|
||
|
+ {
|
||
|
+ return com.destroystokyo.paper.PaperConfig.config;
|
||
|
+ }
|
||
|
+
|
||
|
@Override
|
||
|
public void restart() {
|
||
|
org.spigotmc.RestartCommand.restart();
|
||
|
diff --git a/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java b/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java
|
||
|
deleted file mode 100644
|
||
|
index 56b644e272ddad0e5410061e0a202daaebb734b8..0000000000000000000000000000000000000000
|
||
|
--- a/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java
|
||
|
+++ /dev/null
|
||
|
@@ -1,163 +0,0 @@
|
||
|
-package org.bukkit.craftbukkit;
|
||
|
-
|
||
|
-import java.util.HashMap;
|
||
|
-import net.minecraft.world.entity.Entity;
|
||
|
-import net.minecraft.world.level.Level;
|
||
|
-import net.minecraft.world.level.block.entity.BlockEntity;
|
||
|
-import net.minecraft.world.level.storage.PrimaryLevelData;
|
||
|
-import org.bukkit.craftbukkit.scheduler.CraftTask;
|
||
|
-import org.bukkit.plugin.java.JavaPluginLoader;
|
||
|
-import org.bukkit.scheduler.BukkitTask;
|
||
|
-import org.spigotmc.CustomTimingsHandler;
|
||
|
-
|
||
|
-public class SpigotTimings {
|
||
|
-
|
||
|
- public static final CustomTimingsHandler serverTickTimer = new CustomTimingsHandler("** Full Server Tick");
|
||
|
- public static final CustomTimingsHandler playerListTimer = new CustomTimingsHandler("Player List");
|
||
|
- public static final CustomTimingsHandler commandFunctionsTimer = new CustomTimingsHandler("Command Functions");
|
||
|
- public static final CustomTimingsHandler connectionTimer = new CustomTimingsHandler("Connection Handler");
|
||
|
- public static final CustomTimingsHandler playerConnectionTimer = new CustomTimingsHandler("** PlayerConnection");
|
||
|
- public static final CustomTimingsHandler tickablesTimer = new CustomTimingsHandler("Tickables");
|
||
|
- public static final CustomTimingsHandler schedulerTimer = new CustomTimingsHandler("Scheduler");
|
||
|
- public static final CustomTimingsHandler timeUpdateTimer = new CustomTimingsHandler("Time Update");
|
||
|
- public static final CustomTimingsHandler serverCommandTimer = new CustomTimingsHandler("Server Command");
|
||
|
- public static final CustomTimingsHandler worldSaveTimer = new CustomTimingsHandler("World Save");
|
||
|
-
|
||
|
- public static final CustomTimingsHandler entityMoveTimer = new CustomTimingsHandler("** entityMove");
|
||
|
- public static final CustomTimingsHandler tickEntityTimer = new CustomTimingsHandler("** tickEntity");
|
||
|
- public static final CustomTimingsHandler activatedEntityTimer = new CustomTimingsHandler("** activatedTickEntity");
|
||
|
- public static final CustomTimingsHandler tickTileEntityTimer = new CustomTimingsHandler("** tickTileEntity");
|
||
|
-
|
||
|
- public static final CustomTimingsHandler timerEntityBaseTick = new CustomTimingsHandler("** livingEntityBaseTick");
|
||
|
- public static final CustomTimingsHandler timerEntityAI = new CustomTimingsHandler("** livingEntityAI");
|
||
|
- public static final CustomTimingsHandler timerEntityAICollision = new CustomTimingsHandler("** livingEntityAICollision");
|
||
|
- public static final CustomTimingsHandler timerEntityAIMove = new CustomTimingsHandler("** livingEntityAIMove");
|
||
|
- public static final CustomTimingsHandler timerEntityTickRest = new CustomTimingsHandler("** livingEntityTickRest");
|
||
|
-
|
||
|
- public static final CustomTimingsHandler processQueueTimer = new CustomTimingsHandler("processQueue");
|
||
|
- public static final CustomTimingsHandler schedulerSyncTimer = new CustomTimingsHandler("** Scheduler - Sync Tasks", JavaPluginLoader.pluginParentTimer);
|
||
|
-
|
||
|
- public static final CustomTimingsHandler playerCommandTimer = new CustomTimingsHandler("** playerCommand");
|
||
|
-
|
||
|
- public static final CustomTimingsHandler entityActivationCheckTimer = new CustomTimingsHandler("entityActivationCheck");
|
||
|
- public static final CustomTimingsHandler checkIfActiveTimer = new CustomTimingsHandler("** checkIfActive");
|
||
|
-
|
||
|
- public static final HashMap<String, CustomTimingsHandler> entityTypeTimingMap = new HashMap<String, CustomTimingsHandler>();
|
||
|
- public static final HashMap<String, CustomTimingsHandler> tileEntityTypeTimingMap = new HashMap<String, CustomTimingsHandler>();
|
||
|
- public static final HashMap<String, CustomTimingsHandler> pluginTaskTimingMap = new HashMap<String, CustomTimingsHandler>();
|
||
|
-
|
||
|
- /**
|
||
|
- * Gets a timer associated with a plugins tasks.
|
||
|
- * @param task
|
||
|
- * @param period
|
||
|
- * @return
|
||
|
- */
|
||
|
- public static CustomTimingsHandler getPluginTaskTimings(BukkitTask task, long period) {
|
||
|
- if (!task.isSync()) {
|
||
|
- return null;
|
||
|
- }
|
||
|
- String plugin;
|
||
|
- final CraftTask ctask = (CraftTask) task;
|
||
|
-
|
||
|
- if (task.getOwner() != null) {
|
||
|
- plugin = task.getOwner().getDescription().getFullName();
|
||
|
- } else {
|
||
|
- plugin = "Unknown";
|
||
|
- }
|
||
|
- String taskname = ctask.getTaskName();
|
||
|
-
|
||
|
- String name = "Task: " + plugin + " Runnable: " + taskname;
|
||
|
- if (period > 0) {
|
||
|
- name += "(interval:" + period + ")";
|
||
|
- } else {
|
||
|
- name += "(Single)";
|
||
|
- }
|
||
|
- CustomTimingsHandler result = pluginTaskTimingMap.get(name);
|
||
|
- if (result == null) {
|
||
|
- result = new CustomTimingsHandler(name, SpigotTimings.schedulerSyncTimer);
|
||
|
- pluginTaskTimingMap.put(name, result);
|
||
|
- }
|
||
|
- return result;
|
||
|
- }
|
||
|
-
|
||
|
- /**
|
||
|
- * Get a named timer for the specified entity type to track type specific timings.
|
||
|
- * @param entity
|
||
|
- * @return
|
||
|
- */
|
||
|
- public static CustomTimingsHandler getEntityTimings(Entity entity) {
|
||
|
- String entityType = entity.getClass().getName();
|
||
|
- CustomTimingsHandler result = entityTypeTimingMap.get(entityType);
|
||
|
- if (result == null) {
|
||
|
- result = new CustomTimingsHandler("** tickEntity - " + entity.getClass().getSimpleName(), activatedEntityTimer);
|
||
|
- entityTypeTimingMap.put(entityType, result);
|
||
|
- }
|
||
|
- return result;
|
||
|
- }
|
||
|
-
|
||
|
- /**
|
||
|
- * Get a named timer for the specified tile entity type to track type specific timings.
|
||
|
- * @param entity
|
||
|
- * @return
|
||
|
- */
|
||
|
- public static CustomTimingsHandler getTileEntityTimings(BlockEntity entity) {
|
||
|
- String entityType = entity.getClass().getName();
|
||
|
- CustomTimingsHandler result = tileEntityTypeTimingMap.get(entityType);
|
||
|
- if (result == null) {
|
||
|
- result = new CustomTimingsHandler("** tickTileEntity - " + entity.getClass().getSimpleName(), tickTileEntityTimer);
|
||
|
- tileEntityTypeTimingMap.put(entityType, result);
|
||
|
- }
|
||
|
- return result;
|
||
|
- }
|
||
|
-
|
||
|
- /**
|
||
|
- * Set of timers per world, to track world specific timings.
|
||
|
- */
|
||
|
- public static class WorldTimingsHandler {
|
||
|
- public final CustomTimingsHandler mobSpawn;
|
||
|
- public final CustomTimingsHandler doChunkUnload;
|
||
|
- public final CustomTimingsHandler doTickPending;
|
||
|
- public final CustomTimingsHandler doTickTiles;
|
||
|
- public final CustomTimingsHandler doChunkMap;
|
||
|
- public final CustomTimingsHandler doSounds;
|
||
|
- public final CustomTimingsHandler entityTick;
|
||
|
- public final CustomTimingsHandler tileEntityTick;
|
||
|
- public final CustomTimingsHandler tileEntityPending;
|
||
|
- public final CustomTimingsHandler tracker;
|
||
|
- public final CustomTimingsHandler doTick;
|
||
|
- public final CustomTimingsHandler tickEntities;
|
||
|
-
|
||
|
- public final CustomTimingsHandler syncChunkLoadTimer;
|
||
|
- public final CustomTimingsHandler syncChunkLoadStructuresTimer;
|
||
|
- public final CustomTimingsHandler syncChunkLoadEntitiesTimer;
|
||
|
- public final CustomTimingsHandler syncChunkLoadTileEntitiesTimer;
|
||
|
- public final CustomTimingsHandler syncChunkLoadTileTicksTimer;
|
||
|
- public final CustomTimingsHandler syncChunkLoadPostTimer;
|
||
|
-
|
||
|
- public WorldTimingsHandler(Level server) {
|
||
|
- String name = ((PrimaryLevelData) server.levelData).getLevelName() + " - ";
|
||
|
-
|
||
|
- mobSpawn = new CustomTimingsHandler("** " + name + "mobSpawn");
|
||
|
- doChunkUnload = new CustomTimingsHandler("** " + name + "doChunkUnload");
|
||
|
- doTickPending = new CustomTimingsHandler("** " + name + "doTickPending");
|
||
|
- doTickTiles = new CustomTimingsHandler("** " + name + "doTickTiles");
|
||
|
- doChunkMap = new CustomTimingsHandler("** " + name + "doChunkMap");
|
||
|
- doSounds = new CustomTimingsHandler("** " + name + "doSounds");
|
||
|
- entityTick = new CustomTimingsHandler("** " + name + "entityTick");
|
||
|
- tileEntityTick = new CustomTimingsHandler("** " + name + "tileEntityTick");
|
||
|
- tileEntityPending = new CustomTimingsHandler("** " + name + "tileEntityPending");
|
||
|
-
|
||
|
- syncChunkLoadTimer = new CustomTimingsHandler("** " + name + "syncChunkLoad");
|
||
|
- syncChunkLoadStructuresTimer = new CustomTimingsHandler("** " + name + "chunkLoad - Structures");
|
||
|
- syncChunkLoadEntitiesTimer = new CustomTimingsHandler("** " + name + "chunkLoad - Entities");
|
||
|
- syncChunkLoadTileEntitiesTimer = new CustomTimingsHandler("** " + name + "chunkLoad - TileEntities");
|
||
|
- syncChunkLoadTileTicksTimer = new CustomTimingsHandler("** " + name + "chunkLoad - TileTicks");
|
||
|
- syncChunkLoadPostTimer = new CustomTimingsHandler("** " + name + "chunkLoad - Post");
|
||
|
-
|
||
|
-
|
||
|
- tracker = new CustomTimingsHandler(name + "tracker");
|
||
|
- doTick = new CustomTimingsHandler(name + "doTick");
|
||
|
- tickEntities = new CustomTimingsHandler(name + "tickEntities");
|
||
|
- }
|
||
|
- }
|
||
|
-}
|
||
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||
|
index 8fbf6c56d8820f3fa86e70a2636c0b58043232c3..61e2d92471d1498eb97d42dc642605a2e00e6089 100644
|
||
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||
|
@@ -1806,6 +1806,14 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||
|
packet.components = components;
|
||
|
getHandle().connection.send(packet);
|
||
|
}
|
||
|
+
|
||
|
+ // Paper start
|
||
|
+ @Override
|
||
|
+ public int getPing()
|
||
|
+ {
|
||
|
+ return getHandle().latency;
|
||
|
+ }
|
||
|
+ // Paper end
|
||
|
};
|
||
|
|
||
|
public Player.Spigot spigot()
|
||
|
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
|
||
|
index 4bf48f77f3f7cd62a91590543f5af441c8268029..ffe9cc1011226d604dc5499e7692e9a9a5132b72 100644
|
||
|
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
|
||
|
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
|
||
|
@@ -1,5 +1,6 @@
|
||
|
package org.bukkit.craftbukkit.scheduler;
|
||
|
|
||
|
+import co.aikar.timings.MinecraftTimings; // Paper
|
||
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.Comparator;
|
||
|
@@ -179,7 +180,8 @@ public class CraftScheduler implements BukkitScheduler {
|
||
|
}
|
||
|
|
||
|
public BukkitTask scheduleInternalTask(Runnable run, int delay, String taskName) {
|
||
|
- final CraftTask task = new CraftTask(run, nextId(), taskName);
|
||
|
+ final CraftTask task = new CraftTask(run, nextId(), "Internal - " + (taskName != null ? taskName : "Unknown"));
|
||
|
+ task.internal = true;
|
||
|
return handle(task, delay);
|
||
|
}
|
||
|
|
||
|
@@ -260,7 +262,7 @@ public class CraftScheduler implements BukkitScheduler {
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
- });
|
||
|
+ }){{this.timings=co.aikar.timings.MinecraftTimings.getCancelTasksTimer();}}; // Paper
|
||
|
handle(task, 0L);
|
||
|
for (CraftTask taskPending = head.getNext(); taskPending != null; taskPending = taskPending.getNext()) {
|
||
|
if (taskPending == task) {
|
||
|
@@ -295,7 +297,7 @@ public class CraftScheduler implements BukkitScheduler {
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
- });
|
||
|
+ }){{this.timings=co.aikar.timings.MinecraftTimings.getCancelTasksTimer(plugin);}}; // Paper
|
||
|
handle(task, 0L);
|
||
|
for (CraftTask taskPending = head.getNext(); taskPending != null; taskPending = taskPending.getNext()) {
|
||
|
if (taskPending == task) {
|
||
|
@@ -402,9 +404,7 @@ public class CraftScheduler implements BukkitScheduler {
|
||
|
if (task.isSync()) {
|
||
|
currentTask = task;
|
||
|
try {
|
||
|
- task.timings.startTiming(); // Spigot
|
||
|
task.run();
|
||
|
- task.timings.stopTiming(); // Spigot
|
||
|
} catch (final Throwable throwable) {
|
||
|
// Paper start
|
||
|
String msg = String.format(
|
||
|
@@ -438,8 +438,10 @@ public class CraftScheduler implements BukkitScheduler {
|
||
|
runners.remove(task.getTaskId());
|
||
|
}
|
||
|
}
|
||
|
+ MinecraftTimings.bukkitSchedulerFinishTimer.startTiming();
|
||
|
pending.addAll(temp);
|
||
|
temp.clear();
|
||
|
+ MinecraftTimings.bukkitSchedulerFinishTimer.stopTiming();
|
||
|
debugHead = debugHead.getNextHead(currentTick);
|
||
|
}
|
||
|
|
||
|
@@ -472,6 +474,7 @@ public class CraftScheduler implements BukkitScheduler {
|
||
|
}
|
||
|
|
||
|
private void parsePending() {
|
||
|
+ MinecraftTimings.bukkitSchedulerPendingTimer.startTiming();
|
||
|
CraftTask head = this.head;
|
||
|
CraftTask task = head.getNext();
|
||
|
CraftTask lastTask = head;
|
||
|
@@ -490,6 +493,7 @@ public class CraftScheduler implements BukkitScheduler {
|
||
|
task.setNext(null);
|
||
|
}
|
||
|
this.head = lastTask;
|
||
|
+ MinecraftTimings.bukkitSchedulerPendingTimer.stopTiming();
|
||
|
}
|
||
|
|
||
|
private boolean isReady(final int currentTick) {
|
||
|
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java
|
||
|
index 09aa6809c5400ce8548ac902908b750ce7c964ec..3c96807e97657502849093e4371e9fef3584a346 100644
|
||
|
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java
|
||
|
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java
|
||
|
@@ -1,12 +1,15 @@
|
||
|
package org.bukkit.craftbukkit.scheduler;
|
||
|
|
||
|
import java.util.function.Consumer;
|
||
|
+
|
||
|
+import co.aikar.timings.NullTimingHandler;
|
||
|
import org.bukkit.Bukkit;
|
||
|
import org.bukkit.plugin.Plugin;
|
||
|
import org.bukkit.scheduler.BukkitTask;
|
||
|
|
||
|
-import org.bukkit.craftbukkit.SpigotTimings; // Spigot
|
||
|
import org.spigotmc.CustomTimingsHandler; // Spigot
|
||
|
+import co.aikar.timings.MinecraftTimings; // Paper
|
||
|
+import co.aikar.timings.Timing; // Paper
|
||
|
|
||
|
public class CraftTask implements BukkitTask, Runnable { // Spigot
|
||
|
|
||
|
@@ -26,12 +29,12 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot
|
||
|
*/
|
||
|
private volatile long period;
|
||
|
private long nextRun;
|
||
|
- private final Runnable rTask;
|
||
|
- private final Consumer<BukkitTask> cTask;
|
||
|
+ public final Runnable rTask; // Paper
|
||
|
+ public final Consumer<BukkitTask> cTask; // Paper
|
||
|
+ public Timing timings; // Paper
|
||
|
private final Plugin plugin;
|
||
|
private final int id;
|
||
|
|
||
|
- final CustomTimingsHandler timings; // Spigot
|
||
|
CraftTask() {
|
||
|
this(null, null, CraftTask.NO_REPEATING, CraftTask.NO_REPEATING);
|
||
|
}
|
||
|
@@ -51,7 +54,7 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot
|
||
|
this.id = id;
|
||
|
this.period = CraftTask.NO_REPEATING;
|
||
|
this.taskName = taskName;
|
||
|
- this.timings = null; // Will be changed in later patch
|
||
|
+ this.timings = MinecraftTimings.getInternalTaskName(taskName);
|
||
|
}
|
||
|
// Paper end
|
||
|
|
||
|
@@ -72,7 +75,7 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot
|
||
|
}
|
||
|
this.id = id;
|
||
|
this.period = period;
|
||
|
- this.timings = this.isSync() ? SpigotTimings.getPluginTaskTimings(this, period) : null; // Spigot
|
||
|
+ timings = task != null ? MinecraftTimings.getPluginTaskTimings(this, period) : NullTimingHandler.NULL; // Paper
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
@@ -92,11 +95,13 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot
|
||
|
|
||
|
@Override
|
||
|
public void run() {
|
||
|
+ try (Timing ignored = timings.startTiming()) { // Paper
|
||
|
if (rTask != null) {
|
||
|
rTask.run();
|
||
|
} else {
|
||
|
cTask.accept(this);
|
||
|
}
|
||
|
+ } // Paper
|
||
|
}
|
||
|
|
||
|
long getPeriod() {
|
||
|
@@ -123,7 +128,7 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot
|
||
|
this.next = next;
|
||
|
}
|
||
|
|
||
|
- Class<?> getTaskClass() {
|
||
|
+ public Class<?> getTaskClass() {
|
||
|
return (rTask != null) ? rTask.getClass() : ((cTask != null) ? cTask.getClass() : null);
|
||
|
}
|
||
|
|
||
|
@@ -147,9 +152,4 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
- // Spigot start
|
||
|
- public String getTaskName() {
|
||
|
- return (getTaskClass() == null) ? "Unknown" : getTaskClass().getName();
|
||
|
- }
|
||
|
- // Spigot end
|
||
|
}
|
||
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftIconCache.java b/src/main/java/org/bukkit/craftbukkit/util/CraftIconCache.java
|
||
|
index e52ef47b783785dc214746b678e7b549aea9a274..3d90b3426873a3528af14f7f1ab0adae0027da2e 100644
|
||
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftIconCache.java
|
||
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftIconCache.java
|
||
|
@@ -5,6 +5,7 @@ import org.bukkit.util.CachedServerIcon;
|
||
|
public class CraftIconCache implements CachedServerIcon {
|
||
|
public final String value;
|
||
|
|
||
|
+ public String getData() { return value; } // Paper
|
||
|
public CraftIconCache(final String value) {
|
||
|
this.value = value;
|
||
|
}
|
||
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||
|
index ec3d663886eb134eb9ecc87e7517a73bcfb9ec02..ef7715774fbdc4c42b217d8192784e09a43fe66f 100644
|
||
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||
|
@@ -156,6 +156,12 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||
|
return CraftNamespacedKey.toMinecraft(mat.getKey());
|
||
|
}
|
||
|
// ========================================================================
|
||
|
+ // Paper start
|
||
|
+ @Override
|
||
|
+ public void reportTimings() {
|
||
|
+ co.aikar.timings.TimingsExport.reportTimings();
|
||
|
+ }
|
||
|
+ // Paper end
|
||
|
|
||
|
public static byte toLegacyData(BlockState data) {
|
||
|
return CraftLegacy.toLegacyData(data);
|
||
|
@@ -330,6 +336,13 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||
|
return clazz;
|
||
|
}
|
||
|
|
||
|
+ // Paper start
|
||
|
+ @Override
|
||
|
+ public String getTimingsServerName() {
|
||
|
+ return com.destroystokyo.paper.PaperConfig.timingsServerName;
|
||
|
+ }
|
||
|
+ // Paper end
|
||
|
+
|
||
|
/**
|
||
|
* This helper class represents the different NBT Tags.
|
||
|
* <p>
|
||
|
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
|
||
|
index ac6fc546931f7884952058b42e7e3fab3ce42998..9bb35ec64e1538aabec9ff7831706c4717239449 100644
|
||
|
--- a/src/main/java/org/spigotmc/ActivationRange.java
|
||
|
+++ b/src/main/java/org/spigotmc/ActivationRange.java
|
||
|
@@ -29,7 +29,7 @@ import net.minecraft.world.entity.raid.Raider;
|
||
|
import net.minecraft.world.level.Level;
|
||
|
import net.minecraft.world.level.chunk.LevelChunk;
|
||
|
import net.minecraft.world.phys.AABB;
|
||
|
-import org.bukkit.craftbukkit.SpigotTimings;
|
||
|
+import co.aikar.timings.MinecraftTimings;
|
||
|
|
||
|
public class ActivationRange
|
||
|
{
|
||
|
@@ -73,8 +73,8 @@ public class ActivationRange
|
||
|
/**
|
||
|
* These entities are excluded from Activation range checks.
|
||
|
*
|
||
|
- * @param entity
|
||
|
- * @param config
|
||
|
+ * @param entity Entity to initialize
|
||
|
+ * @param config Spigot config to determine ranges
|
||
|
* @return boolean If it should always tick.
|
||
|
*/
|
||
|
public static boolean initializeEntityActivationState(Entity entity, SpigotWorldConfig config)
|
||
|
@@ -109,7 +109,7 @@ public class ActivationRange
|
||
|
*/
|
||
|
public static void activateEntities(Level world)
|
||
|
{
|
||
|
- SpigotTimings.entityActivationCheckTimer.startTiming();
|
||
|
+ MinecraftTimings.entityActivationCheckTimer.startTiming();
|
||
|
final int miscActivationRange = world.spigotConfig.miscActivationRange;
|
||
|
final int raiderActivationRange = world.spigotConfig.raiderActivationRange;
|
||
|
final int animalActivationRange = world.spigotConfig.animalActivationRange;
|
||
|
@@ -146,7 +146,7 @@ public class ActivationRange
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
- SpigotTimings.entityActivationCheckTimer.stopTiming();
|
||
|
+ MinecraftTimings.entityActivationCheckTimer.stopTiming();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
@@ -243,10 +243,8 @@ public class ActivationRange
|
||
|
*/
|
||
|
public static boolean checkIfActive(Entity entity)
|
||
|
{
|
||
|
- SpigotTimings.checkIfActiveTimer.startTiming();
|
||
|
// Never safe to skip fireworks or entities not yet added to chunk
|
||
|
if ( !entity.inChunk || entity instanceof FireworkRocketEntity ) {
|
||
|
- SpigotTimings.checkIfActiveTimer.stopTiming();
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
@@ -270,7 +268,6 @@ public class ActivationRange
|
||
|
{
|
||
|
isActive = false;
|
||
|
}
|
||
|
- SpigotTimings.checkIfActiveTimer.stopTiming();
|
||
|
return isActive;
|
||
|
}
|
||
|
}
|