From 73dd214ae66bab483ee8b4f0ed03881466da92e8 Mon Sep 17 00:00:00 2001 From: Luck Date: Tue, 12 Jul 2022 22:37:59 +0100 Subject: Improve/fix game thread dumper --- .../java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java | 9 ++++++++- .../java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java | 9 ++++++++- .../main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java | 7 ------- 3 files changed, 16 insertions(+), 9 deletions(-) (limited to 'spark-forge/src/main/java') diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java index 04c8785..a4c6bd1 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java @@ -29,6 +29,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.forge.ForgeCommandSender; @@ -58,10 +59,12 @@ public class ForgeClientSparkPlugin extends ForgeSparkPlugin implements Command< } private final Minecraft minecraft; + private final ThreadDumper gameThreadDumper; public ForgeClientSparkPlugin(ForgeSparkMod mod, Minecraft minecraft) { super(mod); this.minecraft = minecraft; + this.gameThreadDumper = new ThreadDumper.Specific(minecraft.gameThread); } @Override @@ -84,7 +87,6 @@ public class ForgeClientSparkPlugin extends ForgeSparkPlugin implements Command< return 0; } - this.threadDumper.ensureSetup(); this.platform.executeCommand(new ForgeCommandSender(context.getSource().getEntity(), this), args); return Command.SINGLE_SUCCESS; } @@ -114,6 +116,11 @@ public class ForgeClientSparkPlugin extends ForgeSparkPlugin implements Command< this.minecraft.executeIfPossible(task); } + @Override + public ThreadDumper getDefaultThreadDumper() { + return this.gameThreadDumper; + } + @Override public TickHook createTickHook() { return new ForgeTickHook(TickEvent.Type.CLIENT); diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java index f4a51e0..1aeb2b1 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.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.forge.ForgeCommandSender; @@ -75,11 +76,13 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin implements Command< } private final MinecraftServer server; + private final ThreadDumper gameThreadDumper; private Map> registeredPermissions = Collections.emptyMap(); public ForgeServerSparkPlugin(ForgeSparkMod mod, MinecraftServer server) { super(mod); this.server = server; + this.gameThreadDumper = new ThreadDumper.Specific(server.getRunningThread()); } @Override @@ -146,7 +149,6 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin implements Command< return 0; } - this.threadDumper.ensureSetup(); CommandSource source = context.getSource().getEntity() != null ? context.getSource().getEntity() : context.getSource().getServer(); this.platform.executeCommand(new ForgeCommandSender(source, this), args); return Command.SINGLE_SUCCESS; @@ -192,6 +194,11 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin implements Command< this.server.executeIfPossible(task); } + @Override + public ThreadDumper getDefaultThreadDumper() { + return this.gameThreadDumper; + } + @Override public TickHook createTickHook() { return new ForgeTickHook(TickEvent.Type.SERVER); diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java index f257e34..36a7ce8 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.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.forge.ForgeClassSourceLookup; @@ -59,7 +58,6 @@ public abstract class ForgeSparkPlugin implements SparkPlugin { protected final ScheduledExecutorService scheduler; protected SparkPlatform platform; - protected final ThreadDumper.GameThread threadDumper = new ThreadDumper.GameThread(); protected ForgeSparkPlugin(ForgeSparkMod mod) { this.mod = mod; @@ -107,11 +105,6 @@ public abstract class ForgeSparkPlugin implements SparkPlugin { } } - @Override - public ThreadDumper getDefaultThreadDumper() { - return this.threadDumper.get(); - } - @Override public ClassSourceLookup createClassSourceLookup() { return new ForgeClassSourceLookup(); -- cgit