-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in bugfix/RAM-4135_image_generator_magnification (pull request #…
…475) Fix magnification doubling and add plot method Approved-by: Randy Taylor
- Loading branch information
Showing
11 changed files
with
249 additions
and
83 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,48 @@ | ||
# conftest.py | ||
|
||
import json | ||
import os | ||
import threading | ||
|
||
import pytest | ||
|
||
# Define the path for the active tests file | ||
ACTIVE_TESTS_FILE = "active_tests.json" | ||
|
||
# Initialize a thread-safe set to store active tests | ||
active_tests_lock = threading.Lock() | ||
active_tests = set() | ||
|
||
|
||
def update_active_tests_file(): | ||
"""Writes the current active tests to a JSON file.""" | ||
with active_tests_lock: | ||
data = list(active_tests) | ||
with open(ACTIVE_TESTS_FILE, "w") as f: | ||
json.dump(data, f) | ||
|
||
|
||
@pytest.hookimpl(hookwrapper=True) | ||
def pytest_runtest_protocol(item, nextitem): | ||
"""Hook to track test start and end, and trace memory allocations.""" | ||
# Before the test runs | ||
with active_tests_lock: | ||
active_tests.add(item.nodeid) | ||
update_active_tests_file() | ||
|
||
try: | ||
# Run the actual test | ||
yield | ||
finally: | ||
# After the test runs | ||
with active_tests_lock: | ||
active_tests.discard(item.nodeid) | ||
update_active_tests_file() | ||
|
||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def ensure_active_tests_file_cleanup(): | ||
"""Ensure that the active tests file is removed after the test session.""" | ||
yield | ||
if os.path.exists(ACTIVE_TESTS_FILE): | ||
os.remove(ACTIVE_TESTS_FILE) |
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,14 +1,67 @@ | ||
#!/bin/bash | ||
|
||
# Configuration | ||
LOG_FILE="memory_usage.log" | ||
echo "Timestamp,MemoryUsage(MB),MemoryLimit(MB)" > $LOG_FILE | ||
ACTIVE_TESTS_FILE="active_tests.json" | ||
# Dynamically set TEMP_DIR based on TMPDIR environment variable; default to /tmp if TMPDIR is not set | ||
TEMP_DIR="${TMPDIR:-/tmp}" | ||
POLL_INTERVAL=10 # Polling interval in seconds | ||
|
||
# Initialize the log file with headers | ||
echo "Timestamp,MemoryUsage(MB),MemoryLimit(MB),ActiveTests,TempDirSize(MB)" > "$LOG_FILE" | ||
|
||
while true; do | ||
# Capture the current timestamp | ||
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) | ||
|
||
# Read memory usage and limit | ||
if [ -f /sys/fs/cgroup/memory/memory.usage_in_bytes ] && [ -f /sys/fs/cgroup/memory/memory.limit_in_bytes ]; then | ||
MEMORY_USAGE=$(cat /sys/fs/cgroup/memory/memory.usage_in_bytes 2>/dev/null || echo 0) | ||
MEMORY_LIMIT=$(cat /sys/fs/cgroup/memory/memory.limit_in_bytes 2>/dev/null || echo 0) | ||
else | ||
# Fallback for systems without cgroup memory files | ||
MEMORY_USAGE=$(free -b | awk '/Mem:/ {print $3}' || echo 0) | ||
MEMORY_LIMIT=$(free -b | awk '/Mem:/ {print $2}' || echo 0) | ||
fi | ||
|
||
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 | ||
|
||
# Read active tests | ||
if [ -f "$ACTIVE_TESTS_FILE" ]; then | ||
# Use jq to parse the JSON array and concatenate test names | ||
ACTIVE_TESTS=$(jq -r '.[]' "$ACTIVE_TESTS_FILE" | paste -sd "," -) | ||
# Handle empty active tests | ||
if [ -z "$ACTIVE_TESTS" ]; then | ||
ACTIVE_TESTS="None" | ||
fi | ||
else | ||
ACTIVE_TESTS="No tests running" | ||
fi | ||
|
||
# Determine the temporary directory to monitor | ||
# Prefer TMPDIR if set; else default to /tmp | ||
if [ -n "$TMPDIR" ]; then | ||
CURRENT_TEMP_DIR="$TMPDIR" | ||
else | ||
CURRENT_TEMP_DIR="/tmp" | ||
fi | ||
|
||
# Calculate the size of the temporary directory in MB | ||
if [ -d "$CURRENT_TEMP_DIR" ]; then | ||
# Use du to calculate the size. Suppress errors for directories with restricted permissions. | ||
TEMP_DIR_SIZE=$(du -sm "$CURRENT_TEMP_DIR" 2>/dev/null | awk '{print $1}') | ||
# Handle cases where du fails | ||
if [ -z "$TEMP_DIR_SIZE" ]; then | ||
TEMP_DIR_SIZE="Unknown" | ||
fi | ||
else | ||
TEMP_DIR_SIZE="Directory not found" | ||
fi | ||
|
||
# Log the data | ||
echo "$TIMESTAMP,$MEMORY_USAGE_MB,$MEMORY_LIMIT_MB,\"$ACTIVE_TESTS\",$TEMP_DIR_SIZE" >> "$LOG_FILE" | ||
|
||
# Wait for the next poll | ||
sleep "$POLL_INTERVAL" | ||
done |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.