Files
photoBooth/photobooth-app/script/script_memory.sh
T
admin 31f4023f16
🚀 Deploy — JH Photomaton / 🔍 Vérification (push) Has been cancelled
🚀 Deploy — JH Photomaton / 🍓 Deploy sur le Pi (push) Has been cancelled
chore: fichiers modifiés sessions précédentes
2026-07-17 17:19:57 +02:00

68 lines
1.7 KiB
Bash

#!/bin/bash
# Output CSV file
CSV_FILE="memory_log.csv"
# Process names to track
PROCESSES_TO_TRACK=("photobooth" "chromium" "firefox") # Add more as needed
# Create system memory CSV if it doesn't exist
if [ ! -f "$MEM_LOG" ]; then
echo "timestamp,total_MB,used_MB,free_MB,shared_MB,buff/cache_MB,available_MB" > "$MEM_LOG"
fi
# Create individual CSVs for each process name if missing
for pname in "${PROCESSES_TO_TRACK[@]}"; do
fname="process_${pname}.csv"
if [ ! -f "$fname" ]; then
echo "timestamp,process_name,pid,%mem,rss_MB,command" > "$fname"
fi
done
# Initialize CSV file with headers
if [ ! -f "$CSV_FILE" ]; then
echo "timestamp,total_MB,used_MB,free_MB,shared_MB,cache_MB,available_MB" > "$CSV_FILE"
fi
# Function to get memory usage and append to CSV
# Adjust "Speicher" to Mem or Swap, see free -m
log_mem_usage() {
free -m | awk -v tstamp="$(date '+%Y-%m-%d %H:%M:%S')" '
/^Mem:/ {
printf "%s,%s,%s,%s,%s,%s,%s\n", tstamp, $2, $3, $4, $5, $6, $7
}
' >> "$CSV_FILE"
}
log_process_mem() {
timestamp="$(date '+%Y-%m-%d %H:%M:%S')"
for pname in "${PROCESSES_TO_TRACK[@]}"; do
outfile="process_${pname}.csv"
ps -C "$pname" -o pid,rss,cmd --no-headers | while read -r pid rss cmd; do
# Convert RSS from KB to integer MB
rss_mb=$((rss / 1024))
echo "$timestamp,$pname,$pid,$rss_mb,\"$cmd\"" >> "$outfile"
done
done
}
# Trap Ctrl+C and exit gracefully
trap "echo -e '\nExiting on Ctrl+C'; exit 0" SIGINT
while true; do
free -h
log_mem_usage
log_process_mem
# curl -X 'GET' \
# 'http://localhost:8083/api/actions/image/0' \
# -H 'accept: application/json'
# echo
sleep 2
done