Skip to content

Commit 3f9f55b

Browse files
committed
Change files for blog example
1 parent 8dd9d6c commit 3f9f55b

File tree

9 files changed

+73
-12
lines changed

9 files changed

+73
-12
lines changed

examples/python/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ WORKDIR /usr/src/app
44

55
COPY --from=pyroscope/pyroscope:latest /usr/bin/pyroscope /usr/bin/pyroscope
66
COPY main.py ./main.py
7+
COPY util.py ./util.py
8+
COPY __init__.py ./__init__.py
9+
COPY fast_package ./fast_package
10+
COPY slow_module ./slow_module
711

812
ENV PYROSCOPE_APPLICATION_NAME=simple.python.app
913
ENV PYROSCOPE_SERVER_ADDRESS=http://pyroscope:4040/

examples/python/__init__.py

Whitespace-only changes.

examples/python/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ services:
1111
build: .
1212
cap_add:
1313
- SYS_PTRACE
14+

examples/python/fast_package/__init__.py

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from util import work
2+
3+
def fast_function(speed):
4+
work(speed)

examples/python/main.py

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,59 @@
1-
def work(n):
2-
i = 0
3-
while i < n:
4-
i += 1
1+
import time
2+
import threading
3+
from fast_package.fast_file import fast_function
4+
from slow_module.slow_file import slow_function
55

6-
def fast_function():
7-
work(20000)
8-
9-
def slow_function():
10-
work(80000)
6+
DURATION = 60 * 10 # ten minutes
117

128
if __name__ == "__main__":
13-
while True:
14-
fast_function()
15-
slow_function()
9+
t_start = time.time()
10+
t_end = time.time() + DURATION
11+
12+
print(f'yoyoy Application started at: {t_start}')
13+
while time.time() < t_end:
14+
threads = list()
15+
fast_thread = threading.Thread(target=fast_function, args=(25000,))
16+
slow_thread = threading.Thread(target=slow_function, args=(8000,))
17+
18+
threads.append(fast_thread)
19+
fast_thread.start()
20+
21+
threads.append(slow_thread)
22+
slow_thread.start()
23+
24+
for index, thread in enumerate(threads):
25+
# print("Main : before joining thread %d.", index)
26+
thread.join()
27+
# print("Main : thread %d done", index)
28+
29+
print(f'yoyoy Application ended at: {t_end}')
30+
31+
print(f'Switching fast and slow around.....')
32+
time.sleep(60)
33+
print(f'Switching fast and slow around.....')
34+
35+
t_start = time.time()
36+
t_end = time.time() + DURATION
37+
38+
print(f'yoyoy Application started at: {t_start}')
39+
while time.time() < t_end:
40+
threads = list()
41+
fast_thread = threading.Thread(target=fast_function, args=(25000,))
42+
slow_thread = threading.Thread(target=slow_function, args=(75000,))
43+
44+
threads.append(fast_thread)
45+
fast_thread.start()
46+
47+
threads.append(slow_thread)
48+
slow_thread.start()
49+
50+
for index, thread in enumerate(threads):
51+
# print("Main : before joining thread %d.", index)
52+
thread.join()
53+
# print("Main : thread %d done", index)
54+
55+
print(f'yoyoy Application ended at: {t_end}')
56+
57+
58+
59+

examples/python/slow_module/__init__.py

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from util import work
2+
3+
def slow_function(speed):
4+
work(speed)

examples/python/util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def work(n):
2+
i = 0
3+
while i < n:
4+
i += 1

0 commit comments

Comments
 (0)