Added skeleton for client side render tick timing.

Fixed name lookup for ticks (will require an AT)
This commit is contained in:
ProfMobius committed 2013-12-23 04:34:09 +01:00
1 parent ab175caa8f
commit 0ae51bbfb8
10 files changed
+311 -20

No files matched your search

@@ -1,28 +1,54 @@
package mcp.mobius.opis.client;
import java.util.EnumSet;
import java.util.logging.Level;
import mcp.mobius.mobiuscore.profiler.DummyProfiler;
import mcp.mobius.mobiuscore.profiler.ProfilerRegistrar;
import mcp.mobius.opis.modOpis;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;
import cpw.mods.fml.common.network.PacketDispatcher;
public class OpisClientTickHandler implements ITickHandler {
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData) {
// TODO Auto-generated method stub
public long profilerUpdateTickCounter = 0;
public long profilerRunningTicks;
}
public static OpisClientTickHandler instance;
public OpisClientTickHandler(){
instance = this;
}
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData) {}
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData) {
if(type.contains(TickType.RENDER)){
if(type.contains(TickType.CLIENT)){
profilerUpdateTickCounter++;
if (profilerRunningTicks < modOpis.profilerMaxTicks && modOpis.profilerRun){
profilerRunningTicks++;
}
else if (profilerRunningTicks >= modOpis.profilerMaxTicks && modOpis.profilerRun){
profilerRunningTicks = 0;
modOpis.profilerRun = false;
ProfilerRegistrar.registerProfilerTileEntity(new DummyProfiler());
ProfilerRegistrar.registerProfilerEntity(new DummyProfiler());
ProfilerRegistrar.registerProfilerTick(new DummyProfiler());
//TODO : Print something to the client chat
System.out.printf("Profiling done\n");
//modOpis.log.log(Level.INFO, "Profiling done");
}
}
}
@Override
public EnumSet<TickType> ticks() {
return EnumSet.of(TickType.RENDER);
return EnumSet.of(TickType.CLIENT);
}
@Override
@@ -0,0 +1,38 @@
package mcp.mobius.opis.commands.client;
import mcp.mobius.opis.network.ClientCommand;
import mcp.mobius.opis.network.server.Packet_ClientCommand;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
public class CommandClientShowRenderTick extends CommandBase {
@Override
public String getCommandName() {
return "opis_ctick";
}
@Override
public String getCommandUsage(ICommandSender icommandsender) {
return "";
}
@Override
public void processCommand(ICommandSender icommandsender, String[] astring) {
((EntityPlayerMP)icommandsender).playerNetServerHandler.sendPacketToPlayer(Packet_ClientCommand.create(ClientCommand.SHOW_RENDER_TICK));
}
@Override
public int getRequiredPermissionLevel()
{
return 0;
}
@Override
public boolean canCommandSenderUseCommand(ICommandSender sender)
{
return true;
}
}
@@ -0,0 +1,38 @@
package mcp.mobius.opis.commands.client;
import mcp.mobius.opis.network.ClientCommand;
import mcp.mobius.opis.network.server.Packet_ClientCommand;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
public class CommandClientStart extends CommandBase {
@Override
public String getCommandName() {
return "opis_cstart";
}
@Override
public String getCommandUsage(ICommandSender icommandsender) {
return "";
}
@Override
public void processCommand(ICommandSender icommandsender, String[] astring) {
((EntityPlayerMP)icommandsender).playerNetServerHandler.sendPacketToPlayer(Packet_ClientCommand.create(ClientCommand.START_PROFILING));
}
@Override
public int getRequiredPermissionLevel()
{
return 0;
}
@Override
public boolean canCommandSenderUseCommand(ICommandSender sender)
{
return true;
}
}
@@ -0,0 +1,57 @@
package mcp.mobius.opis.data.client;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import cpw.mods.fml.common.IScheduledTickHandler;
import cpw.mods.fml.common.SingleIntervalHandler;
import mcp.mobius.opis.data.holders.TickHandlerStats;
public class TickHandlerClientManager {
public static HashMap<String, TickHandlerStats> startStats = new HashMap<String, TickHandlerStats>();
public static HashMap<String, TickHandlerStats> endStats = new HashMap<String, TickHandlerStats>();
public static void addHandlerStart(IScheduledTickHandler handler, long timing){
String name = getHandlerName(handler);
if (!(startStats.containsKey(name)))
startStats.put(name, new TickHandlerStats(name));
startStats.get(name).addMeasure(timing);
}
public static void addHandlerEnd(IScheduledTickHandler handler, long timing){
String name = getHandlerName(handler);
if (!(endStats.containsKey(name)))
endStats.put(name, new TickHandlerStats(name));
endStats.get(name).addMeasure(timing);
}
public static ArrayList<TickHandlerStats> getCumulatedStats(){
HashMap<String, TickHandlerStats> totalStats = new HashMap<String, TickHandlerStats>();
for (String key : startStats.keySet()){
totalStats.put(key, new TickHandlerStats(key));
totalStats.get(key).setGeometricMean(startStats.get(key).getGeometricMean() + endStats.get(key).getGeometricMean());
}
ArrayList<TickHandlerStats> sortedStats = new ArrayList(totalStats.values());
Collections.sort(sortedStats);
return sortedStats;
}
public static String getHandlerName(IScheduledTickHandler handler){
String name = handler.getLabel();
if (name == null || name.equals(""))
if (handler instanceof SingleIntervalHandler)
name = ((SingleIntervalHandler)handler).wrapped.getClass().getName();
else
name = handler.getClass().getName();
return name;
}
}
@@ -0,0 +1,75 @@
package mcp.mobius.opis.data.client;
import java.util.EnumSet;
import mcp.mobius.mobiuscore.profiler.IProfilerTick;
import mcp.mobius.opis.modOpis;
import mcp.mobius.opis.client.OpisClientTickHandler;
import mcp.mobius.opis.data.server.TickHandlerManager;
import mcp.mobius.opis.server.OpisServerTickHandler;
import cpw.mods.fml.common.IScheduledTickHandler;
import cpw.mods.fml.common.TickType;
public class TickHandlerClientProfiler implements IProfilerTick {
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;}
}
private String currentHandler = null;
private Clock clock = new Clock();
@Override
public void StartTickStart(IScheduledTickHandler ticker, EnumSet<TickType> ticksToRun) {
//if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) return;
if ((!modOpis.profilerRun) || (OpisClientTickHandler.instance.profilerUpdateTickCounter % modOpis.profilerDelay != 0)) return;
if (!ticksToRun.contains(TickType.RENDER)) return;
String name = TickHandlerClientManager.getHandlerName(ticker);
this.currentHandler = name;
this.clock.start();
}
@Override
public void StopTickStart(IScheduledTickHandler ticker, EnumSet<TickType> ticksToRun) {
if ((!modOpis.profilerRun) || (OpisClientTickHandler.instance.profilerUpdateTickCounter % modOpis.profilerDelay != 0)) return;
if (!ticksToRun.contains(TickType.RENDER)) return;
this.clock.stop();
String name = TickHandlerClientManager.getHandlerName(ticker);
if (!this.currentHandler.equals(name))
throw new RuntimeException(String.format("Mismatched tick handler during the profiling ! %s %s", this.currentHandler, ticker.getLabel()));
//EntityManager.addEntity(ent, this.clock.timeDelta);
TickHandlerClientManager.addHandlerStart(ticker, this.clock.timeDelta);
this.currentHandler = null;
}
@Override
public void StartTickEnd(IScheduledTickHandler ticker, EnumSet<TickType> ticksToRun) {
if ((!modOpis.profilerRun) || (OpisClientTickHandler.instance.profilerUpdateTickCounter % modOpis.profilerDelay != 0)) return;
if (!ticksToRun.contains(TickType.RENDER)) return;
String name = TickHandlerClientManager.getHandlerName(ticker);
this.currentHandler = name;
this.clock.start();
}
@Override
public void StopTickEnd(IScheduledTickHandler ticker, EnumSet<TickType> ticksToRun) {
if ((!modOpis.profilerRun) || (OpisClientTickHandler.instance.profilerUpdateTickCounter % modOpis.profilerDelay != 0)) return;
if (!ticksToRun.contains(TickType.RENDER)) return;
this.clock.stop();
String name = TickHandlerClientManager.getHandlerName(ticker);
if (!this.currentHandler.equals(name))
throw new RuntimeException(String.format("Mismatched tick handler during the profiling ! %s %s", this.currentHandler, ticker.getLabel()));
TickHandlerClientManager.addHandlerEnd(ticker, this.clock.timeDelta);
this.currentHandler = null;
}
}
@@ -5,6 +5,7 @@ import java.util.Collections;
import java.util.HashMap;
import cpw.mods.fml.common.IScheduledTickHandler;
import cpw.mods.fml.common.SingleIntervalHandler;
import mcp.mobius.opis.data.holders.TickHandlerStats;
public class TickHandlerManager {
@@ -13,15 +14,19 @@ public class TickHandlerManager {
public static HashMap<String, TickHandlerStats> endStats = new HashMap<String, TickHandlerStats>();
public static void addHandlerStart(IScheduledTickHandler handler, long timing){
if (!(startStats.containsKey(handler.getLabel())))
startStats.put(handler.getLabel(), new TickHandlerStats(handler.getLabel()));
startStats.get(handler.getLabel()).addMeasure(timing);
String name = getHandlerName(handler);
if (!(startStats.containsKey(name)))
startStats.put(name, new TickHandlerStats(name));
startStats.get(name).addMeasure(timing);
}
public static void addHandlerEnd(IScheduledTickHandler handler, long timing){
if (!(endStats.containsKey(handler.getLabel())))
endStats.put(handler.getLabel(), new TickHandlerStats(handler.getLabel()));
endStats.get(handler.getLabel()).addMeasure(timing);
String name = getHandlerName(handler);
if (!(endStats.containsKey(name)))
endStats.put(name, new TickHandlerStats(name));
endStats.get(name).addMeasure(timing);
}
public static ArrayList<TickHandlerStats> getCumulatedStats(){
@@ -38,5 +43,14 @@ public class TickHandlerManager {
return sortedStats;
}
public static String getHandlerName(IScheduledTickHandler handler){
String name = handler.getLabel();
if (name == null || name.equals(""))
if (handler instanceof SingleIntervalHandler)
name = ((SingleIntervalHandler)handler).wrapped.getClass().getName();
else
name = handler.getClass().getName();
return name;
}
}
@@ -25,7 +25,9 @@ public class TickHandlerProfiler implements IProfilerTick {
//if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) return;
if ((!modOpis.profilerRun) || (OpisServerTickHandler.instance.profilerUpdateTickCounter % modOpis.profilerDelay != 0)) return;
if (!ticksToRun.contains(TickType.SERVER)) return;
this.currentHandler = ticker.getLabel();
String name = TickHandlerManager.getHandlerName(ticker);
this.currentHandler = name;
this.clock.start();
}
@@ -35,7 +37,8 @@ public class TickHandlerProfiler implements IProfilerTick {
if (!ticksToRun.contains(TickType.SERVER)) return;
this.clock.stop();
if (!this.currentHandler.equals(ticker.getLabel()))
String name = TickHandlerManager.getHandlerName(ticker);
if (!this.currentHandler.equals(name))
throw new RuntimeException(String.format("Mismatched tick handler during the profiling ! %s %s", this.currentHandler, ticker.getLabel()));
//EntityManager.addEntity(ent, this.clock.timeDelta);
@@ -47,7 +50,9 @@ public class TickHandlerProfiler implements IProfilerTick {
public void StartTickEnd(IScheduledTickHandler ticker, EnumSet<TickType> ticksToRun) {
if ((!modOpis.profilerRun) || (OpisServerTickHandler.instance.profilerUpdateTickCounter % modOpis.profilerDelay != 0)) return;
if (!ticksToRun.contains(TickType.SERVER)) return;
this.currentHandler = ticker.getLabel();
String name = TickHandlerManager.getHandlerName(ticker);
this.currentHandler = name;
this.clock.start();
}
@@ -57,7 +62,8 @@ public class TickHandlerProfiler implements IProfilerTick {
if (!ticksToRun.contains(TickType.SERVER)) return;
this.clock.stop();
if (!this.currentHandler.equals(ticker.getLabel()))
String name = TickHandlerManager.getHandlerName(ticker);
if (!this.currentHandler.equals(name))
throw new RuntimeException(String.format("Mismatched tick handler during the profiling ! %s %s", this.currentHandler, ticker.getLabel()));
TickHandlerManager.addHandlerEnd(ticker, this.clock.timeDelta);
+7 -1
View File
@@ -8,6 +8,8 @@ import net.minecraftforge.common.MinecraftForge;
import mcp.mobius.mobiuscore.profiler.ProfilerRegistrar;
import mcp.mobius.opis.client.OpisClientEventHandler;
import mcp.mobius.opis.client.OpisClientTickHandler;
import mcp.mobius.opis.commands.client.CommandClientShowRenderTick;
import mcp.mobius.opis.commands.client.CommandClientStart;
import mcp.mobius.opis.commands.client.CommandClientTest;
import mcp.mobius.opis.commands.server.CommandAmountEntities;
import mcp.mobius.opis.commands.server.CommandChunkDump;
@@ -89,6 +91,7 @@ public class modOpis {
@EventHandler
public void load(FMLInitializationEvent event) {
TickRegistry.registerTickHandler(new OpisServerTickHandler(), Side.SERVER);
TickRegistry.registerTickHandler(new OpisClientTickHandler(), Side.CLIENT);
}
@EventHandler
@@ -115,8 +118,11 @@ public class modOpis {
event.registerServerCommand(new CommandHandler());
event.registerServerCommand(new CommandClientTest());
event.registerServerCommand(new CommandClientStart());
event.registerServerCommand(new CommandClientShowRenderTick());
event.registerServerCommand(new CommandHelp());
//event.registerServerCommand(new CommandHelp());
//event.registerServerCommand(new CommandTPS());
GameRegistry.registerPlayerTracker(new OpisPlayerTracker());
@@ -2,4 +2,9 @@ package mcp.mobius.opis.network;
public class ClientCommand {
public static byte TEST_CMD = 0x00;
public static byte START_PROFILING = 0x01;
public static byte STOP_PROFILING = 0x02;
public static byte RESET_PROFILING = 0x03;
public static byte SHOW_RENDER_TICK = 0x04;
}
@@ -1,5 +1,15 @@
package mcp.mobius.opis.network;
import java.util.ArrayList;
import java.util.logging.Level;
import mcp.mobius.mobiuscore.profiler.ProfilerRegistrar;
import mcp.mobius.opis.modOpis;
import mcp.mobius.opis.client.OpisClientTickHandler;
import mcp.mobius.opis.data.client.TickHandlerClientManager;
import mcp.mobius.opis.data.client.TickHandlerClientProfiler;
import mcp.mobius.opis.data.holders.TickHandlerStats;
public class ClientCommandHandler {
private static ClientCommandHandler _instance;
@@ -12,6 +22,22 @@ public class ClientCommandHandler {
}
public void handle(byte cmd){
System.out.printf("Received client cmd with id %s\n", cmd);
if (cmd == ClientCommand.START_PROFILING){
modOpis.log.log(Level.INFO, "Started profiling");
modOpis.profilerRun = true;
OpisClientTickHandler.instance.profilerRunningTicks = 0;
TickHandlerClientManager.startStats.clear();
TickHandlerClientManager.endStats.clear();
ProfilerRegistrar.registerProfilerTick(new TickHandlerClientProfiler());
}
else if (cmd == ClientCommand.SHOW_RENDER_TICK){
modOpis.log.log(Level.INFO, "=== RENDER TICK ===");
ArrayList<TickHandlerStats> stats = TickHandlerClientManager.getCumulatedStats();
for (TickHandlerStats stat : stats){
System.out.printf("%s \n", stat);
}
}
}
}