aboutsummaryrefslogtreecommitdiff
path: root/spark-fabric/src/main/java
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2022-07-12 22:37:59 +0100
committerLuck <git@lucko.me>2022-07-12 22:37:59 +0100
commit73dd214ae66bab483ee8b4f0ed03881466da92e8 (patch)
tree11b433c6b9b15e75249732248c150c35af08c24f /spark-fabric/src/main/java
parenta10f966a443d56845a5efb1e65232e6b87eabb96 (diff)
downloadspark-73dd214ae66bab483ee8b4f0ed03881466da92e8.tar.gz
spark-73dd214ae66bab483ee8b4f0ed03881466da92e8.tar.bz2
spark-73dd214ae66bab483ee8b4f0ed03881466da92e8.zip
Improve/fix game thread dumper
Diffstat (limited to 'spark-fabric/src/main/java')
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/MinecraftClientAccessor.java34
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java10
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java9
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricSparkPlugin.java7
4 files changed, 51 insertions, 9 deletions
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/MinecraftClientAccessor.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/MinecraftClientAccessor.java
new file mode 100644
index 0000000..7a4fb78
--- /dev/null
+++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/MinecraftClientAccessor.java
@@ -0,0 +1,34 @@
+/*
+ * 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.fabric.mixin;
+
+import net.minecraft.client.MinecraftClient;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Accessor;
+
+@Mixin(MinecraftClient.class)
+public interface MinecraftClientAccessor {
+
+ @Accessor
+ Thread getThread();
+
+}
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java
index 1876658..19d0707 100644
--- a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java
+++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java
@@ -30,6 +30,7 @@ import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import me.lucko.spark.common.platform.PlatformInfo;
import me.lucko.spark.common.platform.world.WorldInfoProvider;
+import me.lucko.spark.common.sampler.ThreadDumper;
import me.lucko.spark.common.tick.TickHook;
import me.lucko.spark.common.tick.TickReporter;
import me.lucko.spark.fabric.FabricCommandSender;
@@ -38,6 +39,7 @@ import me.lucko.spark.fabric.FabricSparkMod;
import me.lucko.spark.fabric.FabricTickHook;
import me.lucko.spark.fabric.FabricTickReporter;
import me.lucko.spark.fabric.FabricWorldInfoProvider;
+import me.lucko.spark.fabric.mixin.MinecraftClientAccessor;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
@@ -57,10 +59,12 @@ public class FabricClientSparkPlugin extends FabricSparkPlugin implements Comman
}
private final MinecraftClient minecraft;
+ private final ThreadDumper gameThreadDumper;
public FabricClientSparkPlugin(FabricSparkMod mod, MinecraftClient minecraft) {
super(mod);
this.minecraft = minecraft;
+ this.gameThreadDumper = new ThreadDumper.Specific(((MinecraftClientAccessor) minecraft).getThread());
}
@Override
@@ -89,7 +93,6 @@ public class FabricClientSparkPlugin extends FabricSparkPlugin implements Comman
return 0;
}
- this.threadDumper.ensureSetup();
this.platform.executeCommand(new FabricCommandSender(context.getSource().getEntity(), this), args);
return Command.SINGLE_SUCCESS;
}
@@ -120,6 +123,11 @@ public class FabricClientSparkPlugin extends FabricSparkPlugin implements Comman
}
@Override
+ public ThreadDumper getDefaultThreadDumper() {
+ return this.gameThreadDumper;
+ }
+
+ @Override
public TickHook createTickHook() {
return new FabricTickHook.Client();
}
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java
index bb1d68c..f840f5e 100644
--- a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java
+++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java
@@ -33,6 +33,7 @@ import me.lucko.spark.common.monitor.ping.PlayerPingProvider;
import me.lucko.spark.common.platform.PlatformInfo;
import me.lucko.spark.common.platform.serverconfig.ServerConfigProvider;
import me.lucko.spark.common.platform.world.WorldInfoProvider;
+import me.lucko.spark.common.sampler.ThreadDumper;
import me.lucko.spark.common.tick.TickHook;
import me.lucko.spark.common.tick.TickReporter;
import me.lucko.spark.fabric.FabricCommandSender;
@@ -63,10 +64,12 @@ public class FabricServerSparkPlugin extends FabricSparkPlugin implements Comman
}
private final MinecraftServer server;
+ private final ThreadDumper gameThreadDumper;
public FabricServerSparkPlugin(FabricSparkMod mod, MinecraftServer server) {
super(mod);
this.server = server;
+ this.gameThreadDumper = new ThreadDumper.Specific(server.getThread());
}
@Override
@@ -97,7 +100,6 @@ public class FabricServerSparkPlugin extends FabricSparkPlugin implements Comman
return 0;
}
- this.threadDumper.ensureSetup();
CommandOutput source = context.getSource().getEntity() != null ? context.getSource().getEntity() : context.getSource().getServer();
this.platform.executeCommand(new FabricCommandSender(source, this), args);
return Command.SINGLE_SUCCESS;
@@ -136,6 +138,11 @@ public class FabricServerSparkPlugin extends FabricSparkPlugin implements Comman
}
@Override
+ public ThreadDumper getDefaultThreadDumper() {
+ return this.gameThreadDumper;
+ }
+
+ @Override
public TickHook createTickHook() {
return new FabricTickHook.Server();
}
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricSparkPlugin.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricSparkPlugin.java
index b1392d4..3126f28 100644
--- a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricSparkPlugin.java
+++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricSparkPlugin.java
@@ -34,7 +34,6 @@ import com.mojang.brigadier.tree.LiteralCommandNode;
import me.lucko.spark.common.SparkPlatform;
import me.lucko.spark.common.SparkPlugin;
import me.lucko.spark.common.command.sender.CommandSender;
-import me.lucko.spark.common.sampler.ThreadDumper;
import me.lucko.spark.common.util.ClassSourceLookup;
import me.lucko.spark.common.util.SparkThreadFactory;
import me.lucko.spark.fabric.FabricClassSourceLookup;
@@ -59,7 +58,6 @@ public abstract class FabricSparkPlugin implements SparkPlugin {
protected final ScheduledExecutorService scheduler;
protected SparkPlatform platform;
- protected final ThreadDumper.GameThread threadDumper = new ThreadDumper.GameThread();
protected FabricSparkPlugin(FabricSparkMod mod) {
this.mod = mod;
@@ -108,11 +106,6 @@ public abstract class FabricSparkPlugin implements SparkPlugin {
}
@Override
- public ThreadDumper getDefaultThreadDumper() {
- return this.threadDumper.get();
- }
-
- @Override
public ClassSourceLookup createClassSourceLookup() {
return new FabricClassSourceLookup();
}