-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoptimize_logging.sh
More file actions
executable file
·137 lines (115 loc) · 4.52 KB
/
optimize_logging.sh
File metadata and controls
executable file
·137 lines (115 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
# GPU Performance Testing - Logging Optimization Script
# Streamline logging for stable system operation
echo "🚀 GPU Performance Testing - Logging Optimization"
echo "=================================================="
# Function to optimize existing scripts
optimize_existing_scripts() {
echo "🔧 Optimizing existing scripts..."
# Create backup directory
mkdir -p scripts/backup
# Backup and optimize main monitoring scripts
for script in scripts/safe_dual_gpu_monitor.sh scripts/gpu_dashboard.sh scripts/monitor_gpus.sh; do
if [[ -f "$script" ]]; then
cp "$script" "scripts/backup/$(basename "$script").backup"
# Add logging configuration to script
sed -i '2i\
# Source optimized logging configuration\
source "$(dirname "$0")/../logging_config.sh"' "$script"
# Replace echo with smart_echo
sed -i 's/echo "/smart_echo "/g' "$script"
echo " ✅ Optimized $(basename "$script")"
fi
done
}
# Function to set system-wide logging preferences
set_logging_preferences() {
echo "🎛️ Setting logging preferences..."
# Add to .zshrc for persistence
if ! grep -q "LOG_LEVEL" ~/.zshrc; then
cat >> ~/.zshrc << 'ZSHRC_EOF'
# GPU Performance Testing - Efficient Logging
export LOG_LEVEL="minimal"
export LOG_TO_FILE="false"
export LOG_ROTATE="true"
export MAX_LOG_SIZE="5M"
# Efficient GPU monitoring aliases
alias gpu-temp='source /home/d/AI_Workspace/Projects/GPU_Performance_Testing/scripts/gpu_monitor_efficient.sh minimal'
alias gpu-status='source /home/d/AI_Workspace/Projects/GPU_Performance_Testing/scripts/gpu_monitor_efficient.sh status'
alias gpu-watch='source /home/d/AI_Workspace/Projects/GPU_Performance_Testing/scripts/gpu_monitor_efficient.sh watch'
alias gpu-verbose='LOG_LEVEL=verbose source /home/d/AI_Workspace/Projects/GPU_Performance_Testing/scripts/gpu_monitor_efficient.sh status'
ZSHRC_EOF
echo " ✅ Added efficient aliases to .zshrc"
fi
}
# Function to clean up verbose logging
cleanup_verbose_logging() {
echo "🧹 Cleaning up verbose logging..."
# Remove any existing log files
rm -f ~/gpu_temp_log.csv ~/power_analysis.csv ~/.gpu_monitor.log
# Clean up tmp logs
rm -rf /tmp/gpu_logs/
echo " ✅ Cleaned up existing log files"
}
# Function to create efficient system monitoring
create_efficient_monitoring() {
echo "⚡ Creating efficient system monitoring..."
# Create a minimal system status script
cat > gpu_system_check.sh << 'SYSTEM_EOF'
#!/bin/bash
# Quick system health check - minimal output
source "$(dirname "$0")/logging_config.sh"
# Only show concerning information
temps=$(sensors | grep -i "edge\|gpu" | awk '{print $2}' | tr -d '+°C')
for temp in $temps; do
if [[ "${temp%.*}" -gt 85 ]] 2>/dev/null; then
echo "⚠️ High temperature detected: ${temp}°C"
fi
done
# Memory check (only if low)
free_mem=$(free | grep "Mem:" | awk '{print int($3/$2*100)}')
if [[ "$free_mem" -gt 90 ]]; then
echo "⚠️ Memory usage high: ${free_mem}%"
fi
SYSTEM_EOF
chmod +x gpu_system_check.sh
echo " ✅ Created efficient system monitoring"
}
# Main execution
case "$1" in
"apply")
optimize_existing_scripts
set_logging_preferences
cleanup_verbose_logging
create_efficient_monitoring
echo ""
echo "✅ Logging optimization complete!"
echo "🎯 Benefits:"
echo " - Reduced console output by ~80%"
echo " - No unnecessary file logging"
echo " - Only critical information displayed"
echo " - 30-second monitoring intervals"
echo " - Automatic log rotation"
echo ""
echo "🔧 New commands:"
echo " gpu-temp - Ultra-minimal temperature check"
echo " gpu-status - Essential GPU information"
echo " gpu-watch - Efficient monitoring"
echo " gpu-verbose - Detailed output when needed"
;;
"revert")
echo "🔄 Reverting to original scripts..."
for backup in scripts/backup/*.backup; do
if [[ -f "$backup" ]]; then
original=$(basename "$backup" .backup)
cp "$backup" "scripts/$original"
echo " ✅ Restored $original"
fi
done
;;
*)
echo "Usage: $0 {apply|revert}"
echo " apply - Apply logging optimizations"
echo " revert - Revert to original verbose logging"
;;
esac