-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added utility for measuring peak memory requirements.
- Loading branch information
jgillam
committed
Aug 22, 2023
1 parent
8956249
commit ddf2dda
Showing
2 changed files
with
30 additions
and
1 deletion.
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,24 @@ | ||
#!/bin/bash | ||
|
||
# Initialize peak memory usage variable for each container | ||
declare -A peak_memory_usage | ||
|
||
while true; do | ||
# Get the memory usage for all running containers | ||
docker_stats=$(docker stats --no-stream --format "{{.Name}} {{.MemUsage}}") | ||
|
||
# Process each line of the output | ||
while IFS= read -r line; do | ||
container_id=$(echo $line | awk '{print $1}') | ||
current_memory_usage=$(echo $line | awk '{print $2}' | sed 's/MiB//') | ||
|
||
# Compare with the peak memory usage and update if necessary | ||
if [[ ! ${peak_memory_usage[$container_id]} || $(echo "$current_memory_usage > ${peak_memory_usage[$container_id]}" | bc -l) -eq 1 ]]; then | ||
peak_memory_usage[$container_id]=$current_memory_usage | ||
echo "New peak memory usage for container $container_id: ${peak_memory_usage[$container_id]} MiB" | ||
fi | ||
done <<< "$docker_stats" | ||
|
||
# Wait for 1 second before checking again | ||
sleep 1 | ||
done |