Yatopia/patches/server/0005-Add-last-tick-time-API.patch
Simon Gardling 61f261ee2a
Updated Upstream and Sidestream(s) (Paper/Airplane/Purpur/Empirecraft/Origami) (#474)
Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Paper Changes:
b8020379c Extract Adventure Version into a variable, add reminder to update the linked JD on the homepage (#5422)
809466f2e Fix anchor respawn acting as a bed respawn when using the end portal (#5540)
d219fd642 [Auto] Updated Upstream (Bukkit/CraftBukkit)
db464b099 Implement methods to convert between Component and Brigadier's Message (#5542)
4047cffca Add PlayerBedFailEnterEvent (#4935)
70d697e6e Update Paperpclip
5ed771591 [CI-SKIP] Remove bad null annotation (#5538)
454a4c78e More World API (#3850)
869e02304 Add PlayerDeepSleepEvent (#5525)
fb56fc35e fix non-dummy objectives not updating
dc859a61f [CI-SKIP] [Auto] Rebuild Patches
7d1689f1a  Add missing checkReachable check for shulker boxes (#5453)
ba8eb3d4b Add missing Javadoc for COLORABLE MaterialTag (#5376)
db801cbf3 Fix PlayerItemHeldEvent firing twice (#5534)
14de2b795 fix PigZombieAngerEvent cancellation (fixes #5319) (v2) (#5329)
86d684ad1 Add get-set drop chance to EntityEquipment (#5528)
33fb8cf63 Add consumeFuel to FurnaceBurnEvent (#5532)
9957f4630 Fix duplicating /give items on item drop cancel (#5536)
d94882043 Fix legacyComposer not using AsyncChatEvent messages (#5509)
053bd82cc Don't print spawn load time when not loading spawn (#5467)
a6d78caae Add isDeeplySleeping to HumanEntity (#5470)
711b7a80b Expose more Adventure serializers through PaperComponents (#5443)
3f63bde0c Set Area Effect Cloud Rotation (#5462)
3523f0fda Remove useless check on player interact cancellation (#5448)
6574d1aa8 fix #5526 - use correct type when sending message to clients
dbfa833ec don't throw when loading TE with invalid keys
a9525a6f7 Do not schedule poi task for each block write on chunk gen

Airplane Changes:
f5fb024 Temporarily revert patch
3c728a7 Oops, these 2 too
37a93e5 Your daily dose of 1-3% optimization patches
bbd689a Remove useless check
d8bdbc5 Reduce allocations for fire spreading
41051fd Redo reduction of entity chunk ticking check patch
31272d8 Flare Update
8f32713 Remove criterion patch
0fed2df Various patches that need to be reorganized later
f78856b Updated Upstream (Tuinity)
f7d6382 Flare Update
71d0799 Update gradle configuration
0f79774 Updated Upstream (Tuinity)

Purpur Changes:
3dce975 Updated Upstream (Paper & Airplane) (#298)
eb07368 Run GitHub Actions for pull requests
e97d062 Updated Upstream (Paper, Tuinity, & Airplane)

Empirecraft Changes:
2a021ede Updated Paper
e963bb2c Add Paper MojangAPI to pom
6f5bf24e Updated Paper

Origami Changes:
73ecdf1 Update Paper
73a3735 Item and exp merge improvements
2021-04-27 12:40:55 -04:00

75 lines
4.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ivan Pekov <ivan@mrivanplays.com>
Date: Sun, 27 Sep 2020 18:30:10 +0300
Subject: [PATCH] Add last tick time API
Original patch by:
Co-authored-by: tr7zw <tr7zw@live.de>
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 7bba8508c22233ac524d782d159d97f6609748af..854dd6b63bdffa0d79befb36aa55bad408302283 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1064,6 +1064,8 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
// Paper End
// Spigot End
+ public static java.time.Duration lastTickTime = java.time.Duration.ZERO; // Yatopia
+
protected void w() {
try {
long serverStartTime = SystemUtils.getMonotonicNanos(); // Paper
@@ -1135,7 +1137,9 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
this.a(gameprofilertick);
this.methodProfiler.a();
this.methodProfiler.enter("tick");
+ long tickStart = System.nanoTime(); // Yatopia
this.a(this::canSleepForTick);
+ lastTickTime = java.time.Duration.ofNanos(System.nanoTime() - tickStart); // Yatopia
this.methodProfiler.exitEnter("nextTickWait");
this.X = true;
// Purpur start - tps catchup
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 7771fa5c98809b6c3aeff78ab9d0b8ec2178accc..449fce2d76c701b789dd09326c9a8fc818b39c45 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -2540,4 +2540,6 @@ public final class CraftServer implements Server {
return getServer().lagging;
}
// Purpur end
+
+ @Override public java.time.Duration getLastTickTime() { return net.minecraft.server.MinecraftServer.lastTickTime; } // Yatopia
}
diff --git a/src/main/java/org/spigotmc/TicksPerSecondCommand.java b/src/main/java/org/spigotmc/TicksPerSecondCommand.java
index 312248b5c6febc6a3c10940714fac7fbc3c53b7f..abc9b7aa53e554ef2196dceafe8db8ba65f34e84 100644
--- a/src/main/java/org/spigotmc/TicksPerSecondCommand.java
+++ b/src/main/java/org/spigotmc/TicksPerSecondCommand.java
@@ -32,6 +32,10 @@ public class TicksPerSecondCommand extends Command
tpsAvg[i] = format( tps[i] );
}
sender.sendMessage(ChatColor.GOLD + "TPS from last 5s, 1m, 5m, 15m: " + org.apache.commons.lang.StringUtils.join(tpsAvg, ", ")); // Purpur
+ // Yatopia start
+ java.time.Duration lastTickTime = org.bukkit.Bukkit.getLastTickTime();
+ sender.sendMessage(ChatColor.GOLD + "Last tick: " + formatTo( lastTickTime, java.util.concurrent.TimeUnit.MILLISECONDS ) + " (" + formatTo( lastTickTime, java.util.concurrent.TimeUnit.NANOSECONDS ) + ")");
+ // Yatopia end
if (args.length > 0 && args[0].equals("mem") && sender.hasPermission("bukkit.command.tpsmemory")) {
sender.sendMessage(ChatColor.GOLD + "Current Memory Usage: " + ChatColor.GREEN + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (1024 * 1024)) + "/" + (Runtime.getRuntime().totalMemory() / (1024 * 1024)) + " mb (Max: " + (Runtime.getRuntime().maxMemory() / (1024 * 1024)) + " mb)");
if (!hasShownMemoryWarning) {
@@ -50,4 +54,16 @@ public class TicksPerSecondCommand extends Command
return ( ( tps > 18.0 ) ? ChatColor.GREEN : ( tps > 16.0 ) ? ChatColor.YELLOW : ChatColor.RED ).toString()
+ ( ( tps > 21.0 ) ? "*" : "" ) + Math.min( Math.round( tps * 100.0 ) / 100.0, 20.0 ); // Paper - only print * at 21, we commonly peak to 20.02 as the tick sleep is not accurate enough, stop the noise
}
+
+ // Yatopia start
+ public static String formatTo(java.time.Duration duration, java.util.concurrent.TimeUnit unit)
+ {
+ java.util.concurrent.TimeUnit nanosUnit = java.util.concurrent.TimeUnit.NANOSECONDS;
+ long nanos = duration.toNanos();
+ long toAskedUnit = unit.convert( nanos, nanosUnit );
+ long ms = nanosUnit.toMillis( nanos );
+ ChatColor startingColor = ms < 40 ? ChatColor.GREEN : ( ms < 50 ) ? ChatColor.YELLOW : ChatColor.RED;
+ return startingColor.toString() + toAskedUnit + ChatColor.GOLD + org.yatopiamc.yatopia.server.util.TimeUtils.getFriendlyName( unit );
+ }
+ // Yatopia end
}