mirror of
https://github.com/GTNewHorizons/Opis.git
synced 2026-11-22 05:02:17 +00:00
Added a command to dump the sorted list of top chunks to the console.
This commit is contained in:
1 parent
327febcd4d
commit
8b4b8095dd
6 files changed
+120
-12
No files matched your search
@@ -0,0 +1,52 @@
|
||||
package mcp.mobius.opis.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mcp.mobius.opis.data.ChunkManager;
|
||||
import mcp.mobius.opis.data.holders.ChunkStats;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
|
||||
public class CommandChunks extends CommandBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "opis_chunks";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
ArrayList<ChunkStats> chunks = new ArrayList<ChunkStats>();
|
||||
|
||||
if (astring.length == 0)
|
||||
chunks = ChunkManager.getTopChunks(20);
|
||||
else
|
||||
try{
|
||||
chunks = ChunkManager.getTopChunks(Integer.valueOf(astring.length));
|
||||
}catch (Exception e){return;}
|
||||
|
||||
System.out.printf("== ==\n");
|
||||
for (ChunkStats stat : chunks){
|
||||
System.out.printf("%s\n", stat);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender par1ICommandSender)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,13 +32,6 @@ public class CommandTileEntitiesList extends CommandBase {
|
||||
tes = TileEntityManager.getTopEntities(Integer.valueOf(astring[0]));
|
||||
} catch (Exception e) {return;}
|
||||
}
|
||||
|
||||
/*
|
||||
System.out.printf("=== ===\n");
|
||||
|
||||
for (TileEntityStats stat : tes)
|
||||
System.out.printf("%s\n", stat);
|
||||
*/
|
||||
|
||||
((EntityPlayerMP)icommandsender).playerNetServerHandler.sendPacketToPlayer(Packet_TileEntitiesTopList.create(tes));
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package mcp.mobius.opis.data;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -10,6 +11,7 @@ import java.util.Set;
|
||||
import mcp.mobius.opis.data.holders.ChunkStats;
|
||||
import mcp.mobius.opis.data.holders.CoordinatesChunk;
|
||||
import mcp.mobius.opis.data.holders.TicketData;
|
||||
import mcp.mobius.opis.data.holders.TileEntityStats;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
@@ -55,4 +57,31 @@ public class ChunkManager {
|
||||
|
||||
return tickets;
|
||||
}
|
||||
|
||||
public static ArrayList<ChunkStats> getChunksUpdateTime(){
|
||||
HashMap<CoordinatesChunk, ChunkStats> chunks = new HashMap<CoordinatesChunk, ChunkStats>();
|
||||
|
||||
for (TileEntityStats stat : TileEntityManager.stats.values()){
|
||||
if (!chunks.containsKey(stat.getChunk()))
|
||||
chunks.put(stat.getChunk(), new ChunkStats(stat.getChunk(), 0, 0));
|
||||
|
||||
chunks.get(stat.getChunk()).nentities += 1;
|
||||
chunks.get(stat.getChunk()).updateTime += stat.getGeometricMean();
|
||||
}
|
||||
|
||||
ArrayList<ChunkStats> chunksUpdate = new ArrayList<ChunkStats>(chunks.values());
|
||||
return chunksUpdate;
|
||||
}
|
||||
|
||||
public static ArrayList<ChunkStats> getTopChunks(int quantity){
|
||||
ArrayList<ChunkStats> chunks = ChunkManager.getChunksUpdateTime();
|
||||
ArrayList<ChunkStats> outList = new ArrayList<ChunkStats>();
|
||||
Collections.sort(chunks);
|
||||
|
||||
for (int i = 0; i < Math.min(quantity, chunks.size()); i++)
|
||||
outList.add(chunks.get(i));
|
||||
|
||||
return outList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +1,45 @@
|
||||
package mcp.mobius.opis.data.holders;
|
||||
|
||||
public class ChunkStats {
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ChunkStats implements ISerializable, Comparable{
|
||||
public int nentities = 0;
|
||||
public double updateTime = 0;
|
||||
|
||||
public CoordinatesChunk coord;
|
||||
|
||||
public ChunkStats(){}
|
||||
|
||||
public ChunkStats(int nentities, double updateTime){
|
||||
public ChunkStats(CoordinatesChunk coord, int nentities, double updateTime){
|
||||
this.nentities = nentities;
|
||||
this.updateTime = updateTime;
|
||||
this.coord = coord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object arg0) {
|
||||
double value = ((ChunkStats)arg0).updateTime - this.updateTime;
|
||||
if (value > 0)
|
||||
return 1;
|
||||
if (value < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException{
|
||||
this.coord.writeToStream(stream);
|
||||
stream.writeInt(this.nentities);
|
||||
stream.writeDouble(this.updateTime);
|
||||
}
|
||||
|
||||
public static ChunkStats readFromStream(DataInputStream stream) throws IOException {
|
||||
CoordinatesChunk coord = CoordinatesChunk.readFromStream(stream);
|
||||
return new ChunkStats(coord, stream.readInt(), stream.readDouble());
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return String.format("%s %s %s", this.coord, this.updateTime / 1000, this.nentities);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import java.util.logging.Logger;
|
||||
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerRegistrar;
|
||||
import mcp.mobius.opis.commands.CommandChunkDump;
|
||||
import mcp.mobius.opis.commands.CommandChunks;
|
||||
import mcp.mobius.opis.commands.CommandFrequency;
|
||||
import mcp.mobius.opis.commands.CommandStart;
|
||||
import mcp.mobius.opis.commands.CommandStop;
|
||||
@@ -59,7 +60,7 @@ public class modOpis {
|
||||
|
||||
@EventHandler
|
||||
public void serverStarting(FMLServerStartingEvent event){
|
||||
//event.registerServerCommand(new CommandChunkDump());
|
||||
event.registerServerCommand(new CommandChunks());
|
||||
event.registerServerCommand(new CommandFrequency());
|
||||
event.registerServerCommand(new CommandStart());
|
||||
event.registerServerCommand(new CommandStop());
|
||||
|
||||
@@ -26,7 +26,8 @@ public class Packet_MeanTime {
|
||||
int nchunks = inputStream.readInt();
|
||||
|
||||
for (int i = 0; i <= nchunks; i++){
|
||||
this.chunkStatus.put(new CoordinatesChunk(dim, inputStream.readInt(), inputStream.readInt()), new ChunkStats(inputStream.readInt(), inputStream.readDouble()));
|
||||
CoordinatesChunk coord = new CoordinatesChunk(dim, inputStream.readInt(), inputStream.readInt());
|
||||
this.chunkStatus.put(coord, new ChunkStats(coord, inputStream.readInt(), inputStream.readDouble()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user