From fd79e5d2a39b84d978b8b4ac3b4517943f11fc09 Mon Sep 17 00:00:00 2001 From: Aleksandar Petrov <8142643+aleks-p@users.noreply.github.com> Date: Thu, 28 Nov 2024 09:31:47 -0400 Subject: [PATCH] Bump async-profiler to 3.0.0.1 --- async-profiler-context/build.gradle | 27 +++++--- .../io/pyroscope/PyroscopeAsyncProfiler.java | 69 +------------------ gradle.properties | 2 + 3 files changed, 21 insertions(+), 77 deletions(-) diff --git a/async-profiler-context/build.gradle b/async-profiler-context/build.gradle index b814e60..f92f8d6 100644 --- a/async-profiler-context/build.gradle +++ b/async-profiler-context/build.gradle @@ -21,7 +21,7 @@ repositories { mavenCentral() } -def asyncProfilerVersion = "3.0.0.0" +def asyncProfilerVersion = project.properties['async_profiler_version'] def pyroscopeVersion = project.properties['pyroscope_version'] dependencies { api files("$buildDir/async-profiler/async-profiler.jar") @@ -64,18 +64,18 @@ shadowJar { archiveClassifier.set('') } -task relocateShadowJar(type: ConfigureShadowRelocation) { +tasks.register('relocateShadowJar', ConfigureShadowRelocation) { target = tasks.shadowJar prefix = "io.pyroscope" } tasks.shadowJar.dependsOn tasks.relocateShadowJar -task asyncProfilerLib { +tasks.register('asyncProfilerLib') { + def useLocalArtifacts = project.findProperty('useLocalAsyncProfilerArtifacts') == 'true' + def suffixes = [ ['linux-arm64', 'tar.gz'], ['linux-x64', 'tar.gz'], - ['linux-musl-x64', 'tar.gz'], - ['linux-musl-arm64', 'tar.gz'], ['macos', 'zip'] ] @@ -87,11 +87,18 @@ task asyncProfilerLib { doLast { suffixes.forEach { suffix, ext -> - def repo = "https://github.com/grafana/async-profiler" - download { - src "$repo/releases/download/v${asyncProfilerVersion}/async-profiler-${asyncProfilerVersion}-${suffix}.${ext}" - dest new File(asyncProfilerDir, "async-profiler-${asyncProfilerVersion}-${suffix}.${ext}") - overwrite true + if (!useLocalArtifacts) { + def repo = "https://github.com/grafana/async-profiler" + download { + src "$repo/releases/download/v${asyncProfilerVersion}/async-profiler-${asyncProfilerVersion}-${suffix}.${ext}" + dest new File(asyncProfilerDir, "async-profiler-${asyncProfilerVersion}-${suffix}.${ext}") + overwrite true + } + } else { + copy { + from file("../async-profiler-${asyncProfilerVersion}-${suffix}.${ext}") + into asyncProfilerDir + } } // Extract the native library files. diff --git a/async-profiler-context/src/main/java/io/pyroscope/labels/io/pyroscope/PyroscopeAsyncProfiler.java b/async-profiler-context/src/main/java/io/pyroscope/labels/io/pyroscope/PyroscopeAsyncProfiler.java index c365c92..750aa19 100644 --- a/async-profiler-context/src/main/java/io/pyroscope/labels/io/pyroscope/PyroscopeAsyncProfiler.java +++ b/async-profiler-context/src/main/java/io/pyroscope/labels/io/pyroscope/PyroscopeAsyncProfiler.java @@ -78,19 +78,10 @@ private static String libraryFileName() { case "Linux": switch (archProperty) { case "amd64": - if (isMusl()) { - arch = "musl-x64"; - } else { - arch = "x64"; - } + arch = "x64"; break; - case "aarch64": - if (isMusl()) { - arch = "musl-arm64"; - } else { - arch = "arm64"; - } + arch = "arm64"; break; default: @@ -135,60 +126,4 @@ private static String targetLibraryFileName(final String libraryFileName) throws return libraryFileName.substring(0, libraryFileName.length() - 3) + "-" + checksum + ".so"; } - - private static boolean isMusl() { - // allow user to force musl/glibc it in case next checks fails - String env = System.getenv("PYROSCOPE_MUSL"); - if (env == null) { - env = System.getProperty("pyroscope.musl"); - } - if (env != null) { - return Boolean.parseBoolean(env); - } - // check ldd on currently running jvm - // $ ldd /usr/lib/jvm/java-11-openjdk/bin/java - // /lib/ld-musl-x86_64.so.1 (0x7f337ca6c000) - // libjli.so => /usr/lib/jvm/java-11-openjdk/bin/../lib/jli/libjli.so (0x7f337ca55000) - // libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7f337ca6c000) - File javaExecutable = new File(System.getProperty("java.home") + "/bin/java"); - if (javaExecutable.exists()) { - for (String l : runProcess("ldd", javaExecutable.getAbsolutePath())) { - if (l.contains("ld-musl-") || l.contains("libc.musl-")) { - return true; - } - } - return false; - } - // $ ldd --version - // musl libc (x86_64) - for (String l : runProcess("ldd", "--version")) { - if (l.contains("musl")) { - return true; - } - } - return false; - } - - private static List runProcess(String... cmd) { - List lines = new ArrayList<>(); - try { - Process pr = new ProcessBuilder(Arrays.asList(cmd)) - .redirectErrorStream(true) // ldd --version prints to stderr - .start(); - BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream())); - String line; - while ((line = in.readLine()) != null) { - lines.add(line); - } - try { - pr.waitFor(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - pr.destroy(); - } catch (IOException e) { - e.printStackTrace(); - } - return lines; - } } diff --git a/gradle.properties b/gradle.properties index 60bf4f3..7face51 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1,3 @@ pyroscope_version=0.14.1 +async_profiler_version=3.0.0.1 +useLocalAsyncProfilerArtifacts=false