aboutsummaryrefslogtreecommitdiff
path: root/spark-common/src/main/java/me/lucko/spark/common/command
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 /spark-common/src/main/java/me/lucko/spark/common/command
parentd15a12788ddc8aba09f49003fcef55b927850de3 (diff)
downloadspark-e02d52ce8d45550a4d77f11971e31cf0732e5f0c.tar.gz
spark-e02d52ce8d45550a4d77f11971e31cf0732e5f0c.tar.bz2
spark-e02d52ce8d45550a4d77f11971e31cf0732e5f0c.zip
Monitor average tick durations & report them in /spark tps
Diffstat (limited to 'spark-common/src/main/java/me/lucko/spark/common/command')
-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
3 files changed, 82 insertions, 31 deletions
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;
private ReportingTickMonitor activeTickMonitor = null;
@Override
public void close() {
if (this.activeTickMonitor != null) {
- this.tickCounter.removeTickTask(this.activeTickMonitor);
+ this.tickHook.removeCallback(this.activeTickMonitor);
this.activeTickMonitor.close();
this.activeTickMonitor = null;
}
@@ -55,10 +55,10 @@ public class TickMonitoringModule implements CommandModule {
.argumentUsage("threshold", "percentage increase")
.argumentUsage("without-gc", null)
.executor((platform, sender, resp, arguments) -> {
- if (this.tickCounter == null) {
- this.tickCounter = platform.getTickCounter();
+ if (this.tickHook == null) {
+ this.tickHook = platform.getTickHook();
}
- if (this.tickCounter == null) {
+ if (this.tickHook == null) {
resp.replyPrefixed(TextComponent.of("Not supported!", TextColor.RED));
return;
}
@@ -69,8 +69,8 @@ public class TickMonitoringModule implements CommandModule {
threshold = 100;
}
- this.activeTickMonitor = new ReportingTickMonitor(platform, resp, this.tickCounter, threshold, !arguments.boolFlag("without-gc"));
- this.tickCounter.addTickTask(this.activeTickMonitor);
+ this.activeTickMonitor = new ReportingTickMonitor(platform, resp, this.tickHook, threshold, !arguments.boolFlag("without-gc"));
+ this.tickHook.addCallback(this.activeTickMonitor);
} else {
close();
resp.broadcastPrefixed(TextComponent.of("Tick monitor disabled."));
@@ -84,8 +84,8 @@ public class TickMonitoringModule implements CommandModule {
private static class ReportingTickMonitor extends TickMonitor {
private final CommandResponseHandler resp;
- ReportingTickMonitor(SparkPlatform platform, CommandResponseHandler resp, TickCounter tickCounter, int percentageChangeThreshold, boolean monitorGc) {
- super(platform, tickCounter, percentageChangeThreshold, monitorGc);
+ ReportingTickMonitor(SparkPlatform platform, CommandResponseHandler resp, TickHook tickHook, int percentageChangeThreshold, boolean monitorGc) {
+ super(platform, tickHook, percentageChangeThreshold, monitorGc);
this.resp = resp;
}