mirror of
https://github.com/BX-Team/DivineMC.git
synced 2025-12-19 14:59:25 +00:00
80 lines
4.9 KiB
Diff
80 lines
4.9 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 code by YatopiaMC, licensed under MIT
|
|
You can find the original code on https://github.com/YatopiaMC/Yatopia
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index 9945d6efac1e1ea0d22d6fdfe8aa5d2805c615b2..b91a634777065969a4f3bb569a32c3645d42c4af 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -1098,6 +1098,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
// Spigot End
|
|
|
|
public static volatile RuntimeException chunkSystemCrash; // Paper - rewrite chunk system
|
|
+ public static java.time.Duration lastTickTime = java.time.Duration.ZERO; // Yatopia
|
|
|
|
protected void runServer() {
|
|
try {
|
|
@@ -1172,7 +1173,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
this.nextTickTime += 50L;
|
|
this.startMetricsRecordingTick();
|
|
this.profiler.push("tick");
|
|
+ long tickStart = System.nanoTime(); // Yatopia
|
|
this.tickServer(this::haveTime);
|
|
+ lastTickTime = java.time.Duration.ofNanos(System.nanoTime() - tickStart); // Yatopia
|
|
this.profiler.popPush("nextTickWait");
|
|
this.mayHaveDelayedTasks = true;
|
|
this.delayedTasksMaxNextTickTime = Math.max(Util.getMillis() + 50L, this.nextTickTime);
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
index efc137a8a9f1da4a7ffff6028af368cc7f90d20a..b8f51b262561fce967f99801ad595de8faaddd0d 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -2922,6 +2922,12 @@ public final class CraftServer implements Server {
|
|
public CraftPotionBrewer getPotionBrewer() {
|
|
return this.potionBrewer;
|
|
}
|
|
-
|
|
// Paper end
|
|
+
|
|
+ // Yatopia start
|
|
+ @Override
|
|
+ public java.time.Duration getLastTickTime() {
|
|
+ return net.minecraft.server.MinecraftServer.lastTickTime;
|
|
+ }
|
|
+ // Yatopia end
|
|
}
|
|
diff --git a/src/main/java/org/spigotmc/TicksPerSecondCommand.java b/src/main/java/org/spigotmc/TicksPerSecondCommand.java
|
|
index 9bede6a26c08ede063c7a38f1149c811df14b258..b735769b7876e54db2950ebb4170484447cfb9a6 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] = TicksPerSecondCommand.format( tps[i] );
|
|
}
|
|
sender.sendMessage(ChatColor.GOLD + "TPS from last 1m, 5m, 15m: " + org.apache.commons.lang.StringUtils.join(tpsAvg, ", "));
|
|
+ // Yatopia start - Last tick time API
|
|
+ java.time.Duration lastTickTime = org.bukkit.Bukkit.getLastTickTime();
|
|
+ sender.sendMessage(ChatColor.GOLD + "Last tick: " + TicksPerSecondCommand.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,15 @@ 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 - Last tick time API
|
|
+ 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
|
|
}
|