From 94debd73b26dbfff556ce7f3dfc51334b48efeb3 Mon Sep 17 00:00:00 2001 From: Aikar Date: Thu, 3 Mar 2016 04:00:11 -0600 Subject: [PATCH] Timings v2 diff --git a/src/main/java/co/aikar/timings/MinecraftTimings.java b/src/main/java/co/aikar/timings/MinecraftTimings.java new file mode 100644 index 0000000000..3f9fb6f906 --- /dev/null +++ b/src/main/java/co/aikar/timings/MinecraftTimings.java @@ -0,0 +1,133 @@ +package co.aikar.timings; + +import com.google.common.collect.MapMaker; +import net.minecraft.server.*; +import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitTask; + +import org.bukkit.craftbukkit.scheduler.CraftTask; + +import java.util.Map; + +// TODO: Re-implement missing timers +public final class MinecraftTimings { + + public static final Timing playerListTimer = Timings.ofSafe("Player List"); + public static final Timing commandFunctionsTimer = Timings.ofSafe("Command Functions"); + public static final Timing connectionTimer = Timings.ofSafe("Connection Handler"); + public static final Timing tickablesTimer = Timings.ofSafe("Tickables"); + public static final Timing minecraftSchedulerTimer = Timings.ofSafe("Minecraft Scheduler"); + public static final Timing bukkitSchedulerTimer = Timings.ofSafe("Bukkit Scheduler"); + public static final Timing bukkitSchedulerPendingTimer = Timings.ofSafe("Bukkit Scheduler - Pending"); + public static final Timing bukkitSchedulerFinishTimer = Timings.ofSafe("Bukkit Scheduler - Finishing"); + public static final Timing chunkIOTickTimer = Timings.ofSafe("ChunkIOTick"); + public static final Timing timeUpdateTimer = Timings.ofSafe("Time Update"); + public static final Timing serverCommandTimer = Timings.ofSafe("Server Command"); + public static final Timing savePlayers = Timings.ofSafe("Save Players"); + + public static final Timing tickEntityTimer = Timings.ofSafe("## tickEntity"); + public static final Timing tickTileEntityTimer = Timings.ofSafe("## tickTileEntity"); + public static final Timing packetProcessTimer = Timings.ofSafe("## Packet Processing"); + public static final Timing scheduledBlocksTimer = Timings.ofSafe("## Scheduled Blocks"); + public static final Timing structureGenerationTimer = Timings.ofSafe("Structure Generation"); + + public static final Timing processQueueTimer = Timings.ofSafe("processQueue"); + + public static final Timing playerCommandTimer = Timings.ofSafe("playerCommand"); + + public static final Timing entityActivationCheckTimer = Timings.ofSafe("entityActivationCheck"); + + public static final Timing antiXrayUpdateTimer = Timings.ofSafe("anti-xray - update"); + public static final Timing antiXrayObfuscateTimer = Timings.ofSafe("anti-xray - obfuscate"); + + private static final Map, String> taskNameCache = new MapMaker().weakKeys().makeMap(); + + private MinecraftTimings() {} + + /** + * Gets a timer associated with a plugins tasks. + * @param bukkitTask + * @param period + * @return + */ + public static Timing getPluginTaskTimings(BukkitTask bukkitTask, long period) { + if (!bukkitTask.isSync()) { + return NullTimingHandler.NULL; + } + Plugin plugin; + + CraftTask craftTask = (CraftTask) bukkitTask; + + final Class taskClass = craftTask.getTaskClass(); + if (bukkitTask.getOwner() != null) { + plugin = bukkitTask.getOwner(); + } else { + plugin = TimingsManager.getPluginByClassloader(taskClass); + } + + final String taskname = taskNameCache.computeIfAbsent(taskClass, clazz -> + clazz.isAnonymousClass() || clazz.isLocalClass() + ? clazz.getName() + : clazz.getCanonicalName()); + + StringBuilder name = new StringBuilder(64); + name.append("Task: ").append(taskname); + if (period > 0) { + name.append(" (interval:").append(period).append(")"); + } else { + name.append(" (Single)"); + } + + if (plugin == null) { + return Timings.ofSafe(null, name.toString()); + } + + return Timings.ofSafe(plugin, name.toString()); + } + + /** + * Get a named timer for the specified entity type to track type specific timings. + * @param entity + * @return + */ + public static Timing getEntityTimings(Entity entity) { + String entityType = entity.getClass().getName(); + return Timings.ofSafe("Minecraft", "## tickEntity - " + entityType, tickEntityTimer); + } + + /** + * Get a named timer for the specified tile entity type to track type specific timings. + * @param entity + * @return + */ + public static Timing getTileEntityTimings(TileEntity entity) { + String entityType = entity.getClass().getName(); + return Timings.ofSafe("Minecraft", "## tickTileEntity - " + entityType, tickTileEntityTimer); + } + public static Timing getCancelTasksTimer() { + return Timings.ofSafe("Cancel Tasks"); + } + public static Timing getCancelTasksTimer(Plugin plugin) { + return Timings.ofSafe(plugin, "Cancel Tasks"); + } + + public static void stopServer() { + TimingsManager.stopServer(); + } + + public static Timing getBlockTiming(Block block) { + return Timings.ofSafe("## Scheduled Block: " + block.toString(), scheduledBlocksTimer); + } +/* + public static Timing getStructureTiming(StructureGenerator structureGenerator) { + return Timings.ofSafe("Structure Generator - " + structureGenerator.getName(), structureGenerationTimer); + }*/ + + public static Timing getPacketTiming(Packet packet) { + return Timings.ofSafe("## Packet - " + packet.getClass().getSimpleName(), packetProcessTimer); + } + + public static Timing getCommandFunctionTiming(CustomFunction function) { + return Timings.ofSafe("Command Function - " + function.getMinecraftKey().toString()); + } +} diff --git a/src/main/java/co/aikar/timings/WorldTimingsHandler.java b/src/main/java/co/aikar/timings/WorldTimingsHandler.java new file mode 100644 index 0000000000..d5d3b2a20c --- /dev/null +++ b/src/main/java/co/aikar/timings/WorldTimingsHandler.java @@ -0,0 +1,105 @@ +package co.aikar.timings; + +import net.minecraft.server.World; +import net.minecraft.server.WorldServer; + +/** + * Set of timers per world, to track world specific timings. + */ +// TODO: Re-implement missing timers +public class WorldTimingsHandler { + public final Timing mobSpawn; + public final Timing doChunkUnload; + public final Timing doPortalForcer; + public final Timing scheduledBlocks; + public final Timing scheduledBlocksCleanup; + public final Timing scheduledBlocksTicking; + public final Timing chunkTicks; + public final Timing lightChunk; + public final Timing chunkTicksBlocks; + public final Timing doVillages; + public final Timing doChunkMap; + public final Timing doChunkMapUpdate; + public final Timing doChunkMapToUpdate; + public final Timing doChunkMapSortMissing; + public final Timing doChunkMapSortSendToPlayers; + public final Timing doChunkMapPlayersNeedingChunks; + public final Timing doChunkMapPendingSendToPlayers; + public final Timing doChunkMapUnloadChunks; + public final Timing doChunkGC; + public final Timing doSounds; + public final Timing entityRemoval; + public final Timing entityTick; + public final Timing tileEntityTick; + public final Timing tileEntityPending; + public final Timing tracker1; + public final Timing tracker2; + public final Timing doTick; + public final Timing tickEntities; + + public final Timing syncChunkLoadTimer; + public final Timing syncChunkLoadDataTimer; + public final Timing syncChunkLoadStructuresTimer; + public final Timing syncChunkLoadPostTimer; + public final Timing syncChunkLoadPopulateTimer; + public final Timing chunkLoadLevelTimer; + public final Timing chunkGeneration; + public final Timing chunkIOStage1; + public final Timing chunkIOStage2; + public final Timing worldSave; + public final Timing worldSaveChunks; + public final Timing worldSaveLevel; + public final Timing chunkSaveData; + + public WorldTimingsHandler(World server) { + String name = server.worldData.getName() +" - "; + + mobSpawn = Timings.ofSafe(name + "mobSpawn"); + doChunkUnload = Timings.ofSafe(name + "doChunkUnload"); + scheduledBlocks = Timings.ofSafe(name + "Scheduled Blocks"); + scheduledBlocksCleanup = Timings.ofSafe(name + "Scheduled Blocks - Cleanup"); + scheduledBlocksTicking = Timings.ofSafe(name + "Scheduled Blocks - Ticking"); + chunkTicks = Timings.ofSafe(name + "Chunk Ticks"); + lightChunk = Timings.ofSafe(name + "Light Chunk"); + chunkTicksBlocks = Timings.ofSafe(name + "Chunk Ticks - Blocks"); + doVillages = Timings.ofSafe(name + "doVillages"); + doChunkMap = Timings.ofSafe(name + "doChunkMap"); + doChunkMapUpdate = Timings.ofSafe(name + "doChunkMap - Update"); + doChunkMapToUpdate = Timings.ofSafe(name + "doChunkMap - To Update"); + doChunkMapSortMissing = Timings.ofSafe(name + "doChunkMap - Sort Missing"); + doChunkMapSortSendToPlayers = Timings.ofSafe(name + "doChunkMap - Sort Send To Players"); + doChunkMapPlayersNeedingChunks = Timings.ofSafe(name + "doChunkMap - Players Needing Chunks"); + doChunkMapPendingSendToPlayers = Timings.ofSafe(name + "doChunkMap - Pending Send To Players"); + doChunkMapUnloadChunks = Timings.ofSafe(name + "doChunkMap - Unload Chunks"); + doSounds = Timings.ofSafe(name + "doSounds"); + doChunkGC = Timings.ofSafe(name + "doChunkGC"); + doPortalForcer = Timings.ofSafe(name + "doPortalForcer"); + entityTick = Timings.ofSafe(name + "entityTick"); + entityRemoval = Timings.ofSafe(name + "entityRemoval"); + tileEntityTick = Timings.ofSafe(name + "tileEntityTick"); + tileEntityPending = Timings.ofSafe(name + "tileEntityPending"); + + syncChunkLoadTimer = Timings.ofSafe(name + "syncChunkLoad"); + syncChunkLoadDataTimer = Timings.ofSafe(name + "syncChunkLoad - Data"); + syncChunkLoadStructuresTimer = Timings.ofSafe(name + "chunkLoad - recreateStructures"); + syncChunkLoadPostTimer = Timings.ofSafe(name + "chunkLoad - Post"); + syncChunkLoadPopulateTimer = Timings.ofSafe(name + "chunkLoad - Populate"); + chunkLoadLevelTimer = Timings.ofSafe(name + "chunkLoad - Load Level"); + chunkGeneration = Timings.ofSafe(name + "chunkGeneration"); + chunkIOStage1 = Timings.ofSafe(name + "ChunkIO Stage 1 - DiskIO"); + chunkIOStage2 = Timings.ofSafe(name + "ChunkIO Stage 2 - Post Load"); + worldSave = Timings.ofSafe(name + "World Save"); + worldSaveLevel = Timings.ofSafe(name + "World Save - Level"); + worldSaveChunks = Timings.ofSafe(name + "World Save - Chunks"); + chunkSaveData = Timings.ofSafe(name + "Chunk Save - Data"); + + tracker1 = Timings.ofSafe(name + "tracker stage 1"); + tracker2 = Timings.ofSafe(name + "tracker stage 2"); + doTick = Timings.ofSafe(name + "doTick"); + tickEntities = Timings.ofSafe(name + "tickEntities"); + } + + public static Timing getTickList(WorldServer worldserver, String timingsType) { + return Timings.ofSafe(worldserver.getWorldData().getName() + " - Scheduled " + timingsType); + } +} diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java index 5518ec1e54..0c65afccfd 100644 --- a/src/main/java/com/destroystokyo/paper/PaperConfig.java +++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java @@ -14,11 +14,14 @@ import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.regex.Pattern; +import com.google.common.collect.Lists; import net.minecraft.server.MinecraftServer; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; +import co.aikar.timings.Timings; +import co.aikar.timings.TimingsManager; public class PaperConfig { @@ -187,4 +190,27 @@ public class PaperConfig { config.addDefault(path, def); return config.getString(path, config.getString(path)); } + + public static String timingsServerName; + private static void timings() { + boolean timings = getBoolean("timings.enabled", true); + boolean verboseTimings = getBoolean("timings.verbose", true); + TimingsManager.privacy = getBoolean("timings.server-name-privacy", false); + TimingsManager.hiddenConfigs = getList("timings.hidden-config-entries", Lists.newArrayList("database", "settings.bungeecord-addresses")); + int timingHistoryInterval = getInt("timings.history-interval", 300); + int timingHistoryLength = getInt("timings.history-length", 3600); + timingsServerName = getString("timings.server-name", "Unknown Server"); + + + Timings.setVerboseTimingsEnabled(verboseTimings); + Timings.setTimingsEnabled(timings); + Timings.setHistoryInterval(timingHistoryInterval * 20); + Timings.setHistoryLength(timingHistoryLength * 20); + + log("Timings: " + timings + + " - Verbose: " + verboseTimings + + " - Interval: " + timeSummary(Timings.getHistoryInterval() / 20) + + " - Length: " + timeSummary(Timings.getHistoryLength() / 20) + + " - Server Name: " + timingsServerName); + } } diff --git a/src/main/java/net/minecraft/server/Block.java b/src/main/java/net/minecraft/server/Block.java index 8b91e27c66..fd23d45346 100644 --- a/src/main/java/net/minecraft/server/Block.java +++ b/src/main/java/net/minecraft/server/Block.java @@ -24,6 +24,15 @@ public class Block implements IMaterial { protected final boolean q; protected final SoundEffectType stepSound; protected final Material material; + // Paper start + public co.aikar.timings.Timing timing; + public co.aikar.timings.Timing getTiming() { + if (timing == null) { + timing = co.aikar.timings.MinecraftTimings.getBlockTiming(this); + } + return timing; + } + // Paper end protected final MaterialMapColor t; private final float frictionFactor; protected final BlockStateList blockStateList; diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java index 9cce929c3e..5c34fe52a4 100644 --- a/src/main/java/net/minecraft/server/Chunk.java +++ b/src/main/java/net/minecraft/server/Chunk.java @@ -546,6 +546,7 @@ public class Chunk implements IChunkAccess { server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkLoadEvent(this.bukkitChunk, this.needsDecoration)); if (this.needsDecoration) { + this.world.timings.syncChunkLoadPopulateTimer.startTiming(); // Paper java.util.Random random = new java.util.Random(); random.setSeed(world.getSeed()); long xRand = random.nextLong() / 2L * 2L + 1L; @@ -564,6 +565,7 @@ public class Chunk implements IChunkAccess { } } server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkPopulateEvent(bukkitChunk)); + this.world.timings.syncChunkLoadPopulateTimer.stopTiming(); // Paper } } } diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java index 845ad7427b..4f0fbe4a0d 100644 --- a/src/main/java/net/minecraft/server/ChunkProviderServer.java +++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java @@ -186,7 +186,9 @@ public class ChunkProviderServer extends IChunkProvider { } public void save(boolean flag) { + try (co.aikar.timings.Timing timed = world.timings.chunkSaveData.startTiming()) { // Paper - Timings this.playerChunkMap.save(flag); + } // Paper - Timings } @Override @@ -296,10 +298,9 @@ public class ChunkProviderServer extends IChunkProvider { this.world.timings.mobSpawn.stopTiming(); // Spigot this.world.getMethodProfiler().exit(); } - - this.world.timings.doTickTiles.startTiming(); // Spigot + this.world.timings.chunkTicks.startTiming(); // Spigot // Paper this.world.a(chunk, l); - this.world.timings.doTickTiles.stopTiming(); // Spigot + this.world.timings.chunkTicks.stopTiming(); // Spigot // Paper } } } @@ -310,9 +311,7 @@ public class ChunkProviderServer extends IChunkProvider { } } - 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 d084d24a01..0fed039f34 100644 --- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java +++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java @@ -1,5 +1,6 @@ package net.minecraft.server; +import co.aikar.timings.Timings; import com.google.common.collect.Maps; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import it.unimi.dsi.fastutil.longs.LongSet; @@ -412,7 +413,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 + world.timings.chunkLoadLevelTimer.startTiming(); // Spigot for (int i = 0; i < nbttaglist.size(); ++i) { NBTTagCompound nbttagcompound1 = nbttaglist.getCompound(i); @@ -424,8 +425,6 @@ 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) { @@ -442,8 +441,6 @@ public class ChunkRegionLoader { } } } - world.timings.syncChunkLoadTileEntitiesTimer.stopTiming(); // Spigot - world.timings.syncChunkLoadTileTicksTimer.startTiming(); // Spigot if (nbttagcompound.hasKeyOfType("TileTicks", 9) && world.getBlockTickList() instanceof TickListServer) { ((TickListServer) world.getBlockTickList()).a(nbttagcompound.getList("TileTicks", 10)); @@ -452,7 +449,7 @@ public class ChunkRegionLoader { if (nbttagcompound.hasKeyOfType("LiquidTicks", 9) && world.getFluidTickList() instanceof TickListServer) { ((TickListServer) world.getFluidTickList()).a(nbttagcompound.getList("LiquidTicks", 10)); } - world.timings.syncChunkLoadTileTicksTimer.stopTiming(); // Spigot + world.timings.chunkLoadLevelTimer.stopTiming(); // Spigot } diff --git a/src/main/java/net/minecraft/server/CustomFunction.java b/src/main/java/net/minecraft/server/CustomFunction.java index 46e7737ca3..a3ef943066 100644 --- a/src/main/java/net/minecraft/server/CustomFunction.java +++ b/src/main/java/net/minecraft/server/CustomFunction.java @@ -13,12 +13,22 @@ public class CustomFunction { private final CustomFunction.c[] a; private final MinecraftKey b; + // Paper start + public co.aikar.timings.Timing timing; + public co.aikar.timings.Timing getTiming() { + if (timing == null) { + timing = co.aikar.timings.MinecraftTimings.getCommandFunctionTiming(this); + } + return timing; + } + // Paper end public CustomFunction(MinecraftKey minecraftkey, CustomFunction.c[] acustomfunction_c) { this.b = minecraftkey; this.a = acustomfunction_c; } + public MinecraftKey getMinecraftKey() { return this.a(); } // Paper - OBFHELPER public MinecraftKey a() { return this.b; } diff --git a/src/main/java/net/minecraft/server/CustomFunctionData.java b/src/main/java/net/minecraft/server/CustomFunctionData.java index 42e01136d9..b7c1d7671e 100644 --- a/src/main/java/net/minecraft/server/CustomFunctionData.java +++ b/src/main/java/net/minecraft/server/CustomFunctionData.java @@ -100,7 +100,7 @@ public class CustomFunctionData implements IResourcePackListener { return 0; } else { - try { + try (co.aikar.timings.Timing timing = customfunction.getTiming().startTiming()) { // Paper this.i = true; int j = 0; CustomFunction.c[] acustomfunction_c = customfunction.b(); diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java index b60956218d..19e2df3098 100644 --- a/src/main/java/net/minecraft/server/DedicatedServer.java +++ b/src/main/java/net/minecraft/server/DedicatedServer.java @@ -31,7 +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 co.aikar.timings.MinecraftTimings; // Paper import org.bukkit.event.server.ServerCommandEvent; import org.bukkit.craftbukkit.util.Waitable; import org.bukkit.event.server.RemoteServerCommandEvent; @@ -428,7 +428,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer } public void handleCommandQueue() { - SpigotTimings.serverCommandTimer.startTiming(); // Spigot + MinecraftTimings.serverCommandTimer.startTiming(); // Spigot while (!this.serverCommandQueue.isEmpty()) { ServerCommand servercommand = (ServerCommand) this.serverCommandQueue.remove(0); @@ -443,7 +443,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer // CraftBukkit end } - SpigotTimings.serverCommandTimer.stopTiming(); // Spigot + MinecraftTimings.serverCommandTimer.stopTiming(); // Spigot } @Override @@ -681,7 +681,20 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer return remoteControlCommandListener.getMessages(); } }; - processQueue.add(waitable); + // Paper start + if (s.toLowerCase().startsWith("timings") && s.toLowerCase().matches("timings (report|paste|get|merged|seperate)")) { + org.bukkit.command.BufferedCommandSender sender = new org.bukkit.command.BufferedCommandSender(); + waitable = new Waitable() { + @Override + protected String evaluate() { + return sender.getBuffer(); + } + }; + co.aikar.timings.Timings.generateReport(new co.aikar.timings.TimingsReportListener(sender, waitable)); + } else { + processQueue.add(waitable); + } + // Paper end try { return waitable.get(); } catch (java.util.concurrent.ExecutionException e) { diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java index 14c3f04170..6127f9ba96 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -29,7 +29,8 @@ 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 co.aikar.timings.MinecraftTimings; // Paper +import co.aikar.timings.Timing; // Paper import org.bukkit.event.entity.EntityCombustByEntityEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.vehicle.VehicleBlockCollisionEvent; @@ -161,7 +162,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke 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 Timing tickTimer = MinecraftTimings.getEntityTimings(this); // Paper // Spigot start public final byte activationType = org.spigotmc.ActivationRange.initializeEntityActivationType(this); public final boolean defaultActivationState; @@ -483,7 +484,6 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke } 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(); @@ -648,7 +648,6 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke 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 f86e6a4c51..85567a7072 100644 --- a/src/main/java/net/minecraft/server/EntityLiving.java +++ b/src/main/java/net/minecraft/server/EntityLiving.java @@ -35,7 +35,7 @@ import org.bukkit.event.entity.EntityTeleportEvent; import org.bukkit.event.player.PlayerItemConsumeEvent; // CraftBukkit end -import org.bukkit.craftbukkit.SpigotTimings; // Spigot +import co.aikar.timings.MinecraftTimings; // Paper public abstract class EntityLiving extends Entity { @@ -2208,7 +2208,6 @@ public abstract class EntityLiving extends Entity { @Override public void tick() { - SpigotTimings.timerEntityBaseTick.startTiming(); // Spigot super.tick(); this.dk(); this.o(); @@ -2283,9 +2282,7 @@ 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); @@ -2365,8 +2362,6 @@ public abstract class EntityLiving extends Entity { if (this.isSleeping()) { this.pitch = 0.0F; } - - SpigotTimings.timerEntityTickRest.stopTiming(); // Spigot } protected float e(float f, float f1) { @@ -2440,7 +2435,6 @@ 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; @@ -2451,7 +2445,6 @@ 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"); @@ -2476,9 +2469,7 @@ 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) { @@ -2486,9 +2477,7 @@ 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 472e8e852f..df9098955c 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -1,5 +1,7 @@ package net.minecraft.server; +import co.aikar.timings.Timings; +import com.google.common.base.Stopwatch; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.gson.JsonElement; @@ -54,8 +56,8 @@ import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.Main; import org.bukkit.event.server.ServerLoadEvent; // CraftBukkit end -import org.bukkit.craftbukkit.SpigotTimings; // Spigot import org.spigotmc.SlackActivityAccountant; // Spigot +import co.aikar.timings.MinecraftTimings; // Paper public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant implements IMojangStatistics, ICommandListener, AutoCloseable, Runnable { @@ -671,6 +673,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant 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"); @@ -999,29 +1000,28 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant { - return (CompletableFuture) either.map((list) -> { + return either.map((list) -> { // Paper - Shut up. try { CompletableFuture> completablefuture1 = chunkstatus.a(this.world, this.chunkGenerator, this.definedStructureManager, this.lightEngine, (ichunkaccess) -> { return this.b(playerchunk); @@ -879,6 +881,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { PlayerChunkMap.EntityTracker playerchunkmap_entitytracker; ObjectIterator objectiterator; + world.timings.tracker1.startTiming(); // Paper for (objectiterator = this.trackedEntities.values().iterator(); objectiterator.hasNext(); playerchunkmap_entitytracker.trackerEntry.a()) { playerchunkmap_entitytracker = (PlayerChunkMap.EntityTracker) objectiterator.next(); @@ -896,13 +899,16 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { playerchunkmap_entitytracker.e = sectionposition1; } } + world.timings.tracker1.stopTiming(); // Paper objectiterator = this.trackedEntities.values().iterator(); + world.timings.tracker2.startTiming(); // Paper while (objectiterator.hasNext()) { playerchunkmap_entitytracker = (PlayerChunkMap.EntityTracker) objectiterator.next(); playerchunkmap_entitytracker.track(list); } + world.timings.tracker2.stopTiming(); // Paper } diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java index 78a090ac75..e07f4a9680 100644 --- a/src/main/java/net/minecraft/server/PlayerConnection.java +++ b/src/main/java/net/minecraft/server/PlayerConnection.java @@ -58,6 +58,7 @@ import org.bukkit.inventory.CraftingInventory; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.InventoryView; import org.bukkit.util.NumberConversions; +import co.aikar.timings.MinecraftTimings; // Paper // CraftBukkit end public class PlayerConnection implements PacketListenerPlayIn { @@ -135,7 +136,6 @@ 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); @@ -208,7 +208,6 @@ 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 } @@ -1647,7 +1646,7 @@ public class PlayerConnection implements PacketListenerPlayIn { // CraftBukkit end private void handleCommand(String s) { - org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.startTiming(); // Spigot + MinecraftTimings.playerCommandTimer.startTiming(); // Paper // CraftBukkit start - whole method if ( org.spigotmc.SpigotConfig.logCommands ) // Spigot this.LOGGER.info(this.player.getName() + " issued server command: " + s); @@ -1658,7 +1657,7 @@ public class PlayerConnection implements PacketListenerPlayIn { this.server.getPluginManager().callEvent(event); if (event.isCancelled()) { - org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.stopTiming(); // Spigot + MinecraftTimings.playerCommandTimer.stopTiming(); // Paper return; } @@ -1671,7 +1670,7 @@ public class PlayerConnection implements PacketListenerPlayIn { 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 + MinecraftTimings.playerCommandTimer.stopTiming(); // Paper } // this.minecraftServer.getCommandDispatcher().a(this.player.getCommandListener(), s); // CraftBukkit end diff --git a/src/main/java/net/minecraft/server/PlayerConnectionUtils.java b/src/main/java/net/minecraft/server/PlayerConnectionUtils.java index cb6d50ea70..9ba03f8ed0 100644 --- a/src/main/java/net/minecraft/server/PlayerConnectionUtils.java +++ b/src/main/java/net/minecraft/server/PlayerConnectionUtils.java @@ -1,5 +1,8 @@ package net.minecraft.server; +import co.aikar.timings.MinecraftTimings; // Paper +import co.aikar.timings.Timing; // Paper + public class PlayerConnectionUtils { public static void ensureMainThread(Packet packet, T t0, WorldServer worldserver) throws CancelledPacketHandleException { @@ -8,9 +11,12 @@ public class PlayerConnectionUtils { public static void ensureMainThread(Packet packet, T t0, IAsyncTaskHandler iasynctaskhandler) throws CancelledPacketHandleException { if (!iasynctaskhandler.isMainThread()) { + Timing timing = MinecraftTimings.getPacketTiming(packet); // Paper iasynctaskhandler.execute(() -> { if (MinecraftServer.getServer().hasStopped() || (t0 instanceof PlayerConnection && ((PlayerConnection) t0).processedDisconnect)) return; // CraftBukkit, MC-142590 + try (Timing ignored = timing.startTiming()) { // Paper packet.a(t0); + } // Paper - timings }); throw CancelledPacketHandleException.INSTANCE; } diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java index 56e36c8668..7a837ec0fc 100644 --- a/src/main/java/net/minecraft/server/PlayerList.java +++ b/src/main/java/net/minecraft/server/PlayerList.java @@ -1,5 +1,6 @@ package net.minecraft.server; +import co.aikar.timings.MinecraftTimings; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; @@ -894,10 +895,11 @@ public abstract class PlayerList { } public void savePlayers() { + MinecraftTimings.savePlayers.startTiming(); // Paper for (int i = 0; i < this.players.size(); ++i) { this.savePlayerFile((EntityPlayer) this.players.get(i)); } - + MinecraftTimings.savePlayers.stopTiming(); // Paper } public WhiteList getWhitelist() { diff --git a/src/main/java/net/minecraft/server/TickListServer.java b/src/main/java/net/minecraft/server/TickListServer.java index 537e610797..b48e5b51a0 100644 --- a/src/main/java/net/minecraft/server/TickListServer.java +++ b/src/main/java/net/minecraft/server/TickListServer.java @@ -25,13 +25,19 @@ public class TickListServer implements TickList { private final List> g = Lists.newArrayList(); private final Consumer> h; - public TickListServer(WorldServer worldserver, Predicate predicate, Function function, Function function1, Consumer> consumer) { + public TickListServer(WorldServer worldserver, Predicate predicate, Function function, Function function1, Consumer> consumer, String timingsType) { // Paper this.a = predicate; this.b = function; this.c = function1; this.f = worldserver; this.h = consumer; + // Paper start + timingCleanup = co.aikar.timings.WorldTimingsHandler.getTickList(worldserver, timingsType + " - Cleanup"); + timingTicking = co.aikar.timings.WorldTimingsHandler.getTickList(worldserver, timingsType + " - Ticking"); } + private final co.aikar.timings.Timing timingCleanup; // Paper + private final co.aikar.timings.Timing timingTicking; // Paper + // Paper end public void a() { int i = this.nextTickList.size(); @@ -51,6 +57,7 @@ public class TickListServer implements TickList { this.f.getMethodProfiler().enter("cleaning"); + timingCleanup.startTiming(); // Paper NextTickListEntry nextticklistentry; // CraftBukkit - decompile error for (int j = 0; j < i; ++j) { @@ -63,9 +70,11 @@ public class TickListServer implements TickList { // this.nextTickListHash.remove(nextticklistentry); // CraftBukkit - use nextTickList this.g.add(nextticklistentry); } + timingCleanup.stopTiming(); // Paper this.f.getMethodProfiler().exit(); this.f.getMethodProfiler().enter("ticking"); + timingTicking.startTiming(); // Paper Iterator iterator = this.g.iterator(); while (iterator.hasNext()) { @@ -88,6 +97,7 @@ public class TickListServer implements TickList { this.f.getMethodProfiler().exit(); this.g.clear(); + timingTicking.stopTiming(); // Paper } } diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java index 4c811325c3..da30d2cf86 100644 --- a/src/main/java/net/minecraft/server/TileEntity.java +++ b/src/main/java/net/minecraft/server/TileEntity.java @@ -8,11 +8,12 @@ import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer; import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry; import org.bukkit.inventory.InventoryHolder; // CraftBukkit end -import org.spigotmc.CustomTimingsHandler; // Spigot +import co.aikar.timings.MinecraftTimings; // Paper +import co.aikar.timings.Timing; // Paper public abstract class TileEntity implements KeyedObject { // Paper - public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getTileEntityTimings(this); // Spigot + public Timing tickTimer = MinecraftTimings.getTileEntityTimings(this); // Paper // CraftBukkit start - data containers private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry(); public final CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY); diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java index cbe87a3389..db50066096 100644 --- a/src/main/java/net/minecraft/server/World.java +++ b/src/main/java/net/minecraft/server/World.java @@ -1,5 +1,7 @@ package net.minecraft.server; +import co.aikar.timings.Timing; +import co.aikar.timings.Timings; import com.google.common.collect.Lists; import java.io.IOException; import java.util.Collection; @@ -20,7 +22,6 @@ 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; @@ -88,7 +89,7 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose public final com.destroystokyo.paper.PaperWorldConfig paperConfig; // Paper - public final SpigotTimings.WorldTimingsHandler timings; // Spigot + public final co.aikar.timings.WorldTimingsHandler timings; // Paper public static BlockPosition lastPhysicsProblem; // Spigot private org.spigotmc.TickLimiter entityLimiter; private org.spigotmc.TickLimiter tileLimiter; @@ -150,7 +151,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 + timings = new co.aikar.timings.WorldTimingsHandler(this); // Paper - code below can generate new world and access timings this.entityLimiter = new org.spigotmc.TickLimiter(spigotConfig.entityMaxTickTime); this.tileLimiter = new org.spigotmc.TickLimiter(spigotConfig.tileMaxTickTime); } @@ -734,14 +735,14 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose } timings.tileEntityPending.stopTiming(); // Spigot + co.aikar.timings.TimingHistory.tileEntityTicks += this.tileEntityListTick.size(); // Paper gameprofilerfiller.exit(); spigotConfig.currentPrimedTnt = 0; // Spigot } public void a(Consumer consumer, Entity entity) { try { - // Spigot start - SpigotTimings.tickEntityTimer.startTiming(); + timings.tickEntities.startTiming(); entity.tickTimer.startTiming(); // Spigot end consumer.accept(entity); @@ -755,7 +756,7 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose // Spigot start finally { entity.tickTimer.stopTiming(); - SpigotTimings.tickEntityTimer.startTiming(); + timings.tickEntities.stopTiming(); } // Spigot end } diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java index d08c5fc93b..a8527784ae 100644 --- a/src/main/java/net/minecraft/server/WorldServer.java +++ b/src/main/java/net/minecraft/server/WorldServer.java @@ -1,5 +1,7 @@ package net.minecraft.server; +import co.aikar.timings.TimingHistory; +import co.aikar.timings.Timings; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Queues; @@ -37,7 +39,6 @@ import org.bukkit.Bukkit; import org.bukkit.WeatherType; import org.bukkit.block.BlockState; -import org.bukkit.craftbukkit.SpigotTimings; // Spigot import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.craftbukkit.util.HashTreeSet; @@ -99,10 +100,10 @@ public class WorldServer extends World { // CraftBukkit end this.nextTickListBlock = new TickListServer<>(this, (block) -> { return block == null || block.getBlockData().isAir(); - }, IRegistry.BLOCK::getKey, IRegistry.BLOCK::get, this::b); + }, IRegistry.BLOCK::getKey, IRegistry.BLOCK::get, this::b, "Blocks"); // Paper - Timings this.nextTickListFluid = new TickListServer<>(this, (fluidtype) -> { return fluidtype == null || fluidtype == FluidTypes.EMPTY; - }, IRegistry.FLUID::getKey, IRegistry.FLUID::get, this::a); + }, IRegistry.FLUID::getKey, IRegistry.FLUID::get, this::a, "Fluids"); // Paper - Timings this.I = Sets.newHashSet(); this.siegeManager = new VillageSiege(this); this.J = new ObjectLinkedOpenHashSet(); @@ -265,12 +266,12 @@ public class WorldServer extends World { gameprofilerfiller.exitEnter("chunkSource"); this.getChunkProvider().tick(booleansupplier); gameprofilerfiller.exitEnter("tickPending"); - timings.doTickPending.startTiming(); // Spigot + timings.scheduledBlocks.startTiming(); // Spigot if (this.worldData.getType() != WorldType.DEBUG_ALL_BLOCK_STATES) { this.nextTickListBlock.a(); this.nextTickListFluid.a(); } - timings.doTickPending.stopTiming(); // Spigot + timings.scheduledBlocks.stopTiming(); // Spigot gameprofilerfiller.exitEnter("village"); timings.doVillages.startTiming(); // Spigot @@ -327,6 +328,7 @@ public class WorldServer extends World { org.spigotmc.ActivationRange.activateEntities(this); // Spigot timings.entityTick.startTiming(); // Spigot + TimingHistory.entityTicks += this.globalEntityList.size(); // Paper while (objectiterator.hasNext()) { Entry entry = (Entry) objectiterator.next(); Entity entity1 = (Entity) entry.getValue(); @@ -430,6 +432,7 @@ public class WorldServer extends World { } gameprofilerfiller.exitEnter("tickBlocks"); + timings.chunkTicksBlocks.startTiming(); // Paper if (i > 0) { ChunkSection[] achunksection = chunk.getSections(); int l = achunksection.length; @@ -461,7 +464,7 @@ public class WorldServer extends World { } } } - + timings.chunkTicksBlocks.stopTiming(); // Paper gameprofilerfiller.exit(); } @@ -754,6 +757,7 @@ public class WorldServer extends World { if (!flag1) { org.bukkit.Bukkit.getPluginManager().callEvent(new org.bukkit.event.world.WorldSaveEvent(getWorld())); // CraftBukkit + try (co.aikar.timings.Timing ignored = timings.worldSave.startTiming()) { // Paper if (iprogressupdate != null) { iprogressupdate.a(new ChatMessage("menu.savingLevel", new Object[0])); } @@ -763,7 +767,10 @@ public class WorldServer extends World { iprogressupdate.c(new ChatMessage("menu.savingChunks", new Object[0])); } + timings.worldSaveChunks.startTiming(); // Paper chunkproviderserver.save(flag); + timings.worldSaveChunks.stopTiming(); // Paper + } // Paper } } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 5dc2bb1246..8e877055c3 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -1926,12 +1926,31 @@ public final class CraftServer implements Server { private final Spigot spigot = new Spigot() { + @Deprecated @Override public YamlConfiguration getConfig() { return org.spigotmc.SpigotConfig.config; } + @Override + public YamlConfiguration getBukkitConfig() + { + return configuration; + } + + @Override + public YamlConfiguration getSpigotConfig() + { + return org.spigotmc.SpigotConfig.config; + } + + @Override + public YamlConfiguration getPaperConfig() + { + return com.destroystokyo.paper.PaperConfig.config; + } + @Override public void restart() { org.spigotmc.RestartCommand.restart(); diff --git a/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java b/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java deleted file mode 100644 index 38f211526b..0000000000 --- a/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java +++ /dev/null @@ -1,166 +0,0 @@ -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 CustomTimingsHandler entityActivationCheckTimer = new CustomTimingsHandler("entityActivationCheck"); - public static final CustomTimingsHandler checkIfActiveTimer = new CustomTimingsHandler("** checkIfActive"); - - public static final HashMap entityTypeTimingMap = new HashMap(); - public static final HashMap tileEntityTypeTimingMap = new HashMap(); - public static final HashMap pluginTaskTimingMap = new HashMap(); - - /** - * 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/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 6806ada495..e45fd0028b 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -1728,6 +1728,14 @@ public class CraftPlayer extends CraftHumanEntity implements Player { packet.components = components; getHandle().playerConnection.sendPacket(packet); } + + // Paper start + @Override + public int getPing() + { + return getHandle().ping; + } + // Paper end }; public Player.Spigot spigot() diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java index b90979c7ba..8823f94f7b 100644 --- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java +++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java @@ -1,5 +1,6 @@ package org.bukkit.craftbukkit.scheduler; +import co.aikar.timings.MinecraftTimings; // Paper import com.google.common.util.concurrent.ThreadFactoryBuilder; import java.util.ArrayList; import java.util.Comparator; @@ -248,7 +249,7 @@ public class CraftScheduler implements BukkitScheduler { } } return false; - }}); + }}){{this.timings=co.aikar.timings.MinecraftTimings.getCancelTasksTimer();}}; // Paper handle(task, 0L); for (CraftTask taskPending = head.getNext(); taskPending != null; taskPending = taskPending.getNext()) { if (taskPending == task) { @@ -283,7 +284,7 @@ public class CraftScheduler implements BukkitScheduler { } } } - }); + }){{this.timings=co.aikar.timings.MinecraftTimings.getCancelTasksTimer(plugin);}}; // Paper handle(task, 0L); for (CraftTask taskPending = head.getNext(); taskPending != null; taskPending = taskPending.getNext()) { if (taskPending == task) { @@ -390,9 +391,7 @@ 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, @@ -419,8 +418,10 @@ public class CraftScheduler implements BukkitScheduler { runners.remove(task.getTaskId()); } } + MinecraftTimings.bukkitSchedulerFinishTimer.startTiming(); pending.addAll(temp); temp.clear(); + MinecraftTimings.bukkitSchedulerFinishTimer.stopTiming(); debugHead = debugHead.getNextHead(currentTick); } @@ -453,6 +454,7 @@ public class CraftScheduler implements BukkitScheduler { } private void parsePending() { + MinecraftTimings.bukkitSchedulerPendingTimer.startTiming(); CraftTask head = this.head; CraftTask task = head.getNext(); CraftTask lastTask = head; @@ -471,6 +473,7 @@ public class CraftScheduler implements BukkitScheduler { task.setNext(null); } this.head = lastTask; + MinecraftTimings.bukkitSchedulerPendingTimer.stopTiming(); } private boolean isReady(final int currentTick) { diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java index 3f55381c15..0d9a466809 100644 --- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java +++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java @@ -1,9 +1,11 @@ package org.bukkit.craftbukkit.scheduler; import java.util.function.Consumer; + +import co.aikar.timings.NullTimingHandler; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.SpigotTimings; // Spigot -import org.spigotmc.CustomTimingsHandler; // Spigot +import co.aikar.timings.MinecraftTimings; // Paper +import co.aikar.timings.Timing; // Paper import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitTask; @@ -26,12 +28,12 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot */ private volatile long period; private long nextRun; - private final Runnable rTask; - private final Consumer cTask; + public final Runnable rTask; // Paper + public final Consumer cTask; // Paper + public Timing timings; // Paper private final Plugin plugin; private final int id; - final CustomTimingsHandler timings; // Spigot CraftTask() { this(null, null, CraftTask.NO_REPEATING, CraftTask.NO_REPEATING); } @@ -40,7 +42,7 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot this(null, task, CraftTask.NO_REPEATING, CraftTask.NO_REPEATING); } - CraftTask(final Plugin plugin, final Object task, final int id, final long period) { + CraftTask(final Plugin plugin, final Object task, final int id, final long period) { // Paper this.plugin = plugin; if (task instanceof Runnable) { this.rTask = (Runnable) task; @@ -57,7 +59,7 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot } this.id = id; this.period = period; - this.timings = this.isSync() ? SpigotTimings.getPluginTaskTimings(this, period) : null; // Spigot + timings = task != null ? MinecraftTimings.getPluginTaskTimings(this, period) : NullTimingHandler.NULL; // Paper } @Override @@ -77,11 +79,13 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot @Override public void run() { + try (Timing ignored = timings.startTiming()) { // Paper if (rTask != null) { rTask.run(); } else { cTask.accept(this); } + } // Paper } long getPeriod() { @@ -108,7 +112,7 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot this.next = next; } - Class getTaskClass() { + public Class getTaskClass() { return (rTask != null) ? rTask.getClass() : ((cTask != null) ? cTask.getClass() : null); } @@ -132,9 +136,4 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot return true; } - // Spigot start - public String getTaskName() { - return (getTaskClass() == null) ? "Unknown" : getTaskClass().getName(); - } - // Spigot end } diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftIconCache.java b/src/main/java/org/bukkit/craftbukkit/util/CraftIconCache.java index e52ef47b78..3d90b34268 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftIconCache.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftIconCache.java @@ -5,6 +5,7 @@ import org.bukkit.util.CachedServerIcon; public class CraftIconCache implements CachedServerIcon { public final String value; + public String getData() { return value; } // Paper public CraftIconCache(final String value) { this.value = value; } diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java index 06728e53d5..783676b747 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java @@ -271,6 +271,13 @@ public final class CraftMagicNumbers implements UnsafeValues { return clazz; } + // Paper start + @Override + public String getTimingsServerName() { + return com.destroystokyo.paper.PaperConfig.timingsServerName; + } + // Paper end + /** * This helper class represents the different NBT Tags. *

diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java index 76b060a126..2daecf5049 100644 --- a/src/main/java/org/spigotmc/ActivationRange.java +++ b/src/main/java/org/spigotmc/ActivationRange.java @@ -30,7 +30,7 @@ import net.minecraft.server.EntityWither; import net.minecraft.server.MathHelper; import net.minecraft.server.MinecraftServer; import net.minecraft.server.World; -import org.bukkit.craftbukkit.SpigotTimings; +import co.aikar.timings.MinecraftTimings; public class ActivationRange { @@ -64,8 +64,8 @@ public class ActivationRange /** * These entities are excluded from Activation range checks. * - * @param entity - * @param world + * @param entity Entity to initialize + * @param config Spigot config to determine ranges * @return boolean If it should always tick. */ public static boolean initializeEntityActivationState(Entity entity, SpigotWorldConfig config) @@ -99,7 +99,7 @@ public class ActivationRange */ public static void activateEntities(World world) { - SpigotTimings.entityActivationCheckTimer.startTiming(); + MinecraftTimings.entityActivationCheckTimer.startTiming(); final int miscActivationRange = world.spigotConfig.miscActivationRange; final int animalActivationRange = world.spigotConfig.animalActivationRange; final int monsterActivationRange = world.spigotConfig.monsterActivationRange; @@ -133,7 +133,7 @@ public class ActivationRange } } } - SpigotTimings.entityActivationCheckTimer.stopTiming(); + MinecraftTimings.entityActivationCheckTimer.stopTiming(); } /** @@ -247,10 +247,8 @@ public class ActivationRange */ public static boolean checkIfActive(Entity entity) { - SpigotTimings.checkIfActiveTimer.startTiming(); // Never safe to skip fireworks or entities not yet added to chunk if ( !entity.inChunk || entity instanceof EntityFireworks ) { - SpigotTimings.checkIfActiveTimer.stopTiming(); return true; } @@ -274,7 +272,6 @@ public class ActivationRange { isActive = false; } - SpigotTimings.checkIfActiveTimer.stopTiming(); return isActive; } } -- 2.21.0