Added a simple generic network profiler

This commit is contained in:
ProfMobius committed 2014-03-31 10:35:09 +02:00
1 parent d08540ace3
commit 7f5491ece1
4 files changed
+66 -33

No files matched your search

@@ -0,0 +1,55 @@
package mcp.mobius.opis.data.server;
import java.util.HashMap;
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
import net.minecraft.network.packet.Packet;
import mcp.mobius.mobiuscore.profiler.IProfilerNetwork;
public enum NetworkProfiler implements IProfilerNetwork {
INSTANCE;
public class Clock{
public long startTime = 0;
public long timeDelta = 0;
public void start(){this.startTime = System.nanoTime();}
public void stop(){this.timeDelta = System.nanoTime() - this.startTime;}
}
public long dataSizeOut = 0;
public long dataSizeIn = 0;
public HashMap<String, Clock> clocks = new HashMap<String, Clock>();
public HashMap<String, DescriptiveStatistics> stats = new HashMap<String, DescriptiveStatistics>();
@Override
public void addPacketOut(Packet packet) {
if (packet != null)
dataSizeOut += packet.getPacketSize() + 1;
}
@Override
public void addPacketIn(Packet packet) {
if (packet != null)
dataSizeIn += packet.getPacketSize() + 1;
}
@Override
public void startNetwork(String subprofile) {
if (!clocks.containsKey(subprofile))
clocks.put(subprofile, new Clock());
clocks.get(subprofile).start();
}
@Override
public void stopNetwork(String subprofile) {
clocks.get(subprofile).stop();
if (!stats.containsKey(subprofile))
stats.put(subprofile, new DescriptiveStatistics(250));
stats.get(subprofile).addValue((double)clocks.get(subprofile).timeDelta/1000.0);
}
}
@@ -1,26 +0,0 @@
package mcp.mobius.opis.data.server;
import net.minecraft.network.packet.Packet;
import mcp.mobius.mobiuscore.profiler.IProfilerPacket;
public class PacketProfiler implements IProfilerPacket {
private static PacketProfiler _instance = new PacketProfiler();
public static PacketProfiler instance() {return _instance;}
public long dataSizeOut = 0;
public long dataSizeIn = 0;
@Override
public void addPacketOut(Packet packet) {
if (packet != null)
dataSizeOut += packet.getPacketSize() + 1;
}
@Override
public void addPacketIn(Packet packet) {
if (packet != null)
dataSizeIn += packet.getPacketSize() + 1;
}
}
@@ -28,7 +28,7 @@ import mcp.mobius.opis.data.managers.GlobalTimingManager;
import mcp.mobius.opis.data.managers.TickHandlerManager;
import mcp.mobius.opis.data.managers.TileEntityManager;
import mcp.mobius.opis.data.server.EntUpdateProfiler;
import mcp.mobius.opis.data.server.PacketProfiler;
import mcp.mobius.opis.data.server.NetworkProfiler;
import mcp.mobius.opis.data.server.WorldTickProfiler;
import mcp.mobius.opis.data.server.TickProfiler;
import mcp.mobius.opis.gui.overlay.OverlayStatus;
@@ -79,8 +79,8 @@ public class OpisServerTickHandler implements ITickHandler {
if (System.nanoTime() - timer1000 > 1000000000L){
timer1000 = System.nanoTime();
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_AMOUNT_UPLOAD, new SerialLong(PacketProfiler.instance().dataSizeOut)));
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_AMOUNT_DOWNLOAD, new SerialLong(PacketProfiler.instance().dataSizeIn)));
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_AMOUNT_UPLOAD, new SerialLong(NetworkProfiler.INSTANCE.dataSizeOut)));
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_AMOUNT_DOWNLOAD, new SerialLong(NetworkProfiler.INSTANCE.dataSizeIn)));
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_CHUNK_FORCED, new SerialInt(ChunkManager.instance().getForcedChunkAmount())));
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_CHUNK_LOADED, new SerialInt(ChunkManager.instance().getLoadedChunkAmount())));
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_TIMING_TICK, TickProfiler.instance().stats));
@@ -99,8 +99,8 @@ public class OpisServerTickHandler implements ITickHandler {
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.STATUS_RUN_UPDATE, new SerialInt(profilerRunningTicks)));
}
PacketProfiler.instance().dataSizeOut = 0L;
PacketProfiler.instance().dataSizeIn = 0L;
NetworkProfiler.INSTANCE.dataSizeOut = 0L;
NetworkProfiler.INSTANCE.dataSizeIn = 0L;
}
// Five second timer
@@ -132,6 +132,10 @@ public class OpisServerTickHandler implements ITickHandler {
System.out.printf("[ %4d ] %20s : %.3f µs\n", cell.getRowKey(), cell.getColumnKey(), cell.getValue());
}
for(String key : NetworkProfiler.INSTANCE.stats.keySet()){
System.out.printf("[ %s ] : %.3f µs\n", key, NetworkProfiler.INSTANCE.stats.get(key).getGeometricMean());
}
/*
for(Table.Cell<CoordinatesChunk, String, Double> cell : GlobalTimingManager.INSTANCE.getStatsChunk().cellSet()){
System.out.printf("[ %s ] %20s : %.3f µs\n", cell.getRowKey(), cell.getColumnKey(), cell.getValue());
+2 -2
View File
@@ -35,7 +35,7 @@ import mcp.mobius.opis.data.server.DeadManSwitch;
import mcp.mobius.opis.data.server.EntUpdateProfiler;
import mcp.mobius.opis.data.server.EntityProfiler;
import mcp.mobius.opis.data.server.HandlerProfiler;
import mcp.mobius.opis.data.server.PacketProfiler;
import mcp.mobius.opis.data.server.NetworkProfiler;
import mcp.mobius.opis.data.server.WorldTickProfiler;
import mcp.mobius.opis.data.server.TickProfiler;
import mcp.mobius.opis.data.server.TileEntityProfiler;
@@ -139,7 +139,7 @@ public class modOpis {
ProfilerRegistrar.registerProfilerWorldTick(new WorldTickProfiler());
ProfilerRegistrar.registerProfilerTick(TickProfiler.instance());
ProfilerRegistrar.registerProfilerEntUpdate(new EntUpdateProfiler());
ProfilerRegistrar.registerProfilerPacket(PacketProfiler.instance());
ProfilerRegistrar.registerProfilerPacket(NetworkProfiler.INSTANCE);
if (lagGenID != -1){
Block blockDemo = new BlockLag(lagGenID, Material.wood);