testserver/CraftBukkit-Patches/0014-Improved-Timings-Syste...

544 lines
25 KiB
Diff
Raw Normal View History

2014-04-24 06:27:12 +00:00
From 151ed358c7071fc7ff19e3a0c0e54f294d10889d Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Thu, 10 Jan 2013 00:18:11 -0500
Subject: [PATCH] Improved Timings System
Tracks nearly every point of minecraft internals and plugin events to give a good quick overview on what is causing TPS loss.
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
2014-04-12 04:18:37 +00:00
index 1b22934..b669d05 100644
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
2014-04-12 04:18:37 +00:00
@@ -133,6 +133,7 @@ public class ChunkProviderServer implements IChunkProvider {
2014-02-12 13:48:26 +00:00
boolean newChunk = false;
if (chunk == null) {
+ org.bukkit.craftbukkit.SpigotTimings.syncChunkLoadTimer.startTiming(); // Spigot
chunk = this.loadChunk(i, j);
if (chunk == null) {
if (this.chunkProvider == null) {
2014-04-12 04:18:37 +00:00
@@ -168,6 +169,7 @@ public class ChunkProviderServer implements IChunkProvider {
2013-12-01 03:40:53 +00:00
}
// CraftBukkit end
chunk.a(this, this, i, j);
+ org.bukkit.craftbukkit.SpigotTimings.syncChunkLoadTimer.stopTiming(); // Spigot
}
2014-02-12 13:48:26 +00:00
return chunk;
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
2014-04-18 17:08:19 +00:00
index 1d0dee0..d817369 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
2014-04-18 17:08:19 +00:00
@@ -15,6 +15,7 @@ import org.bukkit.entity.Hanging;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Painting;
import org.bukkit.entity.Vehicle;
2013-06-02 01:29:44 +00: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;
import org.bukkit.event.painting.PaintingBreakByEntityEvent;
2014-04-18 17:08:19 +00:00
@@ -114,6 +115,8 @@ public abstract class Entity {
2013-07-02 03:03:56 +00:00
public boolean valid; // CraftBukkit
2014-01-31 20:42:29 +00:00
public org.bukkit.projectiles.ProjectileSource projectileSource; // CraftBukkit - For projectiles only
+ public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getEntityTimings(this); // Spigot
+
2013-12-01 03:40:53 +00:00
public int getId() {
return this.id;
}
2014-04-18 17:08:19 +00:00
@@ -426,7 +429,8 @@ public abstract class Entity {
2014-03-23 00:06:43 +00:00
if (d0 == 0 && d1 == 0 && d2 == 0 && this.vehicle == null && this.passenger == null) {
2013-12-01 03:40:53 +00:00
return;
}
2014-03-23 00:06:43 +00:00
- // CraftBukkit end
+ // CraftBukkit end
+ org.bukkit.craftbukkit.SpigotTimings.entityMoveTimer.startTiming(); // Spigot
2014-03-23 00:06:43 +00:00
if (this.X) {
this.boundingBox.d(d0, d1, d2);
this.locX = (this.boundingBox.a + this.boundingBox.d) / 2.0D;
2014-04-18 17:08:19 +00:00
@@ -735,6 +739,7 @@ public abstract class Entity {
this.world.methodProfiler.b();
}
+ org.bukkit.craftbukkit.SpigotTimings.entityMoveTimer.stopTiming(); // Spigot
}
2014-03-23 00:06:43 +00:00
protected String G() {
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2014-04-18 17:08:19 +00:00
index 17b15f6..21cf068 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2014-04-12 04:18:37 +00:00
@@ -37,6 +37,7 @@ import jline.console.ConsoleReader;
import joptsimple.OptionSet;
import org.bukkit.World.Environment;
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
import org.bukkit.craftbukkit.util.Waitable;
import org.bukkit.event.server.RemoteServerCommandEvent;
import org.bukkit.event.world.WorldSaveEvent;
2014-04-12 04:18:37 +00:00
@@ -545,6 +546,7 @@ public abstract class MinecraftServer implements ICommandListener, Runnable, IMo
2014-03-23 00:06:43 +00:00
protected void t() {}
2014-03-23 00:06:43 +00:00
protected void u() throws ExceptionWorldConflict { // CraftBukkit - added throws
+ SpigotTimings.serverTickTimer.startTiming(); // Spigot
long i = System.nanoTime();
2014-03-23 00:06:43 +00:00
++this.ticks;
2014-04-12 04:18:37 +00:00
@@ -596,6 +598,7 @@ public abstract class MinecraftServer implements ICommandListener, Runnable, IMo
2014-03-23 00:06:43 +00:00
public void v() {
this.methodProfiler.a("levels");
+ SpigotTimings.schedulerTimer.startTiming(); // Spigot
2013-03-25 07:57:00 +00:00
// CraftBukkit start
this.server.getScheduler().mainThreadHeartbeat(this.ticks);
2014-04-12 04:18:37 +00:00
@@ -604,7 +607,10 @@ public abstract class MinecraftServer implements ICommandListener, Runnable, IMo
processQueue.remove().run();
}
+ SpigotTimings.schedulerTimer.stopTiming(); // Spigot
+ SpigotTimings.chunkIOTickTimer.startTiming(); // Spigot
org.bukkit.craftbukkit.chunkio.ChunkIOExecutor.tick();
+ SpigotTimings.chunkIOTickTimer.stopTiming(); // Spigot
2013-03-25 07:57:00 +00:00
// Send time updates to everyone, it will get the right time from the world the player is in.
if (this.ticks % 20 == 0) {
2014-04-12 04:18:37 +00:00
@@ -655,7 +661,9 @@ public abstract class MinecraftServer implements ICommandListener, Runnable, IMo
this.methodProfiler.b();
this.methodProfiler.a("tracker");
+ worldserver.timings.tracker.startTiming(); // Spigot
worldserver.getTracker().updatePlayers();
+ worldserver.timings.tracker.stopTiming(); // Spigot
this.methodProfiler.b();
this.methodProfiler.b();
// } // CraftBukkit
2014-04-12 04:18:37 +00:00
@@ -664,16 +672,24 @@ public abstract class MinecraftServer implements ICommandListener, Runnable, IMo
}
this.methodProfiler.c("connection");
+ SpigotTimings.connectionTimer.startTiming(); // Spigot
2014-04-12 04:18:37 +00:00
this.ai().c();
+ SpigotTimings.connectionTimer.stopTiming(); // Spigot
this.methodProfiler.c("players");
+ SpigotTimings.playerListTimer.startTiming(); // Spigot
2014-04-12 04:18:37 +00:00
this.u.tick();
+ SpigotTimings.playerListTimer.stopTiming(); // Spigot
this.methodProfiler.c("tickables");
+ SpigotTimings.tickablesTimer.startTiming(); // Spigot
2014-04-12 04:18:37 +00:00
for (i = 0; i < this.n.size(); ++i) {
((IUpdatePlayerListBox) this.n.get(i)).a();
}
+ SpigotTimings.tickablesTimer.stopTiming(); // Spigot
this.methodProfiler.b();
+ SpigotTimings.serverTickTimer.stopTiming(); // Spigot
+ org.spigotmc.CustomTimingsHandler.tick(); // Spigot
}
public boolean getAllowNether() {
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
2014-04-18 23:15:23 +00:00
index 75a5cbe..5cde08f 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
2014-04-18 23:15:23 +00:00
@@ -940,6 +940,7 @@ public class PlayerConnection implements PacketPlayInListener {
// CraftBukkit end
private void handleCommand(String s) {
+ org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.startTiming(); // Spigot
2014-03-23 00:06:43 +00:00
// CraftBukkit start - whole method
CraftPlayer player = this.getPlayer();
2014-04-18 23:15:23 +00:00
@@ -947,19 +948,23 @@ public class PlayerConnection implements PacketPlayInListener {
this.server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
+ org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.stopTiming(); // Spigot
return;
}
try {
2014-03-23 00:06:43 +00:00
this.c.info(event.getPlayer().getName() + " issued server command: " + event.getMessage());
if (this.server.dispatchCommand(event.getPlayer(), event.getMessage().substring(1))) {
+ org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.stopTiming(); // Spigot
return;
}
} catch (org.bukkit.command.CommandException ex) {
player.sendMessage(org.bukkit.ChatColor.RED + "An internal error occurred while attempting to perform this command");
2013-03-25 07:57:00 +00:00
java.util.logging.Logger.getLogger(PlayerConnection.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.stopTiming(); // Spigot
return;
}
+ org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.stopTiming(); // Spigot
2013-12-01 03:40:53 +00:00
//this.minecraftServer.getCommandHandler().a(this.player, s);
// CraftBukkit end
2013-12-01 03:40:53 +00:00
}
diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
2014-03-23 00:06:43 +00:00
index 2a3d647..78e17d7 100644
--- a/src/main/java/net/minecraft/server/TileEntity.java
+++ b/src/main/java/net/minecraft/server/TileEntity.java
2013-12-01 03:40:53 +00:00
@@ -7,10 +7,12 @@ import java.util.concurrent.Callable;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2013-06-02 01:29:44 +00:00
+import org.spigotmc.CustomTimingsHandler; // Spigot
import org.bukkit.inventory.InventoryHolder; // CraftBukkit
public class TileEntity {
+ public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getTileEntityTimings(this); // Spigot
2013-12-01 03:40:53 +00:00
private static final Logger a = LogManager.getLogger();
private static Map i = new HashMap();
private static Map j = new HashMap();
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
2014-04-24 06:27:12 +00:00
index 1031066..6946e31 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
2014-04-24 06:27:12 +00:00
@@ -16,6 +16,7 @@ import org.bukkit.Bukkit;
import org.bukkit.block.BlockState;
2013-12-03 04:13:39 +00:00
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.util.LongHashSet;
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.craftbukkit.CraftServer;
2014-02-12 13:48:26 +00:00
import org.bukkit.craftbukkit.CraftWorld;
2014-04-24 06:27:12 +00:00
@@ -132,6 +133,8 @@ public abstract class World implements IBlockAccess {
2014-04-18 23:15:23 +00:00
public ChunkGenerator generator;
2013-06-20 08:52:23 +00:00
public final org.spigotmc.SpigotWorldConfig spigotConfig; // Spigot
+ public final SpigotTimings.WorldTimingsHandler timings; // Spigot
+
public CraftWorld getWorld() {
return this.world;
}
2014-04-24 06:27:12 +00:00
@@ -211,6 +214,7 @@ public abstract class World implements IBlockAccess {
this.a();
this.getServer().addWorld(this.world); // CraftBukkit
+ timings = new SpigotTimings.WorldTimingsHandler(this); // Spigot
}
protected abstract IChunkProvider j();
2014-04-24 06:27:12 +00:00
@@ -1314,6 +1318,7 @@ public abstract class World implements IBlockAccess {
this.f.clear();
this.methodProfiler.c("regular");
+ timings.entityTick.startTiming(); // Spigot
2014-02-12 13:48:26 +00:00
// CraftBukkit start - Use field for loop variable
for (this.tickPosition = 0; this.tickPosition < this.entityList.size(); ++this.tickPosition) {
entity = (Entity) this.entityList.get(this.tickPosition);
2014-04-24 06:27:12 +00:00
@@ -1337,7 +1342,9 @@ public abstract class World implements IBlockAccess {
this.methodProfiler.a("tick");
if (!entity.dead) {
try {
+ SpigotTimings.tickEntityTimer.startTiming(); // Spigot
this.playerJoinedWorld(entity);
+ SpigotTimings.tickEntityTimer.stopTiming(); // Spigot
} catch (Throwable throwable1) {
crashreport = CrashReport.a(throwable1, "Ticking entity");
crashreportsystemdetails = crashreport.a("Entity being ticked");
2014-04-24 06:27:12 +00:00
@@ -1362,7 +1369,9 @@ public abstract class World implements IBlockAccess {
this.methodProfiler.b();
}
+ timings.entityTick.stopTiming(); // Spigot
2013-12-01 03:40:53 +00:00
this.methodProfiler.c("blockEntities");
+ timings.tileEntityTick.startTiming(); // Spigot
2014-03-23 00:06:43 +00:00
this.M = true;
Iterator iterator = this.tileEntityList.iterator();
2014-04-24 06:27:12 +00:00
@@ -1377,8 +1386,11 @@ public abstract class World implements IBlockAccess {
if (!tileentity.r() && tileentity.o() && this.isLoaded(tileentity.x, tileentity.y, tileentity.z)) {
try {
+ tileentity.tickTimer.startTiming(); // Spigot
tileentity.h();
+ tileentity.tickTimer.stopTiming(); // Spigot
} catch (Throwable throwable2) {
+ tileentity.tickTimer.stopTiming(); // Spigot
2013-12-01 03:40:53 +00:00
crashreport = CrashReport.a(throwable2, "Ticking block entity");
crashreportsystemdetails = crashreport.a("Block entity being ticked");
tileentity.a(crashreportsystemdetails);
2014-04-24 06:27:12 +00:00
@@ -1398,6 +1410,8 @@ public abstract class World implements IBlockAccess {
}
}
+ timings.tileEntityTick.stopTiming(); // Spigot
+ timings.tileEntityPending.startTiming(); // Spigot
2014-03-23 00:06:43 +00:00
this.M = false;
if (!this.b.isEmpty()) {
this.tileEntityList.removeAll(this.b);
2014-04-24 06:27:12 +00:00
@@ -1436,6 +1450,7 @@ public abstract class World implements IBlockAccess {
this.a.clear();
}
+ timings.tileEntityPending.stopTiming(); // Spigot
this.methodProfiler.b();
this.methodProfiler.b();
}
2014-04-24 06:27:12 +00:00
@@ -1458,6 +1473,7 @@ public abstract class World implements IBlockAccess {
byte b0 = 32;
2013-12-01 03:40:53 +00:00
if (!flag || this.b(i - b0, 0, j - b0, i + b0, 0, j + b0)) {
+ entity.tickTimer.startTiming(); // Spigot
2014-03-23 00:06:43 +00:00
entity.S = entity.locX;
entity.T = entity.locY;
entity.U = entity.locZ;
2014-04-24 06:27:12 +00:00
@@ -1519,6 +1535,7 @@ public abstract class World implements IBlockAccess {
entity.passenger = null;
}
}
+ entity.tickTimer.stopTiming(); // Spigot
}
}
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
2014-04-24 06:27:12 +00:00
index 3d938d8..2dc3a13 100644
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
2014-04-24 06:27:12 +00:00
@@ -185,10 +185,13 @@ public class WorldServer extends World {
// CraftBukkit start - Only call spawner if we have players online and the world allows for mobs or animals
long time = this.worldData.getTime();
if (this.getGameRules().getBoolean("doMobSpawning") && (this.allowMonsters || this.allowAnimals) && (this instanceof WorldServer && this.players.size() > 0)) {
+ timings.mobSpawn.startTiming(); // Spigot
2013-12-01 03:40:53 +00:00
this.R.spawnEntities(this, this.allowMonsters && (this.ticksPerMonsterSpawns != 0 && time % this.ticksPerMonsterSpawns == 0L), this.allowAnimals && (this.ticksPerAnimalSpawns != 0 && time % this.ticksPerAnimalSpawns == 0L), this.worldData.getTime() % 400L == 0L);
+ timings.mobSpawn.stopTiming(); // Spigot
2014-03-23 00:06:43 +00:00
// CraftBukkit end
}
2014-03-23 00:06:43 +00:00
+ timings.doChunkUnload.startTiming(); // Spigot
this.methodProfiler.c("chunkSource");
this.chunkProvider.unloadChunks();
int j = this.a(1.0F);
2014-04-24 06:27:12 +00:00
@@ -202,21 +205,36 @@ public class WorldServer extends World {
2013-07-02 03:03:56 +00:00
this.worldData.setDayTime(this.worldData.getDayTime() + 1L);
}
+ timings.doChunkUnload.stopTiming(); // Spigot
this.methodProfiler.c("tickPending");
+ timings.doTickPending.startTiming(); // Spigot
this.a(false);
+ timings.doTickPending.stopTiming(); // Spigot
2013-12-01 03:40:53 +00:00
this.methodProfiler.c("tickBlocks");
+ timings.doTickTiles.startTiming(); // Spigot
this.g();
+ timings.doTickTiles.stopTiming(); // Spigot
this.methodProfiler.c("chunkMap");
+ timings.doChunkMap.startTiming(); // Spigot
this.manager.flush();
+ timings.doChunkMap.stopTiming(); // Spigot
this.methodProfiler.c("village");
+ timings.doVillages.startTiming(); // Spigot
this.villages.tick();
this.siegeManager.a();
+ timings.doVillages.stopTiming(); // Spigot
this.methodProfiler.c("portalForcer");
+ timings.doPortalForcer.startTiming(); // Spigot
2013-12-01 03:40:53 +00:00
this.Q.a(this.getTime());
+ timings.doPortalForcer.stopTiming(); // Spigot
this.methodProfiler.b();
+ timings.doSounds.startTiming(); // Spigot
2013-12-01 03:40:53 +00:00
this.Z();
+ timings.doSounds.stopTiming(); // Spigot
2013-07-02 03:03:56 +00:00
+ timings.doChunkGC.startTiming(); // Spigot
this.getWorld().processChunkGC(); // CraftBukkit
+ timings.doChunkGC.stopTiming(); // Spigot
}
public BiomeMeta a(EnumCreatureType enumcreaturetype, int i, int j, int k) {
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 0000000..8340c13
--- /dev/null
+++ b/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java
@@ -0,0 +1,125 @@
+package org.bukkit.craftbukkit;
+
+import net.minecraft.server.*;
2013-06-02 01:29:44 +00:00
+import org.spigotmc.CustomTimingsHandler;
+import org.bukkit.scheduler.BukkitTask;
+
+import java.util.HashMap;
+import org.bukkit.craftbukkit.scheduler.CraftTask;
+
+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 connectionTimer = new CustomTimingsHandler("Player Tick");
+ public static final CustomTimingsHandler tickablesTimer = new CustomTimingsHandler("Tickables");
+ public static final CustomTimingsHandler schedulerTimer = new CustomTimingsHandler("Scheduler");
+ public static final CustomTimingsHandler chunkIOTickTimer = new CustomTimingsHandler("ChunkIOTick");
+ public static final CustomTimingsHandler syncChunkLoadTimer = new CustomTimingsHandler("syncChunkLoad");
+
+ 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 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) {
+ String plugin = task.getOwner().getDescription().getFullName();
+ String name = "Task: " + plugin + " Runnable: " + ( (CraftTask) task ).getTaskClass().getSimpleName();
+ if (period > 0) {
+ name += "(interval:" + period +")";
+ } else {
+ name += "(Single)";
+ }
+ CustomTimingsHandler result = pluginTaskTimingMap.get(name);
+ if (result == null) {
+ result = new CustomTimingsHandler(name);
+ 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().getSimpleName();
+ CustomTimingsHandler result = entityTypeTimingMap.get(entityType);
+ if (result == null) {
+ result = new CustomTimingsHandler("** tickEntity - " + entityType, 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().getSimpleName();
+ CustomTimingsHandler result = tileEntityTypeTimingMap.get(entityType);
+ if (result == null) {
+ result = new CustomTimingsHandler("** tickTileEntity - " + entityType, 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 doChunkGC;
+ public final CustomTimingsHandler doSounds;
+ public final CustomTimingsHandler entityTick;
+ public final CustomTimingsHandler tileEntityTick;
+ public final CustomTimingsHandler tileEntityPending;
+ public final CustomTimingsHandler tracker;
+
+ 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");
+ doChunkGC = new CustomTimingsHandler(name + "doChunkGC");
+ doPortalForcer = new CustomTimingsHandler(name + "doPortalForcer");
+ entityTick = new CustomTimingsHandler(name + "entityTick");
+ tileEntityTick = new CustomTimingsHandler(name + "tileEntityTick");
+ tileEntityPending = new CustomTimingsHandler(name + "tileEntityPending");
+ tracker = new CustomTimingsHandler(name + "tracker");
+ }
+ }
+}
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java
index 55db3ff..7d294c0 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java
@@ -1,11 +1,13 @@
package org.bukkit.craftbukkit.scheduler;
import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
2013-06-02 01:29:44 +00:00
+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;
/**
@@ -22,6 +24,7 @@ class CraftTask implements BukkitTask, Runnable {
private final Plugin plugin;
private final int id;
+ CustomTimingsHandler timings = null; // Spigot
CraftTask() {
this(null, null, -1, -1);
}
@@ -50,7 +53,22 @@ class CraftTask implements BukkitTask, Runnable {
}
public void run() {
+ // Spigot start - Wrap custom timings on Tasks
+ if (!Bukkit.getServer().getPluginManager().useTimings()) {
+ task.run();
+ return;
+ }
+ if (timings == null && this.getOwner() != null && this.isSync()) {
+ timings = SpigotTimings.getPluginTaskTimings(this, period);
+ }
+ if (timings != null) {
+ timings.startTiming();
+ }
task.run();
+ if (timings != null) {
+ timings.stopTiming();
+ }
+ // Spigot end
}
long getPeriod() {
@@ -77,7 +95,7 @@ class CraftTask implements BukkitTask, Runnable {
this.next = next;
}
- Class<? extends Runnable> getTaskClass() {
+ public Class<? extends Runnable> getTaskClass() { // Spigot
return task.getClass();
}
--
2014-04-18 17:08:19 +00:00
1.9.1