forked from ekfriis/farmout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
farmoutSummary
executable file
·282 lines (217 loc) · 6.69 KB
/
farmoutSummary
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/bin/bash
#
# Usage:
# farmoutSummary <jobName>
# or
# farmoutSummary all
#
# Lists number of jobs that had
# return values == 0, and also != 0
#
# Michael Anderson
# www.hep.wisc.edu/~mbanderson
# Sept 07, 2007
##################################################
FARMOUT_USER=${FARMOUT_USER:-${USER}}
farmoutDir="/scratch/${FARMOUT_USER}"
dCacheDir="/hdfs/store/user/${FARMOUT_USER}"
##################################################
##################################################
printUsage() {
echo
echo "For more information:"
echo " farmoutSummary <jobName>"
echo " farmoutSummary all"
}
##################################################
##################################################
basename() {
# This shell function is faster than calling /bin/basename
path=$1
suffix=$2
path=${path##*/} # get everything after the final '/'
if [ ! -z $suffix ]; then
path=${path%$suffix}
fi
echo $path
}
##################################################
##################################################
# Check number of folders in user's dCache area.
# If there's too many folders, this will be too
# slow. So quit.
checkNumFolders() {
dirCount=`ls $dCacheDir | wc -l`
if [ "$dirCount" -gt 50 ]; then
echo "Too many folders (greater than 50) in"
echo " $dCacheDir"
echo "to summarize in reasonable time."
exit
fi
}
##################################################
##################################################
# Gives summary information about a workflow
# Example:
# $ farmoutSummary aTestThing-photonjetanalyzer
# 6.7M /scratch/mbanderson/aTestThing-photonjetanalyzer/
# 5 jobs with 5 normal terminations, 0 abnormal terminations, and 0 not done.
checkThisJob() {
dirCount=0
notDoneCount=0
goodCount=0
badCount=0
thisBaseDir=$1
echo -e `du -hs $thisBaseDir | awk '{print $1}'`" \c"
echo $thisBaseDir"/"
for dir in "$thisBaseDir/"*; do
# Store the name of this directory alone
dir=`basename $dir`
# Make sure this is a directory
if [[ -d "$thisBaseDir/$dir" ]]; then
# Increment Directory Count
dirCount=`expr $dirCount + 1`
# Store name of the log file
logFile="$thisBaseDir/$dir/$dir.log"
# Grab the return value for a terminated job
returnVal=`tail -12 "$logFile" | grep "termination" | awk '{print $6}' | cut -d")" -f1`
if [[ -n "$returnVal" ]]; then
if [[ "$returnVal" -eq "0" ]]; then
goodCount=`expr $goodCount + 1`
else
badCount=`expr $badCount + 1`
# Figure out the last host it ran on
# host=`grep "Job executing" "$logFile" | tail -1 | awk '{print $9}'`
# Print out the returnVal from host (should be optional)
# echo "Return value" $returnVal "from host" $host
fi
else
notDoneCount=`expr $notDoneCount + 1`
fi
fi
done
echo -e " "$dirCount "jobs with\c"
echo -e " "$goodCount "normal terminations,\c"
echo -e " "$badCount "abnormal terminations, and\c"
echo -e " "$notDoneCount "not done."
}
##################################################
##################################################
checkAllJobs() {
for jobDir in "$farmoutDir/"*; do
if [[ -d "$jobDir" && -e "$jobDir/submit" ]]; then
checkThisJob $jobDir
fi
done
}
##################################################
##################################################
listAllJobs() {
echo "In" $farmoutDir"/ on "$HOSTNAME
echo -e "\n"Jobs"\t"Job Name
dirCount=0
for jobDir in "$farmoutDir/"*; do
if [[ -d "$jobDir" && -e "$jobDir/submit" ]]; then
dirCount=`expr $dirCount + 1`
jobDir=`basename $jobDir`
#echo -e `du -hs $farmoutDir/$jobDir | awk '{print $1}'`"\c\t"
echo -e `ls $farmoutDir/$jobDir/ | wc | awk '{print $1}'`"\c"
echo -e "\t"$jobDir"\t"
fi
done
if [[ "$dirCount" -eq 0 ]]; then
echo -e "\t No available jobs."
fi
}
##################################################
##################################################
listCondorJobs() {
echo "Currently on condor:"
echo `condor_q "${FARMOUT_USER}" 2> /dev/null | tail -1`
echo
}
##################################################
##################################################
listDCacheFolders() {
echo
echo "In" $dCacheDir
echo ROOT
echo -e Files"\t"Job Name
dirCount=0
for jobDir in "$dCacheDir/"*; do
if [[ -d "$jobDir" ]]; then
dirCount=`expr $dirCount + 1`
jobDir=`basename $jobDir`
#echo -e `du -hs $dCacheDir/$jobDir | awk '{print $1}'`"\c\t"
echo -e `ls $dCacheDir/$jobDir/*.root | wc | awk '{print $1}'`"\c"
echo -e "\t"$jobDir"\t"
fi
done
}
##################################################
##################################################
# Looks for submit files on this machine
# and finds if there is corresponding jobs
# in the dCache folder.
#
# Example output:
# Submitted Completed
# Jobs ROOT Files Job Name
# 134 134 JetET80-photonjetanalyzer
# 25 13 PhotonJet20-200-photonjetanalyzer
# 11 11 RelValSingleElectronPt35-photonjetanalyzer
listSubAndOut() {
echo -e "Submit folder: $HOSTNAME:$farmoutDir \c"
echo -e `du -hs $farmoutDir | awk '{print $1}'`
echo -e "Output folder: $dCacheDir\n"
echo "Submitted Completed"
printf "%9s" "Jobs"
echo -e " "ROOT Files"\t"Job Name
dirCount=0
for jobDir in "$farmoutDir/"*; do
jobDir=`basename $jobDir`
if [[ -d "$farmoutDir/$jobDir" && -e "$farmoutDir/$jobDir/submit" ]]; then
# We have found a submitted job on this machine & its corresponding dCacheDir
dirCount=`expr $dirCount + 1`
# Print number of submitted jobs
#printf "%9s" "`ls -d $farmoutDir/$jobDir/*/ | wc | awk '{print $1}'`"
printf "%9s" "`find $farmoutDir/$jobDir/*/ -type d | wc -l `"
#printf "%9s" "`tail -8 $farmoutDir/$jobDir/submit | grep InitialDir | awk '{print $3}' | awk -F'-' '{print $2+1}'`"
# Print number of completed ROOT files
if [[ -d "$dCacheDir/$jobDir" ]]; then
#echo -e " "`ls $dCacheDir/$jobDir/*.root | wc | awk '{print $1}'`"\c"
#echo -e " "`find $dCacheDir/$jobDir/ -name \*.root | wc -l `"\c"
printf " %-12s" `find $dCacheDir/$jobDir/ -name \*.root | wc -l `
else
printf " %-12s" " "
fi
# Print the name of the job
echo -e "$jobDir\t"
fi
done
}
##################################################
##################################################
# Main method
if [ $# -ne 1 ]; then
#listAllJobs
#listDCacheFolders
listCondorJobs
checkNumFolders
listSubAndOut
printUsage
else
if [[ "$1" == "all" ]]; then
checkAllJobs
else
jobDir="$farmoutDir/$1"
# Make sure it is a valid job
if [[ -d "$jobDir" && -e "$jobDir/submit" ]]; then
checkThisJob "$jobDir"
else
echo $jobDir "is not a valid job to check!"
listAllJobs
printUsage
fi
fi
fi