mirror of
https://github.com/GTNewHorizons/Opis.git
synced 2026-11-21 12:42:11 +00:00
Thread display now contains the class too.
Network profiling is now force sided Rewrote the getEffectiveSide method to take network threads into account
This commit is contained in:
1 parent
23f07cf14f
commit
3d8319dc6b
8 files changed
+99
-17
No files matched your search
@@ -33,6 +33,7 @@ import mcp.mobius.opis.data.holders.newtypes.DataPacket;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataPacket250;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataStringUpdate;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataBlockTileEntity;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataThread;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataTileEntity;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataTileEntityRender;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataTiming;
|
||||
@@ -73,6 +74,7 @@ public enum DataType {
|
||||
DATAPACKET (DataPacket.class),
|
||||
DATAPACKET250 (DataPacket250.class),
|
||||
DATASTRINGUPD (DataStringUpdate.class),
|
||||
DATATHREAD (DataThread.class),
|
||||
DATATILEENTITY (DataTileEntity.class),
|
||||
DATATILEENTITYRENDER (DataTileEntityRender.class),
|
||||
DATATIMING (DataTiming.class),
|
||||
|
||||
@@ -4,10 +4,17 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.server.ServerListenThread;
|
||||
import net.minecraft.server.ThreadMinecraftServer;
|
||||
import net.minecraft.network.TcpReaderThread;
|
||||
import net.minecraft.network.TcpWriterThread;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.server.FMLServerHandler;
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import mcp.mobius.opis.data.managers.StringCache;
|
||||
import mcp.mobius.opis.helpers.Helpers;
|
||||
|
||||
|
||||
public class CachedString implements Comparable, ISerializable{
|
||||
|
||||
@@ -20,22 +27,27 @@ public class CachedString implements Comparable, ISerializable{
|
||||
}
|
||||
|
||||
public CachedString(String str){
|
||||
if(FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){
|
||||
|
||||
//if(FMLCommonHandler.instance().getSide() == Side.SERVER){
|
||||
if(Helpers.getEffectiveSide() == Side.SERVER){
|
||||
this.index = StringCache.INSTANCE.getIndex(str);
|
||||
this.str = str;
|
||||
} else {
|
||||
this.index = -1;
|
||||
this.str = str;
|
||||
this.str = str;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
public int compareTo(Object o) {
|
||||
return ((CachedString)o).str.compareTo(this.str); // Reverse order ! Put higher values FIRST
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return str;
|
||||
//return String.format("[%d] %s",this.index, this.str);
|
||||
return str;
|
||||
}
|
||||
|
||||
public void writeToStream(DataOutputStream stream) throws IOException{
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
|
||||
public class DataThread implements ISerializable{
|
||||
|
||||
public CachedString name;
|
||||
public CachedString clzz;
|
||||
|
||||
public DataThread fill(Thread thread){
|
||||
this.name = new CachedString(thread.getName());
|
||||
this.clzz = new CachedString(thread.getClass().getSimpleName());
|
||||
return this;
|
||||
}
|
||||
|
||||
public void writeToStream(DataOutputStream stream) throws IOException{
|
||||
this.name.writeToStream(stream);
|
||||
this.clzz.writeToStream(stream);
|
||||
|
||||
}
|
||||
|
||||
public static DataThread readFromStream(DataInputStream stream) throws IOException {
|
||||
DataThread retVal = new DataThread();
|
||||
retVal.name = CachedString.readFromStream(stream);
|
||||
retVal.clzz = CachedString.readFromStream(stream);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,19 +26,27 @@ public enum StringCache implements IMessageHandler {
|
||||
|
||||
public String getString(int index){
|
||||
String retVal = this.cache.get(index);
|
||||
if (retVal == null)
|
||||
if (retVal == null){
|
||||
modOpis.log.info(String.format("++++ Couldn't find string for index %d", index));
|
||||
return "<ERROR>";
|
||||
else
|
||||
}else
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public int getIndex(String str){
|
||||
|
||||
if (cache.inverse().containsKey(str)){
|
||||
//if (cache.inverse().get(str) == -1){
|
||||
// throw new RuntimeException(String.format("Found a misaligned key ! %s", str));
|
||||
//}
|
||||
|
||||
return cache.inverse().get(str);
|
||||
}
|
||||
else{
|
||||
currentIndex += 1;
|
||||
cache.put(currentIndex, str);
|
||||
|
||||
System.out.printf("++++ Adding string %s with index %d to cache\n", str, currentIndex);
|
||||
|
||||
DataStringUpdate upd = new DataStringUpdate(str, currentIndex);
|
||||
this.toSend.add(upd);
|
||||
@@ -66,8 +74,8 @@ public enum StringCache implements IMessageHandler {
|
||||
public boolean handleMessage(Message msg, NetDataRaw rawdata) {
|
||||
switch(msg){
|
||||
case STATUS_STRINGUPD:{
|
||||
//modOpis.log.info("Received String Cache update");
|
||||
DataStringUpdate data = (DataStringUpdate)rawdata.value;
|
||||
modOpis.log.info(String.format("++++ Received String Cache update : [%d] %s", data.index, data.str));
|
||||
try{
|
||||
this.cache.put(data.index, data.str);
|
||||
} catch (IllegalArgumentException e){
|
||||
@@ -78,10 +86,11 @@ public enum StringCache implements IMessageHandler {
|
||||
break;
|
||||
}
|
||||
case STATUS_STRINGUPD_FULL:{
|
||||
modOpis.log.info(String.format("Received full String Cache update containing %d entries", rawdata.array.size()));
|
||||
modOpis.log.info(String.format("++++ Received full String Cache update containing %d entries", rawdata.array.size()));
|
||||
|
||||
for (ISerializable idata : rawdata.array){
|
||||
DataStringUpdate data = (DataStringUpdate)idata;
|
||||
modOpis.log.info(String.format("++++ Received String Cache update : [%d] %s", data.index, data.str));
|
||||
try{
|
||||
this.cache.put(data.index, data.str);
|
||||
} catch (IllegalArgumentException e){
|
||||
|
||||
@@ -3,8 +3,10 @@ package mcp.mobius.opis.data.profilers;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataPacket;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataPacket250;
|
||||
import mcp.mobius.opis.helpers.Helpers;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
|
||||
@@ -37,7 +39,9 @@ public class ProfilerPacket extends ProfilerAbstract {
|
||||
|
||||
@Override
|
||||
public void start(Object key) {
|
||||
if (key != null){
|
||||
if (key != null && Helpers.getEffectiveSide() == Side.SERVER){
|
||||
//System.out.printf("%s | %s\n", Thread.currentThread().getClass(), Thread.currentThread().getName());
|
||||
|
||||
Packet packet = (Packet)key;
|
||||
dataAmount += packet.getPacketSize() + 1;
|
||||
data.get(packet.getPacketId()).fill(packet);
|
||||
|
||||
@@ -26,6 +26,7 @@ import mcp.mobius.opis.data.holders.newtypes.CachedString;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataDimension;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataPacket;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataPacket250;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataThread;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataTiming;
|
||||
import mcp.mobius.opis.data.holders.stats.StatsChunk;
|
||||
import mcp.mobius.opis.data.managers.ChunkManager;
|
||||
@@ -98,9 +99,9 @@ public enum OpisServerTickHandler implements ITickHandler {
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<CachedString> threads = new ArrayList<CachedString>();
|
||||
ArrayList<DataThread> threads = new ArrayList<DataThread>();
|
||||
for (Thread t : Thread.getAllStackTraces().keySet()){
|
||||
threads.add(new CachedString(t.getName()));
|
||||
threads.add(new DataThread().fill(t));
|
||||
}
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataList.create(Message.LIST_THREADS, threads));
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package mcp.mobius.opis.helpers;
|
||||
|
||||
import net.minecraft.network.TcpReaderThread;
|
||||
import net.minecraft.network.TcpWriterThread;
|
||||
import net.minecraft.server.ServerListenThread;
|
||||
import net.minecraft.server.ThreadMinecraftServer;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
public class Helpers {
|
||||
public static Side getEffectiveSide(){
|
||||
Thread thr = Thread.currentThread();
|
||||
|
||||
if ((thr instanceof ThreadMinecraftServer) || (thr instanceof ServerListenThread) || (thr instanceof TcpWriterThread) || (thr instanceof TcpReaderThread))
|
||||
{
|
||||
return Side.SERVER;
|
||||
}
|
||||
|
||||
return Side.CLIENT;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package mcp.mobius.opis.swing.panels.debug;
|
||||
|
||||
import mcp.mobius.opis.api.ITabPanel;
|
||||
import mcp.mobius.opis.data.holders.newtypes.CachedString;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataThread;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataTileEntity;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataRaw;
|
||||
@@ -26,9 +27,9 @@ public class PanelThreads extends JPanelMsgHandler implements ITabPanel {
|
||||
add(scrollPane, "cell 0 0,grow");
|
||||
|
||||
table = new JTableStats(
|
||||
new String[] {"Name"},
|
||||
new Class[] {CachedString.class},
|
||||
new int[] {SwingConstants.LEFT}
|
||||
new String[] {"Name", "Class"},
|
||||
new Class[] {CachedString.class, CachedString.class},
|
||||
new int[] {SwingConstants.LEFT, SwingConstants.LEFT}
|
||||
);
|
||||
scrollPane.setViewportView(table);
|
||||
}
|
||||
@@ -41,11 +42,11 @@ public class PanelThreads extends JPanelMsgHandler implements ITabPanel {
|
||||
((JTableStats)this.getTable()).setTableData(rawdata.array);
|
||||
|
||||
DefaultTableModel model = (DefaultTableModel)this.getTable().getModel();
|
||||
int row = this.getTable().clearTable(CachedString.class);
|
||||
int row = this.getTable().clearTable(DataThread.class);
|
||||
|
||||
for (Object o : rawdata.array){
|
||||
CachedString data = (CachedString)o;
|
||||
model.addRow(new Object[] { data });
|
||||
DataThread data = (DataThread)o;
|
||||
model.addRow(new Object[] { data.name, data.clzz });
|
||||
}
|
||||
|
||||
this.getTable().dataUpdated(row);
|
||||
|
||||
Reference in new issue
Block a user