From 278f767695bc073c4529d964d5df4f1b971b2445 Mon Sep 17 00:00:00 2001 From: James Kerns Date: Tue, 12 Nov 2024 07:58:27 -0600 Subject: [PATCH] add BB pipe memory monitor as done for RM. --- bitbucket-pipelines.yml | 24 ++++++++++++++++++++++++ memory_monitor.sh | 14 ++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 memory_monitor.sh diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 401c82bc..39e77434 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -40,7 +40,13 @@ definitions: name: Run CBCT Tests size: 2x script: + # set up memory monitoring + - chmod +x memory_monitor.sh + - nohup ./memory_monitor.sh & + - MONITOR_PID=$! - uv run pytest tests_basic/test_cbct.py -n 2 --cov=pylinac.cbct --cov-report term --junitxml=./test-reports/pytest_results.xml + # clean up memory monitor + - kill $MONITOR_PID caches: - testfiles condition: @@ -49,6 +55,8 @@ definitions: - "pylinac/core/**" - "tests_basic/test_cbct.py" - "pylinac/ct.py" + artifacts: + - memory_usage.log - step: &quart-tests name: Run Quart Tests script: @@ -189,24 +197,40 @@ definitions: name: Run Winston-Lutz Tests size: 2x script: + # set up memory monitoring + - chmod +x memory_monitor.sh + - nohup ./memory_monitor.sh & + - MONITOR_PID=$! - uv run pytest tests_basic/test_winstonlutz.py --cov-report term --junitxml=./test-reports/pytest_results.xml + # clean up memory monitor + - kill $MONITOR_PID condition: changesets: includePaths: - "pylinac/core/**" - "tests_basic/test_winstonlutz.py" - "pylinac/winston_lutz.py" + artifacts: + - memory_usage.log - step: &winston-lutz-mtmf-tests name: Run Winston-Lutz Multi-Target Multi-Field Tests size: 2x script: + # set up memory monitoring + - chmod +x memory_monitor.sh + - nohup ./memory_monitor.sh & + - MONITOR_PID=$! - uv run pytest tests_basic/test_winstonlutz_mtmf.py --cov-report term --junitxml=./test-reports/pytest_results.xml + # clean up memory monitor + - kill $MONITOR_PID condition: changesets: includePaths: - "pylinac/core/**" - "tests_basic/test_winstonlutz.py" - "pylinac/winston_lutz.py" + artifacts: + - memory_usage.log - step: &plan-generator-tests name: Plan generator tests script: diff --git a/memory_monitor.sh b/memory_monitor.sh new file mode 100644 index 00000000..b53c7ecd --- /dev/null +++ b/memory_monitor.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +LOG_FILE="memory_usage.log" +echo "Timestamp,MemoryUsage(MB),MemoryLimit(MB)" > $LOG_FILE + +while true; do + TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S") + MEMORY_USAGE=$(cat /sys/fs/cgroup/memory/memory.usage_in_bytes) + MEMORY_LIMIT=$(cat /sys/fs/cgroup/memory/memory.limit_in_bytes) + MEMORY_USAGE_MB=$((MEMORY_USAGE / 1024 / 1024)) + MEMORY_LIMIT_MB=$((MEMORY_LIMIT / 1024 / 1024)) + echo "$TIMESTAMP,$MEMORY_USAGE_MB,$MEMORY_LIMIT_MB" >> $LOG_FILE + sleep 10 +done