mirror of
https://hub.spigotmc.org/stash/scm/spigot/spigot.git
synced 2025-09-18 21:33:01 +00:00
828 lines
39 KiB
Diff
828 lines
39 KiB
Diff
From fbc8035627189c73975915326ddfa93fcb199b0b Mon Sep 17 00:00:00 2001
|
|
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
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
index 984353897..289f95c00 100644
|
|
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
@@ -85,9 +85,11 @@ public class ChunkProviderServer extends IChunkProvider {
|
|
}
|
|
}
|
|
|
|
+ world.timings.syncChunkLoadTimer.startTiming(); // Spigot
|
|
CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> completablefuture = this.getChunkFutureMainThread(i, j, chunkstatus, flag);
|
|
|
|
this.serverThreadQueue.awaitTasks(completablefuture::isDone);
|
|
+ world.timings.syncChunkLoadTimer.stopTiming(); // Spigot
|
|
ichunkaccess = (IChunkAccess) ((Either) completablefuture.join()).map((ichunkaccess1) -> {
|
|
return ichunkaccess1;
|
|
}, (playerchunk_failure) -> {
|
|
@@ -271,12 +273,16 @@ public class ChunkProviderServer extends IChunkProvider {
|
|
|
|
public void tick(BooleanSupplier booleansupplier) {
|
|
this.world.getMethodProfiler().enter("purge");
|
|
+ this.world.timings.doChunkMap.startTiming(); // Spigot
|
|
this.chunkMapDistance.purgeTickets();
|
|
this.tickDistanceManager();
|
|
+ this.world.timings.doChunkMap.stopTiming(); // Spigot
|
|
this.world.getMethodProfiler().exitEnter("chunks");
|
|
this.tickChunks();
|
|
+ this.world.timings.doChunkUnload.startTiming(); // Spigot
|
|
this.world.getMethodProfiler().exitEnter("unload");
|
|
this.playerChunkMap.unloadChunks(booleansupplier);
|
|
+ this.world.timings.doChunkUnload.stopTiming(); // Spigot
|
|
this.world.getMethodProfiler().exit();
|
|
this.clearCache();
|
|
}
|
|
@@ -317,6 +323,7 @@ public class ChunkProviderServer extends IChunkProvider {
|
|
chunk.b(chunk.q() + j);
|
|
if (flag1 && (this.allowMonsters || this.allowAnimals) && this.world.getWorldBorder().isInBounds(chunk.getPos())) {
|
|
this.world.getMethodProfiler().enter("spawner");
|
|
+ this.world.timings.mobSpawn.startTiming(); // Spigot
|
|
EnumCreatureType[] aenumcreaturetype1 = aenumcreaturetype;
|
|
int i1 = aenumcreaturetype.length;
|
|
|
|
@@ -354,10 +361,13 @@ public class ChunkProviderServer extends IChunkProvider {
|
|
}
|
|
}
|
|
|
|
+ this.world.timings.mobSpawn.stopTiming(); // Spigot
|
|
this.world.getMethodProfiler().exit();
|
|
}
|
|
|
|
+ this.world.timings.doTickTiles.startTiming(); // Spigot
|
|
this.world.a(chunk, k);
|
|
+ this.world.timings.doTickTiles.stopTiming(); // Spigot
|
|
}
|
|
}
|
|
});
|
|
@@ -370,7 +380,9 @@ public class ChunkProviderServer extends IChunkProvider {
|
|
this.world.getMethodProfiler().exit();
|
|
}
|
|
|
|
+ this.world.timings.tracker.startTiming(); // Spigot
|
|
this.playerChunkMap.g();
|
|
+ this.world.timings.tracker.stopTiming(); // Spigot
|
|
}
|
|
|
|
@Override
|
|
diff --git a/src/main/java/net/minecraft/server/ChunkRegionLoader.java b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
|
|
index 7814efa60..1894509df 100644
|
|
--- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java
|
|
+++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
|
|
@@ -407,6 +407,7 @@ public class ChunkRegionLoader {
|
|
private static void loadEntities(NBTTagCompound nbttagcompound, Chunk chunk) {
|
|
NBTTagList nbttaglist = nbttagcompound.getList("Entities", 10);
|
|
World world = chunk.getWorld();
|
|
+ world.timings.syncChunkLoadEntitiesTimer.startTiming(); // Spigot
|
|
|
|
for (int i = 0; i < nbttaglist.size(); ++i) {
|
|
NBTTagCompound nbttagcompound1 = nbttaglist.getCompound(i);
|
|
@@ -418,6 +419,8 @@ public class ChunkRegionLoader {
|
|
chunk.d(true);
|
|
}
|
|
|
|
+ world.timings.syncChunkLoadEntitiesTimer.stopTiming(); // Spigot
|
|
+ world.timings.syncChunkLoadTileEntitiesTimer.startTiming(); // Spigot
|
|
NBTTagList nbttaglist1 = nbttagcompound.getList("TileEntities", 10);
|
|
|
|
for (int j = 0; j < nbttaglist1.size(); ++j) {
|
|
@@ -434,6 +437,7 @@ public class ChunkRegionLoader {
|
|
}
|
|
}
|
|
}
|
|
+ world.timings.syncChunkLoadTileEntitiesTimer.stopTiming(); // Spigot
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java
|
|
index bc7c4e0ad..7b9586ed0 100644
|
|
--- a/src/main/java/net/minecraft/server/DedicatedServer.java
|
|
+++ b/src/main/java/net/minecraft/server/DedicatedServer.java
|
|
@@ -31,6 +31,7 @@ import org.apache.logging.log4j.Level;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.craftbukkit.LoggerOutputStream;
|
|
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
|
|
import org.bukkit.event.server.ServerCommandEvent;
|
|
import org.bukkit.craftbukkit.util.Waitable;
|
|
import org.bukkit.event.server.RemoteServerCommandEvent;
|
|
@@ -398,6 +399,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
|
}
|
|
|
|
public void handleCommandQueue() {
|
|
+ SpigotTimings.serverCommandTimer.startTiming(); // Spigot
|
|
while (!this.serverCommandQueue.isEmpty()) {
|
|
ServerCommand servercommand = (ServerCommand) this.serverCommandQueue.remove(0);
|
|
|
|
@@ -412,6 +414,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
|
// CraftBukkit end
|
|
}
|
|
|
|
+ SpigotTimings.serverCommandTimer.stopTiming(); // Spigot
|
|
}
|
|
|
|
@Override
|
|
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
|
|
index 638c2feb9..47abdd250 100644
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
|
@@ -29,6 +29,7 @@ import org.bukkit.command.CommandSender;
|
|
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;
|
|
@@ -160,6 +161,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener {
|
|
public boolean valid;
|
|
public org.bukkit.projectiles.ProjectileSource projectileSource; // For projectiles only
|
|
public boolean forceExplosionKnockback; // SPIGOT-949
|
|
+ public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getEntityTimings(this); // Spigot
|
|
|
|
public float getBukkitYaw() {
|
|
return this.yaw;
|
|
@@ -481,6 +483,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener {
|
|
}
|
|
|
|
public void move(EnumMoveType enummovetype, Vec3D vec3d) {
|
|
+ org.bukkit.craftbukkit.SpigotTimings.entityMoveTimer.startTiming(); // Spigot
|
|
if (this.noclip) {
|
|
this.a(this.getBoundingBox().b(vec3d));
|
|
this.recalcPosition();
|
|
@@ -645,6 +648,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener {
|
|
|
|
this.world.getMethodProfiler().exit();
|
|
}
|
|
+ org.bukkit.craftbukkit.SpigotTimings.entityMoveTimer.stopTiming(); // Spigot
|
|
}
|
|
|
|
protected Vec3D a(Vec3D vec3d, EnumMoveType enummovetype) {
|
|
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
|
|
index d3b3bcea4..5caa8d93f 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityLiving.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
|
|
@@ -35,6 +35,8 @@ import org.bukkit.event.entity.EntityTeleportEvent;
|
|
import org.bukkit.event.player.PlayerItemConsumeEvent;
|
|
// CraftBukkit end
|
|
|
|
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
|
|
+
|
|
public abstract class EntityLiving extends Entity {
|
|
|
|
private static final UUID b = UUID.fromString("662A6B8D-DA3E-4C1C-8813-96EA6097278D");
|
|
@@ -2204,6 +2206,7 @@ public abstract class EntityLiving extends Entity {
|
|
|
|
@Override
|
|
public void tick() {
|
|
+ SpigotTimings.timerEntityBaseTick.startTiming(); // Spigot
|
|
super.tick();
|
|
this.dl();
|
|
this.o();
|
|
@@ -2278,7 +2281,9 @@ public abstract class EntityLiving extends Entity {
|
|
}
|
|
}
|
|
|
|
+ SpigotTimings.timerEntityBaseTick.stopTiming(); // Spigot
|
|
this.movementTick();
|
|
+ SpigotTimings.timerEntityTickRest.startTiming(); // Spigot
|
|
double d0 = this.locX - this.lastX;
|
|
double d1 = this.locZ - this.lastZ;
|
|
float f = (float) (d0 * d0 + d1 * d1);
|
|
@@ -2359,6 +2364,7 @@ public abstract class EntityLiving extends Entity {
|
|
this.pitch = 0.0F;
|
|
}
|
|
|
|
+ SpigotTimings.timerEntityTickRest.stopTiming(); // Spigot
|
|
}
|
|
|
|
protected float e(float f, float f1) {
|
|
@@ -2432,6 +2438,7 @@ public abstract class EntityLiving extends Entity {
|
|
|
|
this.setMot(d4, d5, d6);
|
|
this.world.getMethodProfiler().enter("ai");
|
|
+ SpigotTimings.timerEntityAI.startTiming(); // Spigot
|
|
if (this.isFrozen()) {
|
|
this.jumping = false;
|
|
this.bb = 0.0F;
|
|
@@ -2442,6 +2449,7 @@ public abstract class EntityLiving extends Entity {
|
|
this.doTick();
|
|
this.world.getMethodProfiler().exit();
|
|
}
|
|
+ SpigotTimings.timerEntityAI.stopTiming(); // Spigot
|
|
|
|
this.world.getMethodProfiler().exit();
|
|
this.world.getMethodProfiler().enter("jump");
|
|
@@ -2466,7 +2474,9 @@ public abstract class EntityLiving extends Entity {
|
|
this.n();
|
|
AxisAlignedBB axisalignedbb = this.getBoundingBox();
|
|
|
|
+ SpigotTimings.timerEntityAIMove.startTiming(); // Spigot
|
|
this.e(new Vec3D((double) this.bb, (double) this.bc, (double) this.bd));
|
|
+ SpigotTimings.timerEntityAIMove.stopTiming(); // Spigot
|
|
this.world.getMethodProfiler().exit();
|
|
this.world.getMethodProfiler().enter("push");
|
|
if (this.bq > 0) {
|
|
@@ -2474,7 +2484,9 @@ public abstract class EntityLiving extends Entity {
|
|
this.a(axisalignedbb, this.getBoundingBox());
|
|
}
|
|
|
|
+ SpigotTimings.timerEntityAICollision.startTiming(); // Spigot
|
|
this.collideNearby();
|
|
+ SpigotTimings.timerEntityAICollision.stopTiming(); // Spigot
|
|
this.world.getMethodProfiler().exit();
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index 38dde3fa6..e8c5c55f1 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -54,6 +54,7 @@ import org.bukkit.craftbukkit.CraftServer;
|
|
import org.bukkit.craftbukkit.Main;
|
|
import org.bukkit.event.server.ServerLoadEvent;
|
|
// CraftBukkit end
|
|
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
|
|
|
|
public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTask> implements IMojangStatistics, ICommandListener, AutoCloseable, Runnable {
|
|
|
|
@@ -909,6 +910,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
|
protected void exit() {}
|
|
|
|
protected void a(BooleanSupplier booleansupplier) {
|
|
+ SpigotTimings.serverTickTimer.startTiming(); // Spigot
|
|
long i = SystemUtils.getMonotonicNanos();
|
|
|
|
++this.ticks;
|
|
@@ -928,12 +930,14 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
|
}
|
|
|
|
if (autosavePeriod > 0 && this.ticks % autosavePeriod == 0) { // CraftBukkit
|
|
+ SpigotTimings.worldSaveTimer.startTiming(); // Spigot
|
|
MinecraftServer.LOGGER.debug("Autosave started");
|
|
this.methodProfiler.enter("save");
|
|
this.playerList.savePlayers();
|
|
this.saveChunks(true, false, false);
|
|
this.methodProfiler.exit();
|
|
MinecraftServer.LOGGER.debug("Autosave finished");
|
|
+ SpigotTimings.worldSaveTimer.stopTiming(); // Spigot
|
|
}
|
|
|
|
this.methodProfiler.enter("snooper");
|
|
@@ -954,21 +958,30 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
|
|
|
this.ao.a(i1 - i);
|
|
this.methodProfiler.exit();
|
|
+ SpigotTimings.serverTickTimer.stopTiming(); // Spigot
|
|
+ org.spigotmc.CustomTimingsHandler.tick(); // Spigot
|
|
}
|
|
|
|
protected void b(BooleanSupplier booleansupplier) {
|
|
+ SpigotTimings.schedulerTimer.startTiming(); // Spigot
|
|
this.server.getScheduler().mainThreadHeartbeat(this.ticks); // CraftBukkit
|
|
+ SpigotTimings.schedulerTimer.stopTiming(); // Spigot
|
|
this.methodProfiler.enter("commandFunctions");
|
|
+ SpigotTimings.commandFunctionsTimer.startTiming(); // Spigot
|
|
this.getFunctionData().tick();
|
|
+ SpigotTimings.commandFunctionsTimer.stopTiming(); // Spigot
|
|
this.methodProfiler.exitEnter("levels");
|
|
Iterator iterator = this.getWorlds().iterator();
|
|
|
|
// 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.
|
|
if (this.ticks % 20 == 0) {
|
|
for (int i = 0; i < this.getPlayerList().players.size(); ++i) {
|
|
@@ -976,6 +989,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
|
entityplayer.playerConnection.sendPacket(new PacketPlayOutUpdateTime(entityplayer.world.getTime(), entityplayer.getPlayerTime(), entityplayer.world.getGameRules().getBoolean(GameRules.DO_DAYLIGHT_CYCLE))); // Add support for per player time
|
|
}
|
|
}
|
|
+ SpigotTimings.timeUpdateTimer.stopTiming(); // Spigot
|
|
|
|
while (iterator.hasNext()) {
|
|
WorldServer worldserver = (WorldServer) iterator.next();
|
|
@@ -995,7 +1009,9 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
|
this.methodProfiler.enter("tick");
|
|
|
|
try {
|
|
+ worldserver.timings.doTick.startTiming(); // Spigot
|
|
worldserver.doTick(booleansupplier);
|
|
+ worldserver.timings.doTick.stopTiming(); // Spigot
|
|
} catch (Throwable throwable) {
|
|
CrashReport crashreport = CrashReport.a(throwable, "Exception ticking world");
|
|
|
|
@@ -1009,14 +1025,20 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
|
}
|
|
|
|
this.methodProfiler.exitEnter("connection");
|
|
+ SpigotTimings.connectionTimer.startTiming(); // Spigot
|
|
this.getServerConnection().c();
|
|
+ SpigotTimings.connectionTimer.stopTiming(); // Spigot
|
|
this.methodProfiler.exitEnter("players");
|
|
+ SpigotTimings.playerListTimer.startTiming(); // Spigot
|
|
this.playerList.tick();
|
|
+ SpigotTimings.playerListTimer.stopTiming(); // Spigot
|
|
this.methodProfiler.exitEnter("server gui refresh");
|
|
|
|
+ SpigotTimings.tickablesTimer.startTiming(); // Spigot
|
|
for (int i = 0; i < this.tickables.size(); ++i) {
|
|
((Runnable) this.tickables.get(i)).run();
|
|
}
|
|
+ SpigotTimings.tickablesTimer.stopTiming(); // Spigot
|
|
|
|
this.methodProfiler.exit();
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
index 7f2967a5f..a1ae37d22 100644
|
|
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
@@ -134,6 +134,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
// CraftBukkit end
|
|
|
|
public void tick() {
|
|
+ org.bukkit.craftbukkit.SpigotTimings.playerConnectionTimer.startTiming(); // Spigot
|
|
this.syncPosition();
|
|
this.player.playerTick();
|
|
this.player.setLocation(this.l, this.m, this.n, this.player.yaw, this.player.pitch);
|
|
@@ -206,6 +207,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
this.player.resetIdleTimer(); // CraftBukkit - SPIGOT-854
|
|
this.disconnect(new ChatMessage("multiplayer.disconnect.idling", new Object[0]));
|
|
}
|
|
+ org.bukkit.craftbukkit.SpigotTimings.playerConnectionTimer.stopTiming(); // Spigot
|
|
|
|
}
|
|
|
|
@@ -1603,6 +1605,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
// CraftBukkit end
|
|
|
|
private void handleCommand(String s) {
|
|
+ org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.startTiming(); // Spigot
|
|
// CraftBukkit start - whole method
|
|
this.LOGGER.info(this.player.getName() + " issued server command: " + s);
|
|
|
|
@@ -1612,6 +1615,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
this.server.getPluginManager().callEvent(event);
|
|
|
|
if (event.isCancelled()) {
|
|
+ org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.stopTiming(); // Spigot
|
|
return;
|
|
}
|
|
|
|
@@ -1623,6 +1627,8 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
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
|
|
}
|
|
// this.minecraftServer.getCommandDispatcher().a(this.player.getCommandListener(), s);
|
|
// CraftBukkit end
|
|
diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
|
|
index 6e143cad3..86890dadd 100644
|
|
--- a/src/main/java/net/minecraft/server/TileEntity.java
|
|
+++ b/src/main/java/net/minecraft/server/TileEntity.java
|
|
@@ -9,9 +9,11 @@ import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer;
|
|
import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry;
|
|
import org.bukkit.inventory.InventoryHolder;
|
|
// CraftBukkit end
|
|
+import org.spigotmc.CustomTimingsHandler; // Spigot
|
|
|
|
public abstract class TileEntity {
|
|
|
|
+ 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;
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
|
index 3c4e09426..031c24bf7 100644
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
|
@@ -20,6 +20,7 @@ import java.util.ArrayList;
|
|
import java.util.Map;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.block.BlockState;
|
|
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
|
|
import org.bukkit.craftbukkit.CraftServer;
|
|
import org.bukkit.craftbukkit.CraftWorld;
|
|
import org.bukkit.craftbukkit.block.CraftBlockState;
|
|
@@ -85,6 +86,8 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose
|
|
public boolean populating;
|
|
public final org.spigotmc.SpigotWorldConfig spigotConfig; // Spigot
|
|
|
|
+ public final SpigotTimings.WorldTimingsHandler timings; // Spigot
|
|
+
|
|
public CraftWorld getWorld() {
|
|
return this.world;
|
|
}
|
|
@@ -140,6 +143,7 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose
|
|
public void c(WorldBorder worldborder, double d0) {}
|
|
});
|
|
// CraftBukkit end
|
|
+ timings = new SpigotTimings.WorldTimingsHandler(this); // Spigot - code below can generate new world and access timings
|
|
}
|
|
|
|
@Override
|
|
@@ -612,6 +616,7 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose
|
|
GameProfilerFiller gameprofilerfiller = this.getMethodProfiler();
|
|
|
|
gameprofilerfiller.enter("blockEntities");
|
|
+ timings.tileEntityTick.startTiming(); // Spigot
|
|
if (!this.tileEntityListUnload.isEmpty()) {
|
|
this.tileEntityListTick.removeAll(this.tileEntityListUnload);
|
|
this.tileEntityList.removeAll(this.tileEntityListUnload);
|
|
@@ -632,6 +637,7 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose
|
|
gameprofilerfiller.a(() -> {
|
|
return String.valueOf(TileEntityTypes.a(tileentity.q()));
|
|
});
|
|
+ tileentity.tickTimer.startTiming(); // Spigot
|
|
if (tileentity.q().a(this.getType(blockposition).getBlock())) {
|
|
((ITickable) tileentity).tick();
|
|
} else {
|
|
@@ -646,6 +652,11 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose
|
|
tileentity.a(crashreportsystemdetails);
|
|
throw new ReportedException(crashreport);
|
|
}
|
|
+ // Spigot start
|
|
+ finally {
|
|
+ tileentity.tickTimer.stopTiming();
|
|
+ }
|
|
+ // Spigot end
|
|
}
|
|
}
|
|
|
|
@@ -658,6 +669,8 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose
|
|
}
|
|
}
|
|
|
|
+ timings.tileEntityTick.stopTiming(); // Spigot
|
|
+ timings.tileEntityPending.startTiming(); // Spigot
|
|
this.tickingTileEntities = false;
|
|
gameprofilerfiller.exitEnter("pendingBlockEntities");
|
|
if (!this.tileEntityListPending.isEmpty()) {
|
|
@@ -690,12 +703,15 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose
|
|
this.tileEntityListPending.clear();
|
|
}
|
|
|
|
+ timings.tileEntityPending.stopTiming(); // Spigot
|
|
gameprofilerfiller.exit();
|
|
}
|
|
|
|
public void a(Consumer<Entity> consumer, Entity entity) {
|
|
try {
|
|
+ SpigotTimings.tickEntityTimer.startTiming(); // Spigot
|
|
consumer.accept(entity);
|
|
+ SpigotTimings.tickEntityTimer.stopTiming(); // Spigot
|
|
} catch (Throwable throwable) {
|
|
CrashReport crashreport = CrashReport.a(throwable, "Ticking entity");
|
|
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Entity being ticked");
|
|
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
|
|
index b71cc720a..03b576c4a 100644
|
|
--- a/src/main/java/net/minecraft/server/WorldServer.java
|
|
+++ b/src/main/java/net/minecraft/server/WorldServer.java
|
|
@@ -33,6 +33,7 @@ import org.apache.logging.log4j.Logger;
|
|
// CraftBukkit start
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.WeatherType;
|
|
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
|
|
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
|
import org.bukkit.event.server.MapInitializeEvent;
|
|
@@ -255,15 +256,21 @@ public class WorldServer extends World {
|
|
gameprofilerfiller.exitEnter("chunkSource");
|
|
this.getChunkProvider().tick(booleansupplier);
|
|
gameprofilerfiller.exitEnter("tickPending");
|
|
+ timings.doTickPending.startTiming(); // Spigot
|
|
if (this.worldData.getType() != WorldType.DEBUG_ALL_BLOCK_STATES) {
|
|
this.nextTickListBlock.a();
|
|
this.nextTickListFluid.a();
|
|
}
|
|
+ timings.doTickPending.stopTiming(); // Spigot
|
|
|
|
gameprofilerfiller.exitEnter("village");
|
|
+ timings.doVillages.startTiming(); // Spigot
|
|
this.siegeManager.a();
|
|
+ timings.doVillages.stopTiming(); // Spigot
|
|
gameprofilerfiller.exitEnter("portalForcer");
|
|
+ timings.doPortalForcer.startTiming(); // Spigot
|
|
this.portalTravelAgent.a(this.getTime());
|
|
+ timings.doPortalForcer.stopTiming(); // Spigot
|
|
gameprofilerfiller.exitEnter("raid");
|
|
this.c.a();
|
|
if (this.mobSpawnerTrader != null) {
|
|
@@ -271,7 +278,9 @@ public class WorldServer extends World {
|
|
}
|
|
|
|
gameprofilerfiller.exitEnter("blockEvents");
|
|
+ timings.doSounds.startTiming(); // Spigot
|
|
this.ae();
|
|
+ timings.doSounds.stopTiming(); // Spigot
|
|
this.ticking = false;
|
|
gameprofilerfiller.exitEnter("entities");
|
|
boolean flag3 = true || !this.players.isEmpty() || !this.getForceLoadedChunks().isEmpty(); // CraftBukkit - this prevents entity cleanup, other issues on servers with no players
|
|
@@ -281,6 +290,7 @@ public class WorldServer extends World {
|
|
}
|
|
|
|
if (flag3 || this.emptyTime++ < 300) {
|
|
+ timings.tickEntities.startTiming(); // Spigot
|
|
this.worldProvider.l();
|
|
gameprofilerfiller.enter("global");
|
|
|
|
@@ -306,6 +316,7 @@ public class WorldServer extends World {
|
|
this.tickingEntities = true;
|
|
ObjectIterator objectiterator = this.entitiesById.int2ObjectEntrySet().iterator();
|
|
|
|
+ timings.entityTick.startTiming(); // Spigot
|
|
while (objectiterator.hasNext()) {
|
|
Entry<Entity> entry = (Entry) objectiterator.next();
|
|
Entity entity1 = (Entity) entry.getValue();
|
|
@@ -344,6 +355,7 @@ public class WorldServer extends World {
|
|
|
|
gameprofilerfiller.exit();
|
|
}
|
|
+ timings.entityTick.stopTiming(); // Spigot
|
|
|
|
this.tickingEntities = false;
|
|
|
|
@@ -352,6 +364,7 @@ public class WorldServer extends World {
|
|
}
|
|
|
|
gameprofilerfiller.exit();
|
|
+ timings.tickEntities.stopTiming(); // Spigot
|
|
this.tickBlockEntities();
|
|
}
|
|
|
|
@@ -534,6 +547,7 @@ public class WorldServer extends World {
|
|
|
|
public void entityJoinedWorld(Entity entity) {
|
|
if (entity instanceof EntityHuman || this.getChunkProvider().a(entity)) {
|
|
+ entity.tickTimer.startTiming(); // Spigot
|
|
entity.H = entity.locX;
|
|
entity.I = entity.locY;
|
|
entity.J = entity.locZ;
|
|
@@ -559,6 +573,7 @@ public class WorldServer extends World {
|
|
this.a(entity, entity1);
|
|
}
|
|
}
|
|
+ entity.tickTimer.stopTiming(); // Spigot
|
|
|
|
}
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
index 37cd0d7b5..e6f8badb1 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -1895,6 +1895,11 @@ public final class CraftServer implements Server {
|
|
private final Spigot spigot = new Spigot()
|
|
{
|
|
|
|
+ @Override
|
|
+ public YamlConfiguration getConfig()
|
|
+ {
|
|
+ return org.spigotmc.SpigotConfig.config;
|
|
+ }
|
|
};
|
|
|
|
public 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..153be935e
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java
|
|
@@ -0,0 +1,163 @@
|
|
+package org.bukkit.craftbukkit;
|
|
+
|
|
+import java.util.HashMap;
|
|
+import net.minecraft.server.Entity;
|
|
+import net.minecraft.server.TileEntity;
|
|
+import net.minecraft.server.World;
|
|
+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 HashMap<String, CustomTimingsHandler> entityTypeTimingMap = new HashMap<String, CustomTimingsHandler>();
|
|
+ public static final HashMap<String, CustomTimingsHandler> tileEntityTypeTimingMap = new HashMap<String, CustomTimingsHandler>();
|
|
+ public static final HashMap<String, CustomTimingsHandler> pluginTaskTimingMap = new HashMap<String, CustomTimingsHandler>();
|
|
+
|
|
+ /**
|
|
+ * Gets a timer associated with a plugins tasks.
|
|
+ * @param task
|
|
+ * @param period
|
|
+ * @return
|
|
+ */
|
|
+ public static CustomTimingsHandler getPluginTaskTimings(BukkitTask task, long period) {
|
|
+ if (!task.isSync()) {
|
|
+ return null;
|
|
+ }
|
|
+ String plugin;
|
|
+ final CraftTask ctask = (CraftTask) task;
|
|
+
|
|
+ if (task.getOwner() != null) {
|
|
+ plugin = task.getOwner().getDescription().getFullName();
|
|
+ } else {
|
|
+ plugin = "Unknown";
|
|
+ }
|
|
+ String taskname = ctask.getTaskName();
|
|
+
|
|
+ String name = "Task: " + plugin + " Runnable: " + taskname;
|
|
+ if (period > 0) {
|
|
+ name += "(interval:" + period +")";
|
|
+ } else {
|
|
+ name += "(Single)";
|
|
+ }
|
|
+ CustomTimingsHandler result = pluginTaskTimingMap.get(name);
|
|
+ if (result == null) {
|
|
+ result = new CustomTimingsHandler(name, SpigotTimings.schedulerSyncTimer);
|
|
+ pluginTaskTimingMap.put(name, result);
|
|
+ }
|
|
+ return result;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Get a named timer for the specified entity type to track type specific timings.
|
|
+ * @param entity
|
|
+ * @return
|
|
+ */
|
|
+ public static CustomTimingsHandler getEntityTimings(Entity entity) {
|
|
+ String entityType = entity.getClass().getName();
|
|
+ CustomTimingsHandler result = entityTypeTimingMap.get(entityType);
|
|
+ if (result == null) {
|
|
+ result = new CustomTimingsHandler("** tickEntity - " + entity.getClass().getSimpleName(), activatedEntityTimer);
|
|
+ entityTypeTimingMap.put(entityType, result);
|
|
+ }
|
|
+ return result;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Get a named timer for the specified tile entity type to track type specific timings.
|
|
+ * @param entity
|
|
+ * @return
|
|
+ */
|
|
+ public static CustomTimingsHandler getTileEntityTimings(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 doPortalForcer;
|
|
+ public final CustomTimingsHandler doTickPending;
|
|
+ public final CustomTimingsHandler doTickTiles;
|
|
+ public final CustomTimingsHandler doVillages;
|
|
+ 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) {
|
|
+ String name = server.worldData.getName() +" - ";
|
|
+
|
|
+ mobSpawn = new CustomTimingsHandler("** " + name + "mobSpawn");
|
|
+ doChunkUnload = new CustomTimingsHandler("** " + name + "doChunkUnload");
|
|
+ doTickPending = new CustomTimingsHandler("** " + name + "doTickPending");
|
|
+ doTickTiles = new CustomTimingsHandler("** " + name + "doTickTiles");
|
|
+ doVillages = new CustomTimingsHandler("** " + name + "doVillages");
|
|
+ doChunkMap = new CustomTimingsHandler("** " + name + "doChunkMap");
|
|
+ doSounds = new CustomTimingsHandler("** " + name + "doSounds");
|
|
+ doPortalForcer = new CustomTimingsHandler("** " + name + "doPortalForcer");
|
|
+ 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 d694a2a24..b90979c7b 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
|
|
@@ -390,7 +390,9 @@ public class CraftScheduler implements BukkitScheduler {
|
|
if (task.isSync()) {
|
|
currentTask = task;
|
|
try {
|
|
+ task.timings.startTiming(); // Spigot
|
|
task.run();
|
|
+ task.timings.stopTiming(); // Spigot
|
|
} catch (final Throwable throwable) {
|
|
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 a85fbbb69..3f55381c1 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java
|
|
@@ -2,11 +2,13 @@ package org.bukkit.craftbukkit.scheduler;
|
|
|
|
import java.util.function.Consumer;
|
|
import org.bukkit.Bukkit;
|
|
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
|
|
+import org.spigotmc.CustomTimingsHandler; // Spigot
|
|
import org.bukkit.plugin.Plugin;
|
|
import org.bukkit.scheduler.BukkitTask;
|
|
|
|
|
|
-class CraftTask implements BukkitTask, Runnable {
|
|
+public class CraftTask implements BukkitTask, Runnable { // Spigot
|
|
|
|
private volatile CraftTask next = null;
|
|
public static final int ERROR = 0;
|
|
@@ -29,6 +31,7 @@ class CraftTask implements BukkitTask, Runnable {
|
|
private final Plugin plugin;
|
|
private final int id;
|
|
|
|
+ final CustomTimingsHandler timings; // Spigot
|
|
CraftTask() {
|
|
this(null, null, CraftTask.NO_REPEATING, CraftTask.NO_REPEATING);
|
|
}
|
|
@@ -54,6 +57,7 @@ class CraftTask implements BukkitTask, Runnable {
|
|
}
|
|
this.id = id;
|
|
this.period = period;
|
|
+ this.timings = this.isSync() ? SpigotTimings.getPluginTaskTimings(this, period) : null; // Spigot
|
|
}
|
|
|
|
@Override
|
|
@@ -127,4 +131,10 @@ class CraftTask implements BukkitTask, Runnable {
|
|
setPeriod(CraftTask.CANCEL);
|
|
return true;
|
|
}
|
|
+
|
|
+ // Spigot start
|
|
+ public String getTaskName() {
|
|
+ return (getTaskClass() == null) ? "Unknown" : getTaskClass().getName();
|
|
+ }
|
|
+ // Spigot end
|
|
}
|
|
--
|
|
2.20.1
|
|
|