-
Notifications
You must be signed in to change notification settings - Fork 2
[python_cpu_sleep_asyncio_3.12] add CPU/sleep attribution scenario (PROF-14213) #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
taegyunkim
wants to merge
4
commits into
main
Choose a base branch
from
prof-14213-cpu-sleep-asyncio
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
21
scenarios/python_cpu_sleep_asyncio_3.12/expected_profile.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ddtrace |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.