aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2020-02-04 00:49:40 +0000
committerLuck <git@lucko.me>2020-02-04 00:49:40 +0000
commite02d52ce8d45550a4d77f11971e31cf0732e5f0c (patch)
treecfcfb2850ff6b279276e43233e5e1acf82993a98
parentd15a12788ddc8aba09f49003fcef55b927850de3 (diff)
downloadspark-e02d52ce8d45550a4d77f11971e31cf0732e5f0c.tar.gz
spark-e02d52ce8d45550a4d77f11971e31cf0732e5f0c.tar.bz2
spark-e02d52ce8d45550a4d77f11971e31cf0732e5f0c.zip
Monitor average tick durations & report them in /spark tps
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitSparkPlugin.java17
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitTickHook.java (renamed from spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitTickCounter.java)8
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/PaperTickHook.java (renamed from spark-bukkit/src/main/java/me/lucko/spark/bukkit/PaperTickCounter.java)8
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/PaperTickReporter.java53
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderProvider.java54
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java44
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/SparkPlugin.java20
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/command/modules/HealthModule.java81
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java10
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/command/modules/TickMonitoringModule.java22
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/monitor/tick/TickMonitor.java16
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/monitor/tick/TickStatistics.java (renamed from spark-common/src/main/java/me/lucko/spark/common/monitor/tick/TpsCalculator.java)92
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/sampler/Sampler.java5
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/sampler/SamplerBuilder.java12
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/sampler/aggregator/TickedDataAggregator.java10
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/sampler/tick/AbstractTickHook.java (renamed from spark-common/src/main/java/me/lucko/spark/common/sampler/AbstractTickCounter.java)12
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/sampler/tick/AbstractTickReporter.java45
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/sampler/tick/TickHook.java (renamed from spark-common/src/main/java/me/lucko/spark/common/sampler/TickCounter.java)22
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/sampler/tick/TickReporter.java57
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/util/RollingAverage.java42
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/FabricTickHook.java (renamed from spark-fabric/src/main/java/me/lucko/spark/fabric/FabricTickCounter.java)10
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java8
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java8
-rw-r--r--spark-forge/src/main/java/me/lucko/spark/forge/ForgeTickHook.java (renamed from spark-forge/src/main/java/me/lucko/spark/forge/ForgeTickCounter.java)8
-rw-r--r--spark-forge/src/main/java/me/lucko/spark/forge/ForgeTickReporter.java71
-rw-r--r--spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java15
-rw-r--r--spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java15
-rw-r--r--spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeSparkPlugin.java9
-rw-r--r--spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeTickHook.java (renamed from spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeTickCounter.java)8
29 files changed, 600 insertions, 182 deletions
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitSparkPlugin.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitSparkPlugin.java
index 0eca719..eca4619 100644
--- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitSparkPlugin.java
+++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitSparkPlugin.java
@@ -25,7 +25,8 @@ import me.lucko.spark.bukkit.placeholder.SparkPlaceholderApi;
import me.lucko.spark.common.SparkPlatform;
import me.lucko.spark.common.SparkPlugin;
import me.lucko.spark.common.sampler.ThreadDumper;
-import me.lucko.spark.common.sampler.TickCounter;
+import me.lucko.spark.common.sampler.tick.TickHook;
+import me.lucko.spark.common.sampler.tick.TickReporter;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -129,16 +130,24 @@ public class BukkitSparkPlugin extends JavaPlugin implements SparkPlugin {
}
@Override
- public TickCounter createTickCounter() {
+ public TickHook createTickHook() {
if (classExists("com.destroystokyo.paper.event.server.ServerTickStartEvent")) {
getLogger().info("Using Paper ServerTickStartEvent for tick monitoring");
- return new PaperTickCounter(this);
+ return new PaperTickHook(this);
} else {
getLogger().info("Using Bukkit scheduler for tick monitoring");
- return new BukkitTickCounter(this);
+ return new BukkitTickHook(this);
}
}
+ @Override
+ public TickReporter createTickReporter() {
+ if (classExists("com.destroystokyo.paper.event.server.ServerTickStartEvent")) {
+ return new PaperTickReporter(this);
+ }
+ return null;
+ }
+
private static boolean classExists(String className) {
try {
Class.forName(className);
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitTickCounter.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitTickHook.java
index 2a71257..184656e 100644
--- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitTickCounter.java
+++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitTickHook.java
@@ -20,16 +20,16 @@
package me.lucko.spark.bukkit;
-import me.lucko.spark.common.sampler.AbstractTickCounter;
-import me.lucko.spark.common.sampler.TickCounter;
+import me.lucko.spark.common.sampler.tick.AbstractTickHook;
+import me.lucko.spark.common.sampler.tick.TickHook;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitTask;
-public class BukkitTickCounter extends AbstractTickCounter implements TickCounter, Runnable {
+public class BukkitTickHook extends AbstractTickHook implements TickHook, Runnable {
private final Plugin plugin;
private BukkitTask task;
- public BukkitTickCounter(Plugin plugin) {
+ public BukkitTickHook(Plugin plugin) {
this.plugin = plugin;
}
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/PaperTickCounter.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/PaperTickHook.java
index 7189429..5ad7b57 100644
--- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/PaperTickCounter.java
+++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/PaperTickHook.java
@@ -21,17 +21,17 @@
package me.lucko.spark.bukkit;
import com.destroystokyo.paper.event.server.ServerTickStartEvent;
-import me.lucko.spark.common.sampler.AbstractTickCounter;
-import me.lucko.spark.common.sampler.TickCounter;
+import me.lucko.spark.common.sampler.tick.AbstractTickHook;
+import me.lucko.spark.common.sampler.tick.TickHook;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
-public class PaperTickCounter extends AbstractTickCounter implements TickCounter, Listener {
+public class PaperTickHook extends AbstractTickHook implements TickHook, Listener {
private final Plugin plugin;
- public PaperTickCounter(Plugin plugin) {
+ public PaperTickHook(Plugin plugin) {
this.plugin = plugin;
}
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/PaperTickReporter.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/PaperTickReporter.java
new file mode 100644
index 0000000..a51be66
--- /dev/null
+++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/PaperTickReporter.java
@@ -0,0 +1,53 @@
+/*
+ * This file is part of spark.
+ *
+ * Copyright (c) lucko (Luck) <luck@lucko.me>
+ * Copyright (c) contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package me.lucko.spark.bukkit;
+
+import com.destroystokyo.paper.event.server.ServerTickEndEvent;
+import me.lucko.spark.common.sampler.tick.AbstractTickReporter;
+import me.lucko.spark.common.sampler.tick.TickReporter;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.Listener;
+import org.bukkit.plugin.Plugin;
+
+public class PaperTickReporter extends AbstractTickReporter implements TickReporter, Listener {
+ private final Plugin plugin;
+
+ public PaperTickReporter(Plugin plugin) {
+ this.plugin = plugin;
+ }
+
+ @EventHandler
+ public void onServerTickEvent(ServerTickEndEvent e) {
+ onTick(e.getTickDuration());
+ }
+
+ @Override
+ public void start() {
+ this.plugin.getServer().getPluginManager().registerEvents(this, this.plugin);
+ }
+
+ @Override
+ public void close() {
+ HandlerList.unregisterAll(this);
+ }
+
+}
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderProvider.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderProvider.java
index d94ce95..0f57149 100644
--- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderProvider.java
+++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderProvider.java
@@ -23,7 +23,7 @@ package me.lucko.spark.bukkit.placeholder;
import me.lucko.spark.common.SparkPlatform;
import me.lucko.spark.common.command.modules.HealthModule;
import me.lucko.spark.common.monitor.cpu.CpuMonitor;
-import me.lucko.spark.common.monitor.tick.TpsCalculator;
+import me.lucko.spark.common.monitor.tick.TickStatistics;
import net.kyori.text.TextComponent;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
@@ -32,37 +32,59 @@ enum SparkPlaceholderProvider {
public static TextComponent respondComponent(SparkPlatform platform, String placeholder) {
if (placeholder.startsWith("tps")) {
- TpsCalculator tpsCalculator = platform.getTpsCalculator();
- if (tpsCalculator == null) {
+ TickStatistics tickStatistics = platform.getTickStatistics();
+ if (tickStatistics == null) {
return null;
}
switch (placeholder) {
case "tps":
- return TextComponent.builder(" ")
- .append(HealthModule.formatTps(tpsCalculator.avg5Sec())).append(TextComponent.of(", "))
- .append(HealthModule.formatTps(tpsCalculator.avg10Sec())).append(TextComponent.of(", "))
- .append(HealthModule.formatTps(tpsCalculator.avg1Min())).append(TextComponent.of(", "))
- .append(HealthModule.formatTps(tpsCalculator.avg5Min())).append(TextComponent.of(", "))
- .append(HealthModule.formatTps(tpsCalculator.avg15Min()))
+ return TextComponent.builder("")
+ .append(HealthModule.formatTps(tickStatistics.tps5Sec())).append(TextComponent.of(", "))
+ .append(HealthModule.formatTps(tickStatistics.tps10Sec())).append(TextComponent.of(", "))
+ .append(HealthModule.formatTps(tickStatistics.tps1Min())).append(TextComponent.of(", "))
+ .append(HealthModule.formatTps(tickStatistics.tps5Min())).append(TextComponent.of(", "))
+ .append(HealthModule.formatTps(tickStatistics.tps15Min()))
.build();
case "tps_5s":
- return HealthModule.formatTps(tpsCalculator.avg5Sec());
+ return HealthModule.formatTps(tickStatistics.tps5Sec());
case "tps_10s":
- return HealthModule.formatTps(tpsCalculator.avg10Sec());
+ return HealthModule.formatTps(tickStatistics.tps10Sec());
case "tps_1m":
- return HealthModule.formatTps(tpsCalculator.avg1Min());
+ return HealthModule.formatTps(tickStatistics.tps1Min());
case "tps_5m":
- return HealthModule.formatTps(tpsCalculator.avg5Min());
+ return HealthModule.formatTps(tickStatistics.tps5Min());
case "tps_15m":
- return HealthModule.formatTps(tpsCalculator.avg15Min());
+ return HealthModule.formatTps(tickStatistics.tps15Min());
+ }
+ }
+
+ if (placeholder.startsWith("tickduration")) {
+ TickStatistics tickStatistics = platform.getTickStatistics();
+ if (tickStatistics == null || !tickStatistics.isDurationSupported()) {
+ return null;
+ }
+
+ switch (placeholder) {
+ case "tickduration":
+ return TextComponent.builder("")
+ .append(HealthModule.formatTickDurations(tickStatistics.duration5Sec())).append(TextComponent.of(", "))
+ .append(HealthModule.formatTickDurations(tickStatistics.duration10Sec())).append(TextComponent.of(", "))
+ .append(HealthModule.formatTickDurations(tickStatistics.duration1Min()))
+ .build();
+ case "tickduration_5s":
+ return HealthModule.formatTickDurations(tickStatistics.duration5Sec());
+ case "tickduration_10s":
+ return HealthModule.formatTickDurations(tickStatistics.duration10Sec());
+ case "tickduration_1m":
+ return HealthModule.formatTickDurations(tickStatistics.duration1Min());
}
}
if (placeholder.startsWith("cpu")) {
switch (placeholder) {
case "cpu_system":
- return TextComponent.builder(" ")
+ return TextComponent.builder("")
.append(HealthModule.formatCpuUsage(CpuMonitor.systemLoad10SecAvg())).append(TextComponent.of(", "))
.append(HealthModule.formatCpuUsage(CpuMonitor.systemLoad1MinAvg())).append(TextComponent.of(", "))
.append(HealthModule.formatCpuUsage(CpuMonitor.systemLoad15MinAvg()))
@@ -74,7 +96,7 @@ enum SparkPlaceholderProvider {
case "cpu_system_15m":
return HealthModule.formatCpuUsage(CpuMonitor.systemLoad15MinAvg());
case "cpu_process":
- return TextComponent.builder(" ")
+ return TextComponent.builder("")
.append(HealthModule.formatCpuUsage(CpuMonitor.processLoad10SecAvg())).append(TextComponent.of(", "))
.append(HealthModule.formatCpuUsage(CpuMonitor.processLoad1MinAvg())).append(TextComponent.of(", "))
.append(HealthModule.formatCpuUsage(CpuMonitor.processLoad15MinAvg()))
diff --git a/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java b/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java
index dc88306..340fa34 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java
@@ -35,8 +35,9 @@ import me.lucko.spark.common.command.sender.CommandSender;
import me.lucko.spark.common.command.tabcomplete.CompletionSupplier;
import me.lucko.spark.common.command.tabcomplete.TabCompleter;
import me.lucko.spark.common.monitor.cpu.CpuMonitor;
-import me.lucko.spark.common.monitor.tick.TpsCalculator;
-import me.lucko.spark.common.sampler.TickCounter;
+import me.lucko.spark.common.monitor.tick.TickStatistics;
+import me.lucko.spark.common.sampler.tick.TickHook;
+import me.lucko.spark.common.sampler.tick.TickReporter;
import me.lucko.spark.common.util.BytebinClient;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
@@ -66,8 +67,9 @@ public class SparkPlatform {
private final List<CommandModule> commandModules;
private final List<Command> commands;
private final ActivityLog activityLog;
- private final TickCounter tickCounter;
- private final TpsCalculator tpsCalculator;
+ private final TickHook tickHook;
+ private final TickReporter tickReporter;
+ private final TickStatistics tickStatistics;
public SparkPlatform(SparkPlugin plugin) {
this.plugin = plugin;
@@ -89,21 +91,29 @@ public class SparkPlatform {
this.activityLog = new ActivityLog(plugin.getPluginDirectory().resolve("activity.json"));
this.activityLog.load();
- this.tickCounter = plugin.createTickCounter();
- this.tpsCalculator = this.tickCounter != null ? new TpsCalculator() : null;
+ this.tickHook = plugin.createTickHook();
+ this.tickReporter = plugin.createTickReporter();
+ this.tickStatistics = this.tickHook != null ? new TickStatistics() : null;
}
public void enable() {
- if (this.tickCounter != null) {
- this.tickCounter.addTickTask(this.tpsCalculator);
- this.tickCounter.start();
+ if (this.tickHook != null) {
+ this.tickHook.addCallback(this.tickStatistics);
+ this.tickHook.start();
+ }
+ if (this.tickReporter != null) {
+ this.tickReporter.addCallback(this.tickStatistics);
+ this.tickReporter.start();
}
CpuMonitor.ensureMonitoring();
}
public void disable() {
- if (this.tickCounter != null) {
- this.tickCounter.close();
+ if (this.tickHook != null) {
+ this.tickHook.close();
+ }
+ if (this.tickReporter != null) {
+ this.tickReporter.close();
}
for (CommandModule module : this.commandModules) {
@@ -119,12 +129,16 @@ public class SparkPlatform {
return this.activityLog;
}
- public TickCounter getTickCounter() {
- return this.tickCounter;
+ public TickHook getTickHook() {
+ return this.tickHook;
+ }
+
+ public TickReporter getTickReporter() {
+ return this.tickReporter;
}
- public TpsCalculator getTpsCalculator() {
- return this.tpsCalculator;
+ public TickStatistics getTickStatistics() {
+ return this.tickStatistics;
}
public void executeCommand(CommandSender sender, String[] args) {
diff --git a/spark-common/src/main/java/me/lucko/spark/common/SparkPlugin.java b/spark-common/src/main/java/me/lucko/spark/common/SparkPlugin.java
index 1171b33..c0a928d 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/SparkPlugin.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/SparkPlugin.java
@@ -22,7 +22,8 @@ package me.lucko.spark.common;
import me.lucko.spark.common.command.sender.CommandSender;
import me.lucko.spark.common.sampler.ThreadDumper;
-import me.lucko.spark.common.sampler.TickCounter;
+import me.lucko.spark.common.sampler.tick.TickHook;
+import me.lucko.spark.common.sampler.tick.TickReporter;
import java.nio.file.Path;
import java.util.stream.Stream;
@@ -79,13 +80,24 @@ public interface SparkPlugin {
}
/**
- * Creates a tick counter for the platform, if supported.
+ * Creates a tick hook for the platform, if supported.
*
* <p>Returns {@code null} if the platform does not have "ticks"</p>
*
- * @return a new tick counter
+ * @return a new tick hook
*/
- default TickCounter createTickCounter() {
+ default TickHook createTickHook() {
+ return null;
+ }
+
+ /**
+ * Creates a tick reporter for the platform, if supported.
+ *
+ * <p>Returns {@code null} if the platform does not have "ticks"</p>
+ *
+ * @return a new tick reporter
+ */
+ default TickReporter createTickReporter() {
return null;
}
diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/HealthModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/HealthModule.java
index 0737a00..08233db 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/HealthModule.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/HealthModule.java
@@ -25,8 +25,9 @@ import me.lucko.spark.common.command.Command;
import me.lucko.spark.common.command.CommandModule;
import me.lucko.spark.common.command.tabcomplete.TabCompleter;
import me.lucko.spark.common.monitor.cpu.CpuMonitor;
-import me.lucko.spark.common.monitor.tick.TpsCalculator;
+import me.lucko.spark.common.monitor.tick.TickStatistics;
import me.lucko.spark.common.util.FormatUtil;
+import me.lucko.spark.common.util.RollingAverage;
import net.kyori.text.Component;
import net.kyori.text.TextComponent;
import net.kyori.text.format.TextColor;
@@ -52,18 +53,29 @@ public class HealthModule implements CommandModule {
consumer.accept(Command.builder()
.aliases("tps", "cpu")
.executor((platform, sender, resp, arguments) -> {
- TpsCalculator tpsCalculator = platform.getTpsCalculator();
- if (tpsCalculator != null) {
+ TickStatistics tickStatistics = platform.getTickStatistics();
+ if (tickStatistics != null) {
resp.replyPrefixed(TextComponent.of("TPS from last 5s, 10s, 1m, 5m, 15m:"));
resp.replyPrefixed(TextComponent.builder(" ")
- .append(formatTps(tpsCalculator.avg5Sec())).append(TextComponent.of(", "))
- .append(formatTps(tpsCalculator.avg10Sec())).append(TextComponent.of(", "))
- .append(formatTps(tpsCalculator.avg1Min())).append(TextComponent.of(", "))
- .append(formatTps(tpsCalculator.avg5Min())).append(TextComponent.of(", "))
- .append(formatTps(tpsCalculator.avg15Min()))
+ .append(formatTps(tickStatistics.tps5Sec())).append(TextComponent.of(", "))
+ .append(formatTps(tickStatistics.tps10Sec())).append(TextComponent.of(", "))
+ .append(formatTps(tickStatistics.tps1Min())).append(TextComponent.of(", "))
+ .append(formatTps(tickStatistics.tps5Min())).append(TextComponent.of(", "))
+ .append(formatTps(tickStatistics.tps15Min()))
.build()
);
resp.replyPrefixed(TextComponent.empty());
+
+ if (tickStatistics.isDurationSupported()) {
+ resp.replyPrefixed(TextComponent.of("Tick durations (avg/min/max ms) from last 5s, 10s, 1m:"));
+ resp.replyPrefixed(TextComponent.builder(" ")
+ .append(formatTickDurations(tickStatistics.duration5Sec())).append(TextComponent.of(", "))
+ .append(formatTickDurations(tickStatistics.duration10Sec())).append(TextComponent.of(", "))
+ .append(formatTickDurations(tickStatistics.duration1Min()))
+ .build()
+ );
+ resp.replyPrefixed(TextComponent.empty());
+ }
}
resp.replyPrefixed(TextComponent.of("CPU usage from last 10s, 1m, 15m:"));
@@ -95,8 +107,8 @@ public class HealthModule implements CommandModule {
List<Component> report = new LinkedList<>();
report.add(TextComponent.empty());
- TpsCalculator tpsCalculator = platform.getTpsCalculator();
- if (tpsCalculator != null) {
+ TickStatistics tickStatistics = platform.getTickStatistics();
+ if (tickStatistics != null) {
report.add(TextComponent.builder("")
.append(TextComponent.builder(">").color(TextColor.DARK_GRAY).decoration(TextDecoration.BOLD, true).build())
.append(TextComponent.space())
@@ -104,14 +116,30 @@ public class HealthModule implements CommandModule {
.build()
);
report.add(TextComponent.builder(" ")
- .append(formatTps(tpsCalculator.avg5Sec())).append(TextComponent.of(", "))
- .append(formatTps(tpsCalculator.avg10Sec())).append(TextComponent.of(", "))
- .append(formatTps(tpsCalculator.avg1Min())).append(TextComponent.of(", "))
- .append(formatTps(tpsCalculator.avg5Min())).append(TextComponent.of(", "))
- .append(formatTps(tpsCalculator.avg15Min()))
+ .append(formatTps(tickStatistics.tps5Sec())).append(TextComponent.of(", "))
+ .append(formatTps(tickStatistics.tps10Sec())).append(TextComponent.of(", "))
+ .append(formatTps(tickStatistics.tps1Min())).append(TextComponent.of(", "))
+ .append(formatTps(tickStatistics.tps5Min())).append(TextComponent.of(", "))
+ .append(formatTps(tickStatistics.tps15Min()))
.build()
);
report.add(TextComponent.empty());
+
+ if (tickStatistics.isDurationSupported()) {
+ report.add(TextComponent.builder("")
+ .append(TextComponent.builder(">").color(TextColor.DARK_GRAY).decoration(TextDecoration.BOLD, true).build())
+ .append(TextComponent.space())
+ .append(TextComponent.of("Tick durations (avg/min/max ms) from last 5s, 10s, 1m:", TextColor.GOLD))
+ .build()
+ );
+ report.add(TextComponent.builder(" ")
+ .append(formatTickDurations(tickStatistics.duration5Sec())).append(TextComponent.of(", "))
+ .append(formatTickDurations(tickStatistics.duration10Sec())).append(TextComponent.of(", "))
+ .append(formatTickDurations(tickStatistics.duration1Min()))
+ .build()
+ );
+ report.add(TextComponent.empty());
+ }
}
report.add(TextComponent.builder("")
@@ -269,6 +297,29 @@ public class HealthModule implements CommandModule {
return TextComponent.of( (tps > 20.0 ? "*" : "") + Math.min(Math.round(tps * 100.0) / 100.0, 20.0), color);
}
+ public static TextComponent formatTickDurations(RollingAverage average){
+ return TextComponent.builder("")
+ .append(formatTickDuration(average.getAverage()))
+ .append(TextComponent.of('/', TextColor.GRAY))
+ .append(formatTickDuration(average.getMin()))
+ .append(TextComponent.of('/', TextColor.GRAY))
+ .append(formatTickDuration(average.getMax()))
+ .build();
+ }
+
+ public static TextComponent formatTickDuration(double duration){
+ TextColor color;
+ if (duration >= 50d) {
+ color = TextColor.RED;
+ } else if (duration >= 40d) {
+ color = TextColor.YELLOW;
+ } else {
+ color = TextColor.GREEN;
+ }
+
+ return TextComponent.of(String.format("%.1f", duration), color);
+ }
+
public static TextComponent formatCpuUsage(double usage) {
TextColor color;
if (usage > 0.9) {
diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java
index cd98aa4..919931e 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java
@@ -32,7 +32,7 @@ import me.lucko.spark.common.sampler.SamplerBuilder;
import me.lucko.spark.common.sampler.ThreadDumper;
import me.lucko.spark.common.sampler.ThreadGrouper;
import me.lucko.spark.common.sampler.ThreadNodeOrder;
-import me.lucko.spark.common.sampler.TickCounter;
+import me.lucko.spark.common.sampler.tick.TickHook;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.format.TextColor;
@@ -167,10 +167,10 @@ public class SamplerModule implements CommandModule {
}
int ticksOver = arguments.intFlag("only-ticks-over");
- TickCounter tickCounter = null;
+ TickHook tickHook = null;
if (ticksOver != -1) {
- tickCounter = platform.getTickCounter();
- if (tickCounter == null) {
+ tickHook = platform.getTickHook();
+ if (tickHook == null) {
resp.replyPrefixed(TextComponent.of("Tick counting is not supported!", TextColor.RED));
return;
}
@@ -193,7 +193,7 @@ public class SamplerModule implements CommandModule {
builder.includeLineNumbers(includeLineNumbers);
builder.ignoreSleeping(ignoreSleeping);
if (ticksOver != -1) {
- builder.ticksOver(ticksOver, tickCounter);
+ builder.ticksOver(ticksOver, tickHook);
}
Sampler sampler = this.activeSampler = builder.start();
diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/TickMonitoringModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/TickMonitoringModule.java
index 0ebb252..245a55b 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/TickMonitoringModule.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/TickMonitoringModule.java
@@ -26,7 +26,7 @@ import me.lucko.spark.common.command.CommandModule;
import me.lucko.spark.common.command.CommandResponseHandler;
import me.lucko.spark.common.command.tabcomplete.TabCompleter;
import me.lucko.spark.common.monitor.tick.TickMonitor;
-import me.lucko.spark.common.sampler.TickCounter;
+import me.lucko.spark.common.sampler.tick.TickHook;
import net.kyori.text.Component;
import net.kyori.text.TextComponent;
import net.kyori.text.format.TextColor;
@@ -35,14 +35,14 @@ import java.util.function.Consumer;
public class TickMonitoringModule implements CommandModule {
- /** The tick monitor instance currently running, if any */
- private TickCounter tickCounter = null;
+ /** The tick hook instance currently running, if any */
+ private TickHook tickHook = null;