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 --- .../fabric/mixin/MinecraftClientAccessor.java | 34 ++++++++++++++++++++++ .../fabric/plugin/FabricClientSparkPlugin.java | 10 ++++++- .../fabric/plugin/FabricServerSparkPlugin.java | 9 +++++- .../spark/fabric/plugin/FabricSparkPlugin.java | 7 ----- 4 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/MinecraftClientAccessor.java (limited to 'spark-fabric/src/main/java') 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) + * 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 . + */ + +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; } @@ -119,6 +122,11 @@ public class FabricClientSparkPlugin extends FabricSparkPlugin implements Comman this.minecraft.executeSync(task); } + @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; @@ -135,6 +137,11 @@ public class FabricServerSparkPlugin extends FabricSparkPlugin implements Comman this.server.executeSync(task); } + @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; @@ -107,11 +105,6 @@ public abstract class FabricSparkPlugin implements SparkPlugin { } } - @Override - public ThreadDumper getDefaultThreadDumper() { - return this.threadDumper.get(); - } - @Override public ClassSourceLookup createClassSourceLookup() { return new FabricClassSourceLookup(); -- cgit