From ebf663695cee233e876cc691c1c34a40e44d406b Mon Sep 17 00:00:00 2001 From: ProfMobius Date: Wed, 9 Apr 2014 16:02:51 +0200 Subject: [PATCH] Added roundtrip time measurement. --- .../opis/events/OpisClientTickHandler.java | 6 ++++ mcp/mobius/opis/modOpis.java | 1 + .../opis/network/ServerMessageHandler.java | 4 +++ mcp/mobius/opis/network/enums/Message.java | 1 + mcp/mobius/opis/proxy/ProxyClient.java | 4 +++ mcp/mobius/opis/swing/SwingUI.java | 3 ++ .../opis/swing/panels/PanelSummary.java | 36 ++++++++++++++++--- 7 files changed, 50 insertions(+), 5 deletions(-) diff --git a/mcp/mobius/opis/events/OpisClientTickHandler.java b/mcp/mobius/opis/events/OpisClientTickHandler.java index a8fa68a..62c0b99 100644 --- a/mcp/mobius/opis/events/OpisClientTickHandler.java +++ b/mcp/mobius/opis/events/OpisClientTickHandler.java @@ -12,12 +12,15 @@ import mcp.mobius.mobiuscore.profiler.ProfilerSection; import mcp.mobius.opis.modOpis; import mcp.mobius.opis.api.TabPanelRegistrar; import mcp.mobius.opis.data.holders.basetypes.CoordinatesBlock; +import mcp.mobius.opis.data.holders.basetypes.SerialLong; import mcp.mobius.opis.data.holders.newtypes.DataBlockRender; import mcp.mobius.opis.data.holders.newtypes.DataEntityRender; import mcp.mobius.opis.data.holders.newtypes.DataTileEntityRender; import mcp.mobius.opis.data.profilers.ProfilerRenderBlock; import mcp.mobius.opis.data.profilers.ProfilerRenderEntity; import mcp.mobius.opis.data.profilers.ProfilerRenderTileEntity; +import mcp.mobius.opis.network.enums.Message; +import mcp.mobius.opis.network.packets.client.Packet_ReqData; import mcp.mobius.opis.swing.panels.PanelRenderEntities; import mcp.mobius.opis.swing.panels.PanelRenderTileEnts; import cpw.mods.fml.common.ITickHandler; @@ -42,6 +45,9 @@ public enum OpisClientTickHandler implements ITickHandler { // One second timer if (System.nanoTime() - timer1000 > 1000000000L){ timer1000 = System.nanoTime(); + + if(modOpis.swingOpen) + PacketDispatcher.sendPacketToServer(Packet_ReqData.create(Message.STATUS_PING, new SerialLong(System.nanoTime()))); } diff --git a/mcp/mobius/opis/modOpis.java b/mcp/mobius/opis/modOpis.java index 970bde0..29d3844 100644 --- a/mcp/mobius/opis/modOpis.java +++ b/mcp/mobius/opis/modOpis.java @@ -92,6 +92,7 @@ public class modOpis { public static boolean microseconds = true; private static int lagGenID = -1; public static CoordinatesBlock selectedBlock = null; + public static boolean swingOpen = false; public Configuration config = null; diff --git a/mcp/mobius/opis/network/ServerMessageHandler.java b/mcp/mobius/opis/network/ServerMessageHandler.java index 09f8303..a3ee3df 100644 --- a/mcp/mobius/opis/network/ServerMessageHandler.java +++ b/mcp/mobius/opis/network/ServerMessageHandler.java @@ -212,6 +212,10 @@ public class ServerMessageHandler { ChunkManager.INSTANCE.purgeChunks(((SerialInt)param1).value); } + else if(maintype == Message.STATUS_PING){ + OpisPacketHandler.validateAndSend(NetDataValue.create(Message.STATUS_PING, param1), (Player)player); + } + else{ modOpis.log.log(Level.WARNING, String.format("Unknown data request : %s ", maintype)); } diff --git a/mcp/mobius/opis/network/enums/Message.java b/mcp/mobius/opis/network/enums/Message.java index 54ec111..2f7dc6b 100644 --- a/mcp/mobius/opis/network/enums/Message.java +++ b/mcp/mobius/opis/network/enums/Message.java @@ -43,6 +43,7 @@ public enum Message { STATUS_CURRENT_TIME, STATUS_TIME_LAST_RUN, STATUS_ACCESS_LEVEL, + STATUS_PING, COMMAND_TELEPORT_BLOCK(PRIVILEGED), COMMAND_TELEPORT_CHUNK(PRIVILEGED), diff --git a/mcp/mobius/opis/proxy/ProxyClient.java b/mcp/mobius/opis/proxy/ProxyClient.java index 4c9434f..2acbc4e 100644 --- a/mcp/mobius/opis/proxy/ProxyClient.java +++ b/mcp/mobius/opis/proxy/ProxyClient.java @@ -15,7 +15,9 @@ import mcp.mobius.opis.api.IMessageHandler; import mcp.mobius.opis.api.MessageHandlerRegistrar; import mcp.mobius.opis.api.TabPanelRegistrar; import mcp.mobius.opis.data.client.DataCache; +import mcp.mobius.opis.data.holders.basetypes.SerialLong; import mcp.mobius.opis.data.holders.newtypes.DataHandler; +import mcp.mobius.opis.data.holders.newtypes.DataTiming; import mcp.mobius.opis.data.holders.stats.StatsChunk; import mcp.mobius.opis.data.managers.ChunkManager; import mcp.mobius.opis.data.managers.MetaManager; @@ -124,12 +126,14 @@ public class ProxyClient extends ProxyServer implements IMessageHandler{ MessageHandlerRegistrar.INSTANCE.registerHandler(Message.STATUS_TIME_LAST_RUN, panelSummary); MessageHandlerRegistrar.INSTANCE.registerHandler(Message.VALUE_TIMING_ENTUPDATE, panelSummary); MessageHandlerRegistrar.INSTANCE.registerHandler(Message.VALUE_TIMING_NETWORK, panelSummary); + MessageHandlerRegistrar.INSTANCE.registerHandler(Message.STATUS_PING, panelSummary); MessageHandlerRegistrar.INSTANCE.registerHandler(Message.LIST_DIMENSION_DATA, panelDimensions); MessageHandlerRegistrar.INSTANCE.registerHandler(Message.CLIENT_CLEAR_SELECTION, modOpis.proxy); MessageHandlerRegistrar.INSTANCE.registerHandler(Message.CLIENT_START_PROFILING, modOpis.proxy); MessageHandlerRegistrar.INSTANCE.registerHandler(Message.CLIENT_SHOW_RENDER_TICK, modOpis.proxy); + MessageHandlerRegistrar.INSTANCE.registerHandler(Message.LIST_CHUNK_ENTITIES, OverlayEntityPerChunk.instance()); MessageHandlerRegistrar.INSTANCE.registerHandler(Message.LIST_CHUNK_TILEENTS, OverlayMeanTime.instance()); diff --git a/mcp/mobius/opis/swing/SwingUI.java b/mcp/mobius/opis/swing/SwingUI.java index 2e97606..2a001c5 100644 --- a/mcp/mobius/opis/swing/SwingUI.java +++ b/mcp/mobius/opis/swing/SwingUI.java @@ -19,6 +19,7 @@ import javax.swing.SwingConstants; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiChat; import cpw.mods.fml.common.network.PacketDispatcher; +import mcp.mobius.opis.modOpis; import mcp.mobius.opis.api.IMessageHandler; import mcp.mobius.opis.api.ITabPanel; import mcp.mobius.opis.api.TabPanelRegistrar; @@ -87,6 +88,7 @@ public class SwingUI extends JFrame implements WindowListener, IMessageHandler{ @Override public void windowClosed(WindowEvent arg0) { + modOpis.swingOpen = false; PacketDispatcher.sendPacketToServer(Packet_ReqData.create(Message.COMMAND_UNREGISTER_SWING)); } @@ -124,6 +126,7 @@ public class SwingUI extends JFrame implements WindowListener, IMessageHandler{ break; } case CLIENT_SHOW_SWING:{ + modOpis.swingOpen = true; this.showUI(); Minecraft.getMinecraft().displayGuiScreen(new GuiChat()); break; diff --git a/mcp/mobius/opis/swing/panels/PanelSummary.java b/mcp/mobius/opis/swing/panels/PanelSummary.java index 73373a6..eff1d35 100644 --- a/mcp/mobius/opis/swing/panels/PanelSummary.java +++ b/mcp/mobius/opis/swing/panels/PanelSummary.java @@ -33,6 +33,7 @@ import javax.swing.JLabel; import javax.swing.JButton; import javax.swing.JProgressBar; +import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; @@ -61,11 +62,14 @@ public class PanelSummary extends JPanelMsgHandler implements ITabPanel{ private JProgressBar progressBarRun; private JLabel lblTimeStamp; + private DescriptiveStatistics pingData = new DescriptiveStatistics(5); + private long nPings = 0; + /** * Create the panel. */ public PanelSummary() { - setLayout(new MigLayout("", "[20px:20px:20px,grow][][20px:20px:20px][60px:60px:60px][][20px:20px:20px][50px:50px:50px][20px:20px:20px][][20px:20px:20px][50px:50px:50px][][20px:20px:20px][grow][]", "[20px:20px:20px][][][][][][][20px:20px:20px][][20px:20px:20px][][grow]")); + setLayout(new MigLayout("", "[20px:20px:20px,grow][][20px:20px:20px][60px:60px:60px][][20px:20px:20px][50px:50px:50px][20px:20px:20px][][20px:20px:20px][50px:50px:50px][][20px:20px:20px][grow][]", "[20px:20px:20px][][][][][][][][][20px:20px:20px][][grow]")); JLabel lblNewLabel_5 = new JLabel("Update time"); add(lblNewLabel_5, "cell 3 1 2 1,alignx right"); @@ -128,6 +132,12 @@ public class PanelSummary extends JPanelMsgHandler implements ITabPanel{ lblAmountEntities = new JLabel("0"); add(lblAmountEntities, "cell 6 4,alignx right"); + JLabel lblNewLabel_6 = new JLabel("Ping"); + add(lblNewLabel_6, "cell 8 4"); + + lblTimingPing = new JLabel("0"); + add(lblTimingPing, "cell 10 4 2 1,alignx right"); + JLabel lblNewLabel_3 = new JLabel("Handlers"); add(lblNewLabel_3, "cell 1 5"); @@ -138,10 +148,10 @@ public class PanelSummary extends JPanelMsgHandler implements ITabPanel{ add(lblAmountHandlers, "cell 6 5,alignx right"); JLabel lblNewLabel_22 = new JLabel("Forced chunks"); - add(lblNewLabel_22, "cell 8 5"); + add(lblNewLabel_22, "cell 8 6"); lblAmountForced = new JLabel("0"); - add(lblAmountForced, "cell 10 5 2 1,alignx right"); + add(lblAmountForced, "cell 10 6 2 1,alignx right"); JLabel lblNewLabel_32 = new JLabel("Network"); add(lblNewLabel_32, "cell 1 6"); @@ -150,10 +160,10 @@ public class PanelSummary extends JPanelMsgHandler implements ITabPanel{ add(lblTimingNetwork, "cell 3 6 2 1,alignx right"); JLabel lblNewLabel_23 = new JLabel("Loaded chunks"); - add(lblNewLabel_23, "cell 8 6"); + add(lblNewLabel_23, "cell 8 7"); lblAmountLoaded = new JLabel("0"); - add(lblAmountLoaded, "cell 10 6 2 1,alignx right"); + add(lblAmountLoaded, "cell 10 7 2 1,alignx right"); JLabel lblNewLabel_4 = new JLabel("Total"); add(lblNewLabel_4, "cell 1 8"); @@ -214,6 +224,7 @@ public class PanelSummary extends JPanelMsgHandler implements ITabPanel{ XYSeriesCollection dataset = new XYSeriesCollection(); XYPlot xyPlot; private JLabel lblTimingNetwork; + private JLabel lblTimingPing; private JPanel createGraph(){ JFreeChart chart = ChartFactory.createXYAreaChart("", "Seconds", "Update Time [ms]", dataset, PlotOrientation.VERTICAL, false, false, false); @@ -369,10 +380,22 @@ public class PanelSummary extends JPanelMsgHandler implements ITabPanel{ } break; } + case VALUE_TIMING_ENTUPDATE:{ break; } + case STATUS_PING:{ + this.pingData.addValue((double)(System.nanoTime() - ((SerialLong)rawdata.value).value)); + this.nPings += 1; + + if (this.nPings % 5 == 0){ + DataTiming timing = new DataTiming(this.pingData.getGeometricMean()); + this.getLblTimingPing().setText(timing.asMillisecond().toString()); + } + break; + } + default: return false; @@ -392,4 +415,7 @@ public class PanelSummary extends JPanelMsgHandler implements ITabPanel{ public JLabel getLblTimingNetwork() { return lblTimingNetwork; } + public JLabel getLblTimingPing() { + return lblTimingPing; + } }