aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0143-Chunk-Save-Stats-Debug-Option.patch
blob: ea8f0505880e7ec0faa5cb459b7ea1d3915ec5af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
From 8efbb3a0533a16d6c9e3ac27e41cd03bba1e35d8 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Fri, 4 Nov 2016 02:12:10 -0400
Subject: [PATCH] Chunk Save Stats Debug Option

Adds a command line flag to enable stats on how chunk saves are processing.

Stats on current queue, how many was processed and how many were queued.

diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
index 9b5908a5b4..2997767282 100644
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
@@ -28,6 +28,11 @@ public class ChunkProviderServer implements IChunkProvider {
     public final LongSet unloadQueue = new LongOpenHashSet();
     public final ChunkGenerator<?> chunkGenerator;
     public final IChunkLoader chunkLoader;
+    // Paper start - chunk save stats
+    private long lastQueuedSaves = 0L; // Paper
+    private long lastProcessedSaves = 0L; // Paper
+    private long lastSaveStatPrinted = System.currentTimeMillis();
+    // Paper end
     public final Long2ObjectMap<Chunk> chunks = Long2ObjectMaps.synchronize(new ChunkMap(8192));
     private Chunk lastChunk;
     private final ChunkTaskScheduler chunkScheduler;
@@ -239,6 +244,29 @@ public class ChunkProviderServer implements IChunkProvider {
             // Paper start
             final ChunkRegionLoader chunkLoader = (ChunkRegionLoader) world.getChunkProvider().chunkLoader;
             final int queueSize = chunkLoader.getQueueSize();
+
+            final long now = System.currentTimeMillis();
+            final long timeSince = (now - lastSaveStatPrinted) / 1000;
+            final Integer printRateSecs = Integer.getInteger("printSaveStats");
+            if (printRateSecs != null && timeSince >= printRateSecs) {
+                final String timeStr = "/" + timeSince  +"s";
+                final long queuedSaves = chunkLoader.getQueuedSaves();
+                long queuedDiff = queuedSaves - lastQueuedSaves;
+                lastQueuedSaves = queuedSaves;
+
+                final long processedSaves = chunkLoader.getProcessedSaves();
+                long processedDiff = processedSaves - lastProcessedSaves;
+                lastProcessedSaves = processedSaves;
+
+                lastSaveStatPrinted = now;
+                if (processedDiff > 0 || queueSize > 0 || queuedDiff > 0) {
+                    System.out.println("[Chunk Save Stats] " + world.worldData.getName() +
+                        " - Current: " + queueSize +
+                        " - Queued: " + queuedDiff + timeStr +
+                        " - Processed: " +processedDiff + timeStr
+                    );
+                }
+            }
             if (!flag && queueSize > world.paperConfig.queueSizeAutoSaveThreshold){
                 return false;
             }
diff --git a/src/main/java/net/minecraft/server/ChunkRegionLoader.java b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
index adfb5d056f..0fc4d9f520 100644
--- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java
+++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
@@ -156,7 +156,13 @@ public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
 
     }
 
-    public int getQueueSize() { return queue.size(); } // Paper
+    // Paper start
+    private long queuedSaves = 0;
+    private final java.util.concurrent.atomic.AtomicLong processedSaves = new java.util.concurrent.atomic.AtomicLong(0L);
+    public int getQueueSize() { return queue.size(); }
+    public long getQueuedSaves() { return queuedSaves; }
+    public long getProcessedSaves() { return processedSaves.longValue(); }
+    // Paper end
 
     // CraftBukkit start - Add async variant, provide compatibility
     @Nullable
@@ -348,6 +354,7 @@ public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
     protected void a(ChunkCoordIntPair chunkcoordintpair, Supplier<NBTTagCompound> nbttagcompound) { // Spigot
         this.saveMap.put(chunkcoordintpair.asLong(), nbttagcompound); // Paper
         queue.add(new QueuedChunk(chunkcoordintpair, nbttagcompound)); // Paper - Chunk queue improvements
+        queuedSaves++; // Paper
         FileIOThread.a().a(this);
     }
 
@@ -375,6 +382,7 @@ public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
             // Paper end
             ChunkCoordIntPair chunkcoordintpair = chunk.coords; // Paper - Chunk queue improvements
             Supplier<NBTTagCompound> nbttagcompound = chunk.compoundSupplier; // Spigot // Paper
+            processedSaves.incrementAndGet(); // Paper
 
             if (nbttagcompound == null) {
                 return true;
-- 
2.21.0