aboutsummaryrefslogtreecommitdiff
path: root/spark-common/src/main/java/me/lucko/spark/common/sampler
diff options
context:
space:
mode:
Diffstat (limited to 'spark-common/src/main/java/me/lucko/spark/common/sampler')
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java24
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncProfilerAccess.java24
2 files changed, 44 insertions, 4 deletions
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..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,17 +76,29 @@ public interface ThreadDumper {
* the game (server/client) thread.
*/
final class GameThread implements Supplier<ThreadDumper> {
+ private Supplier<Thread> threadSupplier;
private Specific dumper = null;
+ public GameThread() {
+
+ }
+
+ public GameThread(Supplier<Thread> 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");
}
- 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 +110,10 @@ public interface ThreadDumper {
private Set<Thread> threads;
private Set<String> threadNamesLowerCase;
+ public Specific(Thread thread) {
+ this.ids = new long[]{thread.getId()};
+ }
+
public Specific(long[] ids) {
this.ids = ids;
}
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<String, String, String> supported = ImmutableTable.<String, String, String>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;
+ }
+ }
}