Skip to content

Commit 764ef1f

Browse files
authored
[python_cpu_sleep_sync_3.12] add CPU/sleep attribution scenario (PROF-14213) (#128)
* [python_cpu_sleep_sync_3.12] add CPU/sleep attribution scenario (PROF-14213) New scenario that alternates 10 ms CPU bursts with 50 ms sleeps in sync mode, asserting on (a) total CPU consumed (167M ns/wall-sec, ±25%) and (b) cpu_burst self-attribution as % of cpu-time profile (50% ±15%). The 50% baseline codifies the architectural attribution ceiling documented in the python-cpu-accuracy survey (Finding 2): with 10 ms bursts sampled at ~10 ms cadence, ~50% of CPU lands on the next sample's stack — typically the sleep frame. Adaptive sampling is disabled (_DD_PROFILING_STACK_ADAPTIVE_SAMPLING_ENABLED=0). Also adds base_images/Dockerfile.python-3.12. * [python_cpu_sleep_sync_3.12] restore upstream-CI comments in Dockerfile.python-3.12 Code-review follow-up: keep the 3.12 base image as a one-line diff against the 3.11 template so the comment explaining DDTRACE_INSTALL_URL (used by dd-trace-py downstream CI) and the commented-out DD_TRACE_DEBUG line stay in sync across versions.
1 parent 30d5247 commit 764ef1f

5 files changed

Lines changed: 74 additions & 0 deletions

File tree

base_images/Dockerfile.python-3.12

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM python:3.12 AS base
2+
3+
# When set, download and run this install script to pre-install ddtrace.
4+
# Used by upstream dd-trace-py CI to test with just-built wheels from S3.
5+
ARG DDTRACE_INSTALL_URL=""
6+
RUN if [ -n "$DDTRACE_INSTALL_URL" ]; then \
7+
curl -fsSL "$DDTRACE_INSTALL_URL" | bash; \
8+
fi
9+
10+
ENV DD_PROFILING_ENABLED=true
11+
ENV DD_TRACE_ENABLED=false
12+
# ENV DD_TRACE_DEBUG=true
13+
ENV DD_PROFILING_OUTPUT_PPROF="/app/data/profiles"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ARG BASE_IMAGE="prof-python-3.12"
2+
FROM $BASE_IMAGE
3+
4+
WORKDIR /usr/src/app
5+
6+
COPY ./scenarios/python_cpu_sleep_sync_3.12/ /usr/src/app
7+
8+
RUN chmod 644 /usr/src/app/main.py
9+
RUN pip install --no-cache-dir -r requirements.txt
10+
11+
ENV EXECUTION_TIME_SEC=30
12+
ENV DD_PROFILING_MEMORY_ENABLED=false
13+
ENV _DD_PROFILING_STACK_ADAPTIVE_SAMPLING_ENABLED=0
14+
15+
CMD ddtrace-run python main.py
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"test_name": "python_cpu_sleep_sync_3.12",
3+
"scale_by_duration": true,
4+
"stacks": [
5+
{
6+
"profile-type": "cpu-time",
7+
"stack-content": [
8+
{
9+
"regular_expression": ".*",
10+
"value": 167000000,
11+
"error_margin": 25
12+
},
13+
{
14+
"regular_expression": ".*cpu_burst.*",
15+
"percent": 50,
16+
"error_margin": 15
17+
}
18+
]
19+
}
20+
]
21+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import os
2+
import time
3+
4+
5+
def cpu_burst(target_seconds: float) -> int:
6+
deadline = time.monotonic() + target_seconds
7+
x = 0x1234
8+
while time.monotonic() < deadline:
9+
x = (x * 48271) % 2147483647
10+
return x
11+
12+
13+
def main() -> None:
14+
execution_time_sec = float(os.environ.get("EXECUTION_TIME_SEC", "30"))
15+
cpu_seconds = 0.01
16+
off_cpu = 0.05
17+
deadline = time.monotonic() + execution_time_sec
18+
while time.monotonic() < deadline:
19+
time.sleep(off_cpu)
20+
cpu_burst(cpu_seconds)
21+
22+
23+
if __name__ == "__main__":
24+
main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ddtrace

0 commit comments

Comments
 (0)