Skip to content

Commit

Permalink
Merge branch 'timings'
Browse files Browse the repository at this point in the history
  • Loading branch information
wode490390 committed Aug 13, 2023
2 parents 4f88a0a + ce8a2dd commit 2ab868b
Show file tree
Hide file tree
Showing 49 changed files with 7 additions and 1,853 deletions.
22 changes: 2 additions & 20 deletions src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@
import cn.nukkit.resourcepacks.ResourcePack;
import cn.nukkit.scheduler.AsyncTask;
import cn.nukkit.utils.*;
import co.aikar.timings.Timing;
import co.aikar.timings.Timings;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.primitives.Floats;
Expand Down Expand Up @@ -955,14 +953,11 @@ protected void sendNextChunk() {
return;
}

Timings.playerChunkSendTimer.startTiming();

this.sendQueuedChunk();

if ((this.canDoFirstSpawn() || System.currentTimeMillis() - this.creationTime > 15000) && !this.spawned && this.teleportPosition == null) {
this.doFirstSpawn();
}
Timings.playerChunkSendTimer.stopTiming();
}

protected boolean canDoFirstSpawn() {
Expand Down Expand Up @@ -1130,8 +1125,6 @@ protected boolean orderChunks() {
return false;
}

Timings.playerChunkOrderTimer.startTiming();

this.nextChunkOrderRun = 200;

loadQueue.clear();
Expand Down Expand Up @@ -1164,7 +1157,6 @@ protected boolean orderChunks() {
this.unloadChunk(Level.getHashX(index), Level.getHashZ(index));
}

Timings.playerChunkOrderTimer.stopTiming();
return true;
}

Expand All @@ -1185,7 +1177,7 @@ public boolean dataPacket(DataPacket packet) {
return false;
}

try (Timing timing = Timings.getSendDataPacketTiming(packet)) {
{
DataPacketSendEvent ev = new DataPacketSendEvent(this, packet);
this.server.getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
Expand Down Expand Up @@ -1515,8 +1507,6 @@ public boolean fastMove(double dx, double dy, double dz) {
return true;
}

Timings.entityMoveTimer.startTiming();

AxisAlignedBB newBB = this.boundingBox.getOffsetBoundingBox(dx, dy, dz);

if (this.isSpectator() || server.getAllowFlight() || !this.level.hasCollision(this, newBB, false)) {
Expand Down Expand Up @@ -1562,7 +1552,6 @@ public boolean fastMove(double dx, double dy, double dz) {
this.motionZ = dz;*/
}

Timings.entityMoveTimer.stopTiming();
return true;
}

Expand Down Expand Up @@ -2128,8 +2117,6 @@ public void checkInteractNearby() {
* @return Entity|null either NULL if no entity is found or an instance of the entity
*/
public EntityInteractable getEntityPlayerLookingAt(int maxDistance) {
timing.startTiming();

EntityInteractable entity = null;

// just a fix because player MAY not be fully initialized
Expand All @@ -2154,7 +2141,6 @@ public EntityInteractable getEntityPlayerLookingAt(int maxDistance) {
}
}

timing.stopTiming();

return entity;
}
Expand Down Expand Up @@ -2454,16 +2440,14 @@ public void handleDataPacket(DataPacket packet) {
return;
}

try (Timing timing = Timings.getReceiveDataPacketTiming(packet)) {
{
DataPacketReceiveEvent ev = new DataPacketReceiveEvent(this, packet);
this.server.getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
timing.stopTiming();
return;
}

if (packet.pid() == ProtocolInfo.BATCH_PACKET) {
timing.stopTiming();
// this.server.getNetwork().processBatch((BatchPacket) packet, this);
// Batch packets are already decoded in Synapse
onPacketViolation(PacketViolationReason.NESTED_BATCH);
Expand Down Expand Up @@ -3226,9 +3210,7 @@ public void onCompletion(Server server) {
break;
}

Timings.playerCommandTimer.startTiming();
this.server.dispatchCommand(playerCommandPreprocessEvent.getPlayer(), playerCommandPreprocessEvent.getMessage().substring(1));
Timings.playerCommandTimer.stopTiming();
break;
case ProtocolInfo.TEXT_PACKET:
if (!this.spawned || !this.isAlive()) {
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/cn/nukkit/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
import cn.nukkit.scheduler.ServerScheduler;
import cn.nukkit.utils.*;
import cn.nukkit.utils.bugreport.ExceptionHandler;
import co.aikar.timings.Timings;
import com.dosse.upnp.UPnP;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
Expand Down Expand Up @@ -659,12 +658,10 @@ public void batchPackets(Player[] players, DataPacket[] packets, boolean forceSy
if (players == null || packets == null || players.length == 0 || packets.length == 0) {
return;
}
Timings.playerNetworkSendTimer.startTiming();

BatchPacketsEvent ev = new BatchPacketsEvent(players, packets, forceSync);
getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
Timings.playerNetworkSendTimer.stopTiming();
return;
}

Expand Down Expand Up @@ -700,7 +697,6 @@ public void batchPackets(Player[] players, DataPacket[] packets, boolean forceSy
throw new RuntimeException(e);
}
}
Timings.playerNetworkSendTimer.stopTiming();
}

public void broadcastPacketsCallback(byte[] data, List<InetSocketAddress> targets) {
Expand Down Expand Up @@ -804,7 +800,6 @@ public void reload() {
this.pluginManager.loadPlugins(this.pluginPath);
this.enablePlugins(PluginLoadOrder.STARTUP);
this.enablePlugins(PluginLoadOrder.POSTWORLD);
Timings.reset();
}

public void shutdown() {
Expand Down Expand Up @@ -861,8 +856,6 @@ public void forceShutdown() {
this.network.unregisterInterface(interfaz);
}

log.debug("Disabling timings");
Timings.stopServer();
if (this.watchdog != null) {
this.watchdog.kill();
}
Expand Down Expand Up @@ -1125,7 +1118,6 @@ private void checkTickUpdates(int currentTick, long tickTime) {

public void doAutoSave() {
if (this.getAutoSave()) {
Timings.levelSaveTimer.startTiming();
for (Player player : new ArrayList<>(this.players.values())) {
if (player.isOnline()) {
player.save(true);
Expand All @@ -1137,7 +1129,6 @@ public void doAutoSave() {
for (Level level : this.getLevels().values()) {
level.save();
}
Timings.levelSaveTimer.stopTiming();
}
}

Expand All @@ -1148,21 +1139,15 @@ private boolean tick() {
return false;
}

Timings.fullServerTickTimer.startTiming();

++this.tickCounter;

Timings.connectionTimer.startTiming();
this.network.processInterfaces();

if (this.rcon != null) {
this.rcon.check();
}
Timings.connectionTimer.stopTiming();

Timings.schedulerTimer.startTiming();
this.scheduler.mainThreadHeartbeat(this.tickCounter);
Timings.schedulerTimer.stopTiming();

this.checkTickUpdates(this.tickCounter, tickTime);

Expand Down Expand Up @@ -1206,7 +1191,6 @@ private boolean tick() {
}
}

Timings.fullServerTickTimer.stopTiming();
//long now = System.currentTimeMillis();
long nowNano = System.nanoTime();
//float tick = Math.min(20, 1000 / Math.max(1, now - tickTime));
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/cn/nukkit/blockentity/BlockEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import cn.nukkit.math.Vector3;
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.utils.ChunkException;
import co.aikar.timings.Timing;
import co.aikar.timings.Timings;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import lombok.extern.log4j.Log4j2;
Expand All @@ -36,14 +34,12 @@ public abstract class BlockEntity extends Position implements BlockEntityID {

protected int lastUpdate;
protected Server server;
protected Timing timing;

public BlockEntity(FullChunk chunk, CompoundTag nbt) {
if (chunk == null || chunk.getProvider() == null) {
throw new ChunkException("Invalid garbage Chunk given to Block Entity");
}

this.timing = Timings.getBlockEntityTiming(this);
this.server = chunk.getProvider().getLevel().getServer();
this.chunk = chunk;
this.setLevel(chunk.getProvider().getLevel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ public boolean onUpdate() {
return true;
}
lastUpdate = currentTick;
timing.startTiming();

boolean hasUpdate = false;

Expand Down Expand Up @@ -208,7 +207,6 @@ public boolean onUpdate() {
this.server.getPluginManager().callEvent(e);
if (e.isCancelled()) {
brewing = false;
timing.stopTiming();
return false;
}
}
Expand Down Expand Up @@ -257,7 +255,6 @@ public boolean onUpdate() {
}
brewing = canBrew;

timing.stopTiming();
return hasUpdate;
}

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/cn/nukkit/blockentity/BlockEntityCampfire.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ public boolean onUpdate() {
return true;
}
lastUpdate = currentTick;
timing.startTiming();

if (!canCooking()) {
timing.stopTiming();
return false;
}

Expand Down Expand Up @@ -140,7 +138,6 @@ public boolean onUpdate() {
level.addLevelSoundEvent(add(0.5, 0.2, 0.5), LevelSoundEventPacket.SOUND_BLOCK_CAMPFIRE_CRACKLE);
}

timing.stopTiming();
return true;
}

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/cn/nukkit/blockentity/BlockEntityFurnace.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ public boolean onUpdate() {
return true;
}
lastUpdate = currentTick;
this.timing.startTiming();

boolean ret = false;
Item fuel = this.inventory.getFuel();
Expand Down Expand Up @@ -310,8 +309,6 @@ public boolean onUpdate() {
}
}

this.timing.stopTiming();

return ret;
}

Expand Down
6 changes: 0 additions & 6 deletions src/main/java/cn/nukkit/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import cn.nukkit.lang.TranslationContainer;
import cn.nukkit.permission.Permissible;
import cn.nukkit.utils.TextFormat;
import co.aikar.timings.Timing;
import co.aikar.timings.Timings;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;

Expand Down Expand Up @@ -44,8 +42,6 @@ public abstract class Command {

protected Map<String, CommandParameter[]> commandParameters = new Object2ObjectOpenHashMap<>();

public Timing timing;

public Command(String name) {
this(name, "", null, new String[0]);
}
Expand All @@ -72,7 +68,6 @@ public Command(String name, String description, String usageMessage, String... a
}
this.aliases = aliases;
this.activeAliases = aliases;
this.timing = Timings.getCommandTiming(this);
this.commandParameters.put("default", new CommandParameter[]{CommandParameter.newType("args", true, CommandParamType.RAWTEXT)});
}

Expand Down Expand Up @@ -191,7 +186,6 @@ public boolean setLabel(String name) {
this.nextLabel = name;
if (!this.isRegistered()) {
this.label = name;
this.timing = Timings.getCommandTiming(this);
return true;
}
return false;
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/cn/nukkit/command/SimpleCommandMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ private void setDefaultCommands() {
// if ((boolean) this.server.getConfig("debug.commands", false)) {
this.register("nukkit", new StatusCommand("status"));
this.register("nukkit", new GarbageCollectorCommand("gc"));
this.register("nukkit", new TimingsCommand("timings"));
//this.register("nukkit", new DumpMemoryCommand("dumpmemory"));
// }

Expand Down Expand Up @@ -275,7 +274,6 @@ public boolean dispatch(CommandSender sender, String cmdLine) {
return false;
}

target.timing.startTiming();
try {
target.execute(sender, sentCommandLabel, args);
} catch (Exception e) {
Expand All @@ -286,7 +284,6 @@ public boolean dispatch(CommandSender sender, String cmdLine) {
logger.logException(e);
}
}
target.timing.stopTiming();

return true;
}
Expand Down
Loading

0 comments on commit 2ab868b

Please sign in to comment.