mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-20 15:29:33 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@9e51f94 Fix ping event always receiving protocol version 0 (#10671) PaperMC/Paper@89ad61f Fix hopper pull event being skipped after the first call (#10667) PaperMC/Paper@eee55d0 Correctly compare holders in BeaconMenu (#10673) PaperMC/Paper@5729b29 Update Adventure to 4.17.0 Release PaperMC/Paper@ab2a85a [ci skip] Clarify var entry in contributing file PaperMC/Paper@f2512b1 Print data component type on encoding error PaperMC/Paper@1b67e02 Fix entity tracker desync when new players are added to the tracker PaperMC/Paper@cc29d2b Invalidate PathTypeCache when pathfinding updates are disabled PaperMC/Paper@b56e92f Fix chunk data version check not running in chunk system PaperMC/Paper@2df1dac Fix DataConverter ConverterParticleToNBT.parseProperties PaperMC/Paper@8748ae1 Use MCDataConverter instead of raw convert call for cmd converter PaperMC/Paper@7f1a154 Add validation to player profile and properties (#10680) PaperMC/Paper@4fd58a1 Add conversion for summon command PaperMC/Paper@39532a1 Fix stacks losing empty attr modifiers PaperMC/Paper@cdb6ba8 Fix keepalive time interval (#10690) PaperMC/Paper@a61d58d adjust ItemMeta to distinguish null and empty modifiers PaperMC/Paper@6c02dbc handle recent ItemMeta changes in serialization logic PaperMC/Paper@447f9a1 [ci skip] Fix paperclip PR label PaperMC/Paper@b98d20a Brigadier Command Support (#8235) PaperMC/Paper@ac554ad Updated Upstream (Bukkit/CraftBukkit) (#10691) PaperMC/Paper@711f82e Fix signed book page serialization (#10696) PaperMC/Paper@7e48f66 Properly pass requirement on namespaced redirects (#10701) PaperMC/Paper@f041f48 Prevent infinite recursion on cyclic brig redirect (#10705) PaperMC/Paper@11c3963 Improve Recipe validation (#10707) PaperMC/Paper@0688f21 Better way to keep paper datapack enabled PaperMC/Paper@218d33c fix creating complex recipes that have air results PaperMC/Paper@fa8a407 Remove Adventure snapshot repo from dev bundle (#10716) PaperMC/Paper@bebcc9c Make exception during command conversion non-fatal PaperMC/Paper@2faa3b2 Correctly copy alias requirements in command upgrader PaperMC/Paper@3fc9358 Show stacktrace when modifyItemStack fails PaperMC/Paper@f175193 Expose server build information (#10729) PaperMC/Paper@d8d59e0 Fix NPE sending resource pack without prompt PaperMC/Paper@5a9afbe Fixes issues in the suppress dismount cancellation patch (#10735) PaperMC/Paper@0ad09de Make PaperSimplePluginClassLoader show class which is not found PaperMC/Paper@b3b3406 fix CompassMeta not being correct (#10737) PaperMC/Paper@591521e Check for more correct profile validation (#10730) PaperMC/Paper@7d2e5c3 Add an 'empty' RecipeChoice for certain ingredient slots (#10710) PaperMC/Paper@9bf4855 Add a better warning message than "Server performance will be affected" for CommandRegisteredEvent use (#10754) PaperMC/Paper@66cb880 Remove ThreadedWorldUpgrader patch PaperMC/Paper@980cff9 Fix compile PaperMC/Paper@d3ffa62 fix default item attributes PaperMC/Paper@b149584 Always show command exception stack traces in logs (#10766) PaperMC/Paper@a9201d4 [ci skip] Move logic in our patches to ItemType/BlockType (#10772) PaperMC/Paper@3de408e Fix equipment slot and group API (#10767) PaperMC/Paper@d408381 Print CommandRegisteredEvent deprecation warnings again (#10756) PaperMC/Paper@6de7a1f Improve default item attributes API (#10765) PaperMC/Paper@2a90732 Remove incorrect logic for Fireball#setVelocity (#10764) PaperMC/Paper@5e7b65a Allow using PluginLoader classpath API from Bukkit plugins (#10758) PaperMC/Paper@3004717 Do not re-wrap vanilla goals (#10751) PaperMC/Paper@377733d Use getter/setter on Mob for equipment drop chances (#10780) PaperMC/Paper@dff591d Allow to define new map cursor types (#10782) PaperMC/Paper@4fd3ac0 [ci skip] Update Player#getListeningPluginChannels Jdoc (#10778) PaperMC/Paper@535dca5 Fix a few issues with ItemMeta (#10740) PaperMC/Paper@26e90b9 Fix CraftMetaBlockState for data components (#10731) PaperMC/Paper@f0bd0cc Expose anvil cost in the API (#10682) PaperMC/Paper@41bee55 Fix NPE for color-related metas PaperMC/Paper@4e10fad reset meta block state on BlockStateMeta#setBlockState PaperMC/Paper@a7ae966 readd itemstack data sanitization (#10454) PaperMC/Paper@ca50b87 Clear firework item properly (#10793) PaperMC/Paper@9774a52 fix and cleanup loot table patches (#10100) PaperMC/Paper@ac4ee06 Fix integer overflow for lag compensating eating check (#10797) PaperMC/Paper@6649a17 Fix BlockStateMeta equals (#10795) PaperMC/Paper@1b8cdc6 Extend Player Interact cancellation to cover Jigsaw blocks (#10719) PaperMC/Paper@841ab41 Fix more item desync when an event is cancelled (#10654) PaperMC/Paper@b0e3ca4 Prevent NPE if hooked entity was cleared (#10712) PaperMC/Paper@347bbe3 Fix Cancelling BlockPlaceEvent calling onRemove (#10773) PaperMC/Paper@23fe116 Fix missing debug trace PaperMC/Paper@b0c9b9c Only remove worldgen block entity on changed block (#10794) PaperMC/Paper@9c917fe [ci skip] Clean up paperclip build-pr workflow (#10802) PaperMC/Paper@9d6f2cc [ci skip] Rebuild patches (#10803)
503 lines
23 KiB
Diff
503 lines
23 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Samsuik <kfian294ma4@gmail.com>
|
|
Date: Sun, 19 Sep 2021 01:10:02 +0100
|
|
Subject: [PATCH] TPS Graph Command
|
|
|
|
|
|
diff --git a/src/main/java/me/samsuik/sakura/command/SakuraCommands.java b/src/main/java/me/samsuik/sakura/command/SakuraCommands.java
|
|
index 22676ec7a7ae9494b198e5e65e6be6d32e0feb85..6edc5195c3b496a12b17b2b9b528505d37ffdb12 100644
|
|
--- a/src/main/java/me/samsuik/sakura/command/SakuraCommands.java
|
|
+++ b/src/main/java/me/samsuik/sakura/command/SakuraCommands.java
|
|
@@ -4,6 +4,7 @@ import io.papermc.paper.command.PaperPluginsCommand;
|
|
import me.samsuik.sakura.command.subcommands.ConfigCommand;
|
|
import me.samsuik.sakura.command.subcommands.FPSCommand;
|
|
import me.samsuik.sakura.command.subcommands.VisualCommand;
|
|
+import me.samsuik.sakura.command.subcommands.TPSCommand;
|
|
import me.samsuik.sakura.player.visibility.Visibility;
|
|
import net.minecraft.server.MinecraftServer;
|
|
import org.bukkit.command.Command;
|
|
@@ -21,6 +22,7 @@ public final class SakuraCommands {
|
|
COMMANDS.put("tntvisibility", new VisualCommand(Visibility.Setting.TNT_VISIBILITY, "tnttoggle"));
|
|
COMMANDS.put("sandvisibility", new VisualCommand(Visibility.Setting.SAND_VISIBILITY, "sandtoggle"));
|
|
COMMANDS.put("minimal", new VisualCommand(Visibility.Setting.MINIMAL, "minimaltnt", "tntlag"));
|
|
+ COMMANDS.put("tps", new TPSCommand("tps"));
|
|
}
|
|
|
|
public static void registerCommands(final MinecraftServer server) {
|
|
diff --git a/src/main/java/me/samsuik/sakura/command/subcommands/TPSCommand.java b/src/main/java/me/samsuik/sakura/command/subcommands/TPSCommand.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..7bd4c5696911730170320060c273f3a7f6a610be
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/samsuik/sakura/command/subcommands/TPSCommand.java
|
|
@@ -0,0 +1,67 @@
|
|
+package me.samsuik.sakura.command.subcommands;
|
|
+
|
|
+import me.samsuik.sakura.command.BaseSubCommand;
|
|
+import me.samsuik.sakura.utils.tps.TPSGraph;
|
|
+import me.samsuik.sakura.utils.tps.TickTracking;
|
|
+import net.kyori.adventure.text.Component;
|
|
+import net.kyori.adventure.text.format.NamedTextColor;
|
|
+import net.kyori.adventure.text.format.TextDecoration;
|
|
+import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
+import net.kyori.adventure.text.minimessage.tag.Tag;
|
|
+import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
|
+import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import net.minecraft.util.Mth;
|
|
+import org.bukkit.command.CommandSender;
|
|
+
|
|
+public final class TPSCommand extends BaseSubCommand {
|
|
+
|
|
+ public TPSCommand(String name) {
|
|
+ super(name);
|
|
+ this.description = "Gets the current ticks per second for the server";
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void execute(CommandSender sender, String[] args) {
|
|
+ var tracking = MinecraftServer.tickTracking;
|
|
+
|
|
+ var average = tracking.averageTps(10) * 1.75;
|
|
+ int lines = 10;
|
|
+
|
|
+ try {
|
|
+ average = Double.parseDouble(args[0]);
|
|
+ lines = Mth.clamp(Integer.parseInt(args[1]), 1, 18);
|
|
+ } catch (NumberFormatException | ArrayIndexOutOfBoundsException ignored) {}
|
|
+
|
|
+ sender.sendMessage(Component.text(".", NamedTextColor.DARK_PURPLE));
|
|
+ sender.sendMessage(createInformationComponent(tracking));
|
|
+
|
|
+ // Create the graph
|
|
+ var graph = new TPSGraph(tracking, lines, 75, average);
|
|
+ graph.map();
|
|
+
|
|
+ // Send the graph to the user
|
|
+ for (var component : graph.components()) {
|
|
+ sender.sendMessage(Component.text("| ", NamedTextColor.DARK_PURPLE).append(component));
|
|
+ }
|
|
+
|
|
+ sender.sendMessage(Component.text("| ", NamedTextColor.DARK_PURPLE).append(Component.text(" ".repeat(75), NamedTextColor.GRAY, TextDecoration.STRIKETHROUGH)));
|
|
+ sender.sendMessage(Component.text("'", NamedTextColor.DARK_PURPLE));
|
|
+ }
|
|
+
|
|
+ private Component createInformationComponent(TickTracking tracking) {
|
|
+ return MiniMessage.miniMessage().deserialize("<dark_purple>| <gray>-------------- <dark_gray>( <white>Now</white>: <tps>, <white>Mem</white>: <memory><gray>%</gray> ) </dark_gray>---------------",
|
|
+ Placeholder.component("tps", Component.text("%.1f".formatted(tracking.averageTps(1)), TPSGraph.colour(tracking.averageTps(1) / 20.0))),
|
|
+ Placeholder.component("memory", Component.text("%.1f".formatted(memoryUsage() * 100), TPSGraph.colour(1.0 - memoryUsage())))
|
|
+ );
|
|
+ }
|
|
+
|
|
+ private double memoryUsage() {
|
|
+ Runtime runtime = Runtime.getRuntime();
|
|
+ double free = runtime.freeMemory();
|
|
+ double max = runtime.maxMemory();
|
|
+ double alloc = runtime.totalMemory();
|
|
+ return (alloc - free) / max;
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/me/samsuik/sakura/utils/tps/TPSGraph.java b/src/main/java/me/samsuik/sakura/utils/tps/TPSGraph.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..fa5d0c046d979901dd302ee3973df27442172add
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/samsuik/sakura/utils/tps/TPSGraph.java
|
|
@@ -0,0 +1,255 @@
|
|
+package me.samsuik.sakura.utils.tps;
|
|
+
|
|
+import me.samsuik.sakura.utils.tps.TickTracking.Point;
|
|
+import net.kyori.adventure.text.Component;
|
|
+import net.kyori.adventure.text.TextComponent;
|
|
+import net.kyori.adventure.text.event.HoverEvent;
|
|
+import net.kyori.adventure.text.format.NamedTextColor;
|
|
+import net.kyori.adventure.text.format.TextColor;
|
|
+import net.kyori.adventure.text.format.TextDecoration;
|
|
+import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
+import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
|
+import net.minecraft.util.Mth;
|
|
+
|
|
+public final class TPSGraph {
|
|
+
|
|
+ private final Parts[][] parts;
|
|
+ private final TickTracking tracked;
|
|
+ private final int lines;
|
|
+ private final int length;
|
|
+ private final double ceiling;
|
|
+
|
|
+ public TPSGraph(TickTracking tracked, int lines, int length, double ceiling) {
|
|
+ this.parts = new Parts[lines][length];
|
|
+ this.tracked = tracked;
|
|
+ this.length = length;
|
|
+ this.lines = lines;
|
|
+ this.ceiling = ceiling;
|
|
+ }
|
|
+
|
|
+ public void map() {
|
|
+ // Create the background
|
|
+ for (var line = 0; line < lines; ++line) {
|
|
+ for (var column = 0; column < length; ++column) {
|
|
+ parts[line][column] = Parts.BACKGROUND;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ // Create normal points on the graph
|
|
+ for (var column = 0; column < length; ++column) {
|
|
+ var tps = tracked.point(column).tps();
|
|
+ // Likely the server has just started
|
|
+ if (tps == 0.0) break;
|
|
+ // Create normal point for column
|
|
+ var line = getLine(tps);
|
|
+ var lineParts = parts[line];
|
|
+ lineParts[column] = Parts.NORMAL;
|
|
+ }
|
|
+
|
|
+ // Create spikes on the graph, what is a spike?
|
|
+ // By spike I am referring to a situation where
|
|
+ // the normal point would be "moving" more than
|
|
+ // 2 lines, which looks terrible.
|
|
+ for (var column = 0; column < length; ++column) {
|
|
+ var nextTps = tracked.point(column + 1).tps();
|
|
+ // Likely the server has just started
|
|
+ if (nextTps == 0.0) break;
|
|
+ var curr = getLine(tracked.point(column).tps());
|
|
+ var prev = getLine(tracked.point(Math.max(column - 1, 0)).tps());
|
|
+ var next = getLine(nextTps);
|
|
+ var min = Math.min(curr, next);
|
|
+ var max = Math.max(curr, next);
|
|
+
|
|
+ if (max - min < 2) {
|
|
+ continue;
|
|
+ }
|
|
+
|
|
+ // Create vertical parts between the two points
|
|
+ for (var line = min; line < max; ++line) {
|
|
+ parts[line][column] = Parts.VERTICAL;
|
|
+ }
|
|
+
|
|
+ parts[min][column] = Parts.TOP;
|
|
+ parts[max][column] = Parts.BOTTOM;
|
|
+
|
|
+ if (column + 1 < length) {
|
|
+ // dodgy hack because the previous value can change +/- 1
|
|
+ // causing the spike to not correctly line up.
|
|
+ // this isn't a problem in the other direction
|
|
+ if (prev == curr + 1 && next < curr) {
|
|
+ parts[max][column] = Parts.SPIKE_TOP_RIGHT;
|
|
+ }
|
|
+
|
|
+ if (min == next) {
|
|
+ parts[min][column] = Parts.SPIKE_BOTTOM_LEFT; // '!
|
|
+ } else if (prev <= min) { // has to be <= due to the issue I noted above
|
|
+ parts[min][column] = Parts.SPIKE_BOTTOM_RIGHT; // !'
|
|
+ }
|
|
+
|
|
+ // cone on the top of a spike
|
|
+ if (max == curr && Math.abs(next - max) > 1 && Math.abs(prev - max) > 1 && prev < max) {
|
|
+ parts[max][column - 1] = Parts.SPIKE_TOP_LEFT;
|
|
+ parts[max][column] = Parts.SPIKE_TOP_RIGHT;
|
|
+ }
|
|
+
|
|
+ // cone on the bottom of a spike
|
|
+ if (min == curr && Math.abs(next - min) > 1 && Math.abs(prev - min) > 1 && prev > min) {
|
|
+ parts[min][column - 1] = Parts.SPIKE_BOTTOM_LEFT;
|
|
+ parts[min][column] = Parts.SPIKE_BOTTOM_RIGHT;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ // Create special points on the graph, this
|
|
+ // is to handle slopes and slight differences
|
|
+ // that show up, anything else should be too
|
|
+ // extreme and get treated as a spike instead.
|
|
+ for (var column = 0; column < length; ++column) {
|
|
+ var tps = tracked.point(column).tps();
|
|
+ // Likely the server has just started
|
|
+ if (tps == 0.0) continue;
|
|
+ var curr = getLine(tps);
|
|
+ var prev = getLine(tracked.point(Math.max(column - 1, 0)).tps());
|
|
+ var next = getLine(tracked.point(column + 1).tps());
|
|
+
|
|
+ // Ignore spikes, it'd mess up and be a waste of time
|
|
+ if (Math.abs(curr - next) >= 2) {
|
|
+ continue;
|
|
+ }
|
|
+
|
|
+ // SANITY: positive = rising, negative = declining
|
|
+ var direction = next - prev;
|
|
+ var change = Math.abs(direction);
|
|
+
|
|
+ if (change >= 2 && Math.max(next, prev) == curr + 1) {
|
|
+ // Create slopes, only requirement is that the highest point
|
|
+ // and the current are one line away from one another.
|
|
+ if (direction < 0) {
|
|
+ parts[curr][column] = Parts.DECLINING;
|
|
+ } else {
|
|
+ parts[curr][column] = Parts.RISING;
|
|
+ }
|
|
+ } else if (Math.abs(curr - next) == 1 || direction == 0) {
|
|
+ // if we have no direction always do this as a special case for slight dips and rises
|
|
+ if (curr < next) {
|
|
+ parts[curr][column] = Parts.TOP;
|
|
+ } else if (curr > next) {
|
|
+ parts[curr][column] = Parts.BOTTOM;
|
|
+ }
|
|
+ } else if (Math.abs(curr - prev) == 1) {
|
|
+ if (prev > curr) {
|
|
+ parts[curr][column] = Parts.TOP;
|
|
+ } else if (prev < curr) {
|
|
+ parts[curr][column] = Parts.BOTTOM;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private int getLine(double tps) {
|
|
+ var per = (ceiling / 10); // How many lines 1 tick should display
|
|
+ var line = (int) (tps / per);
|
|
+ return Mth.clamp(line, 0, lines - 1);
|
|
+ }
|
|
+
|
|
+ public Component[] components() {
|
|
+ // Create graph component array
|
|
+ var graph = new TextComponent.Builder[lines];
|
|
+
|
|
+ // Initialise graph components
|
|
+ for (var line = 0; line < graph.length; ++line) {
|
|
+ graph[line] = Component.text();
|
|
+ }
|
|
+
|
|
+ // Write the graph
|
|
+ for (var line = 0; line < parts.length; line++) {
|
|
+ writeLine(graph[line], parts[parts.length - line - 1]);
|
|
+ }
|
|
+
|
|
+ // Create built component array
|
|
+ var parts = new Component[graph.length];
|
|
+
|
|
+ // Store built components
|
|
+ for (var i = 0; i < graph.length; i++) {
|
|
+ parts[i] = graph[i].build();
|
|
+ }
|
|
+
|
|
+ return parts;
|
|
+ }
|
|
+
|
|
+ private void writeLine(TextComponent.Builder builder, Parts[] lineParts) {
|
|
+ for (var column = 0; column < lineParts.length; column++) {
|
|
+ var point = tracked.point(column);
|
|
+ var part = lineParts[column];
|
|
+
|
|
+ var colour = colour(point.tps() / 20.0);
|
|
+ var component = part.getPart();
|
|
+
|
|
+ if (part != Parts.BACKGROUND) {
|
|
+ component = component.color(colour);
|
|
+ }
|
|
+
|
|
+ // Display information from the current point
|
|
+ builder.append(appendHoverEvent(component, point, colour));
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private Component appendHoverEvent(Component in, Point point, TextColor colour) {
|
|
+ return in.hoverEvent(HoverEvent.showText(MiniMessage.miniMessage().deserialize("""
|
|
+ TPS: <tps>
|
|
+ MS: (<ms>, <highest>)
|
|
+ Chunks: <chunks>
|
|
+ Entities: <entities>""",
|
|
+ Placeholder.component("tps", Component.text("%.1f".formatted(point.tps()), colour)),
|
|
+ Placeholder.component("ms", Component.text("%.1f".formatted(point.mspt()), colour)),
|
|
+ Placeholder.component("highest", Component.text("%.1f".formatted(point.highest()), colour)),
|
|
+ Placeholder.unparsed("chunks", String.valueOf(point.chunks())),
|
|
+ Placeholder.unparsed("entities", String.valueOf(point.entities()))
|
|
+ )));
|
|
+ }
|
|
+
|
|
+ public static TextColor colour(double percentage) {
|
|
+ if (percentage > 0.75) return shift(percentage, 1.0, 0.75, NamedTextColor.GREEN, NamedTextColor.YELLOW);
|
|
+ if (percentage > 0.6) return shift(percentage, 0.75, 0.6, NamedTextColor.YELLOW, NamedTextColor.GOLD);
|
|
+ if (percentage > 0.4) return shift(percentage, 0.6, 0.4, NamedTextColor.GOLD, NamedTextColor.RED);
|
|
+ if (percentage > 0.2) return shift(percentage, 0.4, 0.2, NamedTextColor.RED, NamedTextColor.DARK_GRAY);
|
|
+ return shift(percentage, 0.2, 0.0, NamedTextColor.DARK_GRAY, NamedTextColor.BLACK);
|
|
+ }
|
|
+
|
|
+ private static TextColor shift(double percentage, double from, double to, TextColor fromColour, TextColor toColour) {
|
|
+ var f = (float) ((percentage - from) / (to - from));
|
|
+ return TextColor.lerp(Math.max(f, 0.0f), fromColour, toColour);
|
|
+ }
|
|
+
|
|
+ public static double format(double num, int decimals) {
|
|
+ var pow = Math.pow(10, decimals);
|
|
+ return Math.round(num * pow) / pow;
|
|
+ }
|
|
+
|
|
+ private enum Parts {
|
|
+ // Adventure doesn't have a Component.text(String, TextDecoration)
|
|
+ BACKGROUND(Component.text("::", NamedTextColor.BLACK)),
|
|
+ NORMAL(Component.text(" ").decorate(TextDecoration.STRIKETHROUGH)),
|
|
+ VERTICAL(Component.text("||")),
|
|
+ RISING(Component.text(".").decorate(TextDecoration.STRIKETHROUGH).append(Component.text("'").decoration(TextDecoration.STRIKETHROUGH, false))),
|
|
+ DECLINING(Component.text("'").append(Component.text(".").decorate(TextDecoration.STRIKETHROUGH))),
|
|
+ SPIKE_TOP_LEFT(Component.text(".!")),
|
|
+ SPIKE_TOP_RIGHT(Component.text("!.")),
|
|
+ SPIKE_BOTTOM_LEFT(Component.text("'!")),
|
|
+ SPIKE_BOTTOM_RIGHT(Component.text("!'")),
|
|
+ TOP(Component.text("''")),
|
|
+ BOTTOM(Component.text("..")),
|
|
+ ;
|
|
+
|
|
+ private final Component part;
|
|
+
|
|
+ Parts(Component component) {
|
|
+ part = component;
|
|
+ }
|
|
+
|
|
+ public Component getPart() {
|
|
+ return part;
|
|
+ }
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/me/samsuik/sakura/utils/tps/TickTracking.java b/src/main/java/me/samsuik/sakura/utils/tps/TickTracking.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..6903863ad293a335a8ed1aeaa06fccb408593373
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/samsuik/sakura/utils/tps/TickTracking.java
|
|
@@ -0,0 +1,53 @@
|
|
+package me.samsuik.sakura.utils.tps;
|
|
+
|
|
+import net.minecraft.server.level.ServerLevel;
|
|
+
|
|
+import java.util.ArrayList;
|
|
+import java.util.Arrays;
|
|
+import java.util.Collection;
|
|
+import java.util.List;
|
|
+import java.util.stream.IntStream;
|
|
+
|
|
+public final class TickTracking {
|
|
+
|
|
+ private final List<Point> history = new ArrayList<>();
|
|
+ private final double[] msptSamples = new double[20];
|
|
+
|
|
+ public TickTracking(int samples) {
|
|
+ for (int i = 0; i < samples; ++i) {
|
|
+ history.add(new Point(0.0, 0.0,0.0, 0, 0));
|
|
+ }
|
|
+ }
|
|
+
|
|
+ Point point(int at) {
|
|
+ return history.get(at);
|
|
+ }
|
|
+
|
|
+ public double averageTps(int samples) {
|
|
+ return IntStream.range(0, samples)
|
|
+ .mapToDouble(i -> history.get(i).tps)
|
|
+ .average()
|
|
+ .orElse(0.0);
|
|
+ }
|
|
+
|
|
+ public void secondSample(Collection<ServerLevel> server, double tps) {
|
|
+ history.remove(history.size() - 1);
|
|
+
|
|
+ int entities = server.stream().mapToInt((world) -> world.entityTickList.entities.size()).sum();
|
|
+ int loaded = server.stream().mapToInt((world) -> world.chunkSource.getInternallyLoadedChunks()).sum();
|
|
+
|
|
+ double mspt = Arrays.stream(msptSamples).average().orElse(0.0);
|
|
+ double max = Arrays.stream(msptSamples).max().orElse(0.0);
|
|
+
|
|
+ history.add(0, new Point(tps, mspt, max, entities, loaded));
|
|
+ }
|
|
+
|
|
+ public void tickSample(long mspt) {
|
|
+ for (int i = msptSamples.length - 2; i >= 0; --i)
|
|
+ msptSamples[i + 1] = msptSamples[i];
|
|
+ msptSamples[0] = mspt;
|
|
+ }
|
|
+
|
|
+ public record Point(double tps, double mspt, double highest, int entities, int chunks) {}
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index 606ae62f597761296412e14750758fa185fc3c48..b72c796d30d4892e30d726c3b2a6b097b941979d 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -1130,6 +1130,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
}
|
|
}
|
|
private static final java.math.BigDecimal TPS_BASE = new java.math.BigDecimal(1E9).multiply(new java.math.BigDecimal(SAMPLE_INTERVAL));
|
|
+ public static final me.samsuik.sakura.utils.tps.TickTracking tickTracking = new me.samsuik.sakura.utils.tps.TickTracking(120); // Sakura - tps graph command
|
|
// Paper end
|
|
// Spigot End
|
|
|
|
@@ -1208,6 +1209,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
if (++MinecraftServer.currentTick % MinecraftServer.SAMPLE_INTERVAL == 0) {
|
|
final long diff = currentTime - tickSection;
|
|
final java.math.BigDecimal currentTps = TPS_BASE.divide(new java.math.BigDecimal(diff), 30, java.math.RoundingMode.HALF_UP);
|
|
+ tickTracking.secondSample(levels.values(), currentTps.doubleValue()); // Sakura
|
|
tps1.add(currentTps, diff);
|
|
tps5.add(currentTps, diff);
|
|
tps15.add(currentTps, diff);
|
|
@@ -1236,6 +1238,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
this.tickServer(flag ? () -> {
|
|
return false;
|
|
} : this::haveTime);
|
|
+ tickTracking.tickSample((System.nanoTime() - currentTime) / 1_000_000L); // Sakura
|
|
this.profiler.popPush("nextTickWait");
|
|
this.mayHaveDelayedTasks = true;
|
|
this.delayedTasksMaxNextTickTimeNanos = Math.max(Util.getNanos() + i, this.nextTickTimeNanos);
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
|
index b99f50604bafecbc68835974c9ed0caa91911a40..c912615ded011741f81c72739639e631f331710e 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
|
@@ -90,6 +90,11 @@ public class ServerChunkCache extends ChunkSource {
|
|
this.clearCache();
|
|
}
|
|
|
|
+ // Sakura start - tps graph command
|
|
+ public final int getInternallyLoadedChunks() {
|
|
+ return loadedChunkMap.size();
|
|
+ }
|
|
+ // Sakura end - tps graph command
|
|
// CraftBukkit start - properly implement isChunkLoaded
|
|
public boolean isChunkLoaded(int chunkX, int chunkZ) {
|
|
ChunkHolder chunk = this.chunkMap.getUpdatingChunkIfPresent(ChunkPos.asLong(chunkX, chunkZ));
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
index 747ebfb09dcd4c619ee0543c8aa79c05416687a4..4a3690c71eda93d2542e8c039442a51882f10475 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -197,7 +197,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
|
private final MinecraftServer server;
|
|
public final PrimaryLevelData serverLevelData; // CraftBukkit - type
|
|
private int lastSpawnChunkRadius;
|
|
- final EntityTickList entityTickList;
|
|
+ public final EntityTickList entityTickList; // Sakura - package-private -> public
|
|
//public final PersistentEntitySectionManager<Entity> entityManager; // Paper - rewrite chunk system
|
|
private final GameEventDispatcher gameEventDispatcher;
|
|
public boolean noSave;
|
|
diff --git a/src/main/java/net/minecraft/world/level/entity/EntityTickList.java b/src/main/java/net/minecraft/world/level/entity/EntityTickList.java
|
|
index 83a39f900551e39d5af6f17a339a386ddee4feef..172c8d9cc94ed6ddfd3f785ca97a6e6ebb58d2d9 100644
|
|
--- a/src/main/java/net/minecraft/world/level/entity/EntityTickList.java
|
|
+++ b/src/main/java/net/minecraft/world/level/entity/EntityTickList.java
|
|
@@ -9,7 +9,7 @@ import javax.annotation.Nullable;
|
|
import net.minecraft.world.entity.Entity;
|
|
|
|
public class EntityTickList {
|
|
- private final io.papermc.paper.util.maplist.IteratorSafeOrderedReferenceSet<Entity> entities = new io.papermc.paper.util.maplist.IteratorSafeOrderedReferenceSet<>(true); // Paper - rewrite this, always keep this updated - why would we EVER tick an entity that's not ticking?
|
|
+ public final io.papermc.paper.util.maplist.IteratorSafeOrderedReferenceSet<Entity> entities = new io.papermc.paper.util.maplist.IteratorSafeOrderedReferenceSet<>(true); // Sakura - tps graph // Paper - rewrite this, always keep this updated - why would we EVER tick an entity that's not ticking?
|
|
|
|
private void ensureActiveIsNotIterated() {
|
|
// Paper - replace with better logic, do not delay removals
|
|
diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java
|
|
index 6c2a3813e7d63d57f07a8fa2edbb9d231221d818..a7333afe790be4ca876cb15c5f32a085dd13c3bb 100644
|
|
--- a/src/main/java/org/spigotmc/SpigotConfig.java
|
|
+++ b/src/main/java/org/spigotmc/SpigotConfig.java
|
|
@@ -283,7 +283,7 @@ public class SpigotConfig
|
|
|
|
private static void tpsCommand()
|
|
{
|
|
- SpigotConfig.commands.put( "tps", new TicksPerSecondCommand( "tps" ) );
|
|
+ // SpigotConfig.commands.put( "tps", new TicksPerSecondCommand( "tps" ) ); // Sakura - TPS Graph
|
|
}
|
|
|
|
public static int playerSample;
|