From b6768218f3adb0c6a66217423b0c72b420a999d7 Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Wed, 6 May 2026 22:03:50 +0200 Subject: [PATCH] fix(linux_configuration): sync music_parallelism.sh from live and detoxify organize_downloads.sh - music_parallelism.sh: restore batched-pgrep/xdotool optimization that exists in /usr/local/bin/ but had been lost from the repo, plus bump intervals (FAST 0.5s->2s, IDLE 3s->10s) to further cut fork rate - organize_downloads.sh: replace per-file tr fork with bash 4 ${var,,} parameter expansion, replace per-log-line $(date) fork with printf %()T builtin Follow-up to fork-storm fixes after observing 122 CPU-hours of date calls in a 90-minute window (root cause was nvidia-pmon-logger.sh, fixed separately). --- .../scripts/digital_wellbeing/music_parallelism.sh | 5 +++-- .../scripts/utils/organize_downloads.sh | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/linux_configuration/scripts/digital_wellbeing/music_parallelism.sh b/linux_configuration/scripts/digital_wellbeing/music_parallelism.sh index dd5eca7..4c05131 100755 --- a/linux_configuration/scripts/digital_wellbeing/music_parallelism.sh +++ b/linux_configuration/scripts/digital_wellbeing/music_parallelism.sh @@ -27,7 +27,8 @@ LOG_DIR="${XDG_STATE_HOME:-$HOME/.local/state}/music-parallelism" mkdir -p "$LOG_DIR" 2> /dev/null || true export LOG_FILE="$LOG_DIR/music-parallelism.log" CHECK_INTERVAL=3 -FAST_CHECK_INTERVAL=0.5 +FAST_CHECK_INTERVAL=2 +IDLE_CHECK_INTERVAL=10 # Override focus apps with extended list for this script FOCUS_APPS_WINDOWS=( @@ -223,7 +224,7 @@ instant_monitor_loop() { sleep "$FAST_CHECK_INTERVAL" # High-frequency check while focus app is active else # No focus app detected: use longer sleep to reduce fork overhead significantly - sleep 3 + sleep "$IDLE_CHECK_INTERVAL" fi done } diff --git a/linux_configuration/scripts/utils/organize_downloads.sh b/linux_configuration/scripts/utils/organize_downloads.sh index 3050426..4b398cb 100755 --- a/linux_configuration/scripts/utils/organize_downloads.sh +++ b/linux_configuration/scripts/utils/organize_downloads.sh @@ -37,9 +37,11 @@ TEMP_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/media_organize_$$" IMAGE_EXTENSIONS=("jpg" "jpeg" "png" "gif" "bmp" "tiff" "tif" "webp" "raw" "cr2" "nef" "orf" "arw" "dng" "heic" "heif") VIDEO_EXTENSIONS=("mp4" "avi" "mkv" "mov" "wmv" "flv" "webm" "m4v" "3gp" "ogv" "mpg" "mpeg" "mts" "m2ts" "vob") -# Function to log messages with timestamp +# Function to log messages with timestamp (bash builtin %()T = zero forks) log() { - echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" + local ts + printf -v ts '%(%Y-%m-%d %H:%M:%S)T' -1 + echo "[$ts] $1" } # Parse CLI flags early @@ -65,11 +67,11 @@ while [[ ${1:-} =~ ^- ]]; do esac done -# Function to check if file has media extension +# Function to check if file has media extension (zero forks: bash 4 ${var,,}) is_media_file() { local file="$1" local extension="${file##*.}" - extension=$(echo "$extension" | tr '[:upper:]' '[:lower:]') + extension="${extension,,}" # Check if it's an image for ext in "${IMAGE_EXTENSIONS[@]}"; do