Files
PlazmaBukkitMC/patches/server/0054-SparklyPaper-MSPT-by-World.patch
2024-12-25 19:12:48 +09:00

178 lines
9.4 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: AlphaKR93 <dev@alpha93.kr>
Date: Fri, 13 Dec 2024 23:36:03 +0900
Subject: [PATCH] SparklyPaper - MSPT by World
diff --git a/src/main/java/io/papermc/paper/command/MSPTCommand.java b/src/main/java/io/papermc/paper/command/MSPTCommand.java
index 8b5293b0c696ef21d0101493ffa41b60bf0bc86b..bf3a6e8e35fe9869dfa56a97dd5d820296de9721 100644
--- a/src/main/java/io/papermc/paper/command/MSPTCommand.java
+++ b/src/main/java/io/papermc/paper/command/MSPTCommand.java
@@ -25,6 +25,29 @@ import static net.kyori.adventure.text.format.NamedTextColor.YELLOW;
public final class MSPTCommand extends Command {
private static final DecimalFormat DF = new DecimalFormat("########0.0");
private static final Component SLASH = text("/");
+ // Plazma start - MSPT by world
+ private static final Component COMMA = text(", ", YELLOW);
+ private static final Component HEADER = text().color(YELLOW).append(
+ text("("),
+ text("avg", GRAY),
+ text("/"),
+ text("min", GRAY),
+ text("/"),
+ text("max", GRAY),
+ text(")")
+ ).append(
+ text(" from last 1s"),
+ text(",", GRAY),
+ text(" 5s"),
+ text(",", GRAY),
+ text(" 10s"),
+ text(",", GRAY),
+ text(" 30s"),
+ text(",", GRAY),
+ text(" 1m"),
+ text(":", YELLOW)
+ ).build();
+ // Plazma end - MSPT by world
public MSPTCommand(final String name) {
super(name);
@@ -45,39 +68,44 @@ public final class MSPTCommand extends Command {
MinecraftServer server = MinecraftServer.getServer();
List<Component> times = new ArrayList<>();
+ // Plazma start - MSPT by world
+ times.addAll(eval(server.tickTimes1s.getTimes()));
times.addAll(eval(server.tickTimes5s.getTimes()));
times.addAll(eval(server.tickTimes10s.getTimes()));
+ times.addAll(eval(server.tickTimes30s.getTimes()));
times.addAll(eval(server.tickTimes60s.getTimes()));
- sender.sendMessage(text().content("Server tick times ").color(GOLD)
- .append(text().color(YELLOW)
- .append(
- text("("),
- text("avg", GRAY),
- text("/"),
- text("min", GRAY),
- text("/"),
- text("max", GRAY),
- text(")")
- )
- ).append(
- text(" from last 5s"),
- text(",", GRAY),
- text(" 10s"),
- text(",", GRAY),
- text(" 1m"),
- text(":", YELLOW)
- )
- );
- sender.sendMessage(text().content("◴ ").color(GOLD)
- .append(text().color(GRAY)
- .append(
- times.get(0), SLASH, times.get(1), SLASH, times.get(2), text(", ", YELLOW),
- times.get(3), SLASH, times.get(4), SLASH, times.get(5), text(", ", YELLOW),
- times.get(6), SLASH, times.get(7), SLASH, times.get(8)
- )
- )
- );
+ sender.sendMessage(text().content("Server tick times ").color(GOLD).append(HEADER));
+ sender.sendMessage(text().content("◴ ").color(GOLD).append(text().color(GRAY).append(
+ times.get(0), SLASH, times.get(1), SLASH, times.get(2), COMMA,
+ times.get(3), SLASH, times.get(4), SLASH, times.get(5), COMMA,
+ times.get(6), SLASH, times.get(7), SLASH, times.get(8), COMMA,
+ times.get(9), SLASH, times.get(10), SLASH, times.get(11), COMMA,
+ times.get(12), SLASH, times.get(13), SLASH, times.get(14)
+ )));
+
+ sender.sendMessage(text());
+ sender.sendMessage(text().content("World tick times ").color(GOLD).append(HEADER));
+ for (net.minecraft.server.level.ServerLevel serverLevel : server.getAllLevels()) {
+ List<Component> worldTimes = new ArrayList<>();
+ worldTimes.addAll(eval(serverLevel.tickTimes1s.getTimes()));
+ worldTimes.addAll(eval(serverLevel.tickTimes5s.getTimes()));
+ worldTimes.addAll(eval(serverLevel.tickTimes10s.getTimes()));
+ worldTimes.addAll(eval(serverLevel.tickTimes30s.getTimes()));
+ worldTimes.addAll(eval(serverLevel.tickTimes60s.getTimes()));
+
+ sender.sendMessage(text().content("◴ " + serverLevel.getWorld().getName() + ": ").color(GOLD).append(
+ text().color(GRAY).append(
+ worldTimes.get(0), SLASH, worldTimes.get(1), SLASH, worldTimes.get(2), COMMA,
+ worldTimes.get(3), SLASH, worldTimes.get(4), SLASH, worldTimes.get(5), COMMA,
+ worldTimes.get(6), SLASH, worldTimes.get(7), SLASH, worldTimes.get(8), COMMA,
+ worldTimes.get(9), SLASH, worldTimes.get(10), SLASH, worldTimes.get(11), COMMA,
+ worldTimes.get(12), SLASH, worldTimes.get(13), SLASH, worldTimes.get(14)
+ ))
+ );
+ }
+ // Plazma end - MSPT by world
+
return true;
}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index fd74856160fa048941e10f52d2061e4ccdc86f31..8964ccc27ea7db306140fd6b04c9f5cb33158aa0 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -264,8 +264,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
private final long[] tickTimesNanos;
private long aggregatedTickTimesNanos;
// Paper start - Add tick times API and /mspt command
+ public final TickTimes tickTimes1s = new TickTimes(20); // Plazma - Add more MSPT
public final TickTimes tickTimes5s = new TickTimes(100);
public final TickTimes tickTimes10s = new TickTimes(200);
+ public final TickTimes tickTimes30s = new TickTimes(600); // Plazma - Add more MSPT
public final TickTimes tickTimes60s = new TickTimes(1200);
// Paper end - Add tick times API and /mspt command
@Nullable
@@ -1743,8 +1745,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.tickTimesNanos[l] = k;
this.smoothedTickTimeMillis = this.smoothedTickTimeMillis * 0.8F + (float) k / (float) TimeUtil.NANOSECONDS_PER_MILLISECOND * 0.19999999F;
// Paper start - Add tick times API and /mspt command
+ this.tickTimes1s.add(this.tickCount, k); // Plazma - Add more MSPT
this.tickTimes5s.add(this.tickCount, k);
this.tickTimes10s.add(this.tickCount, k);
+ this.tickTimes30s.add(this.tickCount, k); // Plazma - Add more MSPT
this.tickTimes60s.add(this.tickCount, k);
// Paper end - Add tick times API and /mspt command
this.logTickMethodTime(i);
@@ -1906,7 +1910,17 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
//gameprofilerfiller.push("tick"); // Plazma - Completely remove Mojang profiler
try {
+ // Plazma start - MSPT by world
+ long i = Util.getNanos();
worldserver.tick(shouldKeepTicking);
+ long d = Util.getNanos() - i;
+
+ worldserver.tickTimes1s.add(this.tickCount, d);
+ worldserver.tickTimes5s.add(this.tickCount, d);
+ worldserver.tickTimes10s.add(this.tickCount, d);
+ worldserver.tickTimes30s.add(this.tickCount, d);
+ worldserver.tickTimes60s.add(this.tickCount, d);
+ // Plazma end - MSPT by world
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Exception ticking world");
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 518b9feb5e2494e52fe9719ddc22dce7da4db0fb..9a54883281352cc4fa08143f5126d61dbd89761d 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -599,6 +599,14 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
}
// Paper end - lag compensation
+ // Plazma start - MSPT by world
+ public final MinecraftServer.TickTimes tickTimes1s = new MinecraftServer.TickTimes(20);
+ public final MinecraftServer.TickTimes tickTimes5s = new MinecraftServer.TickTimes(100);
+ public final MinecraftServer.TickTimes tickTimes10s = new MinecraftServer.TickTimes(200);
+ public final MinecraftServer.TickTimes tickTimes30s = new MinecraftServer.TickTimes(600);
+ public final MinecraftServer.TickTimes tickTimes60s = new MinecraftServer.TickTimes(1200);
+ // Plazma end - MSPT by world
+
// Add env and gen to constructor, IWorldDataServer -> WorldDataServer
public ServerLevel(MinecraftServer minecraftserver, Executor executor, LevelStorageSource.LevelStorageAccess convertable_conversionsession, PrimaryLevelData iworlddataserver, ResourceKey<Level> resourcekey, LevelStem worlddimension, ChunkProgressListener worldloadlistener, boolean flag, long i, List<CustomSpawner> list, boolean flag1, @Nullable RandomSequences randomsequences, org.bukkit.World.Environment env, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider) {
// Plazma start - Configurable Plazma