Skip to content

Commit dfb69d4

Browse files
[python_basic_memory] Initial commit
1 parent 35c644a commit dfb69d4

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
ARG BASE_IMAGE="prof-python-3.11"
2+
FROM $BASE_IMAGE
3+
4+
# Copy the Python target into the container
5+
COPY ./scenarios/python_basic_memory_3.11/requirements.txt /app/requirements.txt
6+
RUN chmod 644 /app/*
7+
8+
RUN pip install -r /app/requirements.txt
9+
10+
COPY ./scenarios/python_basic_memory_3.11/main.py /app/main.py
11+
12+
# Set the working directory to the location of the program
13+
WORKDIR /app
14+
15+
ENV EXECUTION_TIME_SEC="2"
16+
ENV DD_TRACE_DEBUG=true
17+
18+
# Run the program when the container starts
19+
CMD python main.py
20+
# CMD ddprof -l notice --preset cpu_live_heap python main.py
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"test_name": "python_basic",
3+
"pprof-regex": "",
4+
"stacks": [
5+
{
6+
"profile-type": "wall-time",
7+
"pprof-regex": "",
8+
"stack-content": [
9+
{
10+
"regular_expression": "^\u003cmodule\u003e;target$",
11+
"value": 1500000000,
12+
"error_margin": 20,
13+
"labels": [
14+
{
15+
"key": "thread name",
16+
"values": [
17+
"MainThread"
18+
],
19+
"values_regex": ""
20+
}
21+
]
22+
},
23+
{
24+
"regular_expression": ".*run;target$",
25+
"value": 500000000,
26+
"error_margin": 25,
27+
"labels": [
28+
{
29+
"key": "thread name",
30+
"values": [
31+
"Thread-1 (target)"
32+
],
33+
"values_regex": ""
34+
}
35+
]
36+
}
37+
]
38+
}
39+
],
40+
"scale_by_duration": false
41+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from datetime import time
2+
import os
3+
import time
4+
from ddtrace.profiling import Profiler
5+
6+
7+
class Target:
8+
def __init__(self):
9+
self.memory = []
10+
11+
def run(self, n):
12+
end_time = time.monotonic() + n
13+
while time.monotonic() < end_time:
14+
self.memory.append(bytearray(1024))
15+
16+
17+
if __name__ == "__main__":
18+
# Simple application that creates two threads with different durations:
19+
# - MainThread runs target() for 2 seconds
20+
# - Worker Thread-1 runs target() for 1 second
21+
# The profiler should capture both threads with their respective durations.
22+
prof = Profiler()
23+
prof.start() # Should be as early as possible, eg before other imports, to ensure everything is profiled
24+
25+
EXECUTION_TIME_SEC = int(os.environ.get("EXECUTION_TIME_SEC", "2"))
26+
27+
Target().run(EXECUTION_TIME_SEC)
28+
29+
prof.stop()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ddtrace==4.0.0

0 commit comments

Comments
 (0)