Refactored TimeUtil and added totalling option.

This commit is contained in:
Jonathan Williams 2014-06-20 20:42:36 -07:00
parent 6cac04d399
commit f2c82cbf95
4 changed files with 86 additions and 29 deletions

View File

@ -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<Entry<String, Long>> _timingList = new ArrayList<Entry<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 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<Long, Long>(System.currentTimeMillis(), _totalList.get(title).getValue()));
}
else
{
_totalList.put(title, new AbstractMap.SimpleEntry<Long, Long>(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<Long, Long>(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<String, Entry<Long, Long>> 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<String, Long>(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<Entry<String, Long>> iterator = _timingList.iterator(); iterator.hasNext();)
{
Entry<String, Long> 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);
}
}
}

View File

@ -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;
}

View File

@ -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)

View File

@ -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()