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 --- .../main/java/me/lucko/spark/common/sampler/ThreadDumper.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'spark-common/src/main/java/me/lucko/spark/common/sampler') diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java index 9d54f50..fe3a6a7 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java +++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java @@ -83,10 +83,8 @@ public interface ThreadDumper { return Objects.requireNonNull(this.dumper, "dumper"); } - public void ensureSetup() { - if (this.dumper == null) { - this.dumper = new Specific(new long[]{Thread.currentThread().getId()}); - } + public void setThread(Thread thread) { + this.dumper = new Specific(new long[]{thread.getId()}); } } @@ -98,6 +96,10 @@ public interface ThreadDumper { private Set threads; private Set threadNamesLowerCase; + public Specific(Thread thread) { + this.ids = new long[]{thread.getId()}; + } + public Specific(long[] ids) { this.ids = ids; } -- cgit From 06de991f44f3f0f33eed21fb92224a395a2a92ff Mon Sep 17 00:00:00 2001 From: Luck Date: Wed, 13 Jul 2022 21:10:28 +0100 Subject: Support linux x64 musl --- spark-common/build.gradle | 9 +------- .../common/sampler/async/AsyncProfilerAccess.java | 24 +++++++++++++++++++++ .../spark/linux/aarch64/libasyncProfiler.so | Bin 328432 -> 333864 bytes .../spark/linux/amd64-musl/libasyncProfiler.so | Bin 0 -> 304568 bytes .../spark/linux/amd64/libasyncProfiler.so | Bin 342239 -> 347712 bytes .../main/resources/spark/macos/libasyncProfiler.so | Bin 688400 -> 690128 bytes 6 files changed, 25 insertions(+), 8 deletions(-) create mode 100755 spark-common/src/main/resources/spark/linux/amd64-musl/libasyncProfiler.so (limited to 'spark-common/src/main/java/me/lucko/spark/common/sampler') diff --git a/spark-common/build.gradle b/spark-common/build.gradle index bc493f3..fbd0db2 100644 --- a/spark-common/build.gradle +++ b/spark-common/build.gradle @@ -8,7 +8,7 @@ license { dependencies { api project(':spark-api') - implementation 'com.github.jvm-profiling-tools:async-profiler:v2.7' + implementation 'com.github.jvm-profiling-tools:async-profiler:v2.8.1' implementation 'org.ow2.asm:asm:9.1' implementation 'com.google.protobuf:protobuf-javalite:3.15.6' implementation 'com.squareup.okhttp3:okhttp:3.14.1' @@ -37,13 +37,6 @@ dependencies { compileOnly 'org.checkerframework:checker-qual:3.8.0' } -processResources { - from(sourceSets.main.resources.srcDirs) { - include 'spark/linux/libasyncProfiler.so' - include 'spark/macosx/libasyncProfiler.so' - } -} - protobuf { protoc { if (System.getProperty("os.name") == "Mac OS X" && System.getProperty("os.arch") == "aarch64") { diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncProfilerAccess.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncProfilerAccess.java index d642a53..ef2c035 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncProfilerAccess.java +++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncProfilerAccess.java @@ -29,13 +29,16 @@ import me.lucko.spark.common.util.TemporaryFiles; import one.profiler.AsyncProfiler; import one.profiler.Events; +import java.io.BufferedReader; import java.io.InputStream; +import java.io.InputStreamReader; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.Locale; import java.util.logging.Level; +import java.util.stream.Collectors; /** * Provides a bridge between spark and async-profiler. @@ -108,8 +111,13 @@ public enum AsyncProfilerAccess { String os = System.getProperty("os.name").toLowerCase(Locale.ROOT).replace(" ", ""); String arch = System.getProperty("os.arch").toLowerCase(Locale.ROOT); + if (os.equals("linux") && arch.equals("amd64") && isLinuxMusl()) { + arch = "amd64-musl"; + } + Table supported = ImmutableTable.builder() .put("linux", "amd64", "linux/amd64") + .put("linux", "amd64-musl", "linux/amd64-musl") .put("linux", "aarch64", "linux/aarch64") .put("macosx", "amd64", "macos") .put("macosx", "aarch64", "macos") @@ -190,4 +198,20 @@ public enum AsyncProfilerAccess { super("A runtime error occurred whilst loading the native library", cause); } } + + // Checks if the system is using musl instead of glibc + private static boolean isLinuxMusl() { + try { + InputStream stream = new ProcessBuilder("sh", "-c", "ldd `which ls`") + .start() + .getInputStream(); + + BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); + String output = reader.lines().collect(Collectors.joining()); + return output.contains("musl"); // shrug + } catch (Throwable e) { + // ignore + return false; + } + } } diff --git a/spark-common/src/main/resources/spark/linux/aarch64/libasyncProfiler.so b/spark-common/src/main/resources/spark/linux/aarch64/libasyncProfiler.so index 35f83b2..c3c2eb2 100755 Binary files a/spark-common/src/main/resources/spark/linux/aarch64/libasyncProfiler.so and b/spark-common/src/main/resources/spark/linux/aarch64/libasyncProfiler.so differ diff --git a/spark-common/src/main/resources/spark/linux/amd64-musl/libasyncProfiler.so b/spark-common/src/main/resources/spark/linux/amd64-musl/libasyncProfiler.so new file mode 100755 index 0000000..4c69ab8 Binary files /dev/null and b/spark-common/src/main/resources/spark/linux/amd64-musl/libasyncProfiler.so differ diff --git a/spark-common/src/main/resources/spark/linux/amd64/libasyncProfiler.so b/spark-common/src/main/resources/spark/linux/amd64/libasyncProfiler.so index edbf103..5612ad9 100755 Binary files a/spark-common/src/main/resources/spark/linux/amd64/libasyncProfiler.so and b/spark-common/src/main/resources/spark/linux/amd64/libasyncProfiler.so differ diff --git a/spark-common/src/main/resources/spark/macos/libasyncProfiler.so b/spark-common/src/main/resources/spark/macos/libasyncProfiler.so index ab818e9..1fc6ba3 100755 Binary files a/spark-common/src/main/resources/spark/macos/libasyncProfiler.so and b/spark-common/src/main/resources/spark/macos/libasyncProfiler.so differ -- cgit From 319aae27ad290338a5558ac53517e144254a86ce Mon Sep 17 00:00:00 2001 From: Luck Date: Sun, 17 Jul 2022 12:19:03 +0100 Subject: Fix fabric client startup error --- .../java/me/lucko/spark/common/sampler/ThreadDumper.java | 14 ++++++++++++++ .../lucko/spark/fabric/plugin/FabricClientSparkPlugin.java | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'spark-common/src/main/java/me/lucko/spark/common/sampler') diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java index fe3a6a7..fd0c413 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java +++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java @@ -76,10 +76,24 @@ public interface ThreadDumper { * the game (server/client) thread. */ final class GameThread implements Supplier { + private Supplier threadSupplier; private Specific dumper = null; + public GameThread() { + + } + + public GameThread(Supplier threadSupplier) { + this.threadSupplier = threadSupplier; + } + @Override public ThreadDumper get() { + if (this.dumper == null) { + setThread(this.threadSupplier.get()); + this.threadSupplier = null; + } + return Objects.requireNonNull(this.dumper, "dumper"); } 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 19d0707..0ef6620 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 @@ -59,12 +59,12 @@ public class FabricClientSparkPlugin extends FabricSparkPlugin implements Comman } private final MinecraftClient minecraft; - private final ThreadDumper gameThreadDumper; + private final ThreadDumper.GameThread gameThreadDumper; public FabricClientSparkPlugin(FabricSparkMod mod, MinecraftClient minecraft) { super(mod); this.minecraft = minecraft; - this.gameThreadDumper = new ThreadDumper.Specific(((MinecraftClientAccessor) minecraft).getThread()); + this.gameThreadDumper = new ThreadDumper.GameThread(() -> ((MinecraftClientAccessor) minecraft).getThread()); } @Override @@ -124,7 +124,7 @@ public class FabricClientSparkPlugin extends FabricSparkPlugin implements Comman @Override public ThreadDumper getDefaultThreadDumper() { - return this.gameThreadDumper; + return this.gameThreadDumper.get(); } @Override -- cgit