Skip to content

Commit

Permalink
adds a java example (#410)
Browse files Browse the repository at this point in the history
* adds a java example

* removes PTRACE requirement
  • Loading branch information
petethepig authored Sep 23, 2021
1 parent 8f86341 commit 1a4741c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
20 changes: 20 additions & 0 deletions examples/java/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
24 changes: 24 additions & 0 deletions examples/java/Main.java
Original file line number Diff line number Diff line change
@@ -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++;
}
}
}
13 changes: 13 additions & 0 deletions examples/java/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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: .

0 comments on commit 1a4741c

Please sign in to comment.