2019-12-18 08:00:00 +11:00
From 08f32d5e1300c0f05d34ce1f73ba4d06834583d2 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
2014-07-07 18:59:02 -04:00
Subject: [PATCH] Spigot Timings
2013-02-26 12:21:40 -05:00
2014-07-07 18:59:02 -04:00
Overhauls the Timings System adding performance tracking all around the Minecraft Server
2013-02-26 12:21:40 -05:00
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
2019-12-11 09:00:00 +11:00
index 715c46ac..2b9a4659 100644
2013-02-26 12:21:40 -05:00
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
2019-07-20 09:00:00 +10:00
@@ -98,9 +98,11 @@ public class ChunkProviderServer extends IChunkProvider {
2019-05-14 10:00:00 +10:00
}
}
2019-04-23 12:00:00 +10:00
+ world.timings.syncChunkLoadTimer.startTiming(); // Spigot
2019-05-14 10:00:00 +10:00
CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> completablefuture = this.getChunkFutureMainThread(i, j, chunkstatus, flag);
this.serverThreadQueue.awaitTasks(completablefuture::isDone);
2019-04-23 12:00:00 +10:00
+ world.timings.syncChunkLoadTimer.stopTiming(); // Spigot
2019-05-14 10:00:00 +10:00
ichunkaccess = (IChunkAccess) ((Either) completablefuture.join()).map((ichunkaccess1) -> {
return ichunkaccess1;
}, (playerchunk_failure) -> {
2019-07-30 20:50:28 +10:00
@@ -324,12 +326,16 @@ public class ChunkProviderServer extends IChunkProvider {
2019-04-23 12:00:00 +10:00
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();
2019-05-28 06:30:00 +10:00
this.clearCache();
2019-04-23 12:00:00 +10:00
}
2019-07-30 20:50:28 +10:00
@@ -370,6 +376,7 @@ public class ChunkProviderServer extends IChunkProvider {
2019-12-11 09:00:00 +11:00
chunk.setInhabitedTime(chunk.getInhabitedTime() + j);
2019-04-23 12:00:00 +10:00
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;
2019-07-30 20:50:28 +10:00
@@ -407,10 +414,13 @@ public class ChunkProviderServer extends IChunkProvider {
2019-04-23 12:00:00 +10:00
}
}
+ this.world.timings.mobSpawn.stopTiming(); // Spigot
this.world.getMethodProfiler().exit();
}
+ this.world.timings.doTickTiles.startTiming(); // Spigot
2019-05-14 10:00:00 +10:00
this.world.a(chunk, k);
2019-04-23 12:00:00 +10:00
+ this.world.timings.doTickTiles.stopTiming(); // Spigot
}
}
2019-06-21 20:00:00 +10:00
});
2019-07-30 20:50:28 +10:00
@@ -423,7 +433,9 @@ public class ChunkProviderServer extends IChunkProvider {
2019-05-14 10:00:00 +10:00
this.world.getMethodProfiler().exit();
2013-02-26 12:21:40 -05:00
}
2019-04-23 12:00:00 +10:00
+ this.world.timings.tracker.startTiming(); // Spigot
this.playerChunkMap.g();
+ this.world.timings.tracker.stopTiming(); // Spigot
}
@Override
2014-07-07 18:59:02 -04:00
diff --git a/src/main/java/net/minecraft/server/ChunkRegionLoader.java b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
2019-12-11 09:00:00 +11:00
index 7e6c3e0c..e16d30f2 100644
2014-07-07 18:59:02 -04:00
--- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java
+++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
2019-12-11 09:00:00 +11:00
@@ -388,6 +388,7 @@ public class ChunkRegionLoader {
2019-04-23 12:00:00 +10:00
private static void loadEntities(NBTTagCompound nbttagcompound, Chunk chunk) {
2018-07-15 10:00:00 +10:00
NBTTagList nbttaglist = nbttagcompound.getList("Entities", 10);
World world = chunk.getWorld();
2014-07-07 18:59:02 -04:00
+ world.timings.syncChunkLoadEntitiesTimer.startTiming(); // Spigot
2018-07-15 10:00:00 +10:00
for (int i = 0; i < nbttaglist.size(); ++i) {
NBTTagCompound nbttagcompound1 = nbttaglist.getCompound(i);
2019-12-11 09:00:00 +11:00
@@ -399,6 +400,8 @@ public class ChunkRegionLoader {
2019-04-23 12:00:00 +10:00
chunk.d(true);
2014-07-07 18:59:02 -04:00
}
2018-07-15 10:00:00 +10:00
2014-07-07 18:59:02 -04:00
+ world.timings.syncChunkLoadEntitiesTimer.stopTiming(); // Spigot
+ world.timings.syncChunkLoadTileEntitiesTimer.startTiming(); // Spigot
2018-07-15 10:00:00 +10:00
NBTTagList nbttaglist1 = nbttagcompound.getList("TileEntities", 10);
2014-07-07 18:59:02 -04:00
2018-07-15 10:00:00 +10:00
for (int j = 0; j < nbttaglist1.size(); ++j) {
2019-12-11 09:00:00 +11:00
@@ -415,6 +418,7 @@ public class ChunkRegionLoader {
2018-07-15 10:00:00 +10:00
}
2014-07-07 18:59:02 -04:00
}
}
+ world.timings.syncChunkLoadTileEntitiesTimer.stopTiming(); // Spigot
}
2018-07-15 10:00:00 +10:00
2014-07-07 18:59:02 -04:00
diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java
2019-12-11 09:00:00 +11:00
index 45bb14a6..839458af 100644
2014-07-07 18:59:02 -04:00
--- a/src/main/java/net/minecraft/server/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/DedicatedServer.java
2019-04-23 12:00:00 +10:00
@@ -31,6 +31,7 @@ import org.apache.logging.log4j.Level;
2014-07-07 18:59:02 -04:00
2018-07-15 10:00:00 +10:00
import org.bukkit.command.CommandSender;
2014-07-07 18:59:02 -04:00
import org.bukkit.craftbukkit.LoggerOutputStream;
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
import org.bukkit.event.server.ServerCommandEvent;
2015-02-28 11:36:22 +00:00
import org.bukkit.craftbukkit.util.Waitable;
import org.bukkit.event.server.RemoteServerCommandEvent;
2019-07-30 20:50:28 +10:00
@@ -408,6 +409,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
2014-07-07 18:59:02 -04:00
}
2018-12-13 11:00:00 +11:00
public void handleCommandQueue() {
2014-07-07 18:59:02 -04:00
+ SpigotTimings.serverCommandTimer.startTiming(); // Spigot
2016-03-01 08:33:06 +11:00
while (!this.serverCommandQueue.isEmpty()) {
ServerCommand servercommand = (ServerCommand) this.serverCommandQueue.remove(0);
2014-07-07 18:59:02 -04:00
2019-07-30 20:50:28 +10:00
@@ -422,6 +424,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
2014-07-07 18:59:02 -04:00
// CraftBukkit end
}
2014-11-26 08:27:08 +11:00
2014-07-07 18:59:02 -04:00
+ SpigotTimings.serverCommandTimer.stopTiming(); // Spigot
}
2019-04-23 12:00:00 +10:00
@Override
2013-02-26 12:21:40 -05:00
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
2019-12-11 09:00:00 +11:00
index b347e3ad..61600eb0 100644
2013-02-26 12:21:40 -05:00
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
2019-04-25 12:00:00 +10:00
@@ -29,6 +29,7 @@ import org.bukkit.command.CommandSender;
2016-03-01 08:33:06 +11:00
import org.bukkit.entity.Hanging;
2013-02-26 12:21:40 -05:00
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Vehicle;
2013-06-02 11:29:44 +10:00
+import org.spigotmc.CustomTimingsHandler; // Spigot
2013-02-26 12:21:40 -05:00
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;
2019-12-11 09:00:00 +11:00
@@ -164,6 +165,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener {
2017-11-07 17:30:57 +11:00
public boolean valid;
public org.bukkit.projectiles.ProjectileSource projectileSource; // For projectiles only
public boolean forceExplosionKnockback; // SPIGOT-949
2013-02-26 12:21:40 -05:00
+ 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() {
return this.yaw;
2019-12-11 09:00:00 +11:00
@@ -490,6 +492,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener {
2014-11-26 08:27:08 +11:00
}
2019-04-23 12:00:00 +10:00
public void move(EnumMoveType enummovetype, Vec3D vec3d) {
2013-02-26 12:21:40 -05:00
+ org.bukkit.craftbukkit.SpigotTimings.entityMoveTimer.startTiming(); // Spigot
2015-02-28 11:36:22 +00:00
if (this.noclip) {
2019-04-23 12:00:00 +10:00
this.a(this.getBoundingBox().b(vec3d));
2014-11-26 08:27:08 +11:00
this.recalcPosition();
2019-12-11 09:00:00 +11:00
@@ -641,6 +644,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener {
2013-02-26 12:21:40 -05:00
2019-04-23 12:00:00 +10:00
this.world.getMethodProfiler().exit();
2013-02-26 12:21:40 -05:00
}
+ org.bukkit.craftbukkit.SpigotTimings.entityMoveTimer.stopTiming(); // Spigot
}
2019-12-11 09:00:00 +11:00
protected BlockPosition ag() {
2014-07-07 18:59:02 -04:00
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
2019-12-11 09:00:00 +11:00
index acf2bfd6..af6e16ab 100644
2014-07-07 18:59:02 -04:00
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
2019-12-11 09:00:00 +11:00
@@ -37,6 +37,8 @@ import org.bukkit.event.entity.EntityTeleportEvent;
2016-03-01 08:33:06 +11:00
import org.bukkit.event.player.PlayerItemConsumeEvent;
2014-07-07 18:59:02 -04:00
// CraftBukkit end
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
+
public abstract class EntityLiving extends Entity {
2019-04-23 12:00:00 +10:00
private static final UUID b = UUID.fromString("662A6B8D-DA3E-4C1C-8813-96EA6097278D");
2019-12-11 09:00:00 +11:00
@@ -2250,6 +2252,7 @@ public abstract class EntityLiving extends Entity {
2014-07-07 18:59:02 -04:00
2019-04-23 12:00:00 +10:00
@Override
2018-07-15 10:00:00 +10:00
public void tick() {
2014-07-07 18:59:02 -04:00
+ SpigotTimings.timerEntityBaseTick.startTiming(); // Spigot
2018-07-15 10:00:00 +10:00
super.tick();
this.o();
2019-12-11 09:00:00 +11:00
this.r();
@@ -2337,7 +2340,9 @@ public abstract class EntityLiving extends Entity {
2014-07-07 18:59:02 -04:00
}
}
+ SpigotTimings.timerEntityBaseTick.stopTiming(); // Spigot
2018-12-13 11:00:00 +11:00
this.movementTick();
2014-07-07 18:59:02 -04:00
+ SpigotTimings.timerEntityTickRest.startTiming(); // Spigot
2019-12-11 09:00:00 +11:00
double d0 = this.locX() - this.lastX;
double d1 = this.locZ() - this.lastZ;
2014-07-07 18:59:02 -04:00
float f = (float) (d0 * d0 + d1 * d1);
2019-12-11 09:00:00 +11:00
@@ -2418,6 +2423,7 @@ public abstract class EntityLiving extends Entity {
2019-04-23 12:00:00 +10:00
this.pitch = 0.0F;
2016-03-01 08:33:06 +11:00
}
2014-07-07 18:59:02 -04:00
+ SpigotTimings.timerEntityTickRest.stopTiming(); // Spigot
}
2019-12-11 09:00:00 +11:00
protected float f(float f, float f1) {
@@ -2496,6 +2502,7 @@ public abstract class EntityLiving extends Entity {
2014-07-07 18:59:02 -04:00
2019-04-23 12:00:00 +10:00
this.setMot(d4, d5, d6);
this.world.getMethodProfiler().enter("ai");
2014-07-07 18:59:02 -04:00
+ SpigotTimings.timerEntityAI.startTiming(); // Spigot
2016-11-17 12:41:12 +11:00
if (this.isFrozen()) {
2019-04-23 12:00:00 +10:00
this.jumping = false;
2019-12-11 09:00:00 +11:00
this.aZ = 0.0F;
@@ -2505,6 +2512,7 @@ public abstract class EntityLiving extends Entity {
2014-11-26 08:27:08 +11:00
this.doTick();
2019-04-23 12:00:00 +10:00
this.world.getMethodProfiler().exit();
2014-07-07 18:59:02 -04:00
}
+ SpigotTimings.timerEntityAI.stopTiming(); // Spigot
2019-04-23 12:00:00 +10:00
this.world.getMethodProfiler().exit();
this.world.getMethodProfiler().enter("jump");
2019-12-11 09:00:00 +11:00
@@ -2528,7 +2536,9 @@ public abstract class EntityLiving extends Entity {
2018-07-15 10:00:00 +10:00
this.n();
AxisAlignedBB axisalignedbb = this.getBoundingBox();
2014-07-07 18:59:02 -04:00
+ SpigotTimings.timerEntityAIMove.startTiming(); // Spigot
2019-12-11 09:00:00 +11:00
this.e(new Vec3D((double) this.aZ, (double) this.ba, (double) this.bb));
2014-07-07 18:59:02 -04:00
+ SpigotTimings.timerEntityAIMove.stopTiming(); // Spigot
2019-04-23 12:00:00 +10:00
this.world.getMethodProfiler().exit();
this.world.getMethodProfiler().enter("push");
2019-12-11 09:00:00 +11:00
if (this.bn > 0) {
@@ -2536,7 +2546,9 @@ public abstract class EntityLiving extends Entity {
2018-07-15 10:00:00 +10:00
this.a(axisalignedbb, this.getBoundingBox());
}
2016-03-01 08:33:06 +11:00
+ SpigotTimings.timerEntityAICollision.startTiming(); // Spigot
2019-04-23 12:00:00 +10:00
this.collideNearby();
2016-03-01 08:33:06 +11:00
+ SpigotTimings.timerEntityAICollision.stopTiming(); // Spigot
2019-04-23 12:00:00 +10:00
this.world.getMethodProfiler().exit();
2016-03-01 08:33:06 +11:00
}
2013-02-26 12:21:40 -05:00
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2019-12-11 09:00:00 +11:00
index c5f63822..699fa893 100644
2013-02-26 12:21:40 -05:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2019-07-20 09:00:00 +10:00
@@ -63,6 +63,7 @@ import org.bukkit.craftbukkit.CraftServer;
2016-07-15 20:11:38 +10:00
import org.bukkit.craftbukkit.Main;
2018-09-08 13:48:25 +10:00
import org.bukkit.event.server.ServerLoadEvent;
2015-07-12 19:59:20 +10:00
// CraftBukkit end
2016-03-01 08:33:06 +11:00
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
2016-07-15 20:11:38 +10:00
2019-04-23 12:00:00 +10:00
public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTask> implements IMojangStatistics, ICommandListener, AutoCloseable, Runnable {
2014-01-22 19:23:59 +11:00
2019-12-11 09:00:00 +11:00
@@ -928,6 +929,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2019-04-23 12:00:00 +10:00
protected void exit() {}
2016-03-01 08:33:06 +11:00
2018-08-26 12:00:00 +10:00
protected void a(BooleanSupplier booleansupplier) {
2014-01-22 19:23:59 +11:00
+ SpigotTimings.serverTickTimer.startTiming(); // Spigot
2018-12-13 11:00:00 +11:00
long i = SystemUtils.getMonotonicNanos();
2014-01-22 19:23:59 +11:00
2014-03-23 00:06:43 +00:00
++this.ticks;
2019-12-11 09:00:00 +11:00
@@ -947,12 +949,14 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2014-07-07 18:59:02 -04:00
}
2014-11-26 08:27:08 +11:00
if (autosavePeriod > 0 && this.ticks % autosavePeriod == 0) { // CraftBukkit
2014-07-07 18:59:02 -04:00
+ SpigotTimings.worldSaveTimer.startTiming(); // Spigot
2019-04-23 12:00:00 +10:00
MinecraftServer.LOGGER.debug("Autosave started");
2018-12-13 11:00:00 +11:00
this.methodProfiler.enter("save");
this.playerList.savePlayers();
2019-04-23 12:00:00 +10:00
this.saveChunks(true, false, false);
2018-12-13 11:00:00 +11:00
this.methodProfiler.exit();
2019-04-23 12:00:00 +10:00
MinecraftServer.LOGGER.debug("Autosave finished");
2014-07-07 18:59:02 -04:00
+ SpigotTimings.worldSaveTimer.stopTiming(); // Spigot
}
2018-12-13 11:00:00 +11:00
this.methodProfiler.enter("snooper");
2019-12-11 09:00:00 +11:00
@@ -973,21 +977,30 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2019-04-23 12:00:00 +10:00
2019-12-11 09:00:00 +11:00
this.circularTimer.a(i1 - i);
2018-12-13 11:00:00 +11:00
this.methodProfiler.exit();
2014-08-05 17:29:09 +01:00
+ SpigotTimings.serverTickTimer.stopTiming(); // Spigot
+ org.spigotmc.CustomTimingsHandler.tick(); // Spigot
}
2019-04-23 12:00:00 +10:00
protected void b(BooleanSupplier booleansupplier) {
2013-02-26 12:21:40 -05:00
+ SpigotTimings.schedulerTimer.startTiming(); // Spigot
2016-06-30 15:22:27 +10:00
this.server.getScheduler().mainThreadHeartbeat(this.ticks); // CraftBukkit
2014-07-07 18:59:02 -04:00
+ SpigotTimings.schedulerTimer.stopTiming(); // Spigot
2019-04-23 12:00:00 +10:00
this.methodProfiler.enter("commandFunctions");
2018-07-15 10:00:00 +10:00
+ SpigotTimings.commandFunctionsTimer.startTiming(); // Spigot
2018-12-13 11:00:00 +11:00
this.getFunctionData().tick();
2018-07-15 10:00:00 +10:00
+ SpigotTimings.commandFunctionsTimer.stopTiming(); // Spigot
2018-12-13 11:00:00 +11:00
this.methodProfiler.exitEnter("levels");
2019-06-21 20:00:00 +10:00
Iterator iterator = this.getWorlds().iterator();
2016-06-30 15:22:27 +10:00
// CraftBukkit start
2014-07-07 18:59:02 -04:00
// Run tasks that are waiting on processing
+ SpigotTimings.processQueueTimer.startTiming(); // Spigot
while (!processQueue.isEmpty()) {
2013-02-26 12:21:40 -05:00
processQueue.remove().run();
}
2014-07-07 18:59:02 -04:00
+ SpigotTimings.processQueueTimer.stopTiming(); // Spigot
2013-02-26 12:21:40 -05:00
2014-07-07 18:59:02 -04:00
+ SpigotTimings.timeUpdateTimer.startTiming(); // Spigot
2013-03-25 18:57:00 +11:00
// Send time updates to everyone, it will get the right time from the world the player is in.
2013-02-26 12:21:40 -05:00
if (this.ticks % 20 == 0) {
2014-07-07 18:59:02 -04:00
for (int i = 0; i < this.getPlayerList().players.size(); ++i) {
2019-12-11 09:00:00 +11:00
@@ -995,6 +1008,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2019-06-21 20:00:00 +10:00
entityplayer.playerConnection.sendPacket(new PacketPlayOutUpdateTime(entityplayer.world.getTime(), entityplayer.getPlayerTime(), entityplayer.world.getGameRules().getBoolean(GameRules.DO_DAYLIGHT_CYCLE))); // Add support for per player time
2014-07-07 18:59:02 -04:00
}
}
+ SpigotTimings.timeUpdateTimer.stopTiming(); // Spigot
2019-06-21 20:00:00 +10:00
while (iterator.hasNext()) {
WorldServer worldserver = (WorldServer) iterator.next();
2019-12-11 09:00:00 +11:00
@@ -1014,7 +1028,9 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2019-04-23 12:00:00 +10:00
this.methodProfiler.enter("tick");
2014-07-07 18:59:02 -04:00
try {
+ worldserver.timings.doTick.startTiming(); // Spigot
2018-08-26 12:00:00 +10:00
worldserver.doTick(booleansupplier);
2014-07-07 18:59:02 -04:00
+ worldserver.timings.doTick.stopTiming(); // Spigot
2015-02-28 11:36:22 +00:00
} catch (Throwable throwable) {
2019-04-23 12:00:00 +10:00
CrashReport crashreport = CrashReport.a(throwable, "Exception ticking world");
2014-07-07 18:59:02 -04:00
2019-12-11 09:00:00 +11:00
@@ -1028,18 +1044,24 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2013-02-26 12:21:40 -05:00
}
2018-12-13 11:00:00 +11:00
this.methodProfiler.exitEnter("connection");
2013-02-26 12:21:40 -05:00
+ SpigotTimings.connectionTimer.startTiming(); // Spigot
2018-07-15 10:00:00 +10:00
this.getServerConnection().c();
2013-02-26 12:21:40 -05:00
+ SpigotTimings.connectionTimer.stopTiming(); // Spigot
2018-12-13 11:00:00 +11:00
this.methodProfiler.exitEnter("players");
2013-02-26 12:21:40 -05:00
+ SpigotTimings.playerListTimer.startTiming(); // Spigot
2018-12-13 11:00:00 +11:00
this.playerList.tick();
2013-02-26 12:21:40 -05:00
+ SpigotTimings.playerListTimer.stopTiming(); // Spigot
2019-12-11 09:00:00 +11:00
if (SharedConstants.b) {
GameTestHarnessTicker.a.b();
}
2019-04-23 12:00:00 +10:00
this.methodProfiler.exitEnter("server gui refresh");
2013-02-26 12:21:40 -05:00
+ SpigotTimings.tickablesTimer.startTiming(); // Spigot
2019-06-21 20:00:00 +10:00
for (int i = 0; i < this.tickables.size(); ++i) {
((Runnable) this.tickables.get(i)).run();
2013-02-26 12:21:40 -05:00
}
+ SpigotTimings.tickablesTimer.stopTiming(); // Spigot
2018-12-13 11:00:00 +11:00
this.methodProfiler.exit();
2013-02-26 12:21:40 -05:00
}
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
2019-12-11 09:00:00 +11:00
index 81d68f69..48151e3b 100644
2013-02-26 12:21:40 -05:00
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
2019-04-30 12:16:33 +10:00
@@ -134,6 +134,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
2018-10-27 17:44:13 +11:00
// CraftBukkit end
2018-12-13 11:00:00 +11:00
public void tick() {
2018-10-27 17:44:13 +11:00
+ org.bukkit.craftbukkit.SpigotTimings.playerConnectionTimer.startTiming(); // Spigot
this.syncPosition();
2019-12-11 09:00:00 +11:00
this.player.lastX = this.player.locX();
this.player.lastY = this.player.locY();
@@ -209,6 +210,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
2018-10-27 17:44:13 +11:00
this.player.resetIdleTimer(); // CraftBukkit - SPIGOT-854
this.disconnect(new ChatMessage("multiplayer.disconnect.idling", new Object[0]));
}
+ org.bukkit.craftbukkit.SpigotTimings.playerConnectionTimer.stopTiming(); // Spigot
}
2019-12-11 09:00:00 +11:00
@@ -1590,6 +1592,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
2013-02-26 12:21:40 -05:00
// CraftBukkit end
2017-05-14 12:00:00 +10:00
private void handleCommand(String s) {
2013-02-26 12:21:40 -05:00
+ org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.startTiming(); // Spigot
2018-07-15 10:00:00 +10:00
// CraftBukkit start - whole method
2016-03-01 08:33:06 +11:00
this.LOGGER.info(this.player.getName() + " issued server command: " + s);
2013-02-26 12:21:40 -05:00
2019-12-11 09:00:00 +11:00
@@ -1599,6 +1602,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
2013-02-26 12:21:40 -05:00
this.server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
+ org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.stopTiming(); // Spigot
return;
}
2019-12-11 09:00:00 +11:00
@@ -1610,6 +1614,8 @@ public class PlayerConnection implements PacketListenerPlayIn {
2013-02-26 12:21:40 -05:00
player.sendMessage(org.bukkit.ChatColor.RED + "An internal error occurred while attempting to perform this command");
2013-03-25 18:57:00 +11:00
java.util.logging.Logger.getLogger(PlayerConnection.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
2013-02-26 12:21:40 -05:00
return;
2018-07-15 10:00:00 +10:00
+ } finally {
+ org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.stopTiming(); // Spigot
2013-02-26 12:21:40 -05:00
}
2018-07-15 10:00:00 +10:00
// this.minecraftServer.getCommandDispatcher().a(this.player.getCommandListener(), s);
2013-02-26 12:21:40 -05:00
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
2019-12-11 09:00:00 +11:00
index 68e220be..b7175ee6 100644
2013-02-26 12:21:40 -05:00
--- a/src/main/java/net/minecraft/server/TileEntity.java
+++ b/src/main/java/net/minecraft/server/TileEntity.java
2019-05-14 10:00:00 +10:00
@@ -9,9 +9,11 @@ import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer;
2019-04-25 14:39:43 +10:00
import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry;
import org.bukkit.inventory.InventoryHolder;
// CraftBukkit end
2013-06-02 11:29:44 +10:00
+import org.spigotmc.CustomTimingsHandler; // Spigot
2013-02-26 12:21:40 -05:00
2014-11-26 08:27:08 +11:00
public abstract class TileEntity {
2013-02-26 12:21:40 -05:00
+ public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getTileEntityTimings(this); // Spigot
2019-04-25 14:39:43 +10:00
// CraftBukkit start - data containers
private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry();
2019-07-03 10:30:37 +10:00
public CraftPersistentDataContainer persistentDataContainer;
2013-02-26 12:21:40 -05:00
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
2019-12-18 08:00:00 +11:00
index b8b2c67f..c0af874f 100644
2013-02-26 12:21:40 -05:00
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
2019-04-23 12:00:00 +10:00
@@ -20,6 +20,7 @@ import java.util.ArrayList;
2016-03-01 08:33:06 +11:00
import java.util.Map;
import org.bukkit.Bukkit;
2014-04-24 16:27:12 +10:00
import org.bukkit.block.BlockState;
2013-02-26 12:21:40 -05:00
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
import org.bukkit.craftbukkit.CraftServer;
2014-02-12 13:48:26 +00:00
import org.bukkit.craftbukkit.CraftWorld;
2018-07-15 10:00:00 +10:00
import org.bukkit.craftbukkit.block.CraftBlockState;
2019-12-11 09:00:00 +11:00
@@ -84,6 +85,8 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
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
2013-02-26 12:21:40 -05:00
+ public final SpigotTimings.WorldTimingsHandler timings; // Spigot
+
public CraftWorld getWorld() {
return this.world;
}
2019-12-11 09:00:00 +11:00
@@ -140,6 +143,7 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
2019-04-23 12:00:00 +10:00
public void c(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
2014-11-26 08:27:08 +11:00
}
2019-04-23 12:00:00 +10:00
@Override
2019-12-11 09:00:00 +11:00
@@ -585,6 +589,7 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
2019-04-23 12:00:00 +10:00
GameProfilerFiller gameprofilerfiller = this.getMethodProfiler();
2013-02-26 12:21:40 -05:00
2019-04-23 12:00:00 +10:00
gameprofilerfiller.enter("blockEntities");
2016-06-15 13:24:40 +10:00
+ timings.tileEntityTick.startTiming(); // Spigot
if (!this.tileEntityListUnload.isEmpty()) {
this.tileEntityListTick.removeAll(this.tileEntityListUnload);
2017-09-18 20:00:00 +10:00
this.tileEntityList.removeAll(this.tileEntityListUnload);
2019-12-11 09:00:00 +11:00
@@ -605,6 +610,7 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
2019-04-23 12:00:00 +10:00
gameprofilerfiller.a(() -> {
2019-12-11 09:00:00 +11:00
return String.valueOf(TileEntityTypes.a(tileentity.getTileType()));
2017-08-03 23:00:00 +10:00
});
2014-11-26 08:27:08 +11:00
+ tileentity.tickTimer.startTiming(); // Spigot
2019-12-11 09:00:00 +11:00
if (tileentity.getTileType().isValidBlock(this.getType(blockposition).getBlock())) {
2019-05-14 10:00:00 +10:00
((ITickable) tileentity).tick();
} else {
2019-12-11 09:00:00 +11:00
@@ -619,6 +625,11 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
2019-04-23 12:00:00 +10:00
tileentity.a(crashreportsystemdetails);
throw new ReportedException(crashreport);
2014-11-26 08:27:08 +11:00
}
+ // Spigot start
+ finally {
+ tileentity.tickTimer.stopTiming();
+ }
+ // Spigot end
}
}
2013-02-26 12:21:40 -05:00
2019-12-11 09:00:00 +11:00
@@ -631,6 +642,8 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
2013-02-26 12:21:40 -05:00
}
}
+ timings.tileEntityTick.stopTiming(); // Spigot
+ timings.tileEntityPending.startTiming(); // Spigot
2019-04-23 12:00:00 +10:00
this.tickingTileEntities = false;
gameprofilerfiller.exitEnter("pendingBlockEntities");
if (!this.tileEntityListPending.isEmpty()) {
2019-12-11 09:00:00 +11:00
@@ -663,12 +676,15 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
2019-04-23 12:00:00 +10:00
this.tileEntityListPending.clear();
2013-02-26 12:21:40 -05:00
}
+ timings.tileEntityPending.stopTiming(); // Spigot
2019-04-23 12:00:00 +10:00
gameprofilerfiller.exit();
2013-02-26 12:21:40 -05:00
}
2017-05-19 21:00:22 +10:00
2019-04-23 12:00:00 +10:00
public void a(Consumer<Entity> consumer, Entity entity) {
try {
2019-05-12 11:39:46 +10:00
+ SpigotTimings.tickEntityTimer.startTiming(); // Spigot
2019-04-23 12:00:00 +10:00
consumer.accept(entity);
2019-05-12 11:39:46 +10:00
+ SpigotTimings.tickEntityTimer.stopTiming(); // Spigot
2019-04-23 12:00:00 +10:00
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Ticking entity");
2019-05-12 11:39:46 +10:00
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Entity being ticked");
2013-02-26 12:21:40 -05:00
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
2019-12-11 09:00:00 +11:00
index 3ae13cc5..8d422fba 100644
2013-02-26 12:21:40 -05:00
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
2019-12-11 09:00:00 +11:00
@@ -40,6 +40,7 @@ import org.apache.logging.log4j.Logger;
2019-10-18 20:03:04 +11:00
import java.util.logging.Level;
2019-05-14 10:00:00 +10:00
import org.bukkit.Bukkit;
2019-04-23 12:00:00 +10:00
import org.bukkit.WeatherType;
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
import org.bukkit.craftbukkit.event.CraftEventFactory;
2019-05-14 10:00:00 +10:00
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.server.MapInitializeEvent;
2019-12-11 09:00:00 +11:00
@@ -297,10 +298,12 @@ public class WorldServer extends World {
2019-04-23 12:00:00 +10:00
gameprofilerfiller.exitEnter("chunkSource");
this.getChunkProvider().tick(booleansupplier);
gameprofilerfiller.exitEnter("tickPending");
2013-06-08 09:21:38 +10:00
+ timings.doTickPending.startTiming(); // Spigot
2019-04-23 12:00:00 +10:00
if (this.worldData.getType() != WorldType.DEBUG_ALL_BLOCK_STATES) {
2019-07-20 09:00:00 +10:00
this.nextTickListBlock.b();
this.nextTickListFluid.b();
2019-04-23 12:00:00 +10:00
}
2013-06-08 09:21:38 +10:00
+ timings.doTickPending.stopTiming(); // Spigot
2019-04-23 12:00:00 +10:00
gameprofilerfiller.exitEnter("raid");
2019-12-11 09:00:00 +11:00
this.persistentRaid.a();
@@ -309,7 +312,9 @@ public class WorldServer extends World {
2019-04-23 12:00:00 +10:00
}
gameprofilerfiller.exitEnter("blockEvents");
2013-06-08 09:21:38 +10:00
+ timings.doSounds.startTiming(); // Spigot
2019-12-11 09:00:00 +11:00
this.ad();
2016-03-01 08:33:06 +11:00
+ timings.doSounds.stopTiming(); // Spigot
2019-04-23 12:00:00 +10:00
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
2019-12-11 09:00:00 +11:00
@@ -319,6 +324,7 @@ public class WorldServer extends World {
2019-04-23 12:00:00 +10:00
}
2015-02-28 11:36:22 +00:00
2019-04-23 12:00:00 +10:00
if (flag3 || this.emptyTime++ < 300) {
+ timings.tickEntities.startTiming(); // Spigot
2019-12-11 09:00:00 +11:00
this.worldProvider.j();
2019-04-23 12:00:00 +10:00
gameprofilerfiller.enter("global");
2019-12-11 09:00:00 +11:00
@@ -344,6 +350,7 @@ public class WorldServer extends World {
2019-04-23 12:00:00 +10:00
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();
2019-12-11 09:00:00 +11:00
@@ -388,6 +395,7 @@ public class WorldServer extends World {
2019-04-23 12:00:00 +10:00
gameprofilerfiller.exit();
}
+ timings.entityTick.stopTiming(); // Spigot
this.tickingEntities = false;
2019-12-11 09:00:00 +11:00
@@ -396,6 +404,7 @@ public class WorldServer extends World {
2019-04-23 12:00:00 +10:00
}
gameprofilerfiller.exit();
+ timings.tickEntities.stopTiming(); // Spigot
this.tickBlockEntities();
}
2013-02-26 12:21:40 -05:00
2019-12-11 09:00:00 +11:00
@@ -584,6 +593,7 @@ public class WorldServer extends World {
2019-05-12 11:39:46 +10:00
public void entityJoinedWorld(Entity entity) {
if (entity instanceof EntityHuman || this.getChunkProvider().a(entity)) {
+ entity.tickTimer.startTiming(); // Spigot
2019-12-11 09:00:00 +11:00
entity.f(entity.locX(), entity.locY(), entity.locZ());
entity.lastYaw = entity.yaw;
entity.lastPitch = entity.pitch;
@@ -607,6 +617,7 @@ public class WorldServer extends World {
2019-05-12 11:39:46 +10:00
this.a(entity, entity1);
}
}
+ entity.tickTimer.stopTiming(); // Spigot
}
}
2014-08-25 20:09:32 +01:00
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2019-12-11 09:00:00 +11:00
index 703940f8..d401babf 100644
2014-08-25 20:09:32 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2019-12-11 09:00:00 +11:00
@@ -1899,6 +1899,11 @@ public final class CraftServer implements Server {
2014-08-25 20:09:32 +01:00
private final Spigot spigot = new Spigot()
{
+ @Override
+ public YamlConfiguration getConfig()
+ {
+ return org.spigotmc.SpigotConfig.config;
+ }
};
public Spigot spigot()
2013-02-26 12:21:40 -05:00
diff --git a/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java b/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java
new file mode 100644
2019-12-11 09:00:00 +11:00
index 00000000..24d4a488
2013-02-26 12:21:40 -05:00
--- /dev/null
+++ b/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java
2019-12-11 09:00:00 +11:00
@@ -0,0 +1,159 @@
2013-02-26 12:21:40 -05:00
+package org.bukkit.craftbukkit;
+
+import java.util.HashMap;
2019-04-23 15:12:43 +10:00
+import net.minecraft.server.Entity;
+import net.minecraft.server.TileEntity;
+import net.minecraft.server.World;
2013-08-03 19:39:35 +10:00
+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;
2013-02-26 12:21:40 -05:00
+
+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");
2014-07-07 18:59:02 -04:00
+ 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");
2013-02-26 12:21:40 -05:00
+ public static final CustomTimingsHandler tickablesTimer = new CustomTimingsHandler("Tickables");
+ public static final CustomTimingsHandler schedulerTimer = new CustomTimingsHandler("Scheduler");
2014-07-07 18:59:02 -04:00
+ 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");
2013-02-26 12:21:40 -05:00
+
+ 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");
+
2014-07-07 18:59:02 -04:00
+ public static final CustomTimingsHandler processQueueTimer = new CustomTimingsHandler("processQueue");
+ public static final CustomTimingsHandler schedulerSyncTimer = new CustomTimingsHandler("** Scheduler - Sync Tasks", JavaPluginLoader.pluginParentTimer);
+
2013-02-26 12:21:40 -05:00
+ 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) {
2014-07-07 18:59:02 -04:00
+ 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;
2013-02-26 12:21:40 -05:00
+ if (period > 0) {
2013-02-27 00:39:53 -05:00
+ name += "(interval:" + period +")";
2013-02-26 12:21:40 -05:00
+ } else {
2013-02-27 00:39:53 -05:00
+ name += "(Single)";
2013-02-26 12:21:40 -05:00
+ }
2013-02-27 00:39:53 -05:00
+ CustomTimingsHandler result = pluginTaskTimingMap.get(name);
+ if (result == null) {
2014-07-07 18:59:02 -04:00
+ result = new CustomTimingsHandler(name, SpigotTimings.schedulerSyncTimer);
2013-02-27 00:39:53 -05:00
+ pluginTaskTimingMap.put(name, result);
+ }
+ return result;
2013-02-26 12:21:40 -05:00
+ }
+
+ /**
+ * Get a named timer for the specified entity type to track type specific timings.
+ * @param entity
+ * @return
+ */
+ public static CustomTimingsHandler getEntityTimings(Entity entity) {
2017-10-28 16:17:34 +11:00
+ String entityType = entity.getClass().getName();
2013-02-26 12:21:40 -05:00
+ CustomTimingsHandler result = entityTypeTimingMap.get(entityType);
+ if (result == null) {
2017-10-28 16:17:34 +11:00
+ result = new CustomTimingsHandler("** tickEntity - " + entity.getClass().getSimpleName(), activatedEntityTimer);
2013-02-26 12:21:40 -05:00
+ 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) {
2017-10-28 16:17:34 +11:00
+ String entityType = entity.getClass().getName();
2013-02-26 12:21:40 -05:00
+ CustomTimingsHandler result = tileEntityTypeTimingMap.get(entityType);
+ if (result == null) {
2017-10-28 16:17:34 +11:00
+ result = new CustomTimingsHandler("** tickTileEntity - " + entity.getClass().getSimpleName(), tickTileEntityTimer);
2013-02-26 12:21:40 -05:00
+ tileEntityTypeTimingMap.put(entityType, result);
+ }
+ return result;
+ }
+
+ /**
+ * Set of timers per world, to track world specific timings.
+ */
+ public static class WorldTimingsHandler {
+ public final CustomTimingsHandler mobSpawn;
2013-06-08 09:21:38 +10:00
+ public final CustomTimingsHandler doChunkUnload;
+ public final CustomTimingsHandler doTickPending;
+ public final CustomTimingsHandler doTickTiles;
+ public final CustomTimingsHandler doChunkMap;
+ public final CustomTimingsHandler doSounds;
2013-02-26 12:21:40 -05:00
+ public final CustomTimingsHandler entityTick;
+ public final CustomTimingsHandler tileEntityTick;
+ public final CustomTimingsHandler tileEntityPending;
+ public final CustomTimingsHandler tracker;
2014-07-07 18:59:02 -04:00
+ 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;
2013-02-26 12:21:40 -05:00
+
+ public WorldTimingsHandler(World server) {
+ String name = server.worldData.getName() +" - ";
+
2014-07-07 18:59:02 -04:00
+ 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");
+
+
2013-02-26 12:21:40 -05:00
+ tracker = new CustomTimingsHandler(name + "tracker");
2014-07-07 18:59:02 -04:00
+ doTick = new CustomTimingsHandler(name + "doTick");
+ tickEntities = new CustomTimingsHandler(name + "tickEntities");
2013-02-26 12:21:40 -05:00
+ }
+ }
+}
2014-07-07 18:59:02 -04:00
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
2019-12-11 09:00:00 +11:00
index d694a2a2..b90979c7 100644
2014-07-07 18:59:02 -04:00
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
2019-04-28 11:41:06 +10:00
@@ -390,7 +390,9 @@ public class CraftScheduler implements BukkitScheduler {
2014-07-07 18:59:02 -04:00
if (task.isSync()) {
2018-06-20 13:18:48 +10:00
currentTask = task;
2014-07-07 18:59:02 -04:00
try {
+ task.timings.startTiming(); // Spigot
task.run();
+ task.timings.stopTiming(); // Spigot
} catch (final Throwable throwable) {
task.getOwner().getLogger().log(
Level.WARNING,
2013-02-26 12:21:40 -05:00
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java
2019-12-11 09:00:00 +11:00
index a85fbbb6..3f55381c 100644
2013-02-26 12:21:40 -05:00
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java
2018-11-23 12:11:41 +11:00
@@ -2,11 +2,13 @@ package org.bukkit.craftbukkit.scheduler;
2013-02-26 12:21:40 -05:00
2018-11-23 12:11:41 +11:00
import java.util.function.Consumer;
2013-02-26 12:21:40 -05:00
import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
2013-06-02 11:29:44 +10:00
+import org.spigotmc.CustomTimingsHandler; // Spigot
2013-02-26 12:21:40 -05:00
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitTask;
2013-08-03 19:39:35 +10:00
-class CraftTask implements BukkitTask, Runnable {
+public class CraftTask implements BukkitTask, Runnable { // Spigot
private volatile CraftTask next = null;
2018-03-30 08:44:10 +11:00
public static final int ERROR = 0;
2018-11-23 12:11:41 +11:00
@@ -29,6 +31,7 @@ class CraftTask implements BukkitTask, Runnable {
2013-02-26 12:21:40 -05:00
private final Plugin plugin;
private final int id;
2014-07-07 18:59:02 -04:00
+ final CustomTimingsHandler timings; // Spigot
2013-02-26 12:21:40 -05:00
CraftTask() {
2018-03-30 08:44:10 +11:00
this(null, null, CraftTask.NO_REPEATING, CraftTask.NO_REPEATING);
2013-02-26 12:21:40 -05:00
}
2018-11-23 12:11:41 +11:00
@@ -54,6 +57,7 @@ class CraftTask implements BukkitTask, Runnable {
}
2014-07-07 18:59:02 -04: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
2013-08-03 19:39:35 +10:00
}
2018-11-23 12:11:41 +11:00
@Override
@@ -127,4 +131,10 @@ class CraftTask implements BukkitTask, Runnable {
2018-03-30 08:44:10 +11:00
setPeriod(CraftTask.CANCEL);
2014-07-07 18:59:02 -04:00
return true;
2013-08-03 19:39:35 +10:00
}
2014-07-07 18:59:02 -04:00
+
+ // Spigot start
+ public String getTaskName() {
2018-11-23 14:22:14 +11:00
+ return (getTaskClass() == null) ? "Unknown" : getTaskClass().getName();
2014-07-07 18:59:02 -04:00
+ }
+ // Spigot end
}
2013-02-26 12:21:40 -05:00
--
2019-04-23 09:33:25 +10:00
2.20.1
2013-02-26 12:21:40 -05:00