mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-18 08:57:44 +01:00
Add tick times API
This commit is contained in:
68
patches/api/0029-Add-tick-times-API.patch
Normal file
68
patches/api/0029-Add-tick-times-API.patch
Normal file
@@ -0,0 +1,68 @@
|
||||
From 43d0712b7263108fc4ad23fc38acb0450ca764e8 Mon Sep 17 00:00:00 2001
|
||||
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
|
||||
Date: Thu, 30 Jan 2020 00:41:08 -0600
|
||||
Subject: [PATCH] Add tick times API
|
||||
|
||||
---
|
||||
src/main/java/org/bukkit/Bukkit.java | 19 +++++++++++++++++++
|
||||
src/main/java/org/bukkit/Server.java | 15 +++++++++++++++
|
||||
2 files changed, 34 insertions(+)
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
|
||||
index f6076e94a..6b9e8b297 100644
|
||||
--- a/src/main/java/org/bukkit/Bukkit.java
|
||||
+++ b/src/main/java/org/bukkit/Bukkit.java
|
||||
@@ -1620,6 +1620,25 @@ public final class Bukkit {
|
||||
public static boolean isLagging() {
|
||||
return server.isLagging();
|
||||
}
|
||||
+
|
||||
+ /**
|
||||
+ * Get the last 100 tick times (in nanos)
|
||||
+ *
|
||||
+ * @return Last 100 tick times (in nanos)
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public static long[] getTickTimes() {
|
||||
+ return server.getTickTimes();
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Get the average tick time (in millis) of the last 100 ticks
|
||||
+ *
|
||||
+ * @return Average tick time (in millis)
|
||||
+ */
|
||||
+ public static double getAverageTickTime() {
|
||||
+ return server.getAverageTickTime();
|
||||
+ }
|
||||
// Purpur end
|
||||
|
||||
@NotNull
|
||||
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
|
||||
index 22f6ac18a..efd7c87f1 100644
|
||||
--- a/src/main/java/org/bukkit/Server.java
|
||||
+++ b/src/main/java/org/bukkit/Server.java
|
||||
@@ -1416,5 +1416,20 @@ public interface Server extends PluginMessageRecipient {
|
||||
* @return True if lagging
|
||||
*/
|
||||
boolean isLagging();
|
||||
+
|
||||
+ /**
|
||||
+ * Get the last 100 tick times (in nanos)
|
||||
+ *
|
||||
+ * @return Last 100 tick times (in nanos)
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ long[] getTickTimes();
|
||||
+
|
||||
+ /**
|
||||
+ * Get the average tick time (in millis) of the last 100 ticks
|
||||
+ *
|
||||
+ * @return Average tick time (in millis)
|
||||
+ */
|
||||
+ double getAverageTickTime();
|
||||
// Purpur end
|
||||
}
|
||||
--
|
||||
2.24.0
|
||||
|
||||
118
patches/server/0098-Add-tick-times-API.patch
Normal file
118
patches/server/0098-Add-tick-times-API.patch
Normal file
@@ -0,0 +1,118 @@
|
||||
From fe123a5e92ad8528ba7093f834591f403525f6e9 Mon Sep 17 00:00:00 2001
|
||||
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
|
||||
Date: Thu, 30 Jan 2020 00:41:24 -0600
|
||||
Subject: [PATCH] Add tick times API
|
||||
|
||||
---
|
||||
.../net/pl3x/purpur/gui/info/RAMDetails.java | 13 +++----------
|
||||
.../org/bukkit/craftbukkit/CraftServer.java | 15 +++++++++++++++
|
||||
.../org/spigotmc/TicksPerSecondCommand.java | 18 +++++++++++++++++-
|
||||
3 files changed, 35 insertions(+), 11 deletions(-)
|
||||
|
||||
diff --git a/src/main/java/net/pl3x/purpur/gui/info/RAMDetails.java b/src/main/java/net/pl3x/purpur/gui/info/RAMDetails.java
|
||||
index b1ea91b49b..2981afaaaa 100644
|
||||
--- a/src/main/java/net/pl3x/purpur/gui/info/RAMDetails.java
|
||||
+++ b/src/main/java/net/pl3x/purpur/gui/info/RAMDetails.java
|
||||
@@ -2,6 +2,7 @@ package net.pl3x.purpur.gui.info;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.SystemUtils;
|
||||
+import org.bukkit.Bukkit;
|
||||
|
||||
import javax.swing.DefaultListCellRenderer;
|
||||
import javax.swing.JList;
|
||||
@@ -13,7 +14,7 @@ import java.util.Locale;
|
||||
import java.util.Vector;
|
||||
|
||||
public class RAMDetails extends JList<String> {
|
||||
- private static final DecimalFormat DECIMAL_FORMAT = SystemUtils.a(new DecimalFormat("########0.000"), (format)
|
||||
+ public static final DecimalFormat DECIMAL_FORMAT = SystemUtils.a(new DecimalFormat("########0.000"), (format)
|
||||
-> format.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance(Locale.ROOT)));
|
||||
private final MinecraftServer server;
|
||||
|
||||
@@ -38,15 +39,7 @@ public class RAMDetails extends JList<String> {
|
||||
Vector<String> vector = new Vector<>();
|
||||
vector.add("Memory use: " + (graph.usedMem / 1024L / 1024L) + " mb (" + (graph.free * 100L / graph.max) + "% free)");
|
||||
vector.add("Heap: " + (graph.total / 1024L / 1024L) + " / " + (graph.max / 1024L / 1024L) + " mb");
|
||||
- vector.add("Avg tick: " + DECIMAL_FORMAT.format(getAverage(server.getTickTimes()) * 1.0E-6D) + " ms");
|
||||
+ vector.add("Avg tick: " + DECIMAL_FORMAT.format(Bukkit.getAverageTickTime()) + " ms");
|
||||
setListData(vector);
|
||||
}
|
||||
-
|
||||
- private double getAverage(long[] values) {
|
||||
- long total = 0L;
|
||||
- for (long value : values) {
|
||||
- total += value;
|
||||
- }
|
||||
- return (double) total / (double) values.length;
|
||||
- }
|
||||
}
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
index 262b82538c..2b78709262 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
@@ -2185,5 +2185,20 @@ public final class CraftServer implements Server {
|
||||
public boolean isLagging() {
|
||||
return getServer().lagging;
|
||||
}
|
||||
+
|
||||
+ @Override
|
||||
+ public long[] getTickTimes() {
|
||||
+ return getServer().getTickTimes();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public double getAverageTickTime() {
|
||||
+ long total = 0L;
|
||||
+ long[] tickTimes = getTickTimes();
|
||||
+ for (long value : tickTimes) {
|
||||
+ total += value;
|
||||
+ }
|
||||
+ return ((double) total / (double) tickTimes.length) * 1.0E-6D;
|
||||
+ }
|
||||
// Purpur end
|
||||
}
|
||||
diff --git a/src/main/java/org/spigotmc/TicksPerSecondCommand.java b/src/main/java/org/spigotmc/TicksPerSecondCommand.java
|
||||
index 2eed9d0a4a..c29380e1c0 100644
|
||||
--- a/src/main/java/org/spigotmc/TicksPerSecondCommand.java
|
||||
+++ b/src/main/java/org/spigotmc/TicksPerSecondCommand.java
|
||||
@@ -4,6 +4,12 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
+// Purpur start
|
||||
+import net.pl3x.purpur.gui.info.RAMDetails;
|
||||
+import org.apache.commons.lang.StringUtils;
|
||||
+import org.bukkit.Bukkit;
|
||||
+// Purpur end
|
||||
+
|
||||
public class TicksPerSecondCommand extends Command
|
||||
{
|
||||
|
||||
@@ -30,12 +36,22 @@ public class TicksPerSecondCommand extends Command
|
||||
for ( int i = 0; i < tps.length; i++) {
|
||||
tpsAvg[i] = format( tps[i] );
|
||||
}
|
||||
- sender.sendMessage( ChatColor.GOLD + "TPS from last 5s, 1m, 5m, 15m: " + org.apache.commons.lang.StringUtils.join(tpsAvg, ", ")); // Purpur
|
||||
+ // Purpur start
|
||||
+ double avg = Bukkit.getAverageTickTime();
|
||||
+ sender.sendMessage( ChatColor.GOLD + "TPS from last 5s, 1m, 5m, 15m: " + StringUtils.join(tpsAvg, ", "));
|
||||
+ sender.sendMessage( ChatColor.GOLD + "Average tick time: " + getColor(avg) + RAMDetails.DECIMAL_FORMAT.format(avg) + " ms");
|
||||
+ // Purpur end
|
||||
// Paper end
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
+ // Purpur start
|
||||
+ private static String getColor(double avg) {
|
||||
+ return (avg >= 50 ? ChatColor.RED : avg >= 40 ? ChatColor.YELLOW : ChatColor.GREEN).toString();
|
||||
+ }
|
||||
+ // Purpur end
|
||||
+
|
||||
private static String format(double tps) // Paper - Made static
|
||||
{
|
||||
return ( ( tps > 18.0 ) ? ChatColor.GREEN : ( tps > 16.0 ) ? ChatColor.YELLOW : ChatColor.RED ).toString()
|
||||
--
|
||||
2.24.0
|
||||
|
||||
Reference in New Issue
Block a user