Skip to content

Commit

Permalink
update to async-profiler 3.0 (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
korniltsev authored Jan 29, 2024
1 parent d630813 commit e435a88
Show file tree
Hide file tree
Showing 15 changed files with 588 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.gradle
**/build/
**/out/
48 changes: 48 additions & 0 deletions .github/workflows/itest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Integration smoke test

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
integration-smoke-test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
svc:
- 'alpine-3.16-8'
- 'alpine-3.16-11'
- 'alpine-3.16-17'
- 'alpine-3.17-8'
- 'alpine-3.17-11'
- 'alpine-3.17-17'
- 'alpine-3.18-8'
- 'alpine-3.18-11'
- 'alpine-3.18-17'
- 'alpine-3.19-8'
- 'alpine-3.19-11'
- 'alpine-3.19-17'
- 'ubuntu-18.04-8'
- 'ubuntu-18.04-11'
- 'ubuntu-18.04-17'
- 'ubuntu-20.04-8'
- 'ubuntu-20.04-11'
- 'ubuntu-20.04-17'
- 'ubuntu-20.04-21'
- 'ubuntu-22.04-8'
- 'ubuntu-22.04-11'
- 'ubuntu-22.04-17'
- 'ubuntu-22.04-21'
steps:
- uses: actions/checkout@v2
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.21.6
- run: make itest
shell: bash
env:
ITEST_SERVICE: ${{ matrix.svc }}
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ docker-example-expt: build
cp agent/build/libs/pyroscope.jar examples
docker-compose -f examples/docker-compose-expt.yml build
docker-compose -f examples/docker-compose-expt.yml up

ITEST_SERVICE ?=

.PHONY: itest
itest:
docker compose -f docker-compose-itest.yaml up --build --force-recreate -d pyroscope $(ITEST_SERVICE)
cd itest/query && go run . $(ITEST_SERVICE)
docker compose -f docker-compose-itest.yaml down pyroscope $(ITEST_SERVICE)
27 changes: 27 additions & 0 deletions alpine-test.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
ARG IMAGE_VERSION
FROM alpine:${IMAGE_VERSION}
ARG IMAGE_VERSION
ARG JAVA_VERSION
RUN apk add openjdk${JAVA_VERSION}
WORKDIR /app
ADD gradlew build.gradle settings.gradle /app/
ADD gradle gradle
RUN ./gradlew --no-daemon --version
ADD agent agent
ADD async-profiler-context async-profiler-context
ADD demo/build.gradle demo/

RUN ./gradlew --no-daemon shadowJar

ADD demo demo

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"]
8 changes: 4 additions & 4 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 = "2.9.0.2"
def asyncProfilerVersion = "3.0.0.0"
def pyroscopeVersion = project.properties['pyroscope_version']
dependencies {
api files("$buildDir/async-profiler/async-profiler.jar")
Expand Down Expand Up @@ -75,6 +75,7 @@ task asyncProfilerLib {
['linux-arm64', 'tar.gz'],
['linux-x64', 'tar.gz'],
['linux-musl-x64', 'tar.gz'],
['linux-musl-arm64', 'tar.gz'],
['macos', 'zip']
]

Expand All @@ -86,8 +87,7 @@ task asyncProfilerLib {

doLast {
suffixes.forEach { suffix, ext ->
// def repo = "https://github.com/jvm-profiling-tools/async-profiler"
def repo = "https://github.com/pyroscope-io/async-profiler"
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}")
Expand All @@ -101,7 +101,7 @@ task asyncProfilerLib {
} else {
from tarTree(resources.gzip("$asyncProfilerDir/async-profiler-${asyncProfilerVersion}-${suffix}.${ext}"))
}
include '**/libasyncProfiler.so'
include '**/libasyncProfiler.*'
eachFile {
it.relativePath = new RelativePath(true, "native/", "libasyncProfiler-${suffix}.so")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ private static String libraryFileName() {
break;

case "aarch64":
arch = "arm64";
if (isMusl()) {
arch = "musl-arm64";
} else {
arch = "arm64";
}
break;

default:
Expand Down
14 changes: 1 addition & 13 deletions demo/src/main/java/App.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import io.pyroscope.http.Format;
import io.pyroscope.javaagent.PyroscopeAgent;
import io.pyroscope.javaagent.Snapshot;
import io.pyroscope.javaagent.api.Exporter;
import io.pyroscope.javaagent.api.Logger;
import io.pyroscope.javaagent.config.Config;
import io.pyroscope.javaagent.impl.DefaultConfigurationProvider;
import io.pyroscope.labels.Pyroscope;
import io.pyroscope.labels.LabelsSet;
import io.pyroscope.labels.Pyroscope;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -26,7 +23,6 @@ public static void main(String[] args) {
.setLogLevel(Logger.Level.DEBUG)
.setLabels(mapOf("user", "tolyan"))
.build())
// .setExporter(new MyStdoutExporter())
.build()
);
Pyroscope.setStaticLabels(mapOf("region", "us-east-1"));
Expand Down Expand Up @@ -68,14 +64,6 @@ private static long fib(Long n) throws InterruptedException {
if (n == 1L) {
return 1L;
}
Thread.sleep(100);
return fib(n - 1) + fib(n - 2);
}

private static class MyStdoutExporter implements Exporter {
@Override
public void export(Snapshot snapshot) {
System.out.printf("Export %d %d%n", snapshot.data.length, snapshot.labels.toByteArray().length);
}
}
}
Binary file added demo/src/main/java/Fib.class
Binary file not shown.
50 changes: 50 additions & 0 deletions demo/src/main/java/Fib.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Fib {
public static final int N_THREADS;

static {
int n;
try {
n = Integer.parseInt(System.getenv("N_THREADS"));
} catch (NumberFormatException e) {
n = 1;
}
N_THREADS = n;
}

public static void main(String[] args) {
appLogic();
}

private static void appLogic() {
ExecutorService executors = Executors.newFixedThreadPool(N_THREADS);
for (int i = 0; i < N_THREADS; i++) {
executors.submit(() -> {
while (true) {
try {
fib(32L);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
});
}
}

private static long fib(Long n) throws InterruptedException {
if (n == 0L) {
return 0L;
}
if (n == 1L) {
return 1L;
}
return fib(n - 1) + fib(n - 2);
}

}
Loading

0 comments on commit e435a88

Please sign in to comment.