2020-07-17 18:05:50 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2020-03-05 21:14:17 +01:00
From: tr7zw <tr7zw@live.de>
2020-08-03 18:48:42 +02:00
Date: Fri, 31 Jul 2020 21:19:26 -0500
Subject: [PATCH] Add getLastTickMs api
2020-03-05 21:14:17 +01:00
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2020-09-11 08:03:00 +02:00
index 323d489b1e690500986bc0cbb4c2c93cc193bf70..5274dcde8b06200357b11b77cc72ec415d4e47e4 100644
2020-03-05 21:14:17 +01:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2020-08-13 17:53:32 +02:00
@@ -928,6 +928,8 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2020-03-05 21:14:17 +01:00
// Paper End
// Spigot End
2020-08-03 18:48:42 +02:00
+ public static long lastTickMs = 0; // Yatopia
+
2020-08-13 17:53:32 +02:00
protected void w() {
2020-04-27 00:29:45 +02:00
try {
2020-08-03 18:48:42 +02:00
long serverStartTime = SystemUtils.getMonotonicNanos(); // Paper
2020-08-13 17:53:32 +02:00
@@ -996,7 +998,9 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2020-06-27 15:45:01 +02:00
this.a(gameprofilertick);
2020-08-03 18:48:42 +02:00
//this.methodProfiler.a(); // Akarin - remove caller
//this.methodProfiler.enter("tick"); // Akarin - remove caller
+ long tickStart = System.currentTimeMillis(); // Yatopia
2020-03-05 21:14:17 +01:00
this.a(this::canSleepForTick);
2020-08-03 18:48:42 +02:00
+ lastTickMs = System.currentTimeMillis() - tickStart; // Yatopia
//this.methodProfiler.exitEnter("nextTickWait"); // Akarin - remove caller
2020-06-27 15:45:01 +02:00
this.X = true;
2020-08-03 18:48:42 +02:00
// Purpur start - tps catchup
2020-03-05 21:14:17 +01:00
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2020-09-11 08:03:00 +02:00
index d7b45169369d6463d1d0b0de0a62b32079da34ce..521e2e4923775aa5a198fd370818a9873019c102 100644
2020-03-05 21:14:17 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2020-08-24 08:08:09 +02:00
@@ -2417,4 +2417,11 @@ public final class CraftServer implements Server {
2020-08-03 18:48:42 +02:00
return getServer().lagging;
2020-03-05 21:14:17 +01:00
}
2020-08-03 18:48:42 +02:00
// Purpur end
2020-03-05 21:14:17 +01:00
+
2020-08-03 18:48:42 +02:00
+ // Yatopia start
+ @Override
2020-08-13 17:53:32 +02:00
+ public long getLastTickMs() {
2020-08-03 18:48:42 +02:00
+ return net.minecraft.server.MinecraftServer.lastTickMs;
+ }
+ // Yatopia end
2020-03-05 21:14:17 +01:00
}
diff --git a/src/main/java/org/spigotmc/TicksPerSecondCommand.java b/src/main/java/org/spigotmc/TicksPerSecondCommand.java
2020-08-15 11:43:24 +02:00
index 3c7b9a6d24e064f9c1ec5fb6d52f42627944d7fa..76cf2353754821361a4541c21fc8d5f1a670b0de 100644
2020-03-05 21:14:17 +01:00
--- a/src/main/java/org/spigotmc/TicksPerSecondCommand.java
+++ b/src/main/java/org/spigotmc/TicksPerSecondCommand.java
2020-06-28 15:31:41 +02:00
@@ -33,7 +33,7 @@ public class TicksPerSecondCommand extends Command
2020-03-05 21:14:17 +01:00
for ( int i = 0; i < tps.length; i++) {
tpsAvg[i] = format( tps[i] );
}
2020-08-03 18:48:42 +02:00
- sender.sendMessage(ChatColor.GOLD + "TPS from last 5s, 1m, 5m, 15m: " + org.apache.commons.lang.StringUtils.join(tpsAvg, ", ")); // Purpur
2020-08-13 17:53:32 +02:00
+ sender.sendMessage(ChatColor.GOLD + "TPS from last 5s, 1m, 5m, 15m: " + org.apache.commons.lang.StringUtils.join(tpsAvg, ", ") + ChatColor.GOLD + " Last tick time: " + format( org.bukkit.Bukkit.getLastTickMs() )); // Purpur // Yatopia
2020-06-30 16:39:06 +02:00
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) {
2020-08-13 17:53:32 +02:00
@@ -52,4 +52,12 @@ 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
2020-08-15 11:43:24 +02:00
+ public static String format(long ms)
2020-08-13 17:53:32 +02:00
+ {
+ ChatColor startingColor = ms < 40 ? ChatColor.GREEN : ( ms < 50 ) ? ChatColor.YELLOW : ChatColor.RED;
2020-08-15 11:43:24 +02:00
+ return startingColor.toString() + ms + ChatColor.GOLD + "ms";
2020-08-13 17:53:32 +02:00
+ }
+ // Yatopia end
}