Skip to content

Commit 1a4741c

Browse files
authored
adds a java example (#410)
* adds a java example * removes PTRACE requirement
1 parent 8f86341 commit 1a4741c

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

examples/java/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM openjdk:11.0.11-jdk
2+
3+
WORKDIR /opt/app
4+
RUN git clone https://github.com/pyroscope-io/pyroscope-java.git
5+
RUN cd pyroscope-java && \
6+
./gradlew shadowJar && \
7+
cp agent/build/libs/pyroscope.jar /opt/app/pyroscope.jar
8+
9+
COPY Main.java ./Main.java
10+
11+
ENV PYROSCOPE_APPLICATION_NAME=simple.java.app
12+
ENV PYROSCOPE_PROFILING_INTERVAL=10ms
13+
ENV PYROSCOPE_PROFILER_EVENT=cpu
14+
ENV PYROSCOPE_UPLOAD_INTERVAL=10s
15+
ENV PYROSCOPE_LOG_LEVEL=debug
16+
ENV PYROSCOPE_SERVER_ADDRESS=http://pyroscope:4040
17+
18+
RUN javac Main.java
19+
20+
CMD ["java", "-XX:-Inline", "-javaagent:pyroscope.jar", "Main"]

examples/java/Main.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Main {
2+
public static int work(int n) {
3+
int i = 0;
4+
for (i = 0; i < n; i++) {}
5+
return i;
6+
}
7+
8+
public static void fastFunction() {
9+
work(20000);
10+
}
11+
12+
public static void slowFunction() {
13+
work(80000);
14+
}
15+
16+
public static void main(String[] args) {
17+
int i = 0;
18+
while (true) {
19+
fastFunction();
20+
slowFunction();
21+
i++;
22+
}
23+
}
24+
}

examples/java/docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
version: "3.9"
3+
services:
4+
pyroscope:
5+
image: "pyroscope/pyroscope:latest"
6+
environment:
7+
- "PYROSCOPE_LOG_LEVEL=debug"
8+
ports:
9+
- "4040:4040"
10+
command:
11+
- "server"
12+
app:
13+
build: .

0 commit comments

Comments
 (0)