-
Notifications
You must be signed in to change notification settings - Fork 1
Python CPU test - basic scenario #4
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Use an official Python runtime as a parent image | ||
| FROM python:3.11 | ||
|
|
||
| # Set the working directory in the container | ||
| WORKDIR /usr/src/app | ||
|
|
||
| # Copy the current directory contents into the container at /app | ||
| COPY ./scenarios/python_cpu/ /usr/src/app | ||
|
|
||
| RUN chmod 644 /usr/src/app/main.py | ||
| # Install any needed packages specified in requirements.txt | ||
| RUN pip install --no-cache-dir -r requirements.txt | ||
|
|
||
| ENV EXECUTION_TIME_SEC=10 | ||
| # Run your python script when the container launches | ||
| ENV DD_PROFILING_ENABLED true | ||
| ENV DD_TRACE_ENABLED false | ||
| ENV DD_TRACE_DEBUG false | ||
| ENV DD_PROFILING_OUTPUT_PPROF="/app/data/profiles" | ||
|
|
||
| CMD ddtrace-run python main.py | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| { | ||
|
r1viollet marked this conversation as resolved.
|
||
| "test_name": "python_cpu", | ||
| "stacks": [ | ||
| { | ||
| "profile-type": "cpu-time", | ||
| "stack-content": [ | ||
| { | ||
| "regular_expression": "\u003cmodule\u003e;main;b", | ||
|
r1viollet marked this conversation as resolved.
|
||
| "percent": 66, | ||
| "error_margin": 5, | ||
|
r1viollet marked this conversation as resolved.
|
||
| "labels": [ | ||
| { | ||
| "key": "thread name", | ||
| "values": [ | ||
| "MainThread" | ||
| ] | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "regular_expression": "\u003cmodule\u003e;main;a", | ||
| "percent": 33, | ||
| "error_margin": 6, | ||
| "labels": [ | ||
| { | ||
| "key": "thread name", | ||
| "values": [ | ||
| "MainThread" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import os | ||
| from time import time | ||
|
|
||
| x = 0 | ||
| i = 0 | ||
|
|
||
| def main(): | ||
| global x, i | ||
| EXECUTION_TIME_SEC = int(os.getenv("EXECUTION_TIME_SEC", "10")) # defaults to 10 if not set | ||
| end = time() + EXECUTION_TIME_SEC | ||
| while time() < end: | ||
| a() | ||
| b() | ||
| # We add a print to prevent optimization that could turn this into a no-op program | ||
| print(x) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this is needed to avoid the compiler optimizing away the writes to x?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, locals would be optimized without a usage in more recent python versions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might want to add a comment explaining this. |
||
|
|
||
| def a(): | ||
| global x, i | ||
| i = 0 | ||
| while i < 1000000: | ||
| x += i | ||
| i += 1 | ||
|
|
||
| def b(): | ||
| global x, i | ||
| i = 0 | ||
| while i < 2000000: | ||
| x += i | ||
| i += 1 | ||
|
|
||
| main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ddtrace |
Uh oh!
There was an error while loading. Please reload this page.