aboutsummaryrefslogtreecommitdiff
path: root/spark-common/src/main/java/me/lucko/spark/common/command
diff options
context:
space:
mode:
authorlucko <git@lucko.me>2021-03-10 15:44:14 +0000
committerGitHub <noreply@github.com>2021-03-10 15:44:14 +0000
commit9ee26a12f12a89a6df14eb86afce5d88b5a2cf25 (patch)
tree840ab480ae324b50cefc63b69dae9b38660dc94f /spark-common/src/main/java/me/lucko/spark/common/command
parentfd6736fc2f0bae48dda1d4b595e867d9c7244c27 (diff)
downloadspark-9ee26a12f12a89a6df14eb86afce5d88b5a2cf25.tar.gz
spark-9ee26a12f12a89a6df14eb86afce5d88b5a2cf25.tar.bz2
spark-9ee26a12f12a89a6df14eb86afce5d88b5a2cf25.zip
async-profiler support (#102)
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/Arguments.java23
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java23
2 files changed, 36 insertions, 10 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/Arguments.java b/spark-common/src/main/java/me/lucko/spark/common/command/Arguments.java
index 2b202af..3cd0365 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/command/Arguments.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/command/Arguments.java
@@ -51,7 +51,7 @@ public class Arguments {
if (flag == null || matches) {
if (!matches) {
- throw new IllegalArgumentException("Expected flag at position " + i + " but got '" + arg + "' instead!");
+ throw new ParseException("Expected flag at position " + i + " but got '" + arg + "' instead!");
}
// store existing value, if present
@@ -83,7 +83,7 @@ public class Arguments {
try {
return Math.abs(Integer.parseInt(it.next()));
} catch (NumberFormatException e) {
- throw new IllegalArgumentException("Invalid input for '" + key + "' argument. Please specify a number!");
+ throw new ParseException("Invalid input for '" + key + "' argument. Please specify a number!");
}
}
return -1; // undefined
@@ -95,7 +95,7 @@ public class Arguments {
try {
return Math.abs(Double.parseDouble(it.next()));
} catch (NumberFormatException e) {
- throw new IllegalArgumentException("Invalid input for '" + key + "' argument. Please specify a number!");
+ throw new ParseException("Invalid input for '" + key + "' argument. Please specify a number!");
}
}
return -1; // undefined
@@ -108,4 +108,21 @@ public class Arguments {
public boolean boolFlag(String key) {
return this.parsedArgs.containsKey(key);
}
+
+ public static final class ParseException extends IllegalArgumentException {
+ public ParseException() {
+ }
+
+ public ParseException(String s) {
+ super(s);
+ }
+
+ public ParseException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ParseException(Throwable cause) {
+ super(cause);
+ }
+ }
}
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 eb77b24..cce3169 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
@@ -33,6 +33,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.async.AsyncSampler;
import me.lucko.spark.common.sampler.node.MergeMode;
import me.lucko.spark.common.sampler.tick.TickHook;
import me.lucko.spark.common.util.MethodDisambiguator;
@@ -55,13 +56,13 @@ import static net.kyori.adventure.text.format.NamedTextColor.*;
public class SamplerModule implements CommandModule {
private static final MediaType SPARK_SAMPLER_MEDIA_TYPE = MediaType.parse("application/x-spark-sampler");
- /** The WarmRoast instance currently running, if any */
+ /** The sampler instance currently running, if any */
private Sampler activeSampler = null;
@Override
public void close() {
if (this.activeSampler != null) {
- this.activeSampler.cancel();
+ this.activeSampler.stop();
this.activeSampler = null;
}
}
@@ -83,6 +84,7 @@ public class SamplerModule implements CommandModule {
.argumentUsage("only-ticks-over", "tick length millis")
.argumentUsage("ignore-sleeping", null)
.argumentUsage("ignore-native", null)
+ .argumentUsage("force-java-sampler", null)
.argumentUsage("order-by-time", null)
.argumentUsage("separate-parent-calls", null)
.executor((platform, sender, resp, arguments) -> {
@@ -118,7 +120,7 @@ public class SamplerModule implements CommandModule {
if (this.activeSampler == null) {
resp.replyPrefixed(text("There isn't an active sampling task running."));
} else {
- this.activeSampler.cancel();
+ this.activeSampler.stop();
resp.broadcastPrefixed(text("The active sampling operation has been stopped! Uploading results..."));
ThreadNodeOrder threadOrder = arguments.boolFlag("order-by-time") ? ThreadNodeOrder.BY_TIME : ThreadNodeOrder.BY_NAME;
String comment = Iterables.getFirst(arguments.stringFlag("comment"), null);
@@ -149,6 +151,7 @@ public class SamplerModule implements CommandModule {
boolean ignoreSleeping = arguments.boolFlag("ignore-sleeping");
boolean ignoreNative = arguments.boolFlag("ignore-native");
+ boolean forceJavaSampler = arguments.boolFlag("force-java-sampler");
Set<String> threads = arguments.stringFlag("thread");
ThreadDumper threadDumper;
@@ -201,19 +204,25 @@ public class SamplerModule implements CommandModule {
builder.samplingInterval(intervalMillis);
builder.ignoreSleeping(ignoreSleeping);
builder.ignoreNative(ignoreNative);
+ builder.forceJavaSampler(forceJavaSampler);
if (ticksOver != -1) {
builder.ticksOver(ticksOver, tickHook);
}
Sampler sampler = this.activeSampler = builder.start();
- resp.broadcastPrefixed(text("Profiler now active!", GOLD));
+ resp.broadcastPrefixed(text()
+ .append(text("Profiler now active!", GOLD))
+ .append(space())
+ .append(text("(" + (sampler instanceof AsyncSampler ? "async" : "built-in java") + ")", DARK_GRAY))
+ .build()
+ );
if (timeoutSeconds == -1) {
resp.broadcastPrefixed(text("Use '/" + platform.getPlugin().getCommandName() + " profiler --stop' to stop profiling and upload the results."));
} else {
resp.broadcastPrefixed(text("The results will be automatically returned after the profiler has been running for " + timeoutSeconds + " seconds."));
}
- CompletableFuture<Sampler> future = this.activeSampler.getFuture();
+ CompletableFuture<? extends Sampler> future = this.activeSampler.getFuture();
// send message if profiling fails
future.whenCompleteAsync((s, throwable) -> {
@@ -253,8 +262,8 @@ public class SamplerModule implements CommandModule {
List<String> opts = new ArrayList<>(Arrays.asList("--info", "--stop", "--cancel",
"--timeout", "--regex", "--combine-all", "--not-combined", "--interval",
- "--only-ticks-over", "--ignore-sleeping", "--ignore-native", "--order-by-time",
- "--separate-parent-calls", "--comment"));
+ "--only-ticks-over", "--ignore-sleeping", "--ignore-native", "--force-java-sampler",
+ "--order-by-time", "--separate-parent-calls", "--comment"));
opts.removeAll(arguments);
opts.add("--thread"); // allowed multiple times