Skip to content

Commit d0572a5

Browse files
committed
adds docker-compose examples for python, ruby and go
1 parent e38f649 commit d0572a5

File tree

11 files changed

+144
-0
lines changed

11 files changed

+144
-0
lines changed

examples/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Examples
2+
3+
These are example projects we set up with pyroscope for you to try out. You'll need `docker` + `docker-compose` to run them:
4+
5+
```shell
6+
cd golang
7+
docker-compose up --build
8+
```
9+
10+
These are very simple projects where the application is basically one `while true` loop and inside that loop it calls a slow function and a fast function. Slow function takes about 80% of the time and the fast one takes about 20%.

examples/golang/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM golang:1.15.6
2+
3+
WORKDIR /go/src/app
4+
5+
COPY main.go ./main.go
6+
7+
RUN go get -d ./
8+
RUN go build -o main .
9+
CMD ["./main"]

examples/golang/docker-compose.yml

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

examples/golang/main

6.03 MB
Binary file not shown.

examples/golang/main.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package main
2+
3+
import (
4+
"log"
5+
6+
"github.com/pyroscope-io/pyroscope/pkg/agent/profiler"
7+
)
8+
9+
func work(n int) {
10+
for i := 0; i < n; i++ {
11+
12+
}
13+
}
14+
15+
func fastFunction() {
16+
work(2000)
17+
}
18+
19+
func slowFunction() {
20+
work(8000)
21+
}
22+
23+
func main() {
24+
profiler.Start(profiler.Config{
25+
ApplicationName: "simple.golang.app",
26+
ServerAddress: "http://pyroscope:8080", // this will run inside docker-compose, hence `pyroscope` for hostname
27+
})
28+
29+
log.Println("test")
30+
for {
31+
fastFunction()
32+
slowFunction()
33+
}
34+
}

examples/python/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:3
2+
3+
WORKDIR /usr/src/app
4+
5+
COPY --from=pyroscope/pyroscope:latest /usr/bin/pyroscope /usr/bin/pyroscope
6+
COPY main.py ./main.py
7+
8+
ENV PYROSCOPE_APPLICATION_NAME=simple.python.app
9+
ENV PYROSCOPE_SERVER_ADDRESS=http://pyroscope:8080/
10+
CMD ["pyroscope", "exec", "python", "main.py"]

examples/python/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+
ports:
7+
- "8080:8080"
8+
command:
9+
- "server"
10+
app:
11+
build: .
12+
cap_add:
13+
- SYS_PTRACE

examples/python/main.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def work(n):
2+
i = 0
3+
while i < n:
4+
i += 1
5+
6+
def fast_function():
7+
work(20000)
8+
9+
def slow_function():
10+
work(80000)
11+
12+
if __name__ == "__main__":
13+
while True:
14+
fast_function()
15+
slow_function()

examples/ruby/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM ruby:2.7.1
2+
3+
WORKDIR /usr/src/app
4+
5+
COPY --from=pyroscope/pyroscope:latest /usr/bin/pyroscope /usr/bin/pyroscope
6+
COPY main.rb ./main.rb
7+
8+
ENV PYROSCOPE_APPLICATION_NAME=simple.ruby.app
9+
ENV PYROSCOPE_SERVER_ADDRESS=http://pyroscope:8080/
10+
CMD ["pyroscope", "exec", "ruby", "main.rb"]

examples/ruby/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+
ports:
7+
- "8080:8080"
8+
command:
9+
- "server"
10+
app:
11+
build: .
12+
cap_add:
13+
- SYS_PTRACE

0 commit comments

Comments
 (0)