aboutsummaryrefslogtreecommitdiff
path: root/spark-common/src/main/java/me/lucko/spark/common/command
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2020-04-05 15:46:51 +0100
committerLuck <git@lucko.me>2020-04-05 15:46:51 +0100
commit6f2153e33d232d5b52418531abc0007dcdc466e9 (patch)
tree72c71f0cfb2b9049fc1beac91440a337d85ef648 /spark-common/src/main/java/me/lucko/spark/common/command
parentcc8ee86e146159735c86925e14c85b4ee5d430bc (diff)
downloadspark-6f2153e33d232d5b52418531abc0007dcdc466e9.tar.gz
spark-6f2153e33d232d5b52418531abc0007dcdc466e9.tar.bz2
spark-6f2153e33d232d5b52418531abc0007dcdc466e9.zip
Allow exact tick duration to be used as threshold in tickmonitoring command (#43)
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/TickMonitoringModule.java22
1 files changed, 15 insertions, 7 deletions
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 245a55b..7014770 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,6 +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.monitor.tick.TickMonitor.ReportPredicate;
import me.lucko.spark.common.sampler.tick.TickHook;
import net.kyori.text.Component;
import net.kyori.text.TextComponent;
@@ -53,6 +54,7 @@ public class TickMonitoringModule implements CommandModule {
consumer.accept(Command.builder()
.aliases("tickmonitoring")
.argumentUsage("threshold", "percentage increase")
+ .argumentUsage("threshold-tick", "tick duration")
.argumentUsage("without-gc", null)
.executor((platform, sender, resp, arguments) -> {
if (this.tickHook == null) {
@@ -64,19 +66,25 @@ public class TickMonitoringModule implements CommandModule {
}
if (this.activeTickMonitor == null) {
- int threshold = arguments.intFlag("threshold");
- if (threshold == -1) {
- threshold = 100;
+ ReportPredicate reportPredicate;
+
+ int threshold;
+ if ((threshold = arguments.intFlag("threshold")) != -1) {
+ reportPredicate = new ReportPredicate.PercentageChangeGt(threshold);
+ } else if ((threshold = arguments.intFlag("threshold-tick")) != -1) {
+ reportPredicate = new ReportPredicate.DurationGt(threshold);
+ } else {
+ reportPredicate = new ReportPredicate.PercentageChangeGt(100);
}
- this.activeTickMonitor = new ReportingTickMonitor(platform, resp, this.tickHook, threshold, !arguments.boolFlag("without-gc"));
+ this.activeTickMonitor = new ReportingTickMonitor(platform, resp, this.tickHook, reportPredicate, !arguments.boolFlag("without-gc"));
this.tickHook.addCallback(this.activeTickMonitor);
} else {
close();
resp.broadcastPrefixed(TextComponent.of("Tick monitor disabled."));
}
})
- .tabCompleter((platform, sender, arguments) -> TabCompleter.completeForOpts(arguments, "--threshold", "--without-gc"))
+ .tabCompleter((platform, sender, arguments) -> TabCompleter.completeForOpts(arguments, "--threshold", "--threshold-tick", "--without-gc"))
.build()
);
}
@@ -84,8 +92,8 @@ public class TickMonitoringModule implements CommandModule {
private static class ReportingTickMonitor extends TickMonitor {
private final CommandResponseHandler resp;
- ReportingTickMonitor(SparkPlatform platform, CommandResponseHandler resp, TickHook tickHook, int percentageChangeThreshold, boolean monitorGc) {
- super(platform, tickHook, percentageChangeThreshold, monitorGc);
+ ReportingTickMonitor(SparkPlatform platform, CommandResponseHandler resp, TickHook tickHook, ReportPredicate reportPredicate, boolean monitorGc) {
+ super(platform, tickHook, reportPredicate, monitorGc);
this.resp = resp;
}