Added timing/debugging code.

This commit is contained in:
Jonathan Williams 2014-06-25 12:06:24 -07:00
parent f2c82cbf95
commit 4f3ffde892
7 changed files with 102 additions and 36 deletions

View File

@ -45,6 +45,7 @@ import mineplex.core.disguise.disguises.DisguisePlayer;
import mineplex.core.packethandler.IPacketRunnable; import mineplex.core.packethandler.IPacketRunnable;
import mineplex.core.packethandler.PacketHandler; import mineplex.core.packethandler.PacketHandler;
import mineplex.core.packethandler.PacketVerifier; import mineplex.core.packethandler.PacketVerifier;
import mineplex.core.timing.TimingManager;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
@ -233,6 +234,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketRunnable
if (event.getType() != UpdateType.SEC) if (event.getType() != UpdateType.SEC)
return; return;
TimingManager.startTotal("Teleport Disguises");
for (Player player : Bukkit.getOnlinePlayers()) for (Player player : Bukkit.getOnlinePlayers())
{ {
for (Player otherPlayer : Bukkit.getOnlinePlayers()) for (Player otherPlayer : Bukkit.getOnlinePlayers())
@ -244,6 +246,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketRunnable
((CraftPlayer)player).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityTeleport(((CraftPlayer)otherPlayer).getHandle())); ((CraftPlayer)player).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityTeleport(((CraftPlayer)otherPlayer).getHandle()));
} }
} }
TimingManager.stopTotal("Teleport Disguises");
} }
public void clearDisguises() public void clearDisguises()

View File

@ -0,0 +1,27 @@
package mineplex.core.timing;
public class TimeData
{
public TimeData(String title, long time)
{
Started = time;
LastMarker = time;
Total = 0L;
}
public String Title;
public long Started;
public long LastMarker;
public long Total;
public void addTime()
{
Total += System.currentTimeMillis() - LastMarker;
LastMarker = System.currentTimeMillis();
}
public void printInfo()
{
System.out.println("]==[TIME DATA]==[" + Title + " took " + Total + "ms in the last " + (System.currentTimeMillis() - Started) + "ms");
}
}

View File

@ -1,18 +1,49 @@
package mineplex.core.common.util; package mineplex.core.timing;
import java.util.AbstractMap;
import java.util.Map.Entry; import java.util.Map.Entry;
public class TimeUtil import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.NautHashMap;
public class TimingManager implements Listener
{ {
private static TimingManager _instance;
private JavaPlugin _plugin;
private static NautHashMap<String, Long> _timingList = new NautHashMap<String, Long>(); private static NautHashMap<String, Long> _timingList = new NautHashMap<String, Long>();
private static NautHashMap<String, Entry<Long, Long>> _totalList = new NautHashMap<String, Entry<Long, Long>>(); private static NautHashMap<String, TimeData> _totalList = new NautHashMap<String, TimeData>();
private static Object _timingLock = new Object(); private static Object _timingLock = new Object();
private static Object _totalLock = new Object(); private static Object _totalLock = new Object();
public static boolean Debug = false; public static boolean Debug = false;
protected TimingManager(JavaPlugin plugin)
{
_instance = this;
_plugin = plugin;
_plugin.getServer().getPluginManager().registerEvents(this, _plugin);
}
public static TimingManager Initialize(JavaPlugin plugin)
{
if (_instance == null)
{
_instance = new TimingManager(plugin);
}
return _instance;
}
public static TimingManager instance()
{
return _instance;
}
public static void startTotal(String title) public static void startTotal(String title)
{ {
if (!Debug) if (!Debug)
@ -22,11 +53,15 @@ public class TimeUtil
{ {
if (_totalList.containsKey(title)) if (_totalList.containsKey(title))
{ {
_totalList.put(title, new AbstractMap.SimpleEntry<Long, Long>(System.currentTimeMillis(), _totalList.get(title).getValue())); TimeData data = _totalList.get(title);
data.LastMarker = System.currentTimeMillis();
_totalList.put(title, data);
} }
else else
{ {
_totalList.put(title, new AbstractMap.SimpleEntry<Long, Long>(System.currentTimeMillis(), 0L)); TimeData data = new TimeData(title, System.currentTimeMillis());
_totalList.put(title, data);
} }
} }
} }
@ -40,8 +75,10 @@ public class TimeUtil
{ {
if (_totalList.containsKey(title)) if (_totalList.containsKey(title))
{ {
long additionalTime = System.currentTimeMillis() - _totalList.get(title).getKey(); TimeData data = _totalList.get(title);
_totalList.put(title, new AbstractMap.SimpleEntry<Long, Long>(System.currentTimeMillis(), _totalList.get(title).getValue() + additionalTime)); data.addTime();
_totalList.put(title, data);
} }
} }
} }
@ -53,7 +90,7 @@ public class TimeUtil
synchronized(_totalLock) synchronized(_totalLock)
{ {
System.out.println("]==[TIMING]==[" + title + " has taken " + _totalList.get(title).getValue() + "ms so far"); _totalList.get(title).printInfo();
} }
} }
@ -64,12 +101,10 @@ public class TimeUtil
synchronized(_totalLock) synchronized(_totalLock)
{ {
for (Entry<String, Entry<Long, Long>> entry : _totalList.entrySet()) for (Entry<String, TimeData> entry : _totalList.entrySet())
{ {
System.out.println("]==[TIMING]==[" + entry.getKey() + " has taken " + entry.getValue().getValue() + "ms so far"); entry.getValue().printInfo();
} }
_totalList.clear();
} }
} }

View File

@ -72,6 +72,7 @@ import mineplex.core.projectile.ProjectileManager;
import mineplex.core.stats.StatsManager; import mineplex.core.stats.StatsManager;
import mineplex.core.status.ServerStatusManager; import mineplex.core.status.ServerStatusManager;
import mineplex.core.teleport.Teleport; import mineplex.core.teleport.Teleport;
import mineplex.core.timing.TimingManager;
public class ArcadeManager extends MiniPlugin implements IRelation public class ArcadeManager extends MiniPlugin implements IRelation
{ {
@ -561,7 +562,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
public ArrayList<String> LoadFiles(String gameName) public ArrayList<String> LoadFiles(String gameName)
{ {
TimeUtil.start("ArcadeManager LoadFiles"); TimingManager.start("ArcadeManager LoadFiles");
File folder = new File(".." + File.separatorChar + ".." + File.separatorChar + "update" + File.separatorChar + "maps" + File.separatorChar + gameName); File folder = new File(".." + File.separatorChar + ".." + File.separatorChar + "update" + File.separatorChar + "maps" + File.separatorChar + gameName);
if (!folder.exists()) folder.mkdirs(); if (!folder.exists()) folder.mkdirs();
@ -590,7 +591,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
for (String map : maps) for (String map : maps)
System.out.println("Found Map: " + map); System.out.println("Found Map: " + map);
TimeUtil.stop("ArcadeManager LoadFiles"); TimingManager.stop("ArcadeManager LoadFiles");
return maps; return maps;
} }

View File

@ -4,13 +4,13 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import mineplex.core.timing.TimingManager;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.TimeUtil;
import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;

View File

@ -4,10 +4,10 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import mineplex.core.common.util.TimeUtil;
import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime;
import mineplex.core.timing.TimingManager;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
@ -94,7 +94,7 @@ public class GameCreationManager implements Listener
HandlerList.unregisterAll(game); HandlerList.unregisterAll(game);
TimeUtil.start("GameCreationManager - Attempting Removal - " + game.GetName()); TimingManager.start("GameCreationManager - Attempting Removal - " + game.GetName());
//Cleaned //Cleaned
if (game.WorldData == null || game.WorldData.World == null) if (game.WorldData == null || game.WorldData.World == null)
@ -107,7 +107,7 @@ public class GameCreationManager implements Listener
boolean removedPlayers = false; boolean removedPlayers = false;
if (UtilTime.elapsed(game.GetStateTime(), 20000)) if (UtilTime.elapsed(game.GetStateTime(), 20000))
{ {
TimeUtil.start("GameCreationManager - Kick Players - " + game.GetName()); TimingManager.start("GameCreationManager - Kick Players - " + game.GetName());
for (Player player : game.WorldData.World.getPlayers()) for (Player player : game.WorldData.World.getPlayers())
{ {
@ -119,7 +119,7 @@ public class GameCreationManager implements Listener
removedPlayers = true; removedPlayers = true;
TimeUtil.stop("GameCreationManager - Kick Players - " + game.GetName()); TimingManager.stop("GameCreationManager - Kick Players - " + game.GetName());
} }
//Clean //Clean
@ -128,17 +128,17 @@ public class GameCreationManager implements Listener
if (game.WorldData.World.getPlayers().isEmpty()) if (game.WorldData.World.getPlayers().isEmpty())
System.out.println("World Player Count [" + game.WorldData.World.getPlayers().size() + "]"); System.out.println("World Player Count [" + game.WorldData.World.getPlayers().size() + "]");
TimeUtil.start("GameCreationManager - Uninit World - " + game.GetName()); TimingManager.start("GameCreationManager - Uninit World - " + game.GetName());
game.WorldData.Uninitialize(); game.WorldData.Uninitialize();
game.WorldData = null; game.WorldData = null;
gameIterator.remove(); gameIterator.remove();
TimeUtil.stop("GameCreationManager - Uninit World - " + game.GetName()); TimingManager.stop("GameCreationManager - Uninit World - " + game.GetName());
}; };
} }
TimeUtil.stop("GameCreationManager - Attempting Removal - " + game.GetName()); TimingManager.stop("GameCreationManager - Attempting Removal - " + game.GetName());
} }
} }
@ -185,13 +185,13 @@ public class GameCreationManager implements Listener
return; return;
} }
TimeUtil.start("DisplayNext"); TimingManager.start("DisplayNext");
Manager.GetLobby().DisplayNext(Manager.GetGame(), pastTeams); Manager.GetLobby().DisplayNext(Manager.GetGame(), pastTeams);
TimeUtil.stop("DisplayNext"); TimingManager.stop("DisplayNext");
TimeUtil.start("registerEvents"); TimingManager.start("registerEvents");
UtilServer.getServer().getPluginManager().registerEvents(Manager.GetGame(), Manager.GetPlugin()); UtilServer.getServer().getPluginManager().registerEvents(Manager.GetGame(), Manager.GetPlugin());
TimeUtil.stop("registerEvents"); TimingManager.stop("registerEvents");
} }
public void SetNextGameType(GameType type) public void SetNextGameType(GameType type)

View File

@ -12,11 +12,11 @@ import java.util.HashMap;
import mineplex.core.common.util.FileUtil; import mineplex.core.common.util.FileUtil;
import mineplex.core.common.util.MapUtil; import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.TimeUtil;
import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.WorldUtil; import mineplex.core.common.util.WorldUtil;
import mineplex.core.common.util.ZipUtil; import mineplex.core.common.util.ZipUtil;
import mineplex.core.timing.TimingManager;
import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.Game;
import net.minecraft.server.v1_7_R3.ChunkPreLoadEvent; import net.minecraft.server.v1_7_R3.ChunkPreLoadEvent;
@ -78,17 +78,17 @@ public class WorldData
{ {
public void run() public void run()
{ {
TimeUtil.start("WorldData loading world."); TimingManager.start("WorldData loading world.");
//Start World //Start World
World = WorldUtil.LoadWorld(new WorldCreator(GetFolder())); World = WorldUtil.LoadWorld(new WorldCreator(GetFolder()));
TimeUtil.stop("WorldData loading world."); TimingManager.stop("WorldData loading world.");
World.setDifficulty(Difficulty.HARD); World.setDifficulty(Difficulty.HARD);
TimeUtil.start("WorldData loading WorldConfig."); TimingManager.start("WorldData loading WorldConfig.");
//Load World Data //Load World Data
worldData.LoadWorldConfig(); worldData.LoadWorldConfig();
TimeUtil.stop("WorldData loading WorldConfig."); TimingManager.stop("WorldData loading WorldConfig.");
} }
}); });
} }
@ -126,16 +126,16 @@ public class WorldData
protected void UnzipWorld() protected void UnzipWorld()
{ {
TimeUtil.start("UnzipWorld creating folders"); TimingManager.start("UnzipWorld creating folders");
String folder = GetFolder(); String folder = GetFolder();
new File(folder).mkdir(); new File(folder).mkdir();
new File(folder + java.io.File.separator + "region").mkdir(); new File(folder + java.io.File.separator + "region").mkdir();
new File(folder + java.io.File.separator + "data").mkdir(); new File(folder + java.io.File.separator + "data").mkdir();
TimeUtil.stop("UnzipWorld creating folders"); TimingManager.stop("UnzipWorld creating folders");
TimeUtil.start("UnzipWorld UnzipToDirectory"); TimingManager.start("UnzipWorld UnzipToDirectory");
ZipUtil.UnzipToDirectory("../../update/maps/" + Host.GetName() + "/" + GetFile() + ".zip", folder); ZipUtil.UnzipToDirectory("../../update/maps/" + Host.GetName() + "/" + GetFile() + ".zip", folder);
TimeUtil.stop("UnzipWorld UnzipToDirectory"); TimingManager.stop("UnzipWorld UnzipToDirectory");
} }
public void LoadWorldConfig() public void LoadWorldConfig()