3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 12:30:06 +01:00
Paper/patches/server/0009-Timings-v2.patch

2317 Zeilen
110 KiB
Diff

2021-06-11 14:02:28 +02:00
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/co/aikar/timings/MinecraftTimings.java b/src/main/java/co/aikar/timings/MinecraftTimings.java
new file mode 100644
2021-06-16 19:48:25 +02:00
index 0000000000000000000000000000000000000000..b47b7dce26805badd422c1867733ff4bfd00e9f4
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/co/aikar/timings/MinecraftTimings.java
@@ -0,0 +1,151 @@
2021-06-11 14:02:28 +02:00
+package co.aikar.timings;
+
+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) {
2021-06-16 19:48:25 +02:00
+ return Timings.ofSafe("Command Function - " + function.getId());
2021-06-11 14:02:28 +02:00
+ }
+}
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..ee53453440177537fc653ea156785d7591498614
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/co/aikar/timings/TimingsExport.java
@@ -0,0 +1,376 @@
2021-06-11 14:02:28 +02:00
+/*
+ * 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;
+
+@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().getSelectedPacks(), pack -> {
+ return ChatColor.stripColor(CraftChatMessage.fromComponent(pack.getChatLink(true)));
2021-06-11 14:02:28 +02:00
+ }))
+ );
+ 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 -> {
2021-06-12 00:37:16 +02:00
+ if (world.getWorld().getName().equals("worldeditregentempworld")) return null;
+ return pair(world.getWorld().getName(), createObject(
2021-06-11 14:02:28 +02:00
+ pair("gamerules", toObjectMapper(world.getWorld().getGameRules(), rule -> {
+ return pair(rule, world.getWorld().getGameRuleValue(rule));
+ })),
+ pair("ticking-distance", world.getChunkSource().chunkMap.getEffectiveViewDistance())
2021-06-11 14:02:28 +02:00
+ ));
+ }));
+
+ 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(TimingsManager.url + "post").openConnection();
2021-06-11 14:02:28 +02:00
+ 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..0fda52841b5e1643efeda92106124998abc4e0aa
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/co/aikar/timings/WorldTimingsHandler.java
@@ -0,0 +1,119 @@
2021-06-11 14:02:28 +02:00
+package co.aikar.timings;
+
+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..f973828da3ab56dba768fb029a271b2e55cfc24e 100644
2021-06-11 14:02:28 +02:00
--- 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,35 @@ public class PaperConfig {
2021-06-11 14:02:28 +02:00
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.url = getString("timings.url", "https://timings.aikar.co/");
+ if (!TimingsManager.url.endsWith("/")) {
+ TimingsManager.url += "/";
+ }
2021-06-11 14:02:28 +02:00
+ 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 +
+ " - Url: " + TimingsManager.url +
2021-06-11 14:02:28 +02:00
+ " - 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
2021-06-16 19:48:25 +02:00
index ca1a9884ab09fc7e575b1d30e2dd0aaff324fb73..b94038e2da0f986403c1ec9b27384344e2bb22f0 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/commands/CommandFunction.java
+++ b/src/main/java/net/minecraft/commands/CommandFunction.java
2021-06-16 19:48:25 +02:00
@@ -16,6 +16,15 @@ import net.minecraft.server.ServerFunctionManager;
2021-06-11 20:02:16 +02:00
public class CommandFunction {
2021-06-11 14:02:28 +02:00
private final CommandFunction.Entry[] entries;
2021-06-11 20:02:16 +02:00
final ResourceLocation id;
2021-06-11 14:02:28 +02:00
+ // 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;
diff --git a/src/main/java/net/minecraft/network/protocol/PacketUtils.java b/src/main/java/net/minecraft/network/protocol/PacketUtils.java
2021-06-11 20:02:16 +02:00
index b3a6aeba2363d283f03982cf749f25cfa11a5052..449f1b2f5dca350dc0912e14c8c2bf3eb4652b92 100644
2021-06-11 14:02:28 +02:00
--- 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;
2021-06-11 20:02:16 +02:00
@@ -23,10 +25,13 @@ public class PacketUtils {
2021-06-11 14:02:28 +02:00
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
2021-06-11 20:02:16 +02:00
if (listener.getConnection().isConnected()) {
2021-06-11 14:02:28 +02:00
+ try (Timing ignored = timing.startTiming()) { // Paper - timings
packet.handle(listener);
+ } // Paper - timings
} else {
2021-06-11 20:02:16 +02:00
PacketUtils.LOGGER.debug("Ignoring packet due to disconnection: {}", packet);
2021-06-11 14:02:28 +02:00
}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2021-07-07 08:52:40 +02:00
index 571e57affcf81151550184b45934ae810885145f..fcc775723bcef7c6b740ee332c21ef70e591c77e 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2021-07-07 08:52:40 +02:00
@@ -180,7 +180,7 @@ import org.bukkit.craftbukkit.Main;
2021-06-11 14:02:28 +02:00
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 {
2021-07-07 08:52:40 +02:00
@@ -895,6 +895,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2021-06-11 14:02:28 +02:00
}
// CraftBukkit end
MinecraftServer.LOGGER.info("Stopping server");
+ MinecraftTimings.stopServer(); // Paper
// CraftBukkit start
if (this.server != null) {
this.server.disablePlugins();
2021-07-07 08:52:40 +02:00
@@ -1097,9 +1098,21 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2021-06-11 14:02:28 +02:00
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() {
2021-06-17 23:39:36 +02:00
+ return this.mayHaveDelayedTasks && Util.getMillis() < this.delayedTasksMaxNextTickTime;
2021-06-11 14:02:28 +02:00
+ }
+
+ 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);
2021-07-07 08:52:40 +02:00
@@ -1107,9 +1120,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2021-06-11 14:02:28 +02:00
// 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
});
}
2021-07-07 08:52:40 +02:00
@@ -1195,10 +1208,18 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2021-06-11 20:02:16 +02:00
public void onServerExit() {}
2021-06-11 14:02:28 +02:00
2021-06-11 20:02:16 +02:00
public void tickServer(BooleanSupplier shouldKeepTicking) {
2021-06-11 14:02:28 +02:00
- 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) {
2021-07-07 08:52:40 +02:00
@@ -1216,14 +1237,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2021-06-11 14:02:28 +02:00
}
2021-06-11 20:02:16 +02:00
if (this.autosavePeriod > 0 && this.tickCount % this.autosavePeriod == 0) { // CraftBukkit
2021-06-11 14:02:28 +02:00
- 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");
2021-07-07 08:52:40 +02:00
@@ -1236,6 +1255,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2021-06-11 14:02:28 +02:00
}
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;
2021-07-07 08:52:40 +02:00
@@ -1246,30 +1272,29 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2021-06-11 14:02:28 +02:00
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
}
2021-06-11 20:02:16 +02:00
public void tickChildren(BooleanSupplier shouldKeepTicking) {
2021-06-11 14:02:28 +02:00
- 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
2021-06-11 20:02:16 +02:00
while (!this.processQueue.isEmpty()) {
this.processQueue.remove().run();
2021-06-11 14:02:28 +02:00
}
- 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) {
2021-07-07 08:52:40 +02:00
@@ -1277,7 +1302,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2021-06-11 14:02:28 +02:00
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();
2021-07-07 08:52:40 +02:00
@@ -1318,24 +1343,24 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2021-06-11 14:02:28 +02:00
}
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) {
2021-06-11 20:02:16 +02:00
GameTestTicker.SINGLETON.tick();
2021-06-11 14:02:28 +02:00
}
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
2021-06-11 20:02:16 +02:00
index b0ff982603e61805e3a0426aa8376330c73d9cf4..cf711f7fecdab70ff2ee48c87a3a1f0845832b74 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/ServerFunctionManager.java
+++ b/src/main/java/net/minecraft/server/ServerFunctionManager.java
2021-06-11 20:02:16 +02:00
@@ -90,7 +90,7 @@ public class ServerFunctionManager {
2021-06-11 14:02:28 +02:00
} else {
2021-06-11 20:02:16 +02:00
int i;
2021-06-11 14:02:28 +02:00
- try {
+ try (co.aikar.timings.Timing timing = function.getTiming().startTiming()) { // Paper
2021-06-11 20:02:16 +02:00
this.context = new ServerFunctionManager.ExecutionContext(tracer);
i = this.context.runTopCommand(function, source);
} finally {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
2021-07-07 08:52:40 +02:00
index fac993d58bd6e3bb19fd69881092a863c8952c65..2b062beaad39f2e86801fdd5b0cc84b253f1348a 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
2021-07-07 08:52:40 +02:00
@@ -67,8 +67,9 @@ import org.apache.logging.log4j.Logger;
2021-06-11 14:02:28 +02:00
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
2021-07-07 08:52:40 +02:00
@@ -467,7 +468,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
2021-06-11 14:02:28 +02:00
}
public void handleConsoleInputs() {
- SpigotTimings.serverCommandTimer.startTiming(); // Spigot
+ MinecraftTimings.serverCommandTimer.startTiming(); // Spigot
while (!this.consoleInput.isEmpty()) {
ConsoleInput servercommand = (ConsoleInput) this.consoleInput.remove(0);
2021-07-07 08:52:40 +02:00
@@ -482,7 +483,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
2021-06-11 14:02:28 +02:00
// CraftBukkit end
}
- SpigotTimings.serverCommandTimer.stopTiming(); // Spigot
+ MinecraftTimings.serverCommandTimer.stopTiming(); // Spigot
}
@Override
2021-07-07 08:52:40 +02:00
@@ -713,6 +714,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
2021-06-11 14:02:28 +02:00
@Override
public String runCommand(String command) {
+ Waitable[] waitableArray = new Waitable[1];
this.rconConsoleSource.prepareForCommand();
this.executeBlocking(() -> {
// CraftBukkit start - fire RemoteServerCommandEvent
2021-07-07 08:52:40 +02:00
@@ -721,10 +723,39 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
2021-06-11 14:02:28 +02:00
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
2021-06-11 20:02:16 +02:00
ConsoleInput serverCommand = new ConsoleInput(event.getCommand(), this.rconConsoleSource.createCommandSourceStack());
2021-06-11 14:02:28 +02:00
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
2021-07-07 08:52:40 +02:00
index 2b62f4664f439808661d559dc99762bfbac09b16..4788946d7fb25c1b0f26e6a038924c4a62978d53 100644
2021-06-11 14:02:28 +02:00
--- 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;
2021-07-07 08:52:40 +02:00
@@ -580,11 +582,14 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-11 14:02:28 +02:00
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) {
2021-07-07 08:52:40 +02:00
@@ -595,7 +600,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-11 14:02:28 +02:00
}
ChunkMap.LOGGER.error("Chunk file at {} is missing level data, skipping", pos);
- }
+ }} // Paper
} catch (ReportedException reportedexception) {
Throwable throwable = reportedexception.getCause();
2021-07-07 08:52:40 +02:00
@@ -709,6 +714,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-11 14:02:28 +02:00
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();
2021-06-11 20:02:16 +02:00
ProtoChunk protochunk = (ProtoChunk) ichunkaccess;
2021-06-11 14:02:28 +02:00
LevelChunk chunk;
2021-07-07 08:52:40 +02:00
@@ -732,6 +738,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-11 14:02:28 +02:00
}
return chunk;
+ } // Paper
});
}, (runnable) -> {
ProcessorHandle mailbox = this.mainThreadMailbox;
2021-07-07 08:52:40 +02:00
@@ -1189,6 +1196,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-11 14:02:28 +02:00
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();
2021-07-07 08:52:40 +02:00
@@ -1206,16 +1214,20 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-11 14:02:28 +02:00
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
}
+
}
2021-06-11 20:02:16 +02:00
public void broadcast(Entity entity, Packet<?> packet) {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index 8639ffa2347e3d5c44ab30de0aa98623f95d1fe7..bafd97074461d5b17b21579ba493ba8eae8468d8 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
2021-07-07 08:52:40 +02:00
@@ -348,13 +348,15 @@ public class ServerChunkCache extends ChunkSource {
2021-06-11 14:02:28 +02:00
}
gameprofilerfiller.incrementCounter("getChunkCacheMiss");
- level.timings.syncChunkLoadTimer.startTiming(); // Spigot
CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> completablefuture = this.getChunkFutureMainThread(x, z, leastStatus, create);
2021-06-11 20:02:16 +02:00
ServerChunkCache.MainThreadExecutor chunkproviderserver_a = this.mainThreadProcessor;
2021-06-11 14:02:28 +02:00
2021-06-11 20:02:16 +02:00
Objects.requireNonNull(completablefuture);
2021-06-11 14:02:28 +02:00
+ if (!completablefuture.isDone()) { // Paper
+ this.level.timings.syncChunkLoad.startTiming(); // Paper
2021-06-11 20:02:16 +02:00
chunkproviderserver_a.managedBlock(completablefuture::isDone);
2021-06-11 14:02:28 +02:00
- level.timings.syncChunkLoadTimer.stopTiming(); // Spigot
+ this.level.timings.syncChunkLoad.stopTiming(); // Paper
+ } // Paper
ichunkaccess = (ChunkAccess) ((Either) completablefuture.join()).map((ichunkaccess1) -> {
return ichunkaccess1;
}, (playerchunk_failure) -> {
2021-07-07 08:52:40 +02:00
@@ -554,7 +556,9 @@ public class ServerChunkCache extends ChunkSource {
2021-06-11 14:02:28 +02:00
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
2021-07-07 08:52:40 +02:00
@@ -592,7 +596,9 @@ public class ServerChunkCache extends ChunkSource {
2021-06-11 14:02:28 +02:00
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");
2021-06-11 20:02:16 +02:00
this.chunkMap.tick(booleansupplier);
2021-07-07 08:52:40 +02:00
@@ -616,13 +622,16 @@ public class ServerChunkCache extends ChunkSource {
2021-06-11 14:02:28 +02:00
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();
2021-07-07 08:52:40 +02:00
@@ -636,15 +645,18 @@ public class ServerChunkCache extends ChunkSource {
2021-06-11 20:02:16 +02:00
NaturalSpawner.spawnForChunk(this.level, chunk, spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag2);
2021-06-11 14:02:28 +02:00
}
2021-06-11 20:02:16 +02:00
- this.level.timings.doTickTiles.startTiming(); // Spigot
+ // this.level.timings.doTickTiles.startTiming(); // Spigot // Paper
this.level.tickChunk(chunk, k);
- this.level.timings.doTickTiles.stopTiming(); // Spigot
+ // this.level.timings.doTickTiles.stopTiming(); // Spigot // Paper
2021-06-11 14:02:28 +02:00
}
}
});
+ 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
}
2021-07-07 08:52:40 +02:00
this.level.getProfiler().popPush("broadcast");
@@ -652,15 +664,20 @@ public class ServerChunkCache extends ChunkSource {
Optional<LevelChunk> optional = ((Either) playerchunk.getTickingChunkFuture().getNow(ChunkHolder.UNLOADED_LEVEL_CHUNK)).left(); // CraftBukkit - decompile error
Objects.requireNonNull(playerchunk);
- optional.ifPresent(playerchunk::broadcastChanges);
+
+ // Paper start - timings
+ optional.ifPresent(chunk -> {
+ this.level.timings.broadcastChunkUpdates.startTiming(); // Paper - timings
+ playerchunk.broadcastChanges(chunk);
+ this.level.timings.broadcastChunkUpdates.stopTiming(); // Paper - timings
+ });
+ // Paper end
});
2021-06-11 14:02:28 +02:00
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 912c9b0c010436854fab7540b0c9cc63115e39a4..253d62b0da6bd59363a85139a5a5d5f11169466a 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
2021-06-11 20:02:16 +02:00
@@ -1,6 +1,8 @@
package net.minecraft.server.level;
2021-06-11 14:02:28 +02:00
import com.google.common.annotations.VisibleForTesting;
+import co.aikar.timings.TimingHistory; // Paper
+import co.aikar.timings.Timings; // Paper
import com.google.common.collect.Lists;
2021-06-11 20:02:16 +02:00
import com.mojang.datafixers.DataFixer;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
@@ -154,7 +156,6 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2021-06-11 14:02:28 +02:00
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;
@@ -217,13 +218,13 @@ public class ServerLevel extends Level implements WorldGenLevel {
2021-06-11 20:02:16 +02:00
DefaultedRegistry registryblocks = Registry.BLOCK;
Objects.requireNonNull(registryblocks);
- this.blockTicks = new ServerTickList<>(this, predicate, Registry.BLOCK::getKey, this::tickBlock); // CraftBukkit - decompile error
+ this.blockTicks = new ServerTickList<>(this, predicate, Registry.BLOCK::getKey, this::tickBlock, "Blocks"); // CraftBukkit - decompile error // Paper - Timings
Predicate<Fluid> predicate2 = (fluidtype) -> { // CraftBukkit - decompile error
2021-06-11 14:02:28 +02:00
return fluidtype == null || fluidtype == Fluids.EMPTY;
2021-06-11 20:02:16 +02:00
};
registryblocks = Registry.FLUID;
Objects.requireNonNull(registryblocks);
- this.liquidTicks = new ServerTickList<>(this, predicate2, Registry.FLUID::getKey, this::tickLiquid); // CraftBukkit - decompile error
+ this.liquidTicks = new ServerTickList<>(this, predicate2, Registry.FLUID::getKey, this::tickLiquid, "Fluids"); // CraftBukkit - decompile error // Paper - Timings
this.navigatingMobs = new ObjectOpenHashSet();
2021-06-11 14:02:28 +02:00
this.blockEvents = new ObjectLinkedOpenHashSet();
2021-06-11 20:02:16 +02:00
this.dragonParts = new Int2ObjectOpenHashMap();
@@ -430,17 +431,21 @@ public class ServerLevel extends Level implements WorldGenLevel {
2021-06-11 14:02:28 +02:00
this.updateSkyBrightness();
this.tickTime();
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
2021-07-07 08:52:40 +02:00
gameprofilerfiller.popPush("chunkSource");
+ this.timings.chunkProviderTick.startTiming(); // Paper - timings
this.getChunkSource().tick(shouldKeepTicking);
+ this.timings.chunkProviderTick.stopTiming(); // Paper - timings
2021-06-11 14:02:28 +02:00
gameprofilerfiller.popPush("blockEvents");
timings.doSounds.startTiming(); // Spigot
this.runBlockEvents();
@@ -598,6 +603,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
2021-06-11 14:02:28 +02:00
}
gameprofilerfiller.popPush("tickBlocks");
+ timings.chunkTicksBlocks.startTiming(); // Paper
if (randomTickSpeed > 0) {
LevelChunkSection[] achunksection = chunk.getSections();
int l = achunksection.length;
@@ -629,7 +635,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
2021-06-11 14:02:28 +02:00
}
}
}
-
+ timings.chunkTicksBlocks.stopTiming(); // Paper
gameprofilerfiller.pop();
}
@@ -755,14 +761,22 @@ public class ServerLevel extends Level implements WorldGenLevel {
2021-06-11 20:02:16 +02:00
}
public void tickNonPassenger(Entity entity) {
+ ++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.setOldPosAndRot();
2021-06-11 20:02:16 +02:00
ProfilerFiller gameprofilerfiller = this.getProfiler();
@@ -781,7 +795,8 @@ public class ServerLevel extends Level implements WorldGenLevel {
2021-06-11 14:02:28 +02:00
2021-06-11 20:02:16 +02:00
this.tickPassenger(entity, entity1);
2021-06-11 14:02:28 +02:00
}
2021-06-11 20:02:16 +02:00
- entity.tickTimer.stopTiming(); // Spigot
+
+ } finally { timer.stopTiming(); } // Paper - timings
2021-06-11 14:02:28 +02:00
}
2021-06-11 20:02:16 +02:00
@@ -823,6 +838,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
2021-06-11 14:02:28 +02:00
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"));
}
@@ -832,7 +848,10 @@ public class ServerLevel extends Level implements WorldGenLevel {
2021-06-11 14:02:28 +02:00
progressListener.progressStage(new TranslatableComponent("menu.savingChunks"));
}
2021-06-11 20:02:16 +02:00
+ timings.worldSaveChunks.startTiming(); // Paper
2021-06-11 14:02:28 +02:00
chunkproviderserver.save(flush);
2021-06-11 20:02:16 +02:00
+ timings.worldSaveChunks.stopTiming(); // Paper
+ }// Paper
if (flush) {
this.entityManager.saveAll();
} else {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2021-07-07 08:52:40 +02:00
index d6bef66d1cc0e3915ca5a9b9d5fc6e645eb5a7de..401520c47e63c3d2055e320daaeb1e74b1f627e1 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2021-07-07 08:52:40 +02:00
@@ -208,6 +208,7 @@ import org.bukkit.inventory.EquipmentSlot;
2021-06-11 14:02:28 +02:00
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.SmithingInventory;
import org.bukkit.util.NumberConversions;
+import co.aikar.timings.MinecraftTimings; // Paper
// CraftBukkit end
2021-06-11 20:02:16 +02:00
public class ServerGamePacketListenerImpl implements ServerPlayerConnection, ServerGamePacketListener {
2021-07-07 08:52:40 +02:00
@@ -287,7 +288,6 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
2021-06-11 14:02:28 +02:00
// 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();
2021-07-07 08:52:40 +02:00
@@ -363,7 +363,6 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
2021-06-11 14:02:28 +02:00
this.player.resetLastActionTime(); // CraftBukkit - SPIGOT-854
this.disconnect(new TranslatableComponent("multiplayer.disconnect.idling"));
}
- org.bukkit.craftbukkit.SpigotTimings.playerConnectionTimer.stopTiming(); // Spigot
}
2021-07-07 08:52:40 +02:00
@@ -1909,7 +1908,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
2021-06-11 14:02:28 +02:00
// 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);
2021-07-07 08:52:40 +02:00
@@ -1920,7 +1919,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
2021-06-11 20:02:16 +02:00
this.cserver.getPluginManager().callEvent(event);
2021-06-11 14:02:28 +02:00
if (event.isCancelled()) {
- org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.stopTiming(); // Spigot
+ MinecraftTimings.playerCommandTimer.stopTiming(); // Paper
return;
}
2021-07-07 08:52:40 +02:00
@@ -1933,7 +1932,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
2021-06-11 14:02:28 +02:00
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
2021-07-07 08:52:40 +02:00
index 8c4744b3a3ebf73d31f59d1566320031550aa3bb..c731f22390773bcd43d392b86ae5b42b0da27c1f 100644
2021-06-11 14:02:28 +02:00
--- 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;
2021-07-07 08:52:40 +02:00
@@ -1010,10 +1011,11 @@ public abstract class PlayerList {
2021-06-11 14:02:28 +02:00
}
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 01a5c95c40b39ba71add80f65359e390b9079f4e..11f9be795dc622f84866acf461cf3b3190b3d62c 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
2021-06-11 20:02:16 +02:00
@@ -126,7 +126,6 @@ import org.bukkit.craftbukkit.event.CraftPortalEvent;
2021-06-11 14:02:28 +02:00
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;
2021-06-11 20:02:16 +02:00
@@ -281,7 +280,6 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
2021-06-11 14:02:28 +02:00
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;
2021-06-11 20:02:16 +02:00
@@ -716,7 +714,6 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
2021-06-11 14:02:28 +02:00
}
2021-06-11 20:02:16 +02:00
public void move(MoverType movementType, Vec3 movement) {
2021-06-11 14:02:28 +02:00
- org.bukkit.craftbukkit.SpigotTimings.entityMoveTimer.startTiming(); // Spigot
if (this.noPhysics) {
2021-06-11 20:02:16 +02:00
this.setPos(this.getX() + movement.x, this.getY() + movement.y, this.getZ() + movement.z);
} else {
@@ -863,7 +860,6 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
this.level.getProfiler().pop();
}
2021-06-11 14:02:28 +02:00
}
- org.bukkit.craftbukkit.SpigotTimings.entityMoveTimer.stopTiming(); // Spigot
}
2021-06-11 20:02:16 +02:00
protected void tryCheckInsideBlocks() {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java
2021-06-17 19:11:00 +02:00
index 7f3d83d3d071f6b441ad119b1c93be035e911e70..8d5c61a77bea2f2f5dbff26cb479f855945f9541 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
2021-06-17 19:11:00 +02:00
@@ -294,17 +294,29 @@ public class EntityType<T extends Entity> implements EntityTypeTest<Entity, T> {
2021-06-11 14:02:28 +02:00
return Registry.ENTITY_TYPE.getOptional(ResourceLocation.tryParse(id));
}
2021-06-11 20:02:16 +02:00
- public EntityType(EntityType.EntityFactory<T> factory, MobCategory spawnGroup, boolean saveable, boolean summonable, boolean fireImmune, boolean spawnableFarFromPlayer, ImmutableSet<Block> canSpawnInside, EntityDimensions dimensions, int maxTrackDistance, int trackTickInterval) {
2021-06-11 14:02:28 +02:00
- this.factory = factory;
- this.category = spawnGroup;
- this.canSpawnFarFromPlayer = spawnableFarFromPlayer;
- this.serialize = saveable;
- this.summon = summonable;
- this.fireImmune = fireImmune;
2021-06-11 20:02:16 +02:00
+ public EntityType(EntityType.EntityFactory<T> factory, MobCategory spawnGroup, boolean saveable, boolean summonable, boolean fireImmune, boolean spawnableFarFromPlayer, ImmutableSet<Block> canSpawnInside, EntityDimensions dimensions, int maxTrackDistance, int trackTickInterval) { this(factory, spawnGroup, saveable, summonable, fireImmune, spawnableFarFromPlayer, canSpawnInside, dimensions, maxTrackDistance, trackTickInterval, "custom"); } // Paper - old signature
+
2021-06-11 14:02:28 +02:00
+ public final String id;
2021-06-11 20:02:16 +02:00
+
+ public EntityType(EntityType.EntityFactory<T> entitytypes_b, MobCategory enumcreaturetype, boolean flag, boolean flag1, boolean flag2, boolean flag3, ImmutableSet<Block> canSpawnInside, EntityDimensions dimensions, int maxTrackDistance, int trackTickInterval, String id) { // Paper - add id
2021-06-11 14:02:28 +02:00
+ this.factory = entitytypes_b;
+ this.category = enumcreaturetype;
+ this.canSpawnFarFromPlayer = flag3;
+ this.serialize = flag;
+ this.summon = flag1;
+ this.fireImmune = flag2;
2021-06-11 20:02:16 +02:00
this.immuneTo = canSpawnInside;
this.dimensions = dimensions;
this.clientTrackingRange = maxTrackDistance;
this.updateInterval = trackTickInterval;
2021-06-11 14:02:28 +02:00
+
+ // 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
2021-06-17 19:11:00 +02:00
@@ -567,6 +579,12 @@ public class EntityType<T extends Entity> implements EntityTypeTest<Entity, T> {
2021-06-11 14:02:28 +02:00
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() {
2021-06-11 20:02:16 +02:00
return this != EntityType.PLAYER && this != EntityType.LLAMA_SPIT && this != EntityType.WITHER && this != EntityType.BAT && this != EntityType.ITEM_FRAME && this != EntityType.GLOW_ITEM_FRAME && this != EntityType.LEASH_KNOT && this != EntityType.PAINTING && this != EntityType.END_CRYSTAL && this != EntityType.EVOKER_FANGS;
2021-06-11 14:02:28 +02:00
}
2021-06-17 19:11:00 +02:00
@@ -659,7 +677,7 @@ public class EntityType<T extends Entity> implements EntityTypeTest<Entity, T> {
2021-06-11 14:02:28 +02:00
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
2021-07-07 08:52:40 +02:00
index 3b09f76805053802bb779e227749d81482636407..759cd74cda7f0d1f3c0f3bc0a2a941e16258a1c0 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
2021-06-11 20:02:16 +02:00
@@ -140,7 +140,7 @@ import org.bukkit.event.entity.EntityTeleportEvent;
2021-06-11 14:02:28 +02:00
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 {
2021-07-07 08:52:40 +02:00
@@ -2761,7 +2761,6 @@ public abstract class LivingEntity extends Entity {
2021-06-11 14:02:28 +02:00
@Override
public void tick() {
- SpigotTimings.timerEntityBaseTick.startTiming(); // Spigot
super.tick();
this.updatingUsingItem();
this.updateSwimAmount();
2021-07-07 08:52:40 +02:00
@@ -2802,9 +2801,7 @@ public abstract class LivingEntity extends Entity {
2021-06-11 14:02:28 +02:00
}
}
- 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);
2021-07-07 08:52:40 +02:00
@@ -2884,8 +2881,6 @@ public abstract class LivingEntity extends Entity {
2021-06-11 14:02:28 +02:00
if (this.isSleeping()) {
2021-06-11 20:02:16 +02:00
this.setXRot(0.0F);
2021-06-11 14:02:28 +02:00
}
-
- SpigotTimings.timerEntityTickRest.stopTiming(); // Spigot
}
public void detectEquipmentUpdates() {
2021-07-07 08:52:40 +02:00
@@ -3067,7 +3062,6 @@ public abstract class LivingEntity extends Entity {
2021-06-11 14:02:28 +02:00
this.setDeltaMovement(d4, d5, d6);
this.level.getProfiler().push("ai");
- SpigotTimings.timerEntityAI.startTiming(); // Spigot
if (this.isImmobile()) {
this.jumping = false;
this.xxa = 0.0F;
2021-07-07 08:52:40 +02:00
@@ -3077,7 +3071,6 @@ public abstract class LivingEntity extends Entity {
2021-06-11 14:02:28 +02:00
this.serverAiStep();
this.level.getProfiler().pop();
}
- SpigotTimings.timerEntityAI.stopTiming(); // Spigot
this.level.getProfiler().pop();
this.level.getProfiler().push("jump");
2021-07-07 08:52:40 +02:00
@@ -3112,9 +3105,9 @@ public abstract class LivingEntity extends Entity {
2021-06-11 14:02:28 +02:00
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();
2021-06-11 20:02:16 +02:00
this.level.getProfiler().push("freezing");
boolean flag1 = this.getType().is((Tag) EntityTypeTags.FREEZE_HURTS_EXTRA_TYPES);
2021-07-07 08:52:40 +02:00
@@ -3143,9 +3136,7 @@ public abstract class LivingEntity extends Entity {
2021-06-11 14:02:28 +02:00
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
2021-07-07 08:52:40 +02:00
index 3286beed6bf79f5f6b91227f596fcc43200e8bda..e38cd4df0924cce7fee4fd98967990945a62ecf4 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -82,7 +82,6 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
-import org.bukkit.craftbukkit.SpigotTimings; // Spigot
import org.bukkit.craftbukkit.block.CapturedBlockState;
import org.bukkit.craftbukkit.block.CraftBlockState;
import org.bukkit.craftbukkit.block.data.CraftBlockData;
2021-07-07 08:52:40 +02:00
@@ -150,7 +149,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2021-06-11 14:02:28 +02:00
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;
2021-07-07 08:52:40 +02:00
@@ -237,7 +236,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2021-06-11 20:02:16 +02:00
}
2021-06-11 14:02:28 +02:00
});
// CraftBukkit end
2021-06-11 20:02:16 +02:00
- this.timings = new SpigotTimings.WorldTimingsHandler(this); // Spigot - code below can generate new world and access timings
2021-06-11 14:02:28 +02:00
+ 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);
}
2021-07-07 08:52:40 +02:00
@@ -725,15 +724,14 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2021-06-11 14:02:28 +02:00
2021-06-11 20:02:16 +02:00
timings.tileEntityTick.stopTiming(); // Spigot
this.tickingBlockEntities = false;
+ co.aikar.timings.TimingHistory.tileEntityTicks += this.blockEntityTickers.size(); // Paper
2021-06-11 14:02:28 +02:00
gameprofilerfiller.pop();
spigotConfig.currentPrimedTnt = 0; // Spigot
}
2021-06-11 20:02:16 +02:00
public <T extends Entity> void guardEntityTick(Consumer<T> tickConsumer, T entity) {
2021-06-11 14:02:28 +02:00
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
2021-06-11 20:02:16 +02:00
index 0be0c9a9f29f29e2622df49861d30a7edbaf0515..702203f4a4fa4fc03c35ec974a97e08ed0f3c67c 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/ServerTickList.java
+++ b/src/main/java/net/minecraft/world/level/ServerTickList.java
2021-06-11 20:02:16 +02:00
@@ -37,12 +37,17 @@ public class ServerTickList<T> implements TickList<T> {
2021-06-11 14:02:28 +02:00
private final List<TickNextTickData<T>> alreadyTicked = Lists.newArrayList();
private final Consumer<TickNextTickData<T>> ticker;
2021-06-11 20:02:16 +02:00
- public ServerTickList(ServerLevel world, Predicate<T> invalidObjPredicate, Function<T, ResourceLocation> idToName, Consumer<TickNextTickData<T>> tickConsumer) {
2021-06-11 14:02:28 +02:00
- this.ignore = invalidObjPredicate;
- this.toId = idToName;
- this.level = world;
2021-06-11 20:02:16 +02:00
- this.ticker = tickConsumer;
+ public ServerTickList(ServerLevel worldserver, Predicate<T> predicate, Function<T, ResourceLocation> function, Consumer<TickNextTickData<T>> consumer, String timingsType) {
2021-06-11 14:02:28 +02:00
+ this.ignore = predicate;
+ this.toId = function;
+ this.level = worldserver;
2021-06-11 20:02:16 +02:00
+ this.ticker = consumer;
2021-06-11 14:02:28 +02:00
+ 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();
2021-06-11 20:02:16 +02:00
@@ -64,6 +69,7 @@ public class ServerTickList<T> implements TickList<T> {
2021-06-11 14:02:28 +02:00
this.level.getProfiler().push("cleaning");
+ this.timingCleanup.startTiming(); // Paper
TickNextTickData nextticklistentry;
while (i > 0 && iterator.hasNext()) {
2021-06-11 20:02:16 +02:00
@@ -79,7 +85,9 @@ public class ServerTickList<T> implements TickList<T> {
2021-06-11 14:02:28 +02:00
--i;
}
}
+ this.timingCleanup.stopTiming(); // Paper
+ this.timingTicking.startTiming(); // Paper
this.level.getProfiler().popPush("ticking");
while ((nextticklistentry = (TickNextTickData) this.currentlyTicking.poll()) != null) {
2021-06-11 20:02:16 +02:00
@@ -99,6 +107,7 @@ public class ServerTickList<T> implements TickList<T> {
2021-06-11 14:02:28 +02:00
}
}
+ 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
2021-07-07 08:52:40 +02:00
index 0cd5448d93091e981374b0c11e95a3baca9defef..72ef08a59dbf72bec2ce54ab76455c4230395959 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/block/Block.java
+++ b/src/main/java/net/minecraft/world/level/block/Block.java
2021-06-11 20:02:16 +02:00
@@ -90,6 +90,15 @@ public class Block extends BlockBehaviour implements ItemLike {
public static final int UPDATE_LIMIT = 512;
2021-06-11 14:02:28 +02:00
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
Updated Upstream (Bukkit/CraftBukkit/Spigot) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 8503c3c9 #621: Add HumanEntity#getItemInUse and Material#getSlipperiness 248deb09 #622: Add methods to check if item is the breed item for an entity 2ce691d8 Clarify Player#breakBlock only works for blocks in the same world 5dcdd48e SPIGOT-6514: Small Dripleaf block data is missing half property cc9610b7 #619: Add Player#breakBlock() 862bc475 Fix bad merge of SPIGOT-6502 fix 989bb0c1 Downgrade SnakeYAML due to issues with comments parsing 1dff62ae Fix inverted visual fire docs CraftBukkit Changes: 40caacc8 SPIGOT-6526: World entities are not populated when plugin onEnable is called c9a92ad0 SPIGOT-6536: Marker position not set on spawn 20d3e57c #855: Add HumanEntity#getItemInUse and Material#getSlipperiness d9c69b44 SPIGOT-6529: Fix BundleMeta#setItems 8bd43be5 SPIGOT-6535: PlayerGameModeChangeEvent event incorrectly reports old gamemode 4ece3ff3 #856: Add methods to check if item is the breed item for an entity dd4bec5f Add additional validation to Player#breakBlock bc835ae6 SPIGOT-6532: Fix Entity#setGlowing 384e116e Restore 1.16.5 behaviour of InventoryDragEvent being called even when a single item is 'dragged' to its own slot b42e708c Fix new map colors rendering as transparent cfe7fecf SPIGOT-6524: Inventory desync when InventoryClickEvent is cancelled eeae1b19 SPIGOT-6522: ItemStack on cursor is always AIR 7490724d Fix missing PlayerEditBookEvent 06875f76 SPIGOT-6513: Placing ItemStack in Inventory causes InventoryAction.NOTHING 27835bde SPIGOT-6519: Fix end gateway teleports 4ac634ad SPIGOT-6515: "Un-waterlogging" throws UnsupportedOperationException in some cases da425fa2 SPIGOT-6518: Anvils falling onto dripstone can sometimes crash server 50530da9 SPIGOT-6514: Small Dripleaf block data is missing half property 6fdecf20 #853: Implement Player#breakBlock() 4db9c49f SPIGOT-6510: Bukkit#createMap throws NullPointerException 89e2b127 SPIGOT-6517: Spider jockey crash on dripstone cbf2f678 SPIGOT-6508: Rename conflicted getServer 74575d48 SPIGOT-6506: Fix crash with custom inventories a3df386f Fix NPE with Entity.getNearbyEntities d747f8ed Fix NPE with World.getNearbyEntities 4d2c7800 Fix second usage of worldGenSettings just in case 5182f923 SPIGOT-6504: Fix generating fresh worlds Spigot Changes: 66f9d3c1 Rebuild patches 191e4971 Rebuild patches a09c0bb6 Restore Spigot experience merging
2021-06-13 07:13:07 +02:00
index 92b042080f06fb95958ff5e824830a84f2d1f2a6..7b333e2d6884b272abefbc820bcce8026a4cdf7e 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java
2021-06-11 20:02:16 +02:00
@@ -19,10 +19,12 @@ import org.bukkit.inventory.InventoryHolder;
2021-06-11 14:02:28 +02:00
// 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 e9a04017df42312e4e0e7e414c9ccc95c71ddae1..4a13b18ce609fc6a86da48b0673ccf9d3e0d8292 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
@@ -731,6 +731,7 @@ public class LevelChunk implements ChunkAccess {
2021-06-11 14:02:28 +02:00
server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkLoadEvent(this.bukkitChunk, this.needsDecoration));
if (this.needsDecoration) {
+ try (co.aikar.timings.Timing ignored = this.level.timings.chunkLoadPopulate.startTiming()) { // Paper
2021-06-11 14:02:28 +02:00
this.needsDecoration = false;
java.util.Random random = new java.util.Random();
2021-06-11 20:02:16 +02:00
random.setSeed(this.level.getSeed());
@@ -750,6 +751,7 @@ public class LevelChunk implements ChunkAccess {
2021-06-11 14:02:28 +02:00
}
}
2021-06-11 20:02:16 +02:00
server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkPopulateEvent(this.bukkitChunk));
2021-06-11 14:02:28 +02:00
+ } // 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
2021-07-07 08:52:40 +02:00
index b645a2fc839dbf922ce73b23b7d53e9a5fe1a2ee..1b478ebfe6792a157772a5812d0daa1a3ccc4776 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java
2021-06-11 20:02:16 +02:00
@@ -1,5 +1,7 @@
2021-06-11 14:02:28 +02:00
package net.minecraft.world.level.chunk.storage;
2021-06-11 20:02:16 +02:00
+
2021-06-11 14:02:28 +02:00
+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;
2021-06-11 20:02:16 +02:00
@@ -433,7 +435,6 @@ public class ChunkSerializer {
private static void postLoadChunk(ServerLevel world, CompoundTag nbt, LevelChunk chunk) {
ListTag nbttaglist;
2021-06-11 14:02:28 +02:00
2021-06-11 20:02:16 +02:00
- world.timings.syncChunkLoadEntitiesTimer.startTiming(); // Spigot
if (nbt.contains("Entities", 9)) {
nbttaglist = nbt.getList("Entities", 10);
if (!nbttaglist.isEmpty()) {
@@ -441,8 +442,6 @@ public class ChunkSerializer {
}
2021-06-11 14:02:28 +02:00
}
- world.timings.syncChunkLoadEntitiesTimer.stopTiming(); // Spigot
- world.timings.syncChunkLoadTileEntitiesTimer.startTiming(); // Spigot
2021-06-11 20:02:16 +02:00
nbttaglist = nbt.getList("TileEntities", 10);
2021-06-11 14:02:28 +02:00
2021-06-11 20:02:16 +02:00
for (int i = 0; i < nbttaglist.size(); ++i) {
@@ -460,8 +459,6 @@ public class ChunkSerializer {
2021-06-11 14:02:28 +02:00
}
}
}
- world.timings.syncChunkLoadTileEntitiesTimer.stopTiming(); // Spigot
-
}
2021-06-11 20:02:16 +02:00
private static CompoundTag packStructureData(ServerLevel world, ChunkPos chunkcoordintpair, Map<StructureFeature<?>, StructureStart<?>> map, Map<StructureFeature<?>, LongSet> map1) {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 7964acaef50a1786c0510e04723e1ec8dc682757..02d8cfeaea105d42a437b08c3ba59c50eda5a452 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -2160,12 +2160,31 @@ public final class CraftServer implements Server {
2021-06-11 14:02:28 +02:00
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 b0ffa23faf62629043dfd613315eaf9c5fcc2cfe..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 = SpigotTimings.pluginTaskTimingMap.get(name);
- if (result == null) {
- result = new CustomTimingsHandler(name, SpigotTimings.schedulerSyncTimer);
- SpigotTimings.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 = SpigotTimings.entityTypeTimingMap.get(entityType);
- if (result == null) {
- result = new CustomTimingsHandler("** tickEntity - " + entity.getClass().getSimpleName(), SpigotTimings.activatedEntityTimer);
- SpigotTimings.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 = SpigotTimings.tileEntityTypeTimingMap.get(entityType);
- if (result == null) {
- result = new CustomTimingsHandler("** tickTileEntity - " + entity.getClass().getSimpleName(), SpigotTimings.tickTileEntityTimer);
- SpigotTimings.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() + " - ";
-
- this.mobSpawn = new CustomTimingsHandler("** " + name + "mobSpawn");
- this.doChunkUnload = new CustomTimingsHandler("** " + name + "doChunkUnload");
- this.doTickPending = new CustomTimingsHandler("** " + name + "doTickPending");
- this.doTickTiles = new CustomTimingsHandler("** " + name + "doTickTiles");
- this.doChunkMap = new CustomTimingsHandler("** " + name + "doChunkMap");
- this.doSounds = new CustomTimingsHandler("** " + name + "doSounds");
- this.entityTick = new CustomTimingsHandler("** " + name + "entityTick");
- this.tileEntityTick = new CustomTimingsHandler("** " + name + "tileEntityTick");
- this.tileEntityPending = new CustomTimingsHandler("** " + name + "tileEntityPending");
-
- this.syncChunkLoadTimer = new CustomTimingsHandler("** " + name + "syncChunkLoad");
- this.syncChunkLoadStructuresTimer = new CustomTimingsHandler("** " + name + "chunkLoad - Structures");
- this.syncChunkLoadEntitiesTimer = new CustomTimingsHandler("** " + name + "chunkLoad - Entities");
- this.syncChunkLoadTileEntitiesTimer = new CustomTimingsHandler("** " + name + "chunkLoad - TileEntities");
- this.syncChunkLoadTileTicksTimer = new CustomTimingsHandler("** " + name + "chunkLoad - TileTicks");
- this.syncChunkLoadPostTimer = new CustomTimingsHandler("** " + name + "chunkLoad - Post");
-
-
- this.tracker = new CustomTimingsHandler(name + "tracker");
- this.doTick = new CustomTimingsHandler(name + "doTick");
- this.tickEntities = new CustomTimingsHandler(name + "tickEntities");
- }
- }
-}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index f1a5257ba8e626cc55bbdd755af23de2326e92f8..7274657daecdaaf961f5bbd69e05fc5b7f0c2fda 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
Updated Upstream (Bukkit/CraftBukkit/Spigot) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 8503c3c9 #621: Add HumanEntity#getItemInUse and Material#getSlipperiness 248deb09 #622: Add methods to check if item is the breed item for an entity 2ce691d8 Clarify Player#breakBlock only works for blocks in the same world 5dcdd48e SPIGOT-6514: Small Dripleaf block data is missing half property cc9610b7 #619: Add Player#breakBlock() 862bc475 Fix bad merge of SPIGOT-6502 fix 989bb0c1 Downgrade SnakeYAML due to issues with comments parsing 1dff62ae Fix inverted visual fire docs CraftBukkit Changes: 40caacc8 SPIGOT-6526: World entities are not populated when plugin onEnable is called c9a92ad0 SPIGOT-6536: Marker position not set on spawn 20d3e57c #855: Add HumanEntity#getItemInUse and Material#getSlipperiness d9c69b44 SPIGOT-6529: Fix BundleMeta#setItems 8bd43be5 SPIGOT-6535: PlayerGameModeChangeEvent event incorrectly reports old gamemode 4ece3ff3 #856: Add methods to check if item is the breed item for an entity dd4bec5f Add additional validation to Player#breakBlock bc835ae6 SPIGOT-6532: Fix Entity#setGlowing 384e116e Restore 1.16.5 behaviour of InventoryDragEvent being called even when a single item is 'dragged' to its own slot b42e708c Fix new map colors rendering as transparent cfe7fecf SPIGOT-6524: Inventory desync when InventoryClickEvent is cancelled eeae1b19 SPIGOT-6522: ItemStack on cursor is always AIR 7490724d Fix missing PlayerEditBookEvent 06875f76 SPIGOT-6513: Placing ItemStack in Inventory causes InventoryAction.NOTHING 27835bde SPIGOT-6519: Fix end gateway teleports 4ac634ad SPIGOT-6515: "Un-waterlogging" throws UnsupportedOperationException in some cases da425fa2 SPIGOT-6518: Anvils falling onto dripstone can sometimes crash server 50530da9 SPIGOT-6514: Small Dripleaf block data is missing half property 6fdecf20 #853: Implement Player#breakBlock() 4db9c49f SPIGOT-6510: Bukkit#createMap throws NullPointerException 89e2b127 SPIGOT-6517: Spider jockey crash on dripstone cbf2f678 SPIGOT-6508: Rename conflicted getServer 74575d48 SPIGOT-6506: Fix crash with custom inventories a3df386f Fix NPE with Entity.getNearbyEntities d747f8ed Fix NPE with World.getNearbyEntities 4d2c7800 Fix second usage of worldGenSettings just in case 5182f923 SPIGOT-6504: Fix generating fresh worlds Spigot Changes: 66f9d3c1 Rebuild patches 191e4971 Rebuild patches a09c0bb6 Restore Spigot experience merging
2021-06-13 07:13:07 +02:00
@@ -1819,6 +1819,14 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-06-11 14:02:28 +02:00
packet.components = components;
2021-06-11 20:02:16 +02:00
CraftPlayer.this.getHandle().connection.send(packet);
2021-06-11 14:02:28 +02:00
}
+
+ // 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 054fcc3713f02e358dfe049491c8d1689ccc750b..07c4d9cd5081378e1b903518f7174fca959cd9e3 100644
2021-06-11 14:02:28 +02:00
--- 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;
@@ -194,7 +195,8 @@ public class CraftScheduler implements BukkitScheduler {
2021-06-11 14:02:28 +02:00
}
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);
}
@@ -275,7 +277,7 @@ public class CraftScheduler implements BukkitScheduler {
2021-06-11 14:02:28 +02:00
}
return false;
}
- });
+ }){{this.timings=co.aikar.timings.MinecraftTimings.getCancelTasksTimer();}}; // Paper
2021-06-11 20:02:16 +02:00
this.handle(task, 0L);
for (CraftTask taskPending = this.head.getNext(); taskPending != null; taskPending = taskPending.getNext()) {
2021-06-11 14:02:28 +02:00
if (taskPending == task) {
@@ -310,7 +312,7 @@ public class CraftScheduler implements BukkitScheduler {
2021-06-11 14:02:28 +02:00
}
}
}
- });
+ }){{this.timings=co.aikar.timings.MinecraftTimings.getCancelTasksTimer(plugin);}}; // Paper
2021-06-11 20:02:16 +02:00
this.handle(task, 0L);
for (CraftTask taskPending = this.head.getNext(); taskPending != null; taskPending = taskPending.getNext()) {
2021-06-11 14:02:28 +02:00
if (taskPending == task) {
@@ -417,9 +419,7 @@ public class CraftScheduler implements BukkitScheduler {
2021-06-11 14:02:28 +02:00
if (task.isSync()) {
2021-06-11 20:02:16 +02:00
this.currentTask = task;
2021-06-11 14:02:28 +02:00
try {
- task.timings.startTiming(); // Spigot
task.run();
- task.timings.stopTiming(); // Spigot
} catch (final Throwable throwable) {
// Paper start
String msg = String.format(
@@ -453,8 +453,10 @@ public class CraftScheduler implements BukkitScheduler {
2021-06-11 20:02:16 +02:00
this.runners.remove(task.getTaskId());
2021-06-11 14:02:28 +02:00
}
}
2021-06-11 20:02:16 +02:00
+ MinecraftTimings.bukkitSchedulerFinishTimer.startTiming(); // Paper
this.pending.addAll(temp);
2021-06-11 14:02:28 +02:00
temp.clear();
2021-06-11 20:02:16 +02:00
+ MinecraftTimings.bukkitSchedulerFinishTimer.stopTiming(); // Paper
this.debugHead = this.debugHead.getNextHead(currentTick);
2021-06-11 14:02:28 +02:00
}
@@ -492,6 +494,7 @@ public class CraftScheduler implements BukkitScheduler {
2021-06-11 14:02:28 +02:00
}
private void parsePending() {
+ MinecraftTimings.bukkitSchedulerPendingTimer.startTiming();
CraftTask head = this.head;
CraftTask task = head.getNext();
CraftTask lastTask = head;
@@ -510,6 +513,7 @@ public class CraftScheduler implements BukkitScheduler {
2021-06-11 14:02:28 +02:00
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 b89846e0f645c79afec018dae1d64a1bda043ed9..3f45bab0e9f7b3697e6d9d1092a1e6e579f7066f 100644
2021-06-11 14:02:28 +02:00
--- 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,13 +29,13 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot
2021-06-11 14:02:28 +02:00
*/
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;
private final long createdAt = System.nanoTime();
2021-06-11 14:02:28 +02:00
- final CustomTimingsHandler timings; // Spigot
CraftTask() {
this(null, null, CraftTask.NO_REPEATING, CraftTask.NO_REPEATING);
}
@@ -52,7 +55,7 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot
2021-06-11 14:02:28 +02:00
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
@@ -73,7 +76,7 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot
2021-06-11 14:02:28 +02:00
}
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
@@ -93,11 +96,13 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot
2021-06-11 14:02:28 +02:00
@Override
public void run() {
+ try (Timing ignored = timings.startTiming()) { // Paper
2021-06-11 20:02:16 +02:00
if (this.rTask != null) {
this.rTask.run();
2021-06-11 14:02:28 +02:00
} else {
2021-06-11 20:02:16 +02:00
this.cTask.accept(this);
2021-06-11 14:02:28 +02:00
}
+ } // Paper
}
long getCreatedAt() {
@@ -128,7 +133,7 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot
2021-06-11 14:02:28 +02:00
this.next = next;
}
- Class<?> getTaskClass() {
2021-06-11 20:02:16 +02:00
+ public Class<?> getTaskClass() { // Paper
return (this.rTask != null) ? this.rTask.getClass() : ((this.cTask != null) ? this.cTask.getClass() : null);
2021-06-11 14:02:28 +02:00
}
@@ -152,9 +157,4 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot
2021-06-11 14:02:28 +02:00
return true;
}
- // Spigot start
- public String getTaskName() {
2021-06-11 20:02:16 +02:00
- return (this.getTaskClass() == null) ? "Unknown" : this.getTaskClass().getName();
2021-06-11 14:02:28 +02:00
- }
- // 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
2021-07-07 08:52:40 +02:00
index 67cae2e6055389e93fb4b94daf8402ec5fdc6f9a..7a3ba7590249d6a3eb37f894c9cfd414a8ccf3fd 100644
2021-06-11 14:02:28 +02:00
--- 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
2021-06-11 20:02:16 +02:00
index e73db1031c40f6bdf422dcefaa55721caf3cb4e9..f023f3a0d1671398363f0caa432ffb61fd07c9b2 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/spigotmc/ActivationRange.java
+++ b/src/main/java/org/spigotmc/ActivationRange.java
2021-06-11 20:02:16 +02:00
@@ -27,7 +27,7 @@ import net.minecraft.world.entity.projectile.ThrownTrident;
import net.minecraft.world.entity.raid.Raider;
2021-06-11 14:02:28 +02:00
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
-import org.bukkit.craftbukkit.SpigotTimings;
+import co.aikar.timings.MinecraftTimings;
public class ActivationRange
{
2021-06-11 20:02:16 +02:00
@@ -71,8 +71,8 @@ public class ActivationRange
2021-06-11 14:02:28 +02:00
/**
* 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)
2021-06-11 20:02:16 +02:00
@@ -107,7 +107,7 @@ public class ActivationRange
2021-06-11 14:02:28 +02:00
*/
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;
2021-06-11 20:02:16 +02:00
@@ -130,7 +130,7 @@ public class ActivationRange
world.getEntities().get(maxBB, ActivationRange::activateEntity);
2021-06-11 14:02:28 +02:00
}
- SpigotTimings.entityActivationCheckTimer.stopTiming();
+ MinecraftTimings.entityActivationCheckTimer.stopTiming();
}
/**
2021-06-11 20:02:16 +02:00
@@ -221,10 +221,8 @@ public class ActivationRange
2021-06-11 14:02:28 +02:00
*/
public static boolean checkIfActive(Entity entity)
{
- SpigotTimings.checkIfActiveTimer.startTiming();
// Never safe to skip fireworks or entities not yet added to chunk
2021-06-11 20:02:16 +02:00
if ( entity instanceof FireworkRocketEntity ) {
2021-06-11 14:02:28 +02:00
- SpigotTimings.checkIfActiveTimer.stopTiming();
return true;
}
2021-06-11 20:02:16 +02:00
@@ -248,7 +246,6 @@ public class ActivationRange
2021-06-11 14:02:28 +02:00
{
isActive = false;
}
- SpigotTimings.checkIfActiveTimer.stopTiming();
return isActive;
}
}