diff --git a/examples/java/Dockerfile b/examples/java/Dockerfile new file mode 100644 index 0000000000..322a870fff --- /dev/null +++ b/examples/java/Dockerfile @@ -0,0 +1,20 @@ +FROM openjdk:11.0.11-jdk + +WORKDIR /opt/app +RUN git clone https://github.com/pyroscope-io/pyroscope-java.git +RUN cd pyroscope-java && \ + ./gradlew shadowJar && \ + cp agent/build/libs/pyroscope.jar /opt/app/pyroscope.jar + +COPY Main.java ./Main.java + +ENV PYROSCOPE_APPLICATION_NAME=simple.java.app +ENV PYROSCOPE_PROFILING_INTERVAL=10ms +ENV PYROSCOPE_PROFILER_EVENT=cpu +ENV PYROSCOPE_UPLOAD_INTERVAL=10s +ENV PYROSCOPE_LOG_LEVEL=debug +ENV PYROSCOPE_SERVER_ADDRESS=http://pyroscope:4040 + +RUN javac Main.java + +CMD ["java", "-XX:-Inline", "-javaagent:pyroscope.jar", "Main"] diff --git a/examples/java/Main.java b/examples/java/Main.java new file mode 100644 index 0000000000..6d6a9a13b9 --- /dev/null +++ b/examples/java/Main.java @@ -0,0 +1,24 @@ +class Main { + public static int work(int n) { + int i = 0; + for (i = 0; i < n; i++) {} + return i; + } + + public static void fastFunction() { + work(20000); + } + + public static void slowFunction() { + work(80000); + } + + public static void main(String[] args) { + int i = 0; + while (true) { + fastFunction(); + slowFunction(); + i++; + } + } +} diff --git a/examples/java/docker-compose.yml b/examples/java/docker-compose.yml new file mode 100644 index 0000000000..a5d8652239 --- /dev/null +++ b/examples/java/docker-compose.yml @@ -0,0 +1,13 @@ +--- +version: "3.9" +services: + pyroscope: + image: "pyroscope/pyroscope:latest" + environment: + - "PYROSCOPE_LOG_LEVEL=debug" + ports: + - "4040:4040" + command: + - "server" + app: + build: .