Skip to content

Commit

Permalink
Merge pull request #170 from grafana/bump-async-profiler
Browse files Browse the repository at this point in the history
Bump async profiler
  • Loading branch information
aleks-p authored Nov 28, 2024
2 parents e1df3dd + bac3de6 commit e102ce2
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 95 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu, macos]
java: ['8', '11', '17']
java: ['8', '11', '17', '21']
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: 'adopt'
distribution: 'zulu'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
- name: Build with Gradle
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: 'adopt'
distribution: 'zulu'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
- name: Test with Gradle
Expand Down
23 changes: 18 additions & 5 deletions alpine-test.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
ARG IMAGE_VERSION
FROM alpine:${IMAGE_VERSION}
ARG IMAGE_VERSION
ARG JAVA_VERSION
RUN apk add openjdk${JAVA_VERSION}

FROM alpine:3.20.3 AS builder
RUN apk add openjdk8

WORKDIR /app
ADD gradlew build.gradle settings.gradle /app/
ADD gradlew build.gradle settings.gradle gradle.properties /app/
ADD gradle gradle
RUN ./gradlew --no-daemon --version
ADD agent agent
ADD async-profiler-context async-profiler-context
ADD demo/build.gradle demo/

# for testing locally produced artifacts
#COPY async-profiler-3.0.0.1-linux-x64.tar.gz .
#COPY async-profiler-3.0.0.1-linux-arm64.tar.gz .
#COPY async-profiler-3.0.0.1-macos.zip .

RUN ./gradlew --no-daemon shadowJar

FROM alpine:${IMAGE_VERSION} AS runner
ARG IMAGE_VERSION
ARG JAVA_VERSION
RUN apk add openjdk${JAVA_VERSION}

WORKDIR /app
ADD demo demo
COPY --from=builder /app/agent/build/libs/pyroscope.jar /app/agent/build/libs/pyroscope.jar

ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/default-jvm/jre/bin


RUN javac demo/src/main/java/Fib.java

ENV PYROSCOPE_LOG_LEVEL=debug
ENV PYROSCOPE_SERVER_ADDRESS=http://pyroscope:4040
ENV PYROSCOPE_APPLICATION_NAME=alpine-${IMAGE_VERSION}-${JAVA_VERSION}
ENV PYROSCOPE_UPLOAD_INTERVAL=15s

CMD ["java", "-javaagent:/app/agent/build/libs/pyroscope.jar", "-cp", "demo/src/main/java/", "Fib"]
27 changes: 17 additions & 10 deletions async-profiler-context/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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']
]

Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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<String> runProcess(String... cmd) {
List<String> lines = new ArrayList<>();
try {
Process pr = new ProcessBuilder(Arrays.<String>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;
}
}
Loading

0 comments on commit e102ce2

Please sign in to comment.