diff options
author | Luck <git@lucko.me> | 2020-02-04 00:49:40 +0000 |
---|---|---|
committer | Luck <git@lucko.me> | 2020-02-04 00:49:40 +0000 |
commit | e02d52ce8d45550a4d77f11971e31cf0732e5f0c (patch) | |
tree | cfcfb2850ff6b279276e43233e5e1acf82993a98 /spark-bukkit/src/main | |
parent | d15a12788ddc8aba09f49003fcef55b927850de3 (diff) | |
download | spark-e02d52ce8d45550a4d77f11971e31cf0732e5f0c.tar.gz spark-e02d52ce8d45550a4d77f11971e31cf0732e5f0c.tar.bz2 spark-e02d52ce8d45550a4d77f11971e31cf0732e5f0c.zip |
Monitor average tick durations & report them in /spark tps
Diffstat (limited to 'spark-bukkit/src/main')
-rw-r--r-- | spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitSparkPlugin.java | 17 | ||||
-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.java | 53 | ||||
-rw-r--r-- | spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderProvider.java | 54 |
5 files changed, 112 insertions, 28 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())) |