From 439951af6a3a057306e7f1e20511978b5ac66623 Mon Sep 17 00:00:00 2001 From: r1viollet Date: Tue, 1 Aug 2023 15:48:44 +0200 Subject: [PATCH 1/3] Python CPU test - basic scenario --- scenarios/python_cpu/Dockerfile | 21 +++++++++++++ scenarios/python_cpu/expected_profile.json | 36 ++++++++++++++++++++++ scenarios/python_cpu/main.py | 30 ++++++++++++++++++ scenarios/python_cpu/requirements.txt | 1 + 4 files changed, 88 insertions(+) create mode 100644 scenarios/python_cpu/Dockerfile create mode 100644 scenarios/python_cpu/expected_profile.json create mode 100644 scenarios/python_cpu/main.py create mode 100644 scenarios/python_cpu/requirements.txt diff --git a/scenarios/python_cpu/Dockerfile b/scenarios/python_cpu/Dockerfile new file mode 100644 index 0000000..fd7f62e --- /dev/null +++ b/scenarios/python_cpu/Dockerfile @@ -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=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 diff --git a/scenarios/python_cpu/expected_profile.json b/scenarios/python_cpu/expected_profile.json new file mode 100644 index 0000000..a8e8459 --- /dev/null +++ b/scenarios/python_cpu/expected_profile.json @@ -0,0 +1,36 @@ +{ + "test_name": "python_cpu", + "stacks": [ + { + "profile-type": "cpu-time", + "stack-content": [ + { + "regular_expression": "\u003cmodule\u003e;main;b", + "percent": 66, + "error_margin": 5, + "labels": [ + { + "key": "thread name", + "values": [ + "MainThread" + ] + } + ] + }, + { + "regular_expression": "\u003cmodule\u003e;main;a", + "percent": 33, + "error_margin": 6, + "labels": [ + { + "key": "thread name", + "values": [ + "MainThread" + ] + } + ] + } + ] + } + ] +} diff --git a/scenarios/python_cpu/main.py b/scenarios/python_cpu/main.py new file mode 100644 index 0000000..ae57514 --- /dev/null +++ b/scenarios/python_cpu/main.py @@ -0,0 +1,30 @@ +import os +from time import time + +x = 0 +i = 0 + +def main(): + global x, i + execution_time = int(os.getenv("EXECUTION_TIME", "10")) # defaults to 10 if not set + end = time() + execution_time + while time() < end: + a() + b() + print(x) + +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() diff --git a/scenarios/python_cpu/requirements.txt b/scenarios/python_cpu/requirements.txt new file mode 100644 index 0000000..749bf29 --- /dev/null +++ b/scenarios/python_cpu/requirements.txt @@ -0,0 +1 @@ +ddtrace From 829edb1131f06430f9569695e20674868418b780 Mon Sep 17 00:00:00 2001 From: r1viollet Date: Wed, 2 Aug 2023 09:26:37 +0200 Subject: [PATCH 2/3] Naming adjustement EXECUTION_TIME -> EXECUTION_TIME_SEC --- README.md | 4 ++-- correctness_test.go | 6 +++--- scenarios/broken_graal_vm/Dockerfile | 2 +- scenarios/ddprof_allocations/Dockerfile | 2 +- scenarios/ddprof_allocations/simple_malloc.cc | 2 +- scenarios/ddprof_clang_pie/Dockerfile | 4 ++-- scenarios/ddprof_clang_pie/main.c | 2 +- scenarios/ddprof_julia/Dockerfile | 4 ++-- scenarios/ddprof_julia/main.jl | 2 +- scenarios/ddprof_live_heap/Dockerfile | 4 ++-- scenarios/ddprof_live_heap/main.cc | 2 +- scenarios/node_heap/Dockerfile | 2 +- scenarios/node_heap/main.js | 2 +- scenarios/node_heap_oom/Dockerfile | 2 +- scenarios/node_heap_oom/main.js | 2 +- scenarios/node_wall/Dockerfile | 2 +- scenarios/node_wall/main.js | 2 +- scenarios/php_allocations/Dockerfile | 2 +- scenarios/php_allocations/main.php | 2 +- scenarios/php_time/Dockerfile | 2 +- scenarios/php_time/main.php | 2 +- scenarios/python_basic/Dockerfile | 2 +- scenarios/python_basic/main.py | 6 +++--- scenarios/python_basic_gevent/Dockerfile | 2 +- scenarios/python_basic_gevent/main.py | 6 +++--- scenarios/python_cpu/Dockerfile | 2 +- scenarios/python_cpu/main.py | 4 ++-- scenarios/ruby_basic/main.rb | 2 +- 28 files changed, 39 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 7580891..af9b31a 100644 --- a/README.md +++ b/README.md @@ -43,14 +43,14 @@ find the pprof files. Create a test scenario and prefix the folders with something relevant like `php`, `ddprof`, `go`... The dockerfile specifies how to install the profiler and run the test app. The dockerfile needs to follow rules -- set variable `EXECUTION_TIME` (which defines how long the tests runs for) +- set variable `EXECUTION_TIME_SEC` (which defines how long the tests runs for) - output pprof data to the `/app/data/` folder The /app/data mirrors the data folder in this repository. ``` # Define OS / Install App... # Install profiler... # Run things -ENV EXECUTION_TIME="60" +ENV EXECUTION_TIME_SEC="60" # Default is that test data is dropped in the data folder ENV DD_PROFILING_PPROF_PREFIX="/app/data/profiles_" CMD ["ddprof", "-l", "notice", "/app/build/some_app" ] diff --git a/correctness_test.go b/correctness_test.go index 2934e19..730d166 100644 --- a/correctness_test.go +++ b/correctness_test.go @@ -111,7 +111,7 @@ func buildTestApp(t *testing.T, config DockerTestConfig) string { return string("test-app") } -// docker run -v ${PWD}/data:/app/data:rw -e EXECUTION_TIME=60 -u $(id -u ${USER}):$(id -g ${USER}) --security-opt seccomp=unconfined test-app:latest +// docker run -v ${PWD}/data:/app/data:rw -e EXECUTION_TIME_SEC=60 -u $(id -u ${USER}):$(id -g ${USER}) --security-opt seccomp=unconfined test-app:latest func runTestApp(t *testing.T, dockerTag string, folder string) string { currentPath, err := os.Getwd() @@ -135,7 +135,7 @@ func runTestApp(t *testing.T, dockerTag string, folder string) string { t.Log(strings.Join(cmdSlice, " ")) args := []string{"run", "-v", mountOption, "-u", userOption, "--security-opt", "seccomp=unconfined"} if DURATION_SET { - args = append(args, "-e", "EXECUTION_TIME="+fmt.Sprint(RUN_SECS)) + args = append(args, "-e", "EXECUTION_TIME_SEC="+fmt.Sprint(RUN_SECS)) } if NETWORK_HOST { args = append(args, "--network=host") @@ -180,7 +180,7 @@ func testScenarios(t *testing.T, scenarioRegexp string) { var ( expectedJson = flag.String("expectedJson", "default.json", "Path to the expected JSON file") - pprofPath = flag.String("pprofPath", "./", "Path to the directory with the pprof") + pprofPath = flag.String("pprofPath", "./", "Path to the directory with the pprof") ) func TestAnalyze(t *testing.T) { diff --git a/scenarios/broken_graal_vm/Dockerfile b/scenarios/broken_graal_vm/Dockerfile index 705e24b..25a0292 100644 --- a/scenarios/broken_graal_vm/Dockerfile +++ b/scenarios/broken_graal_vm/Dockerfile @@ -23,7 +23,7 @@ RUN ./install_profiler.sh /usr/local/bin ENV DD_PROFILING_PPROF_PREFIX="/app/data/profiles_" ENV DD_PROFILING_NATIVE_LOG_MODE="/app/data/ddprof_log" -# If upload period is > EXECUTION_TIME, it can cause issues when shutting down containers +# If upload period is > EXECUTION_TIME_SEC, it can cause issues when shutting down containers ENV DD_PROFILING_UPLOAD_PERIOD="10" CMD ddprof -l notice /app/DummyApp 11 diff --git a/scenarios/ddprof_allocations/Dockerfile b/scenarios/ddprof_allocations/Dockerfile index 93d55c6..f342a38 100644 --- a/scenarios/ddprof_allocations/Dockerfile +++ b/scenarios/ddprof_allocations/Dockerfile @@ -28,7 +28,7 @@ COPY ./binaries/ /app/binaries/ ADD ./profilers/ddprof/install_profiler.sh . RUN ./install_profiler.sh /usr/local/bin -ENV EXECUTION_TIME="11" +ENV EXECUTION_TIME_SEC="11" # Default is that test data is dropped in the data folder ENV DD_PROFILING_PPROF_PREFIX="/app/data/profiles_" ENV DD_PROFILING_UPLOAD_PERIOD="10" diff --git a/scenarios/ddprof_allocations/simple_malloc.cc b/scenarios/ddprof_allocations/simple_malloc.cc index a32698d..66f7c37 100644 --- a/scenarios/ddprof_allocations/simple_malloc.cc +++ b/scenarios/ddprof_allocations/simple_malloc.cc @@ -216,7 +216,7 @@ int main(int argc, char *argv[]) { app.add_option( "--timeout", opts.timeout_duration, "Timeout after N seconds") ->default_val(0) - ->envname("EXECUTION_TIME") + ->envname("EXECUTION_TIME_SEC") ->check(CLI::NonNegativeNumber); app.add_option( "--spin", opts.spin_duration_per_loop, diff --git a/scenarios/ddprof_clang_pie/Dockerfile b/scenarios/ddprof_clang_pie/Dockerfile index af2be9a..633f037 100644 --- a/scenarios/ddprof_clang_pie/Dockerfile +++ b/scenarios/ddprof_clang_pie/Dockerfile @@ -29,10 +29,10 @@ FROM base AS final ADD ./profilers/ddprof/install_profiler.sh . RUN ./install_profiler.sh /usr/local/bin -ENV EXECUTION_TIME="12" +ENV EXECUTION_TIME_SEC="12" # Default is that test data is dropped in the data folder ENV DD_PROFILING_PPROF_PREFIX="/app/data/profiles_" ENV DD_PROFILING_NATIVE_LOG_MODE="/app/data/ddprof_log" -# If upload period is > EXECUTION_TIME, it can cause issues when shutting down containers +# If upload period is > EXECUTION_TIME_SEC, it can cause issues when shutting down containers ENV DD_PROFILING_UPLOAD_PERIOD="10" CMD ["ddprof", "-l", "notice", "/app/build/clang_pie" ] diff --git a/scenarios/ddprof_clang_pie/main.c b/scenarios/ddprof_clang_pie/main.c index 9b0def2..7a4e999 100644 --- a/scenarios/ddprof_clang_pie/main.c +++ b/scenarios/ddprof_clang_pie/main.c @@ -23,7 +23,7 @@ void b() { int main(int argc, char *argv[]) { int test_duration = 60; - const char *exec_time_env = getenv("EXECUTION_TIME"); + const char *exec_time_env = getenv("EXECUTION_TIME_SEC"); if (exec_time_env) { test_duration = atoi(exec_time_env); if (test_duration == 0) { diff --git a/scenarios/ddprof_julia/Dockerfile b/scenarios/ddprof_julia/Dockerfile index f11385a..6255421 100644 --- a/scenarios/ddprof_julia/Dockerfile +++ b/scenarios/ddprof_julia/Dockerfile @@ -22,7 +22,7 @@ ARG CACHE_DATE=2023-03-01_09:58:27 ADD ./profilers/ddprof/install_profiler.sh . RUN ./install_profiler.sh /usr/local/bin -ENV EXECUTION_TIME="11" +ENV EXECUTION_TIME_SEC="11" # Default is that test data is dropped in the data folder ENV DD_PROFILING_PPROF_PREFIX="/app/data/profiles_" ENV DD_PROFILING_UPLOAD_PERIOD="10" @@ -33,7 +33,7 @@ ENV ENABLE_JITPROFILING=1 # The rpath is defined by the caller of dlopen. Intercepting the call changes # who is calling dlopen. This is not easy to fix, so I'm adding the path to Julia libs # Debug command: -# ENABLE_JITPROFILING=1 LD_LIBRARY_PATH=~/dd/scripts/julia-1.8.5/lib/julia/ EXECUTION_TIME=30 ddprof -l notice +# ENABLE_JITPROFILING=1 LD_LIBRARY_PATH=~/dd/scripts/julia-1.8.5/lib/julia/ EXECUTION_TIME_SEC=30 ddprof -l notice # --show_sample julia scenarios/ddprof_julia/main.jl ENV LD_LIBRARY_PATH="/usr/local/julia/lib:${LD_LIBRARY_PATH}" RUN mkdir /.debug && mkdir /.debug/jit && chmod 777 /.debug/jit diff --git a/scenarios/ddprof_julia/main.jl b/scenarios/ddprof_julia/main.jl index 0764f3c..637ba28 100644 --- a/scenarios/ddprof_julia/main.jl +++ b/scenarios/ddprof_julia/main.jl @@ -3,7 +3,7 @@ include("b.jl") test_duration = 60 -exec_time_env = ENV["EXECUTION_TIME"] +exec_time_env = ENV["EXECUTION_TIME_SEC"] if exec_time_env != nothing test_duration = parse(Int, exec_time_env) if test_duration == 0 diff --git a/scenarios/ddprof_live_heap/Dockerfile b/scenarios/ddprof_live_heap/Dockerfile index 634264b..662931c 100644 --- a/scenarios/ddprof_live_heap/Dockerfile +++ b/scenarios/ddprof_live_heap/Dockerfile @@ -21,11 +21,11 @@ FROM base AS final ADD ./profilers/ddprof/install_profiler.sh . RUN ./install_profiler.sh /usr/local/bin -ENV EXECUTION_TIME="12" +ENV EXECUTION_TIME_SEC="12" # Default is that test data is dropped in the data folder ENV DD_PROFILING_PPROF_PREFIX="/app/data/profiles_" ENV DD_PROFILING_NATIVE_LOG_MODE="/app/data/ddprof_log" -# If upload period is > EXECUTION_TIME, it can cause issues when shutting down containers +# If upload period is > EXECUTION_TIME_SEC, it can cause issues when shutting down containers ENV DD_PROFILING_UPLOAD_PERIOD="10" # ddprof -l debug -e "sALLOC period=1 mode=l" -u 30 ./test # Force deterministic by sampling all allocations diff --git a/scenarios/ddprof_live_heap/main.cc b/scenarios/ddprof_live_heap/main.cc index 5d1fd6e..34352fd 100644 --- a/scenarios/ddprof_live_heap/main.cc +++ b/scenarios/ddprof_live_heap/main.cc @@ -39,7 +39,7 @@ void thread_function() { int main(int argc, char** argv) { int test_duration = 10; - const char* exec_time_env = getenv("EXECUTION_TIME"); + const char* exec_time_env = getenv("EXECUTION_TIME_SEC"); if (exec_time_env) { test_duration = atoi(exec_time_env); if (test_duration == 0) { diff --git a/scenarios/node_heap/Dockerfile b/scenarios/node_heap/Dockerfile index 6fbdea1..574ae94 100644 --- a/scenarios/node_heap/Dockerfile +++ b/scenarios/node_heap/Dockerfile @@ -8,7 +8,7 @@ COPY ./scenarios/node_heap/* ./ RUN chmod 755 /app/* RUN npm install -ENV EXECUTION_TIME="10" +ENV EXECUTION_TIME_SEC="10" ENV DD_PROFILING_PPROF_PREFIX="/app/data/profiles_" ENV DD_PROFILING_EXPORTERS=file ENV DD_PROFILING_ENABLED=1 diff --git a/scenarios/node_heap/main.js b/scenarios/node_heap/main.js index 1bd26a9..955be3c 100644 --- a/scenarios/node_heap/main.js +++ b/scenarios/node_heap/main.js @@ -30,6 +30,6 @@ async function foo(iterCount, allocPeriodMs) { var refs = [] const allocSize = 1024 * 1024 * 2 const allocPeriodMs = 100 -const durationMs = (process.argv[2] || process.env.EXECUTION_TIME || 2) * 1000 +const durationMs = (process.argv[2] || process.env.EXECUTION_TIME_SEC || 2) * 1000 const iterCount = durationMs / allocPeriodMs setTimeout(() => foo(iterCount, allocPeriodMs), 100) diff --git a/scenarios/node_heap_oom/Dockerfile b/scenarios/node_heap_oom/Dockerfile index 5d3c5b4..d894633 100644 --- a/scenarios/node_heap_oom/Dockerfile +++ b/scenarios/node_heap_oom/Dockerfile @@ -8,7 +8,7 @@ COPY ./scenarios/node_heap_oom/* ./ RUN chmod 755 /app/* RUN npm install -ENV EXECUTION_TIME="10" +ENV EXECUTION_TIME_SEC="10" ENV DD_PROFILING_PPROF_PREFIX="/app/data/profiles_" ENV DD_PROFILING_EXPORTERS=file ENV DD_PROFILING_ENABLED=1 diff --git a/scenarios/node_heap_oom/main.js b/scenarios/node_heap_oom/main.js index 7bbbcaa..13b242f 100644 --- a/scenarios/node_heap_oom/main.js +++ b/scenarios/node_heap_oom/main.js @@ -7,5 +7,5 @@ async function foo(size) { for (let i = 0; i < n; i++) { x[i] = Math.random() } } -const durationMs = (process.argv[2] || process.env.EXECUTION_TIME || 2) * 1000 +const durationMs = (process.argv[2] || process.env.EXECUTION_TIME_SEC || 2) * 1000 setTimeout(() => foo(1024 * 1024 * 50), durationMs) diff --git a/scenarios/node_wall/Dockerfile b/scenarios/node_wall/Dockerfile index ebea7a2..fd54a27 100644 --- a/scenarios/node_wall/Dockerfile +++ b/scenarios/node_wall/Dockerfile @@ -8,7 +8,7 @@ COPY ./scenarios/node_wall/* ./ RUN chmod 755 /app/* RUN npm install -ENV EXECUTION_TIME="10" +ENV EXECUTION_TIME_SEC="10" ENV DD_PROFILING_PPROF_PREFIX="/app/data/profiles_" ENV DD_PROFILING_EXPORTERS=file ENV DD_PROFILING_ENABLED=1 diff --git a/scenarios/node_wall/main.js b/scenarios/node_wall/main.js index f60f653..1ee5bdc 100644 --- a/scenarios/node_wall/main.js +++ b/scenarios/node_wall/main.js @@ -52,5 +52,5 @@ async function foo(nsecs) { setImmediate(work); } -const executionTime = process.argv[2] || process.env.EXECUTION_TIME || 2 +const executionTime = process.argv[2] || process.env.EXECUTION_TIME_SEC || 2 setTimeout(() => foo(executionTime), 100) diff --git a/scenarios/php_allocations/Dockerfile b/scenarios/php_allocations/Dockerfile index c51b683..761ee99 100644 --- a/scenarios/php_allocations/Dockerfile +++ b/scenarios/php_allocations/Dockerfile @@ -13,7 +13,7 @@ RUN ./install_profiler.sh COPY ./scenarios/php_allocations/main.php . RUN chmod 644 ./main.php -ENV EXECUTION_TIME="10" +ENV EXECUTION_TIME_SEC="10" ENV DD_PROFILING_OUTPUT_PPROF="/app/data/php.pprof" ENV DD_PROFILING_EXPERIMENTAL_ALLOCATION_ENABLED=true ENV DD_PROFILING_ENABLED=true diff --git a/scenarios/php_allocations/main.php b/scenarios/php_allocations/main.php index 7e8e1af..3e982f7 100644 --- a/scenarios/php_allocations/main.php +++ b/scenarios/php_allocations/main.php @@ -12,7 +12,7 @@ function b() function main() { - $duration = $_ENV["EXECUTION_TIME"] ?? 10; + $duration = $_ENV["EXECUTION_TIME_SEC"] ?? 10; $end = microtime(true) + $duration; while (microtime(true) < $end) { $start = microtime(true); diff --git a/scenarios/php_time/Dockerfile b/scenarios/php_time/Dockerfile index 833ec74..afb6f1b 100644 --- a/scenarios/php_time/Dockerfile +++ b/scenarios/php_time/Dockerfile @@ -13,7 +13,7 @@ RUN ./install_profiler.sh COPY ./scenarios/php_time/main.php . RUN chmod 644 ./main.php -ENV EXECUTION_TIME="10" +ENV EXECUTION_TIME_SEC="10" ENV DD_PROFILING_OUTPUT_PPROF="/app/data/php.pprof" ENV DD_PROFILING_EXPERIMENTAL_CPU_TIME_ENABLED=true ENV DD_PROFILING_EXPERIMENTAL_ALLOCATION_ENABLED=false diff --git a/scenarios/php_time/main.php b/scenarios/php_time/main.php index 044803f..4e118b2 100644 --- a/scenarios/php_time/main.php +++ b/scenarios/php_time/main.php @@ -19,7 +19,7 @@ function b() { } function main() { - $duration = $_ENV["EXECUTION_TIME"]; + $duration = $_ENV["EXECUTION_TIME_SEC"]; $end = microtime(true) + ($duration / 2); while (microtime(true) < $end) { a(); diff --git a/scenarios/python_basic/Dockerfile b/scenarios/python_basic/Dockerfile index 3c867f1..b6c933f 100644 --- a/scenarios/python_basic/Dockerfile +++ b/scenarios/python_basic/Dockerfile @@ -1,6 +1,6 @@ FROM python:3.10 -ENV EXECUTION_TIME="2" +ENV EXECUTION_TIME_SEC="2" ENV DD_PROFILING_ENABLED true ENV DD_TRACE_ENABLED false ENV DD_TRACE_DEBUG true diff --git a/scenarios/python_basic/main.py b/scenarios/python_basic/main.py index 8586364..7a7a314 100644 --- a/scenarios/python_basic/main.py +++ b/scenarios/python_basic/main.py @@ -8,11 +8,11 @@ def target(n): if __name__ == "__main__": - execution_time = int(os.environ.get("EXECUTION_TIME", "2")) + EXECUTION_TIME_SEC = int(os.environ.get("EXECUTION_TIME_SEC", "2")) - t = Thread(target=target, args=(execution_time / 2,)) + t = Thread(target=target, args=(EXECUTION_TIME_SEC / 2,)) t.start() - target(execution_time) + target(EXECUTION_TIME_SEC) t.join() diff --git a/scenarios/python_basic_gevent/Dockerfile b/scenarios/python_basic_gevent/Dockerfile index 8c3d0c6..517d786 100644 --- a/scenarios/python_basic_gevent/Dockerfile +++ b/scenarios/python_basic_gevent/Dockerfile @@ -1,6 +1,6 @@ FROM python:3.10 -ENV EXECUTION_TIME="2" +ENV EXECUTION_TIME_SEC="2" ENV DD_PROFILING_ENABLED true ENV DD_TRACE_ENABLED false ENV DD_TRACE_DEBUG true diff --git a/scenarios/python_basic_gevent/main.py b/scenarios/python_basic_gevent/main.py index 8ba3fd3..b96b93e 100644 --- a/scenarios/python_basic_gevent/main.py +++ b/scenarios/python_basic_gevent/main.py @@ -12,11 +12,11 @@ def target(n): if __name__ == "__main__": - execution_time = int(os.environ.get("EXECUTION_TIME", "2")) + EXECUTION_TIME_SEC = int(os.environ.get("EXECUTION_TIME_SEC", "2")) - t = Thread(target=target, args=(execution_time / 2,)) + t = Thread(target=target, args=(EXECUTION_TIME_SEC / 2,)) t.start() - target(execution_time) + target(EXECUTION_TIME_SEC) t.join() diff --git a/scenarios/python_cpu/Dockerfile b/scenarios/python_cpu/Dockerfile index fd7f62e..c35a719 100644 --- a/scenarios/python_cpu/Dockerfile +++ b/scenarios/python_cpu/Dockerfile @@ -11,7 +11,7 @@ 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=10 +ENV EXECUTION_TIME_SEC=10 # Run your python script when the container launches ENV DD_PROFILING_ENABLED true ENV DD_TRACE_ENABLED false diff --git a/scenarios/python_cpu/main.py b/scenarios/python_cpu/main.py index ae57514..fe2225e 100644 --- a/scenarios/python_cpu/main.py +++ b/scenarios/python_cpu/main.py @@ -6,8 +6,8 @@ def main(): global x, i - execution_time = int(os.getenv("EXECUTION_TIME", "10")) # defaults to 10 if not set - end = time() + execution_time + 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() diff --git a/scenarios/ruby_basic/main.rb b/scenarios/ruby_basic/main.rb index b71f7c5..31a4b1e 100644 --- a/scenarios/ruby_basic/main.rb +++ b/scenarios/ruby_basic/main.rb @@ -32,7 +32,7 @@ def b end test_duration = 50 -exec_time_env = ENV['EXECUTION_TIME'] +exec_time_env = ENV['EXECUTION_TIME_SEC'] if exec_time_env test_duration = exec_time_env.to_i if test_duration == 0 From 3398098f7a22cc82a286c01da54d5f68804f842e Mon Sep 17 00:00:00 2001 From: r1viollet Date: Fri, 4 Aug 2023 11:44:59 +0200 Subject: [PATCH 3/3] Python cpu test - add a comment around reason for print --- scenarios/python_cpu/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scenarios/python_cpu/main.py b/scenarios/python_cpu/main.py index fe2225e..73e9c43 100644 --- a/scenarios/python_cpu/main.py +++ b/scenarios/python_cpu/main.py @@ -11,6 +11,7 @@ def main(): while time() < end: a() b() + # We add a print to prevent optimization that could turn this into a no-op program print(x) def a():