-
Notifications
You must be signed in to change notification settings - Fork 72
/
debug.sh
129 lines (113 loc) · 3.81 KB
/
debug.sh
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
#!/bin/bash
# Debug bad jobs.
# Show which jobs did not finish successfully or normally, show their input files.
# Show warnings and errors in the logs of individual jobs.
TYPE="o2" # conversion, ali, o2
BAD=0
UNFINISHED=0
FILES=0
WARNINGS=0
ERRORS=0
# Identify a bad job (without output file or successful end).
IsBadJob() {
STRING="Dumping"
[ "$TYPE" == "ali" ] && STRING="long) 0"
[ -f "$DIRJOB/AnalysisResults.root" ] || return 0
tail -n 1 "$LOG" | grep -q "$STRING" && return 1 || return 0
}
# Identify an unfinished job (running, hanging, aborted).
IsUnfinishedJob() {
STRING="Dumping"
[ "$TYPE" == "ali" ] && STRING="long) 0"
tail -n 2 "$LOG" | grep -q "$STRING" && return 1 || return 0
}
# Print warnings in the log.
PrintWarnings() {
if [ "$TYPE" == "o2" ]; then
grep -q -e "\\[WARN\\]" -e "Warning in " "$LOG" && {
[ "$PRINTDIR" -eq 1 ] || { echo -e "\n$DIRJOB"; PRINTDIR=1; }
grep -e "\\[WARN\\]" -e "Warning in " "$LOG" | sort -u
}
elif [ "$TYPE" == "ali" ]; then
grep -q -e '^'"W-" -e '^'"Warning" "$LOG" && {
[ "$PRINTDIR" -eq 1 ] || { echo -e "\n$DIRJOB"; PRINTDIR=1; }
grep -e '^'"W-" -e '^'"Warning" "$LOG" | sort -u
}
fi
}
# Print errors in the log.
PrintErrors() {
if [ "$TYPE" == "o2" ]; then
grep -q -e "\\[ERROR\\]" -e "\\[FATAL\\]" -e "segmentation" -e "Segmentation" -e "command not found" -e "Error:" -e "Error in " "$LOG" && {
[ "$PRINTDIR" -eq 1 ] || { echo -e "\n$DIRJOB"; PRINTDIR=1; }
grep -e "\\[ERROR\\]" -e "\\[FATAL\\]" -e "segmentation" -e "Segmentation" -e "command not found" -e "Error:" -e "Error in " "$LOG" | sort -u
}
elif [ "$TYPE" == "ali" ]; then
grep -q -e '^'"E-" -e '^'"Error" -e '^'"F-" -e '^'"Fatal" -e "segmentation" -e "Segmentation" "$LOG" && {
[ "$PRINTDIR" -eq 1 ] || { echo -e "\n$DIRJOB"; PRINTDIR=1; }
grep -e '^'"E-" -e '^'"Error" -e '^'"F-" -e '^'"Fatal" -e "segmentation" -e "Segmentation" "$LOG" | sort -u
}
fi
}
# Print out syntax.
Help() {
echo "Usage: bash [<path>/]$(basename "$0") [-h] [-t TYPE] [-b [-u]] [-f] [-w] [-e]"
echo "TYPE: conversion, ali, o2 (o2 by default)"
echo "-b Show bad jobs (without output file or successful end)."
echo "-u Mark unfinished jobs (running, hanging, aborted). (Requires -b.)"
echo "-f Show input files of bad jobs."
echo "-w Show warnings (for all jobs)."
echo "-e Show errors (for all jobs)."
}
####################################################################################################
# Parse command line options.
while getopts ":ht:bufwe" opt; do
case ${opt} in
h)
Help; exit 0;;
t)
TYPE="$OPTARG";;
b)
BAD=1;;
u)
UNFINISHED=1;;
f)
FILES=1;;
w)
WARNINGS=1;;
e)
ERRORS=1;;
\?)
echo "Error: Invalid option: $OPTARG" 1>&2; Help; exit 1;;
:)
echo "Error: Invalid option: $OPTARG requires an argument." 1>&2; Help; exit 1;;
esac
done
[[ "$TYPE" != "o2" && "$TYPE" != "ali" && "$TYPE" != "conversion" ]] && { echo "Error: Unsupported type: $TYPE" 1>&2; exit 1; }
if ! [[ $BAD -eq 1 || $FILES -eq 1 || $WARNINGS -eq 1 || $ERRORS -eq 1 ]]; then
echo "Nothing to do"; Help; exit 0
fi
DIR="output_$TYPE"
[ -d "$DIR" ] || { echo "Error: Directory $DIR does not exist." 1>&2; exit 1; }
[ "$TYPE" == "conversion" ] && TYPE="ali"
# Loop over log files
for LOG in "$DIR"/*/log_*.log; do
DIRJOB="$(dirname "$LOG")"
PRINTDIR=0
IsBadJob && {
[ $BAD -eq 1 ] && {
TEXT="$DIRJOB"
[ $UNFINISHED -eq 1 ] && { IsUnfinishedJob && TEXT+=" unfinished"; }
if ! [[ $FILES -eq 1 || $WARNINGS -eq 1 || $ERRORS -eq 1 ]]; then
echo "$TEXT"
else
echo -e "\n$TEXT"
fi
PRINTDIR=1
}
[ $FILES -eq 1 ] && cat "$DIRJOB"/list_*.txt
}
[ $WARNINGS -eq 1 ] && PrintWarnings
[ $ERRORS -eq 1 ] && PrintErrors
done
exit 0