Skip to content

Commit

Permalink
Update async-profiler to 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SirYwell committed Feb 8, 2024
1 parent 7fe6531 commit 900e09e
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 85 deletions.
2 changes: 1 addition & 1 deletion spark-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extensions.configure(LicenseExtension.class) {

dependencies {
api project(':spark-api')
implementation 'com.github.jvm-profiling-tools:async-profiler:v2.8.3'
implementation 'tools.profiler:async-profiler:3.0'
implementation 'org.ow2.asm:asm:9.1'
implementation 'net.bytebuddy:byte-buddy-agent:1.11.0'
implementation 'com.google.protobuf:protobuf-javalite:3.21.11'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,14 @@
import one.profiler.AsyncProfiler;
import one.profiler.Events;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Locale;
import java.util.Objects;
import java.util.logging.Level;
import java.util.stream.Collectors;

/**
* Provides a bridge between spark and async-profiler.
Expand All @@ -52,6 +49,9 @@ public static synchronized AsyncProfilerAccess getInstance(SparkPlatform platfor
if (instance == null) {
Objects.requireNonNull(platform, "platform");
instance = new AsyncProfilerAccess(platform);
if (instance.profiler != null) {
platform.getPlugin().log(Level.INFO, "Using async-profiler version " + instance.profiler.getVersion());
}
}
return instance;
}
Expand Down Expand Up @@ -143,14 +143,9 @@ private static AsyncProfiler load(SparkPlatform platform) throws Exception {
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("linux", "amd64", "linux-x64")
.put("linux", "aarch64", "linux-arm64")
.put("macosx", "amd64", "macos")
.put("macosx", "aarch64", "macos")
.build();
Expand All @@ -161,7 +156,7 @@ private static AsyncProfiler load(SparkPlatform platform) throws Exception {
}

// extract the profiler binary from the spark jar file
String resource = "spark/" + libPath + "/libasyncProfiler.so";
String resource = libPath + "/libasyncProfiler.so";
URL profilerResource = AsyncProfilerAccess.class.getClassLoader().getResource(resource);
if (profilerResource == null) {
throw new IllegalStateException("Could not find " + resource + " in spark jar file");
Expand Down Expand Up @@ -231,20 +226,4 @@ public NativeLoadingException(Throwable cause) {
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;
}
}
}
Loading

0 comments on commit 900e09e

Please sign in to comment.