2023-03-10 09:18:12 +01:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Fri, 10 Mar 2023 00:16:26 -0800
Subject: [PATCH] Add chunk system throughput counters to /tps
2024-07-31 05:09:52 +02:00
diff --git a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/task/ChunkFullTask.java b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/task/ChunkFullTask.java
index fbdf721e8b4cfe6cef4ee60c53c680cbfc858d88..8581b8771b8cc89ff7bdb63fbfd5628a1e7d4762 100644
--- a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/task/ChunkFullTask.java
+++ b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/task/ChunkFullTask.java
@@ -28,6 +28,9 @@ public final class ChunkFullTask extends ChunkProgressionTask implements Runnabl
private final ChunkAccess fromChunk;
private final PrioritisedExecutor.PrioritisedTask convertToFullTask;
2023-03-10 09:18:12 +01:00
+ public static final io.papermc.paper.util.IntervalledCounter chunkLoads = new io.papermc.paper.util.IntervalledCounter(java.util.concurrent.TimeUnit.SECONDS.toNanos(15L));
+ public static final io.papermc.paper.util.IntervalledCounter chunkGenerates = new io.papermc.paper.util.IntervalledCounter(java.util.concurrent.TimeUnit.SECONDS.toNanos(15L));
+
public ChunkFullTask(final ChunkTaskScheduler scheduler, final ServerLevel world, final int chunkX, final int chunkZ,
final NewChunkHolder chunkHolder, final ChunkAccess fromChunk, final PrioritisedExecutor.Priority priority) {
super(scheduler, world, chunkX, chunkZ);
2024-07-31 05:09:52 +02:00
@@ -41,6 +44,20 @@ public final class ChunkFullTask extends ChunkProgressionTask implements Runnabl
2023-03-10 09:18:12 +01:00
return ChunkStatus.FULL;
}
+ public static double genRate(final long time) {
+ synchronized (chunkGenerates) {
+ chunkGenerates.updateCurrentTime(time);
+ return chunkGenerates.getRate();
+ }
+ }
+
+ public static double loadRate(final long time) {
+ synchronized (chunkLoads) {
+ chunkLoads.updateCurrentTime(time);
+ return chunkLoads.getRate();
+ }
+ }
+
@Override
public void run() {
2024-07-31 05:09:52 +02:00
// See Vanilla ChunkPyramid#LOADING_PYRAMID.FULL for what this function should be doing
@@ -55,6 +72,17 @@ public final class ChunkFullTask extends ChunkProgressionTask implements Runnabl
((ChunkSystemPoiManager)this.world.getPoiManager()).moonrise$checkConsistency(this.fromChunk);
2023-03-10 09:18:12 +01:00
}
+ final long time = System.nanoTime();
+ if (this.fromChunk instanceof ImposterProtoChunk wrappedFull) {
+ synchronized (chunkLoads) {
+ chunkLoads.updateAndAdd(1L, time);
+ }
+ } else {
+ synchronized (chunkGenerates) {
+ chunkGenerates.updateAndAdd(1L, time);
+ }
+ }
+
if (this.fromChunk instanceof ImposterProtoChunk wrappedFull) {
chunk = wrappedFull.getWrapped();
} else {
diff --git a/src/main/java/io/papermc/paper/threadedregions/commands/CommandServerHealth.java b/src/main/java/io/papermc/paper/threadedregions/commands/CommandServerHealth.java
2024-07-31 05:09:52 +02:00
index 3bcb1dc98c61e025874cc9e008faa722581a530c..012d3a7da7fe483393a0888c823bd2e78f5c3908 100644
2023-03-10 09:18:12 +01:00
--- a/src/main/java/io/papermc/paper/threadedregions/commands/CommandServerHealth.java
+++ b/src/main/java/io/papermc/paper/threadedregions/commands/CommandServerHealth.java
2023-04-09 03:44:37 +02:00
@@ -170,6 +170,9 @@ public final class CommandServerHealth extends Command {
2023-03-10 09:18:12 +01:00
totalUtil += (report == null ? 0.0 : report.utilisation());
}
2024-07-31 05:09:52 +02:00
+ final double genRate = ca.spottedleaf.moonrise.patches.chunk_system.scheduling.task.ChunkFullTask.genRate(currTime);
+ final double loadRate = ca.spottedleaf.moonrise.patches.chunk_system.scheduling.task.ChunkFullTask.loadRate(currTime);
2023-03-10 09:18:12 +01:00
+
totalUtil += globalTickReport.utilisation();
tpsByRegion.sort(null);
2023-04-09 03:44:37 +02:00
@@ -284,6 +287,12 @@ public final class CommandServerHealth extends Command {
.append(Component.text(ONE_DECIMAL_PLACES.get().format(maxThreadCount * 100.0), INFORMATION))
2023-03-10 09:18:12 +01:00
.append(Component.text("%\n", PRIMARY))
+ .append(Component.text(" - ", LIST, TextDecoration.BOLD))
+ .append(Component.text("Load rate: ", PRIMARY))
2023-04-09 03:44:37 +02:00
+ .append(Component.text(TWO_DECIMAL_PLACES.get().format(loadRate) + ", ", INFORMATION))
2023-03-10 09:18:12 +01:00
+ .append(Component.text("Gen rate: ", PRIMARY))
2023-04-09 03:44:37 +02:00
+ .append(Component.text(TWO_DECIMAL_PLACES.get().format(genRate) + "\n", INFORMATION))
2023-03-10 09:18:12 +01:00
+
.append(Component.text(" - ", LIST, TextDecoration.BOLD))
.append(Component.text("Lowest Region TPS: ", PRIMARY))
2023-04-09 03:44:37 +02:00
.append(Component.text(TWO_DECIMAL_PLACES.get().format(minTps) + "\n", CommandUtil.getColourForTPS(minTps)))