diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/TimeUtil.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/TimeUtil.java index 4340bf207..0044887fe 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/TimeUtil.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/TimeUtil.java @@ -1,40 +1,98 @@ package mineplex.core.common.util; import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; import java.util.Map.Entry; public class TimeUtil { - private static List> _timingList = new ArrayList>(); + private static NautHashMap _timingList = new NautHashMap(); + private static NautHashMap> _totalList = new NautHashMap>(); + private static Object _timingLock = new Object(); + private static Object _totalLock = new Object(); + + public static boolean Debug = false; + + public static void startTotal(String title) + { + if (!Debug) + return; + + synchronized(_totalLock) + { + if (_totalList.containsKey(title)) + { + _totalList.put(title, new AbstractMap.SimpleEntry(System.currentTimeMillis(), _totalList.get(title).getValue())); + } + else + { + _totalList.put(title, new AbstractMap.SimpleEntry(System.currentTimeMillis(), 0L)); + } + } + } + + public static void stopTotal(String title) + { + if (!Debug) + return; + + synchronized(_totalLock) + { + if (_totalList.containsKey(title)) + { + long additionalTime = System.currentTimeMillis() - _totalList.get(title).getKey(); + _totalList.put(title, new AbstractMap.SimpleEntry(System.currentTimeMillis(), _totalList.get(title).getValue() + additionalTime)); + } + } + } + + public static void printTotal(String title) + { + if (!Debug) + return; + + synchronized(_totalLock) + { + System.out.println("]==[TIMING]==[" + title + " has taken " + _totalList.get(title).getValue() + "ms so far"); + } + } + + public static void printTotals() + { + if (!Debug) + return; + + synchronized(_totalLock) + { + for (Entry> entry : _totalList.entrySet()) + { + System.out.println("]==[TIMING]==[" + entry.getKey() + " has taken " + entry.getValue().getValue() + "ms so far"); + } + + _totalList.clear(); + } + } public static void start(String title) { + if (!Debug) + return; + synchronized(_timingLock) { - _timingList.add(new AbstractMap.SimpleEntry(title, System.currentTimeMillis())); + _timingList.put(title, System.currentTimeMillis()); } } - public static void stop() + public static void stop(String title) { + if (!Debug) + return; + synchronized(_timingLock) { - Collections.reverse(_timingList); - - for (Iterator> iterator = _timingList.iterator(); iterator.hasNext();) - { - Entry entry = iterator.next(); - - System.out.println("==[TimeUtil]==" + entry.getKey()+ " took " + (System.currentTimeMillis() - entry.getValue()) + "ms"); - iterator.remove(); - } - - Collections.reverse(_timingList); + System.out.println("]==[TIMING]==[" + title + " took " + (System.currentTimeMillis() - _timingList.get(title)) + "ms"); + _timingList.remove(title); } } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index 397d82d60..5fd2bb608 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -590,7 +590,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation for (String map : maps) System.out.println("Found Map: " + map); - TimeUtil.stop(); + TimeUtil.stop("ArcadeManager LoadFiles"); return maps; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java index 33a033c07..c00e95110 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; -import mineplex.core.antihack.AntiHack; import mineplex.core.common.util.TimeUtil; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilServer; @@ -120,7 +119,7 @@ public class GameCreationManager implements Listener removedPlayers = true; - TimeUtil.stop(); + TimeUtil.stop("GameCreationManager - Kick Players - " + game.GetName()); } //Clean @@ -135,11 +134,11 @@ public class GameCreationManager implements Listener game.WorldData = null; gameIterator.remove(); - TimeUtil.stop(); + TimeUtil.stop("GameCreationManager - Uninit World - " + game.GetName()); }; } - TimeUtil.stop(); + TimeUtil.stop("GameCreationManager - Attempting Removal - " + game.GetName()); } } @@ -188,11 +187,11 @@ public class GameCreationManager implements Listener TimeUtil.start("DisplayNext"); Manager.GetLobby().DisplayNext(Manager.GetGame(), pastTeams); - TimeUtil.stop(); + TimeUtil.stop("DisplayNext"); TimeUtil.start("registerEvents"); UtilServer.getServer().getPluginManager().registerEvents(Manager.GetGame(), Manager.GetPlugin()); - TimeUtil.stop(); + TimeUtil.stop("registerEvents"); } public void SetNextGameType(GameType type) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldData.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldData.java index e6de130fa..f598bb867 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldData.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldData.java @@ -81,14 +81,14 @@ public class WorldData TimeUtil.start("WorldData loading world."); //Start World World = WorldUtil.LoadWorld(new WorldCreator(GetFolder())); - TimeUtil.stop(); + TimeUtil.stop("WorldData loading world."); World.setDifficulty(Difficulty.HARD); TimeUtil.start("WorldData loading WorldConfig."); //Load World Data worldData.LoadWorldConfig(); - TimeUtil.stop(); + TimeUtil.stop("WorldData loading WorldConfig."); } }); } @@ -131,11 +131,11 @@ public class WorldData new File(folder).mkdir(); new File(folder + java.io.File.separator + "region").mkdir(); new File(folder + java.io.File.separator + "data").mkdir(); - TimeUtil.stop(); + TimeUtil.stop("UnzipWorld creating folders"); TimeUtil.start("UnzipWorld UnzipToDirectory"); ZipUtil.UnzipToDirectory("../../update/maps/" + Host.GetName() + "/" + GetFile() + ".zip", folder); - TimeUtil.stop(); + TimeUtil.stop("UnzipWorld UnzipToDirectory"); } public void LoadWorldConfig()