spigot/CraftBukkit-Patches/0008-Spigot-Timings.patch

830 lines
40 KiB
Diff
Raw Normal View History

2025-04-13 10:28:23 +10:00
From e4230a5fcdcdf8ef356934e620e5482200699b2f Mon Sep 17 00:00:00 2001
2017-11-07 18:58:02 +11:00
From: Aikar <aikar@aikar.co>
Date: Thu, 10 Jan 2013 00:18:11 -0500
Subject: [PATCH] Spigot Timings
Overhauls the Timings System adding performance tracking all around the Minecraft Server
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2025-03-26 03:05:00 +11:00
index b2a556f60..a1a7cba6e 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2025-03-26 03:05:00 +11:00
@@ -201,6 +201,8 @@ import org.bukkit.craftbukkit.Main;
2021-03-16 09:00:00 +11:00
import org.bukkit.event.server.ServerLoadEvent;
// CraftBukkit end
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
+
2024-10-23 02:15:00 +11:00
public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTask> implements ServerInfo, ChunkIOErrorReporter, ICommandListener {
2021-03-16 09:00:00 +11:00
2022-03-01 02:00:00 +11:00
public static final Logger LOGGER = LogUtils.getLogger();
2025-03-26 03:05:00 +11:00
@@ -1319,6 +1321,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2024-10-23 02:15:00 +11:00
}
}
2021-03-16 09:00:00 +11:00
+ SpigotTimings.serverTickTimer.startTiming(); // Spigot
2021-06-11 15:00:00 +10:00
++this.tickCount;
2024-10-23 02:15:00 +11:00
this.tickRateManager.tick();
this.tickChildren(booleansupplier);
2025-03-26 03:05:00 +11:00
@@ -1344,10 +1347,13 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2024-10-23 02:15:00 +11:00
this.smoothedTickTimeMillis = this.smoothedTickTimeMillis * 0.8F + (float) k / (float) TimeRange.NANOSECONDS_PER_MILLISECOND * 0.19999999F;
2024-04-24 01:15:00 +10:00
this.logTickMethodTime(i);
2024-10-23 02:15:00 +11:00
gameprofilerfiller.pop();
2021-03-16 09:00:00 +11:00
+ SpigotTimings.serverTickTimer.stopTiming(); // Spigot
+ org.spigotmc.CustomTimingsHandler.tick(); // Spigot
}
2024-10-23 02:15:00 +11:00
private void autoSave() {
this.ticksUntilAutosave = this.autosavePeriod; // CraftBukkit
+ SpigotTimings.worldSaveTimer.startTiming(); // Spigot
MinecraftServer.LOGGER.debug("Autosave started");
GameProfilerFiller gameprofilerfiller = Profiler.get();
2025-03-26 03:05:00 +11:00
@@ -1355,6 +1361,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2024-10-23 02:15:00 +11:00
this.saveEverything(true, false, false);
gameprofilerfiller.pop();
MinecraftServer.LOGGER.debug("Autosave finished");
+ SpigotTimings.worldSaveTimer.stopTiming(); // Spigot
}
2024-04-24 01:15:00 +10:00
private void logTickMethodTime(long i) {
2025-03-26 03:05:00 +11:00
@@ -1427,17 +1434,24 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2023-09-22 02:40:00 +10:00
this.getPlayerList().getPlayers().forEach((entityplayer) -> {
entityplayer.connection.suspendFlushing();
});
2021-03-16 09:00:00 +11:00
+ SpigotTimings.schedulerTimer.startTiming(); // Spigot
2024-10-23 02:15:00 +11:00
this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit
2021-03-16 09:00:00 +11:00
+ SpigotTimings.schedulerTimer.stopTiming(); // Spigot
2024-10-23 02:15:00 +11:00
gameprofilerfiller.push("commandFunctions");
2021-03-16 09:00:00 +11:00
+ SpigotTimings.commandFunctionsTimer.startTiming(); // Spigot
2021-11-22 09:00:00 +11:00
this.getFunctions().tick();
2021-03-16 09:00:00 +11:00
+ SpigotTimings.commandFunctionsTimer.stopTiming(); // Spigot
2024-10-23 02:15:00 +11:00
gameprofilerfiller.popPush("levels");
2021-03-16 09:00:00 +11:00
// CraftBukkit start
// Run tasks that are waiting on processing
+ SpigotTimings.processQueueTimer.startTiming(); // Spigot
while (!processQueue.isEmpty()) {
processQueue.remove().run();
}
+ SpigotTimings.processQueueTimer.stopTiming(); // Spigot
+ SpigotTimings.timeUpdateTimer.startTiming(); // Spigot
// Send time updates to everyone, it will get the right time from the world the player is in.
2021-06-11 15:00:00 +10:00
if (this.tickCount % 20 == 0) {
2021-03-16 09:00:00 +11:00
for (int i = 0; i < this.getPlayerList().players.size(); ++i) {
2025-03-26 03:05:00 +11:00
@@ -1445,6 +1459,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2024-10-23 02:15:00 +11:00
entityplayer.connection.send(new PacketPlayOutUpdateTime(entityplayer.level().getGameTime(), entityplayer.getPlayerTime(), entityplayer.serverLevel().getGameRules().getBoolean(GameRules.RULE_DAYLIGHT))); // Add support for per player time
2021-03-16 09:00:00 +11:00
}
}
+ SpigotTimings.timeUpdateTimer.stopTiming(); // Spigot
2025-03-26 03:05:00 +11:00
for (WorldServer worldserver : this.getAllLevels()) {
gameprofilerfiller.push(() -> {
@@ -1463,7 +1478,9 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2024-10-23 02:15:00 +11:00
gameprofilerfiller.push("tick");
2021-03-16 09:00:00 +11:00
try {
+ worldserver.timings.doTick.startTiming(); // Spigot
2021-11-22 09:00:00 +11:00
worldserver.tick(booleansupplier);
2021-03-16 09:00:00 +11:00
+ worldserver.timings.doTick.stopTiming(); // Spigot
} catch (Throwable throwable) {
2021-11-22 09:00:00 +11:00
CrashReport crashreport = CrashReport.forThrowable(throwable, "Exception ticking world");
2021-03-16 09:00:00 +11:00
2025-03-26 03:05:00 +11:00
@@ -1476,18 +1493,24 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2021-03-16 09:00:00 +11:00
}
2024-10-23 02:15:00 +11:00
gameprofilerfiller.popPush("connection");
2021-03-16 09:00:00 +11:00
+ SpigotTimings.connectionTimer.startTiming(); // Spigot
2024-10-23 02:15:00 +11:00
this.tickConnection();
2021-03-16 09:00:00 +11:00
+ SpigotTimings.connectionTimer.stopTiming(); // Spigot
2024-10-23 02:15:00 +11:00
gameprofilerfiller.popPush("players");
2021-03-16 09:00:00 +11:00
+ SpigotTimings.playerListTimer.startTiming(); // Spigot
this.playerList.tick();
+ SpigotTimings.playerListTimer.stopTiming(); // Spigot
2025-03-26 03:05:00 +11:00
if (this.tickRateManager.runsNormally()) {
2021-11-22 09:00:00 +11:00
GameTestHarnessTicker.SINGLETON.tick();
2021-03-16 09:00:00 +11:00
}
2024-10-23 02:15:00 +11:00
gameprofilerfiller.popPush("server gui refresh");
2021-03-16 09:00:00 +11:00
+ SpigotTimings.tickablesTimer.startTiming(); // Spigot
for (int i = 0; i < this.tickables.size(); ++i) {
((Runnable) this.tickables.get(i)).run();
}
+ SpigotTimings.tickablesTimer.stopTiming(); // Spigot
2024-10-23 02:15:00 +11:00
gameprofilerfiller.popPush("send chunks");
2025-03-26 03:05:00 +11:00
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
2025-03-26 03:05:00 +11:00
index 496ca6184..6e2684753 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
2024-10-23 02:15:00 +11:00
@@ -65,6 +65,7 @@ import org.apache.logging.log4j.Level;
2022-03-01 02:00:00 +11:00
import org.apache.logging.log4j.LogManager;
2021-03-16 09:00:00 +11:00
import org.apache.logging.log4j.io.IoBuilder;
import org.bukkit.command.CommandSender;
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
2024-04-07 11:54:30 +10:00
import org.bukkit.craftbukkit.util.TerminalCompletionHandler;
import org.bukkit.craftbukkit.util.TerminalConsoleWriterThread;
2021-03-16 09:00:00 +11:00
import org.bukkit.event.server.ServerCommandEvent;
2025-03-26 03:05:00 +11:00
@@ -376,6 +377,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
2021-03-16 09:00:00 +11:00
}
2021-11-22 09:00:00 +11:00
public void handleConsoleInputs() {
2021-03-16 09:00:00 +11:00
+ SpigotTimings.serverCommandTimer.startTiming(); // Spigot
2021-06-11 15:00:00 +10:00
while (!this.consoleInput.isEmpty()) {
ServerCommand servercommand = (ServerCommand) this.consoleInput.remove(0);
2021-03-16 09:00:00 +11:00
2025-03-26 03:05:00 +11:00
@@ -390,6 +392,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
2021-03-16 09:00:00 +11:00
// CraftBukkit end
}
+ SpigotTimings.serverCommandTimer.stopTiming(); // Spigot
}
@Override
diff --git a/src/main/java/net/minecraft/server/level/ChunkProviderServer.java b/src/main/java/net/minecraft/server/level/ChunkProviderServer.java
2025-03-26 03:05:00 +11:00
index 03f9d3c7a..4fdf130de 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/server/level/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/level/ChunkProviderServer.java
2025-03-26 03:05:00 +11:00
@@ -160,11 +160,13 @@ public class ChunkProviderServer extends IChunkProvider {
2019-05-14 10:00:00 +10:00
}
2019-04-23 12:00:00 +10:00
2021-11-22 09:00:00 +11:00
gameprofilerfiller.incrementCounter("getChunkCacheMiss");
2021-06-11 15:00:00 +10:00
+ level.timings.syncChunkLoadTimer.startTiming(); // Spigot
2024-04-24 01:15:00 +10:00
CompletableFuture<ChunkResult<IChunkAccess>> completablefuture = this.getChunkFutureMainThread(i, j, chunkstatus, flag);
2025-03-26 03:05:00 +11:00
ChunkProviderServer.a chunkproviderserver_a = this.mainThreadProcessor;
2019-05-14 10:00:00 +10:00
2021-06-11 15:00:00 +10:00
Objects.requireNonNull(completablefuture);
2025-03-26 03:05:00 +11:00
chunkproviderserver_a.managedBlock(completablefuture::isDone);
2021-06-11 15:00:00 +10:00
+ level.timings.syncChunkLoadTimer.stopTiming(); // Spigot
2024-04-24 01:15:00 +10:00
ChunkResult<IChunkAccess> chunkresult = (ChunkResult) completablefuture.join();
2025-03-26 03:05:00 +11:00
IChunkAccess ichunkaccess1 = chunkresult.orElse(null); // CraftBukkit - decompile error
2024-04-24 01:15:00 +10:00
2025-03-26 03:05:00 +11:00
@@ -365,19 +367,25 @@ public class ChunkProviderServer extends IChunkProvider {
2024-10-23 02:15:00 +11:00
GameProfilerFiller gameprofilerfiller = Profiler.get();
gameprofilerfiller.push("purge");
2021-06-11 15:00:00 +10:00
+ this.level.timings.doChunkMap.startTiming(); // Spigot
2024-04-24 01:15:00 +10:00
if (this.level.tickRateManager().runsNormally() || !flag) {
2025-03-26 03:05:00 +11:00
this.ticketStorage.purgeStaleTickets();
2024-04-24 01:15:00 +10:00
}
2021-11-22 09:00:00 +11:00
this.runDistanceManagerUpdates();
2021-06-11 15:00:00 +10:00
+ this.level.timings.doChunkMap.stopTiming(); // Spigot
2024-10-23 02:15:00 +11:00
gameprofilerfiller.popPush("chunks");
2022-03-01 02:00:00 +11:00
if (flag) {
this.tickChunks();
2023-12-06 03:40:00 +11:00
+ this.level.timings.tracker.startTiming(); // Spigot
this.chunkMap.tick();
+ this.level.timings.tracker.stopTiming(); // Spigot
2022-03-01 02:00:00 +11:00
}
2021-06-11 15:00:00 +10:00
+ this.level.timings.doChunkUnload.startTiming(); // Spigot
2024-10-23 02:15:00 +11:00
gameprofilerfiller.popPush("unload");
2021-11-22 09:00:00 +11:00
this.chunkMap.tick(booleansupplier);
2021-06-11 15:00:00 +10:00
+ this.level.timings.doChunkUnload.stopTiming(); // Spigot
2024-10-23 02:15:00 +11:00
gameprofilerfiller.pop();
2019-05-28 06:30:00 +10:00
this.clearCache();
2019-04-23 12:00:00 +10:00
}
2025-03-26 03:05:00 +11:00
@@ -454,7 +462,9 @@ public class ChunkProviderServer extends IChunkProvider {
2024-10-23 02:15:00 +11:00
2025-03-26 03:05:00 +11:00
gameprofilerfiller.popPush("tickTickingChunks");
this.chunkMap.forEachBlockTickingChunk((chunk1) -> {
+ this.level.timings.doTickTiles.startTiming(); // Spigot
this.level.tickChunk(chunk1, k);
+ this.level.timings.doTickTiles.stopTiming(); // Spigot
});
gameprofilerfiller.pop();
gameprofilerfiller.popPush("customSpawners");
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/server/level/WorldServer.java b/src/main/java/net/minecraft/server/level/WorldServer.java
2025-04-13 10:28:23 +10:00
index 229e7ef9b..34c4d8464 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/server/level/WorldServer.java
+++ b/src/main/java/net/minecraft/server/level/WorldServer.java
2025-03-26 03:05:00 +11:00
@@ -178,6 +178,7 @@ import net.minecraft.world.level.levelgen.ChunkProviderFlat;
2024-04-24 01:15:00 +10:00
import net.minecraft.world.level.storage.WorldDataServer;
2021-03-16 09:00:00 +11:00
import org.bukkit.Bukkit;
import org.bukkit.WeatherType;
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
import org.bukkit.craftbukkit.event.CraftEventFactory;
2022-06-08 02:00:00 +10:00
import org.bukkit.craftbukkit.generator.CustomWorldChunkManager;
2025-04-13 10:28:23 +10:00
import org.bukkit.craftbukkit.util.CraftLocation;
@@ -381,6 +382,7 @@ public class WorldServer extends World implements ServerEntityGetter, GeneratorA
2023-12-06 03:40:00 +11:00
}
2024-10-23 02:15:00 +11:00
gameprofilerfiller.push("tickPending");
2021-03-16 09:00:00 +11:00
+ timings.doTickPending.startTiming(); // Spigot
2023-12-06 03:40:00 +11:00
if (!this.isDebug() && flag) {
2025-03-26 03:05:00 +11:00
long k = this.getGameTime();
2025-04-13 10:28:23 +10:00
@@ -390,6 +392,7 @@ public class WorldServer extends World implements ServerEntityGetter, GeneratorA
2025-03-26 03:05:00 +11:00
this.fluidTicks.tick(k, 65536, this::tickFluid);
2021-11-22 09:00:00 +11:00
gameprofilerfiller.pop();
2021-03-16 09:00:00 +11:00
}
+ timings.doTickPending.stopTiming(); // Spigot
2021-11-22 09:00:00 +11:00
gameprofilerfiller.popPush("raid");
2023-12-06 03:40:00 +11:00
if (flag) {
2025-04-13 10:28:23 +10:00
@@ -400,7 +403,9 @@ public class WorldServer extends World implements ServerEntityGetter, GeneratorA
2022-03-01 02:00:00 +11:00
this.getChunkSource().tick(booleansupplier, true);
2021-11-22 09:00:00 +11:00
gameprofilerfiller.popPush("blockEvents");
2023-12-06 03:40:00 +11:00
if (flag) {
+ timings.doSounds.startTiming(); // Spigot
this.runBlockEvents();
+ timings.doSounds.stopTiming(); // Spigot
}
2021-06-11 15:00:00 +10:00
this.handlingTick = false;
2025-04-13 10:28:23 +10:00
@@ -413,12 +418,14 @@ public class WorldServer extends World implements ServerEntityGetter, GeneratorA
2018-07-15 10:00:00 +10:00
2023-12-06 03:40:00 +11:00
if (flag1 || this.emptyTime++ < 300) {
2021-11-22 09:00:00 +11:00
gameprofilerfiller.push("entities");
2021-03-16 09:00:00 +11:00
+ timings.tickEntities.startTiming(); // Spigot
2023-12-06 03:40:00 +11:00
if (this.dragonFight != null && flag) {
2021-11-22 09:00:00 +11:00
gameprofilerfiller.push("dragonFight");
this.dragonFight.tick();
gameprofilerfiller.pop();
2021-03-16 09:00:00 +11:00
}
2021-03-16 09:00:00 +11:00
+ timings.entityTick.startTiming(); // Spigot
2021-11-22 09:00:00 +11:00
this.entityTickList.forEach((entity) -> {
2021-06-11 15:00:00 +10:00
if (!entity.isRemoved()) {
2024-10-23 02:15:00 +11:00
if (!tickratemanager.isEntityFrozen(entity)) {
2025-04-13 10:28:23 +10:00
@@ -443,6 +450,8 @@ public class WorldServer extends World implements ServerEntityGetter, GeneratorA
2021-06-11 15:00:00 +10:00
}
}
});
2021-03-16 09:00:00 +11:00
+ timings.entityTick.stopTiming(); // Spigot
+ timings.tickEntities.stopTiming(); // Spigot
2021-11-22 09:00:00 +11:00
gameprofilerfiller.pop();
2021-03-16 09:00:00 +11:00
this.tickBlockEntities();
}
2025-04-13 10:28:23 +10:00
@@ -849,6 +858,7 @@ public class WorldServer extends World implements ServerEntityGetter, GeneratorA
2021-06-11 15:00:00 +10:00
}
2021-11-22 09:00:00 +11:00
public void tickNonPassenger(Entity entity) {
2021-06-11 15:00:00 +10:00
+ entity.tickTimer.startTiming(); // Spigot
2021-11-22 09:00:00 +11:00
entity.setOldPosAndRot();
2024-10-23 02:15:00 +11:00
GameProfilerFiller gameprofilerfiller = Profiler.get();
2021-06-11 15:00:00 +10:00
2025-04-13 10:28:23 +10:00
@@ -864,6 +874,7 @@ public class WorldServer extends World implements ServerEntityGetter, GeneratorA
2025-03-26 03:05:00 +11:00
for (Entity entity1 : entity.getPassengers()) {
2021-11-22 09:00:00 +11:00
this.tickPassenger(entity, entity1);
2021-03-16 09:00:00 +11:00
}
2021-06-11 15:00:00 +10:00
+ entity.tickTimer.stopTiming(); // Spigot
}
2021-06-11 15:00:00 +10:00
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/server/network/PlayerConnection.java b/src/main/java/net/minecraft/server/network/PlayerConnection.java
index 6ba2871eb..0819474b6 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/server/network/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/network/PlayerConnection.java
2025-03-26 03:05:00 +11:00
@@ -353,6 +353,7 @@ public class PlayerConnection extends ServerCommonPacketListenerImpl implements
2022-07-28 04:00:00 +10:00
@Override
2021-03-16 09:00:00 +11:00
public void tick() {
+ org.bukkit.craftbukkit.SpigotTimings.playerConnectionTimer.startTiming(); // Spigot
2022-06-08 02:00:00 +10:00
if (this.ackBlockChangesUpTo > -1) {
this.send(new ClientboundBlockChangedAckPacket(this.ackBlockChangesUpTo));
this.ackBlockChangesUpTo = -1;
2025-03-26 03:05:00 +11:00
@@ -408,6 +409,7 @@ public class PlayerConnection extends ServerCommonPacketListenerImpl implements
2021-11-22 09:00:00 +11:00
this.player.resetLastActionTime(); // CraftBukkit - SPIGOT-854
2024-06-14 01:05:00 +10:00
this.disconnect((IChatBaseComponent) IChatBaseComponent.translatable("multiplayer.disconnect.idling"));
}
2021-03-16 09:00:00 +11:00
+ org.bukkit.craftbukkit.SpigotTimings.playerConnectionTimer.stopTiming(); // Spigot
2022-06-08 02:00:00 +10:00
}
2022-12-08 03:00:00 +11:00
2025-03-26 03:05:00 +11:00
@@ -2251,6 +2253,7 @@ public class PlayerConnection extends ServerCommonPacketListenerImpl implements
}
2021-03-16 09:00:00 +11:00
private void handleCommand(String s) {
+ org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.startTiming(); // Spigot
2021-11-22 09:00:00 +11:00
this.LOGGER.info(this.player.getScoreboardName() + " issued server command: " + s);
2021-03-16 09:00:00 +11:00
2022-06-08 02:00:00 +10:00
CraftPlayer player = this.getCraftPlayer();
2025-03-26 03:05:00 +11:00
@@ -2259,6 +2262,7 @@ public class PlayerConnection extends ServerCommonPacketListenerImpl implements
2021-06-11 15:00:00 +10:00
this.cserver.getPluginManager().callEvent(event);
2021-03-16 09:00:00 +11:00
if (event.isCancelled()) {
+ org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.stopTiming(); // Spigot
return;
}
2025-03-26 03:05:00 +11:00
@@ -2270,6 +2274,8 @@ public class PlayerConnection extends ServerCommonPacketListenerImpl implements
2021-03-16 09:00:00 +11:00
player.sendMessage(org.bukkit.ChatColor.RED + "An internal error occurred while attempting to perform this command");
java.util.logging.Logger.getLogger(PlayerConnection.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
return;
+ } finally {
+ org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.stopTiming(); // Spigot
}
2022-06-08 02:00:00 +10:00
}
// CraftBukkit end
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 26d92a2ef..111869fce 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
2025-03-26 03:05:00 +11:00
@@ -156,6 +156,7 @@ import org.bukkit.command.CommandSender;
2016-03-01 08:33:06 +11:00
import org.bukkit.entity.Hanging;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Vehicle;
2013-06-02 11:29:44 +10:00
+import org.spigotmc.CustomTimingsHandler; // Spigot
import org.bukkit.event.entity.EntityCombustByEntityEvent;
2014-04-18 17:08:19 +00:00
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
2016-03-01 08:33:06 +11:00
import org.bukkit.event.vehicle.VehicleBlockCollisionEvent;
2025-03-26 03:05:00 +11:00
@@ -337,6 +338,7 @@ public abstract class Entity implements SyncedDataHolder, INamableTileEntity, En
2023-12-01 08:04:04 +11:00
// Marks an entity, that it was removed by a plugin via Entity#remove
// Main use case currently is for SPIGOT-7487, preventing dropping of leash when leash is removed
public boolean pluginRemoved = false;
+ public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getEntityTimings(this); // Spigot
2016-03-01 08:33:06 +11:00
2017-11-07 17:30:57 +11:00
public float getBukkitYaw() {
2021-06-11 15:00:00 +10:00
return this.yRot;
2025-03-26 03:05:00 +11:00
@@ -865,6 +867,7 @@ public abstract class Entity implements SyncedDataHolder, INamableTileEntity, En
}
2019-04-23 12:00:00 +10:00
public void move(EnumMoveType enummovetype, Vec3D vec3d) {
+ org.bukkit.craftbukkit.SpigotTimings.entityMoveTimer.startTiming(); // Spigot
2021-06-11 15:00:00 +10:00
if (this.noPhysics) {
2021-11-22 09:00:00 +11:00
this.setPos(this.getX() + vec3d.x, this.getY() + vec3d.y, this.getZ() + vec3d.z);
2021-06-11 15:00:00 +10:00
} else {
2025-03-26 03:05:00 +11:00
@@ -993,6 +996,7 @@ public abstract class Entity implements SyncedDataHolder, INamableTileEntity, En
2024-10-23 02:15:00 +11:00
gameprofilerfiller.pop();
2021-06-11 15:00:00 +10:00
}
}
+ org.bukkit.craftbukkit.SpigotTimings.entityMoveTimer.stopTiming(); // Spigot
}
2024-10-23 02:15:00 +11:00
private void applyMovementEmissionAndPlaySound(Entity.MovementEmission entity_movementemission, Vec3D vec3d, BlockPosition blockposition, IBlockData iblockdata) {
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/world/entity/EntityLiving.java b/src/main/java/net/minecraft/world/entity/EntityLiving.java
2025-04-13 10:28:23 +10:00
index d2d6de827..325d5dae8 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/world/entity/EntityLiving.java
+++ b/src/main/java/net/minecraft/world/entity/EntityLiving.java
2025-03-26 03:05:00 +11:00
@@ -164,6 +164,8 @@ import org.bukkit.event.player.PlayerDropItemEvent;
2016-03-01 08:33:06 +11:00
import org.bukkit.event.player.PlayerItemConsumeEvent;
// CraftBukkit end
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
+
2023-03-15 03:30:00 +11:00
public abstract class EntityLiving extends Entity implements Attackable {
2022-03-01 02:00:00 +11:00
private static final Logger LOGGER = LogUtils.getLogger();
2025-03-26 03:05:00 +11:00
@@ -3166,6 +3168,7 @@ public abstract class EntityLiving extends Entity implements Attackable {
2019-04-23 12:00:00 +10:00
@Override
2018-07-15 10:00:00 +10:00
public void tick() {
+ SpigotTimings.timerEntityBaseTick.startTiming(); // Spigot
2018-07-15 10:00:00 +10:00
super.tick();
2021-11-22 09:00:00 +11:00
this.updatingUsingItem();
this.updateSwimAmount();
2025-03-26 03:05:00 +11:00
@@ -3207,7 +3210,9 @@ public abstract class EntityLiving extends Entity implements Attackable {
2022-07-28 04:00:00 +10:00
}
if (!this.isRemoved()) {
+ SpigotTimings.timerEntityBaseTick.stopTiming(); // Spigot
this.aiStep();
+ SpigotTimings.timerEntityTickRest.startTiming(); // Spigot
}
2021-11-22 09:00:00 +11:00
double d0 = this.getX() - this.xo;
2025-03-26 03:05:00 +11:00
@@ -3282,6 +3287,7 @@ public abstract class EntityLiving extends Entity implements Attackable {
2025-03-26 03:05:00 +11:00
this.refreshDirtyAttributes();
2024-10-23 02:15:00 +11:00
this.elytraAnimationState.tick();
+ SpigotTimings.timerEntityTickRest.stopTiming(); // Spigot
}
2023-09-25 08:07:32 +10:00
public void detectEquipmentUpdatesPublic() { // CraftBukkit
2025-03-26 03:05:00 +11:00
@@ -3439,6 +3445,7 @@ public abstract class EntityLiving extends Entity implements Attackable {
2024-10-23 02:15:00 +11:00
GameProfilerFiller gameprofilerfiller = Profiler.get();
2024-10-23 02:15:00 +11:00
gameprofilerfiller.push("ai");
+ SpigotTimings.timerEntityAI.startTiming(); // Spigot
2025-03-26 03:05:00 +11:00
this.applyInput();
2021-11-22 09:00:00 +11:00
if (this.isImmobile()) {
2019-04-23 12:00:00 +10:00
this.jumping = false;
2025-03-26 03:05:00 +11:00
@@ -3449,6 +3456,7 @@ public abstract class EntityLiving extends Entity implements Attackable {
2021-11-22 09:00:00 +11:00
this.serverAiStep();
2024-10-23 02:15:00 +11:00
gameprofilerfiller.pop();
}
+ SpigotTimings.timerEntityAI.stopTiming(); // Spigot
2024-10-23 02:15:00 +11:00
gameprofilerfiller.pop();
gameprofilerfiller.push("jump");
@@ -3493,6 +3501,7 @@ public abstract class EntityLiving extends Entity implements Attackable {
2023-06-08 01:30:00 +10:00
this.resetFallDistance();
}
2018-07-15 10:00:00 +10:00
+ SpigotTimings.timerEntityAIMove.startTiming(); // Spigot
2025-03-26 03:05:00 +11:00
label122:
2023-06-08 01:30:00 +10:00
{
EntityLiving entityliving = this.getControllingPassenger();
@@ -3508,6 +3517,7 @@ public abstract class EntityLiving extends Entity implements Attackable {
2025-03-26 03:05:00 +11:00
this.travel(vec3d1);
}
2023-03-15 03:30:00 +11:00
}
+ SpigotTimings.timerEntityAIMove.stopTiming(); // Spigot
2023-03-15 03:30:00 +11:00
2025-03-26 03:05:00 +11:00
if (!this.level().isClientSide() || this.isLocalInstanceAuthoritative()) {
2024-10-23 02:15:00 +11:00
this.applyEffectsFromBlocks();
@@ -3541,7 +3551,9 @@ public abstract class EntityLiving extends Entity implements Attackable {
2021-11-22 09:00:00 +11:00
this.checkAutoSpinAttack(axisalignedbb, this.getBoundingBox());
2018-07-15 10:00:00 +10:00
}
2016-03-01 08:33:06 +11:00
+ SpigotTimings.timerEntityAICollision.startTiming(); // Spigot
2021-11-22 09:00:00 +11:00
this.pushEntities();
2016-03-01 08:33:06 +11:00
+ SpigotTimings.timerEntityAICollision.stopTiming(); // Spigot
2024-10-23 02:15:00 +11:00
gameprofilerfiller.pop();
world = this.level();
2025-03-26 03:05:00 +11:00
if (world instanceof WorldServer worldserver1) {
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/world/level/SpawnerCreature.java b/src/main/java/net/minecraft/world/level/SpawnerCreature.java
2025-03-26 03:05:00 +11:00
index 1dc65bcb3..d93940fb5 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/world/level/SpawnerCreature.java
+++ b/src/main/java/net/minecraft/world/level/SpawnerCreature.java
2025-03-26 03:05:00 +11:00
@@ -144,6 +144,7 @@ public final class SpawnerCreature {
2024-10-23 02:15:00 +11:00
GameProfilerFiller gameprofilerfiller = Profiler.get();
2020-06-25 10:00:00 +10:00
2024-10-23 02:15:00 +11:00
gameprofilerfiller.push("spawner");
2020-06-25 10:00:00 +10:00
+ worldserver.timings.mobSpawn.startTiming(); // Spigot
2025-03-26 03:05:00 +11:00
for (EnumCreatureType enumcreaturetype : list) {
if (spawnercreature_d.canSpawnForCategoryLocal(enumcreaturetype, chunk.getPos())) {
@@ -155,6 +156,7 @@ public final class SpawnerCreature {
2020-06-25 10:00:00 +10:00
}
}
+ worldserver.timings.mobSpawn.stopTiming(); // Spigot
2024-10-23 02:15:00 +11:00
gameprofilerfiller.pop();
2020-06-25 10:00:00 +10:00
}
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/world/level/World.java b/src/main/java/net/minecraft/world/level/World.java
2025-04-13 10:28:23 +10:00
index 17231dbab..1367de17b 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/world/level/World.java
+++ b/src/main/java/net/minecraft/world/level/World.java
2025-03-26 03:05:00 +11:00
@@ -100,6 +100,7 @@ import net.minecraft.world.level.dimension.WorldDimension;
2024-04-24 01:15:00 +10:00
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.CraftServer;
2014-02-12 13:48:26 +00:00
import org.bukkit.craftbukkit.CraftWorld;
2021-06-11 15:00:00 +10:00
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
2020-01-28 09:50:23 +11:00
import org.bukkit.craftbukkit.block.CapturedBlockState;
2021-06-11 15:00:00 +10:00
import org.bukkit.craftbukkit.block.data.CraftBlockData;
2022-02-07 18:54:42 +11:00
import org.bukkit.craftbukkit.util.CraftSpawnCategory;
2025-03-26 03:05:00 +11:00
@@ -162,6 +163,8 @@ public abstract class World implements GeneratorAccess, UUIDLookup<Entity>, Auto
2019-04-23 12:00:00 +10:00
public boolean populating;
2013-06-20 18:52:23 +10:00
public final org.spigotmc.SpigotWorldConfig spigotConfig; // Spigot
+ public final SpigotTimings.WorldTimingsHandler timings; // Spigot
+
public CraftWorld getWorld() {
return this.world;
}
2025-03-26 03:05:00 +11:00
@@ -249,6 +252,7 @@ public abstract class World implements GeneratorAccess, UUIDLookup<Entity>, Auto
2021-11-22 09:00:00 +11:00
public void onBorderSetDamageSafeZOne(WorldBorder worldborder, double d0) {}
2016-03-06 14:36:33 +11:00
});
2016-03-01 11:23:45 +11:00
// CraftBukkit end
2016-03-01 08:33:06 +11:00
+ timings = new SpigotTimings.WorldTimingsHandler(this); // Spigot - code below can generate new world and access timings
}
2019-04-23 12:00:00 +10:00
@Override
2025-03-26 03:05:00 +11:00
@@ -630,12 +634,15 @@ public abstract class World implements GeneratorAccess, UUIDLookup<Entity>, Auto
2024-10-23 02:15:00 +11:00
GameProfilerFiller gameprofilerfiller = Profiler.get();
2021-11-22 09:00:00 +11:00
gameprofilerfiller.push("blockEntities");
2021-06-11 15:00:00 +10:00
+ timings.tileEntityPending.startTiming(); // Spigot
this.tickingBlockEntities = true;
if (!this.pendingBlockEntityTickers.isEmpty()) {
this.blockEntityTickers.addAll(this.pendingBlockEntityTickers);
this.pendingBlockEntityTickers.clear();
}
+ timings.tileEntityPending.stopTiming(); // Spigot
2016-06-15 13:24:40 +10:00
+ timings.tileEntityTick.startTiming(); // Spigot
2023-12-06 03:40:00 +11:00
Iterator<TickingBlockEntity> iterator = this.blockEntityTickers.iterator();
boolean flag = this.tickRateManager().runsNormally();
2021-06-11 15:00:00 +10:00
2025-03-26 03:05:00 +11:00
@@ -649,13 +656,16 @@ public abstract class World implements GeneratorAccess, UUIDLookup<Entity>, Auto
}
}
+ timings.tileEntityTick.stopTiming(); // Spigot
2021-06-11 15:00:00 +10:00
this.tickingBlockEntities = false;
2021-11-22 09:00:00 +11:00
gameprofilerfiller.pop();
}
2017-05-19 21:00:22 +10:00
2021-11-22 09:00:00 +11:00
public <T extends Entity> void guardEntityTick(Consumer<T> consumer, T t0) {
2019-04-23 12:00:00 +10:00
try {
+ SpigotTimings.tickEntityTimer.startTiming(); // Spigot
2021-06-11 15:00:00 +10:00
consumer.accept(t0);
+ SpigotTimings.tickEntityTimer.stopTiming(); // Spigot
2019-04-23 12:00:00 +10:00
} catch (Throwable throwable) {
2021-11-22 09:00:00 +11:00
CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking entity");
CrashReportSystemDetails crashreportsystemdetails = crashreport.addCategory("Entity being ticked");
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/world/level/block/entity/TileEntity.java b/src/main/java/net/minecraft/world/level/block/entity/TileEntity.java
2025-03-26 03:05:00 +11:00
index 41fb22584..0884a055c 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/world/level/block/entity/TileEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/TileEntity.java
2025-03-26 03:05:00 +11:00
@@ -39,8 +39,11 @@ import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry;
2021-03-16 09:00:00 +11:00
import org.bukkit.inventory.InventoryHolder;
// CraftBukkit end
2019-04-23 12:00:00 +10:00
2021-03-16 09:00:00 +11:00
+import org.spigotmc.CustomTimingsHandler; // Spigot
+
public abstract class TileEntity {
2019-04-23 12:00:00 +10:00
2021-03-16 09:00:00 +11:00
+ public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getTileEntityTimings(this); // Spigot
// CraftBukkit start - data containers
private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry();
public CraftPersistentDataContainer persistentDataContainer;
2021-06-11 15:00:00 +10:00
diff --git a/src/main/java/net/minecraft/world/level/chunk/Chunk.java b/src/main/java/net/minecraft/world/level/chunk/Chunk.java
2025-03-26 03:05:00 +11:00
index b8cfd5254..3eb64195a 100644
2021-06-11 15:00:00 +10:00
--- a/src/main/java/net/minecraft/world/level/chunk/Chunk.java
+++ b/src/main/java/net/minecraft/world/level/chunk/Chunk.java
2025-03-26 03:05:00 +11:00
@@ -865,6 +865,7 @@ public class Chunk extends IChunkAccess {
2024-10-23 02:15:00 +11:00
GameProfilerFiller gameprofilerfiller = Profiler.get();
2021-06-11 15:00:00 +10:00
2021-11-22 09:00:00 +11:00
gameprofilerfiller.push(this::getType);
2021-06-11 15:00:00 +10:00
+ this.blockEntity.tickTimer.startTiming(); // Spigot
2021-11-22 09:00:00 +11:00
IBlockData iblockdata = Chunk.this.getBlockState(blockposition);
2021-06-11 15:00:00 +10:00
2021-11-22 09:00:00 +11:00
if (this.blockEntity.getType().isValid(iblockdata)) {
2025-03-26 03:05:00 +11:00
@@ -882,6 +883,10 @@ public class Chunk extends IChunkAccess {
2021-06-11 15:00:00 +10:00
2021-11-22 09:00:00 +11:00
this.blockEntity.fillCrashReportCategory(crashreportsystemdetails);
2021-06-11 15:00:00 +10:00
throw new ReportedException(crashreport);
+ // Spigot start
+ } finally {
+ this.blockEntity.tickTimer.stopTiming();
+ // Spigot end
}
}
}
2024-10-23 02:15:00 +11:00
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/SerializableChunkData.java b/src/main/java/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
2025-03-26 03:05:00 +11:00
index dd631503a..d8d87cf5e 100644
2024-10-23 02:15:00 +11:00
--- a/src/main/java/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
2025-03-26 03:05:00 +11:00
@@ -479,10 +479,13 @@ public record SerializableChunkData(IRegistry<BiomeBase> biomeRegistry, ChunkCoo
2024-10-23 02:15:00 +11:00
@Nullable
private static Chunk.c postLoadChunk(WorldServer worldserver, List<NBTTagCompound> list, List<NBTTagCompound> list1) {
return list.isEmpty() && list1.isEmpty() ? null : (chunk) -> {
2021-11-22 09:00:00 +11:00
+ worldserver.timings.syncChunkLoadEntitiesTimer.startTiming(); // Spigot
2024-10-23 02:15:00 +11:00
if (!list.isEmpty()) {
worldserver.addLegacyChunkEntities(EntityTypes.loadEntitiesRecursive(list, worldserver, EntitySpawnReason.LOAD));
2021-11-22 09:00:00 +11:00
}
+ worldserver.timings.syncChunkLoadEntitiesTimer.stopTiming(); // Spigot
2021-03-16 09:00:00 +11:00
2021-11-22 09:00:00 +11:00
+ worldserver.timings.syncChunkLoadTileEntitiesTimer.startTiming(); // Spigot
2025-03-26 03:05:00 +11:00
for (NBTTagCompound nbttagcompound : list1) {
boolean flag = nbttagcompound.getBooleanOr("keepPacked", false);
@@ -497,6 +500,7 @@ public record SerializableChunkData(IRegistry<BiomeBase> biomeRegistry, ChunkCoo
2021-11-22 09:00:00 +11:00
}
}
}
2021-11-22 09:00:00 +11:00
+ worldserver.timings.syncChunkLoadTileEntitiesTimer.stopTiming(); // Spigot
2021-03-16 09:00:00 +11:00
2021-11-29 09:47:45 +11:00
};
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2025-03-26 03:05:00 +11:00
index d002ad986..c89785454 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -2574,6 +2574,11 @@ public final class CraftServer implements Server {
2021-03-09 08:47:45 +11:00
private final org.bukkit.Server.Spigot spigot = new org.bukkit.Server.Spigot()
{
+ @Override
+ public YamlConfiguration getConfig()
+ {
+ return org.spigotmc.SpigotConfig.config;
+ }
};
2021-03-09 08:47:45 +11:00
public org.bukkit.Server.Spigot spigot()
diff --git a/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java b/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java
new file mode 100644
index 000000000..aff7b6b43
--- /dev/null
+++ b/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java
2020-06-25 10:00:00 +10:00
@@ -0,0 +1,160 @@
+package org.bukkit.craftbukkit;
+
+import java.util.HashMap;
2021-03-16 09:00:00 +11:00
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.level.World;
+import net.minecraft.world.level.block.entity.TileEntity;
+import net.minecraft.world.level.storage.WorldDataServer;
+import org.bukkit.craftbukkit.scheduler.CraftTask;
2019-04-23 15:12:43 +10:00
+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");
2017-05-14 12:00:00 +10:00
+ public static final CustomTimingsHandler commandFunctionsTimer = new CustomTimingsHandler("Command Functions");
+ public static final CustomTimingsHandler connectionTimer = new CustomTimingsHandler("Connection Handler");
2018-10-27 17:44:13 +11:00
+ 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 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) {
2021-01-31 10:08:46 +11:00
+ name += "(interval:" + period + ")";
+ } else {
+ name += "(Single)";
+ }
+ CustomTimingsHandler result = pluginTaskTimingMap.get(name);
+ if (result == null) {
+ result = new CustomTimingsHandler(name, SpigotTimings.schedulerSyncTimer);
+ pluginTaskTimingMap.put(name, result);
+ }
+ return result;
+ }
+
+ /**
+ * Get a named timer for the specified entity type to track type specific timings.
+ * @param entity
+ * @return
+ */
+ public static CustomTimingsHandler getEntityTimings(Entity entity) {
+ String entityType = entity.getClass().getName();
+ CustomTimingsHandler result = entityTypeTimingMap.get(entityType);
+ if (result == null) {
+ result = new CustomTimingsHandler("** tickEntity - " + entity.getClass().getSimpleName(), activatedEntityTimer);
+ entityTypeTimingMap.put(entityType, result);
+ }
+ return result;
+ }
+
+ /**
+ * Get a named timer for the specified tile entity type to track type specific timings.
+ * @param entity
+ * @return
+ */
+ public static CustomTimingsHandler getTileEntityTimings(TileEntity entity) {
+ String entityType = entity.getClass().getName();
+ CustomTimingsHandler result = tileEntityTypeTimingMap.get(entityType);
+ if (result == null) {
+ result = new CustomTimingsHandler("** tickTileEntity - " + entity.getClass().getSimpleName(), tickTileEntityTimer);
+ tileEntityTypeTimingMap.put(entityType, result);
+ }
+ return result;
+ }
+
+ /**
+ * Set of timers per world, to track world specific timings.
+ */
+ public static class WorldTimingsHandler {
+ public final CustomTimingsHandler mobSpawn;
+ public final CustomTimingsHandler doChunkUnload;
+ public final CustomTimingsHandler doTickPending;
+ public final CustomTimingsHandler doTickTiles;
+ public final CustomTimingsHandler doChunkMap;
+ public final CustomTimingsHandler doSounds;
+ public final CustomTimingsHandler entityTick;
+ public final CustomTimingsHandler tileEntityTick;
+ public final CustomTimingsHandler tileEntityPending;
+ public final CustomTimingsHandler tracker;
+ public final CustomTimingsHandler doTick;
+ public final CustomTimingsHandler tickEntities;
+
+ public final CustomTimingsHandler syncChunkLoadTimer;
+ public final CustomTimingsHandler syncChunkLoadStructuresTimer;
+ public final CustomTimingsHandler syncChunkLoadEntitiesTimer;
+ public final CustomTimingsHandler syncChunkLoadTileEntitiesTimer;
+ public final CustomTimingsHandler syncChunkLoadTileTicksTimer;
+ public final CustomTimingsHandler syncChunkLoadPostTimer;
+
+ public WorldTimingsHandler(World server) {
2021-11-22 09:00:00 +11:00
+ String name = ((WorldDataServer) server.levelData).getLevelName() + " - ";
+
+ mobSpawn = new CustomTimingsHandler("** " + name + "mobSpawn");
+ doChunkUnload = new CustomTimingsHandler("** " + name + "doChunkUnload");
+ doTickPending = new CustomTimingsHandler("** " + name + "doTickPending");
+ doTickTiles = new CustomTimingsHandler("** " + name + "doTickTiles");
+ doChunkMap = new CustomTimingsHandler("** " + name + "doChunkMap");
+ doSounds = new CustomTimingsHandler("** " + name + "doSounds");
+ entityTick = new CustomTimingsHandler("** " + name + "entityTick");
+ tileEntityTick = new CustomTimingsHandler("** " + name + "tileEntityTick");
+ tileEntityPending = new CustomTimingsHandler("** " + name + "tileEntityPending");
+
+ syncChunkLoadTimer = new CustomTimingsHandler("** " + name + "syncChunkLoad");
+ syncChunkLoadStructuresTimer = new CustomTimingsHandler("** " + name + "chunkLoad - Structures");
+ syncChunkLoadEntitiesTimer = new CustomTimingsHandler("** " + name + "chunkLoad - Entities");
+ syncChunkLoadTileEntitiesTimer = new CustomTimingsHandler("** " + name + "chunkLoad - TileEntities");
+ syncChunkLoadTileTicksTimer = new CustomTimingsHandler("** " + name + "chunkLoad - TileTicks");
+ syncChunkLoadPostTimer = new CustomTimingsHandler("** " + name + "chunkLoad - Post");
+
+
+ tracker = new CustomTimingsHandler(name + "tracker");
+ doTick = new CustomTimingsHandler(name + "doTick");
+ tickEntities = new CustomTimingsHandler(name + "tickEntities");
+ }
+ }
+}
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
index 83c8e0715..323d57e01 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
2021-07-18 16:36:04 +10:00
@@ -411,7 +411,9 @@ public class CraftScheduler implements BukkitScheduler {
if (task.isSync()) {
2018-06-20 13:18:48 +10:00
currentTask = task;
try {
+ task.timings.startTiming(); // Spigot
task.run();
+ task.timings.stopTiming(); // Spigot
} catch (final Throwable throwable) {
task.getOwner().getLogger().log(
Level.WARNING,
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java
index c885bc744..70794669f 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java
2021-03-09 08:47:45 +11:00
@@ -5,7 +5,10 @@ import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitTask;
-class CraftTask implements BukkitTask, Runnable {
2021-03-09 08:47:45 +11:00
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
+import org.spigotmc.CustomTimingsHandler; // Spigot
+
+public class CraftTask implements BukkitTask, Runnable { // Spigot
private volatile CraftTask next = null;
public static final int ERROR = 0;
2021-07-18 16:36:04 +10:00
@@ -29,6 +32,7 @@ class CraftTask implements BukkitTask, Runnable {
private final int id;
2021-07-18 16:36:04 +10:00
private final long createdAt = System.nanoTime();
+ final CustomTimingsHandler timings; // Spigot
CraftTask() {
this(null, null, CraftTask.NO_REPEATING, CraftTask.NO_REPEATING);
}
2021-07-18 16:36:04 +10:00
@@ -54,6 +58,7 @@ class CraftTask implements BukkitTask, Runnable {
2018-11-23 12:11:41 +11:00
}
this.id = id;
this.period = period;
2018-11-23 12:11:41 +11:00
+ this.timings = this.isSync() ? SpigotTimings.getPluginTaskTimings(this, period) : null; // Spigot
}
2018-11-23 12:11:41 +11:00
@Override
2021-07-18 16:36:04 +10:00
@@ -131,4 +136,10 @@ class CraftTask implements BukkitTask, Runnable {
setPeriod(CraftTask.CANCEL);
return true;
}
+
+ // Spigot start
+ public String getTaskName() {
2018-11-23 14:22:14 +11:00
+ return (getTaskClass() == null) ? "Unknown" : getTaskClass().getName();
+ }
+ // Spigot end
}
--
2025-03-26 03:05:00 +11:00
2.49.0