9
0
mirror of https://github.com/Dreeam-qwq/Gale.git synced 2025-12-21 07:49:22 +00:00
Files
Gale/patches/server/0109-Measure-last-tick-time.patch

65 lines
3.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Sat, 26 Nov 2022 16:54:05 +0100
Subject: [PATCH] Measure last tick time
License: MIT (https://opensource.org/licenses/MIT)
Gale - https://galemc.org
This patch is based on the following patch:
"Add getLastTickMs api"
By: tr7zw <tr7zw@live.de>
As part of: YAPFA (https://github.com/tr7zw/YAPFA)
Licensed under: MIT (https://opensource.org/licenses/MIT)
* YAPFA copyright *
Copyright 2020 tr7zw
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index c64874029dae951abf5d57b8dd7875d2ebfc8b54..5b347162c668dd97f1b601d93318efa7abeb03e2 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1184,6 +1184,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// Paper end
// Spigot End
+ // Gale start - YAPFA - last tick time
+ public static long lastTickProperTime;
+ public static long lastTickOversleepTime;
+ // Gale end - YAPFA - last tick time
+
protected void runServer() {
try {
long serverStartTime = Util.getNanos(); // Paper
@@ -1269,9 +1274,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
//MinecraftServer.currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit // Paper - don't overwrite current tick time
lastTick = currentTime;
this.nextTickTimeNanos += i;
+ long tickProperStart = System.nanoTime(); // Gale - YAPFA - last tick time
this.tickServer(flag ? () -> {
return false;
} : this::haveTime);
+ lastTickProperTime = (System.nanoTime() - tickProperStart) / 1000000L; // Gale - YAPFA - last tick time
// Paper start - rewrite chunk system
final Throwable crash = this.chunkSystemCrash;
if (crash != null) {
@@ -1435,9 +1442,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
protected void waitUntilNextTick() {
//this.executeAll(); // Paper - move this into the tick method for timings
+ long tickOversleepStart = System.nanoTime(); // Gale - YAPFA - last tick time
this.managedBlock(() -> {
return !this.canSleepForTickNoOversleep(); // Paper - move oversleep into full server tick
});
+ lastTickOversleepTime = (System.nanoTime() - tickOversleepStart) / 1000000L; // Gale - YAPFA - last tick time
}
@Override