-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlogging_config.sh
More file actions
executable file
·104 lines (91 loc) · 3.06 KB
/
logging_config.sh
File metadata and controls
executable file
·104 lines (91 loc) · 3.06 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
#!/bin/bash
# GPU Performance Testing - Logging Configuration
# Optimized for stable system operation
# Global logging configuration
export LOG_LEVEL="${LOG_LEVEL:-minimal}" # minimal, standard, verbose
export LOG_TO_FILE="${LOG_TO_FILE:-false}"
export LOG_DIR="${LOG_DIR:-/tmp/gpu_logs}"
export LOG_ROTATE="${LOG_ROTATE:-true}"
export MAX_LOG_SIZE="${MAX_LOG_SIZE:-10M}"
# Initialize logging system
init_logging() {
case "$LOG_LEVEL" in
"minimal")
export ENABLE_CONSOLE_LOG=false
export ENABLE_FILE_LOG=false
export ENABLE_ERROR_LOG=true
;;
"standard")
export ENABLE_CONSOLE_LOG=true
export ENABLE_FILE_LOG=false
export ENABLE_ERROR_LOG=true
;;
"verbose")
export ENABLE_CONSOLE_LOG=true
export ENABLE_FILE_LOG=true
export ENABLE_ERROR_LOG=true
;;
esac
# Create log directory if file logging is enabled
if [[ "$ENABLE_FILE_LOG" == "true" && "$LOG_TO_FILE" == "true" ]]; then
mkdir -p "$LOG_DIR"
fi
}
# Optimized logging functions
log_minimal() {
# Only errors and critical information
[[ "$ENABLE_ERROR_LOG" == "true" ]] && echo "[ERROR] $*" >&2
}
log_standard() {
# Essential information only
[[ "$ENABLE_CONSOLE_LOG" == "true" ]] && echo "$*"
}
log_verbose() {
# Detailed information
[[ "$ENABLE_CONSOLE_LOG" == "true" ]] && echo "[VERBOSE] $*"
[[ "$ENABLE_FILE_LOG" == "true" && "$LOG_TO_FILE" == "true" ]] && echo "[$(date '+%H:%M:%S')] $*" >> "$LOG_DIR/gpu_monitor.log"
}
# Smart echo replacement
smart_echo() {
case "$LOG_LEVEL" in
"minimal")
# Only show critical GPU status
if [[ "$*" == *"ERROR"* || "$*" == *"CRITICAL"* || "$*" == *"Temperature"* ]]; then
echo "$*"
fi
;;
"standard")
# Show essential monitoring info
if [[ "$*" != *"VERBOSE"* && "$*" != *"DEBUG"* ]]; then
echo "$*"
fi
;;
"verbose")
# Show everything
echo "$*"
;;
esac
}
# Efficient GPU status (minimal output)
gpu_status_minimal() {
# Only show temperature and critical errors
if command -v sensors &> /dev/null; then
amd_temp=$(sensors | grep -i "edge" | head -1 | awk '{print $2}' | tr -d '+°C')
[[ -n "$amd_temp" ]] && echo "GPU: ${amd_temp}°C"
fi
# NVIDIA minimal check
if command -v nvidia-smi &> /dev/null; then
nvidia_temp=$(nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits 2>/dev/null)
[[ -n "$nvidia_temp" ]] && echo "NVIDIA: ${nvidia_temp}°C"
fi
}
# Log rotation for efficiency
rotate_logs() {
if [[ "$LOG_ROTATE" == "true" && -d "$LOG_DIR" ]]; then
find "$LOG_DIR" -type f -name "*.log" -size +$MAX_LOG_SIZE -exec truncate -s 0 {} \;
fi
}
# Export functions for use in other scripts
declare -f smart_echo log_minimal log_standard log_verbose gpu_status_minimal rotate_logs
# Initialize on source
init_logging