Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions base_images/Dockerfile.python-3.12
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.12 AS base

# When set, download and run this install script to pre-install ddtrace.
# Used by upstream dd-trace-py CI to test with just-built wheels from S3.
ARG DDTRACE_INSTALL_URL=""
RUN if [ -n "$DDTRACE_INSTALL_URL" ]; then \
curl -fsSL "$DDTRACE_INSTALL_URL" | bash; \
fi

ENV DD_PROFILING_ENABLED=true
ENV DD_TRACE_ENABLED=false
# ENV DD_TRACE_DEBUG=true
ENV DD_PROFILING_OUTPUT_PPROF="/app/data/profiles"
15 changes: 15 additions & 0 deletions scenarios/python_cpu_sleep_asyncio_3.12/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ARG BASE_IMAGE="prof-python-3.12"
FROM $BASE_IMAGE

WORKDIR /usr/src/app

COPY ./scenarios/python_cpu_sleep_asyncio_3.12/ /usr/src/app

RUN chmod 644 /usr/src/app/main.py
RUN pip install --no-cache-dir -r requirements.txt

ENV EXECUTION_TIME_SEC=30
ENV DD_PROFILING_MEMORY_ENABLED=false
ENV _DD_PROFILING_STACK_ADAPTIVE_SAMPLING_ENABLED=0

CMD ddtrace-run python main.py
21 changes: 21 additions & 0 deletions scenarios/python_cpu_sleep_asyncio_3.12/expected_profile.json
Comment thread
taegyunkim marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"test_name": "python_cpu_sleep_asyncio_3.12",
"scale_by_duration": true,
"stacks": [
{
"profile-type": "cpu-time",
"stack-content": [
{
"regular_expression": ".*",
"value": 667000000,
"error_margin": 25
},
{
"regular_expression": ".*cpu_burst.*",
"percent": 80,
"error_margin": 10
}
]
}
]
}
37 changes: 37 additions & 0 deletions scenarios/python_cpu_sleep_asyncio_3.12/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import asyncio
import os
import time


def cpu_burst(target_seconds: float) -> int:
deadline = time.monotonic() + target_seconds
x = 0x1234
while time.monotonic() < deadline:
x = (x * 48271) % 2147483647
return x


async def slot(cpu_seconds: float, off_cpu: float, deadline: float) -> None:
while time.monotonic() < deadline:
await asyncio.sleep(off_cpu)
cpu_burst(cpu_seconds)


async def main() -> None:
execution_time_sec = float(os.environ.get("EXECUTION_TIME_SEC", "30"))
cpu_seconds = 0.01
off_cpu = 0.05
concurrency = 4
stagger = 0.01

deadline = time.monotonic() + execution_time_sec
tasks: list[asyncio.Task[None]] = []
for i in range(concurrency):
if i > 0:
await asyncio.sleep(stagger)
tasks.append(asyncio.create_task(slot(cpu_seconds, off_cpu, deadline)))
await asyncio.gather(*tasks)


if __name__ == "__main__":
asyncio.run(main())
1 change: 1 addition & 0 deletions scenarios/python_cpu_sleep_asyncio_3.12/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ddtrace
Loading