1 | #!/bin/ksh |
---|
2 | |
---|
3 | #************************************************************** |
---|
4 | # Author: Patrick Brockmann, Martial Mancip |
---|
5 | # Contact: Patrick.Brockmann__at__cea.fr Martial.Mancip__at__ipsl.jussieu.fr |
---|
6 | # $Revision:: $ Revision of last commit |
---|
7 | # $Author:: $ Author of last commit |
---|
8 | # $Date:: $ Date of last commit |
---|
9 | # IPSL (2006) |
---|
10 | # This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC |
---|
11 | # |
---|
12 | #************************************************************** |
---|
13 | |
---|
14 | #================================================== |
---|
15 | # The documentation of this file can be automatically generated |
---|
16 | # if you use the prefix #D- for comments to be extracted. |
---|
17 | # Extract with command: cat lib* | grep "^#D-" | cut -c "4-" |
---|
18 | #================================================== |
---|
19 | |
---|
20 | #================================================== |
---|
21 | # Add high level verbosity |
---|
22 | typeset -i Verbosity=${Verbosity:=3} |
---|
23 | |
---|
24 | #================================================== |
---|
25 | # DEBUG_debug |
---|
26 | # Add low level verbosity |
---|
27 | typeset DEBUG_debug=${DEBUG_debug:=false} |
---|
28 | |
---|
29 | #================================================== |
---|
30 | # GENERATE RANDOM ERROR ; only apply if ( ${DEBUG_debug} ) |
---|
31 | typeset RandomError=false |
---|
32 | |
---|
33 | # Stack file containing call tree will be stored there. |
---|
34 | if ( $DEBUG_debug ) ; then |
---|
35 | if [ X${TaskType} = Xcomputing ]; then |
---|
36 | typeset StackFileLocation=${StackFileLocation:=${PWD}} |
---|
37 | typeset StackFileName=computing.stack.$$ |
---|
38 | elif [ X${TaskType} = Xpost-processing ]; then |
---|
39 | typeset StackFileLocation=${POST_DIR:=${StackFileLocation}} |
---|
40 | typeset StackFileName=post-processing.stack.$$ |
---|
41 | elif [ X${TaskType} = Xchecking ]; then |
---|
42 | typeset StackFileLocation=${POST_DIR:=${PWD}} |
---|
43 | typeset StackFileName=checking.stack.$$ |
---|
44 | else |
---|
45 | typeset StackFileLocation=${POST_DIR:=${PWD}} |
---|
46 | typeset StackFileName=checking.stack.$$ |
---|
47 | fi |
---|
48 | |
---|
49 | if [ -f ${StackFileLocation}/${StackFileName} ] ; |
---|
50 | then |
---|
51 | echo "Stack of an libIGCM job :" >> ${StackFileLocation}/${StackFileName} |
---|
52 | else |
---|
53 | echo "Stack of an libIGCM job :" > ${StackFileLocation}/${StackFileName} |
---|
54 | fi |
---|
55 | fi |
---|
56 | |
---|
57 | #================================================== |
---|
58 | # NULL_STR |
---|
59 | # Default null string |
---|
60 | typeset -r NULL_STR="_0_" |
---|
61 | |
---|
62 | #================================================== |
---|
63 | # libIGCM_CurrentTag |
---|
64 | # Current libIGCM tag, check compatibilty with *.card |
---|
65 | typeset -r libIGCM_CurrentTag="1.0" |
---|
66 | |
---|
67 | #================================================== |
---|
68 | # Exit Flag (internal debug) |
---|
69 | # When true, end the master loop AFTER SAVES FILES |
---|
70 | ExitFlag=false |
---|
71 | |
---|
72 | #================================================== |
---|
73 | # Declare a stack of functions calls |
---|
74 | unset IGCM_debug_Stack |
---|
75 | unset IGCM_debug_StackArgs |
---|
76 | unset IGCM_debug_StackTiming |
---|
77 | IGCM_debug_Stack[0]=${NULL_STR} |
---|
78 | IGCM_debug_StackArgs[0]=${NULL_STR} |
---|
79 | IGCM_debug_StackTiming[0]=${NULL_STR} |
---|
80 | IGCM_debug_LenStack=0 |
---|
81 | |
---|
82 | #D-#================================================================== |
---|
83 | #D-function IGCM_debug_getDate_ms |
---|
84 | #D- * Purpose: Give number of milliseconds since 01-jan-1970 |
---|
85 | function IGCM_debug_getDate_ms |
---|
86 | { |
---|
87 | typeset nanosecs ms |
---|
88 | # nano secondes since 01-jan-1970 |
---|
89 | nanosecs=$( date +%s%N ) |
---|
90 | |
---|
91 | # truncate the last 6 digits to get milliseconds since 01-jan-1970 |
---|
92 | ms=${nanosecs:0:${#nanosecs}-6} |
---|
93 | |
---|
94 | echo "$ms" |
---|
95 | } |
---|
96 | |
---|
97 | #D-#================================================================== |
---|
98 | #D-function IGCM_debug_sizeOfTabContent |
---|
99 | #D- * Purpose: Give sumed size of a list of files |
---|
100 | #D- * Usage: IGCM_debug_sizeOfTabContent entityList destination |
---|
101 | #D- * where entityList is a list of files or directory |
---|
102 | #D- * where dest is either a directory or a file name |
---|
103 | function IGCM_debug_sizeOfTabContent |
---|
104 | { |
---|
105 | typeset entityListe destination iEntity sizeKo sumSizeKo sumSizeMo |
---|
106 | |
---|
107 | eval set +A entityListe \${${1}} |
---|
108 | destination=${2} |
---|
109 | sumSizeKo=0 |
---|
110 | |
---|
111 | # Here we will try to compute size (file or directory size) from local path and not from archive. |
---|
112 | for ((i = 0; i < ${#entityListe[*]}; i += 1)) ; do |
---|
113 | if [ -f ${entityListe[$i]} ] ; then |
---|
114 | # One file or a bunch of files has been copied without renaming from a visible filesystem |
---|
115 | iEntity=${entityListe[$i]} |
---|
116 | elif [ -f ${entityListe[$i]##/*/} ] ; then |
---|
117 | # One file or a bunch of files has been copied without renaming from an non visible filesystem |
---|
118 | # remove path /home/login/../ from entityListe elements |
---|
119 | iEntity=${entityListe[$i]##/*/} |
---|
120 | elif [ -f ${destination} ] ; then |
---|
121 | # a file has been copied and renamed |
---|
122 | iEntity=${destination} |
---|
123 | elif [ -f ${destination}/${entityListe[$i]##/*/} ] ; then |
---|
124 | # a copy in a directory but not in ${PWD} |
---|
125 | iEntity=${destination}/${entityListe[$i]##/*/} |
---|
126 | elif [ -d ${entityListe[$i]} ] ; then |
---|
127 | # a directory has been copied from a non remote place |
---|
128 | iEntity=${entityListe[$i]} |
---|
129 | elif [ -d ${destination}/${entityListe[$i]##/*/} ] ; then |
---|
130 | # a directory has been copied from a remote archive and not renamed |
---|
131 | iEntity=${destination}/${entityListe[$i]##/*/} |
---|
132 | elif [ -d ${destination} ] ; then |
---|
133 | # a directory has been copied from a remote archive and renamed |
---|
134 | iEntity=${destination} |
---|
135 | fi |
---|
136 | sizeKo=$( du --apparent-size -sk ${iEntity} | gawk '{print $1}' ) |
---|
137 | sumSizeKo=$(( $sumSizeKo + $sizeKo )) |
---|
138 | done |
---|
139 | sumSizeMo=$( echo "scale=6;${sumSizeKo}/1024" | bc ) |
---|
140 | echo "${sumSizeKo}|${sumSizeMo}" |
---|
141 | } |
---|
142 | |
---|
143 | #D-#================================================================== |
---|
144 | #D-function IGCM_debug_SendAMQP |
---|
145 | #D- * Purpose: Send body; encoded body and config.card to rabbitMQ |
---|
146 | function IGCM_debug_sendAMQP |
---|
147 | { |
---|
148 | typeset decal first additionnalOption encodedBody |
---|
149 | |
---|
150 | # Encode message Body |
---|
151 | encodedBody=$( echo "${Body}" | base64 -w 0 ) |
---|
152 | |
---|
153 | # Send config.card ? |
---|
154 | if [ X${1} = Xactivate ] ; then |
---|
155 | # Encode config.card |
---|
156 | cat ${SUBMIT_DIR}/config.card | base64 -w 0 > ${SUBMIT_DIR}/config.card.base64 |
---|
157 | # Prepare additionnal option |
---|
158 | additionnalOption="-f ${SUBMIT_DIR}/config.card.base64" |
---|
159 | else |
---|
160 | additionnalOption= |
---|
161 | fi |
---|
162 | |
---|
163 | # Only cosmetics : stack file |
---|
164 | decal=0 |
---|
165 | while [ ${decal} -lt ${IGCM_debug_LenStack} ]; do |
---|
166 | printf ' ' >> ${StackFileLocation}/${StackFileName} |
---|
167 | (( decal = decal + 1 )) |
---|
168 | done |
---|
169 | # Log to stack file |
---|
170 | echo sendAMQPMsg -h localhost -p 5672 ${additionnalOption} -b "${Body}" >> ${StackFileLocation}/${StackFileName} |
---|
171 | |
---|
172 | # Log separately AMQP send message command |
---|
173 | echo sendAMQPMsg -h localhost -p 5672 ${additionnalOption} -b ${encodedBody} >> /tmp/send.AMQP.${jobid}.history.txt |
---|
174 | |
---|
175 | # Send the message |
---|
176 | sendAMQPMsg -h localhost -p 5672 ${additionnalOption} -b ${encodedBody} |
---|
177 | status=$? |
---|
178 | if [ ${status} -gt 0 ] ; then |
---|
179 | IGCM_debug_Print 2 "IGCM_debug_Push/PopStack/ActivateBigBro : command sendAMQPMsg failed error code ${status}" |
---|
180 | echo sendAMQPMsg -h localhost -p 5672 -b "${Body}" |
---|
181 | exit |
---|
182 | fi |
---|
183 | } |
---|
184 | |
---|
185 | #D-#================================================================== |
---|
186 | #D-function IGCM_debug_CallStack |
---|
187 | #D-* Purpose: Print the call stack tree from the oldest to the youngest (opposite of the display standard) |
---|
188 | #D- |
---|
189 | function IGCM_debug_CallStack { |
---|
190 | if ( $DEBUG_debug ) ; then |
---|
191 | # Cosmetics |
---|
192 | typeset i decal |
---|
193 | i=0 |
---|
194 | until [ $i -eq ${IGCM_debug_LenStack} ]; do |
---|
195 | decal=0 |
---|
196 | until [ $decal -eq ${i} ]; do |
---|
197 | printf -- ' ' |
---|
198 | (( decal = decal + 1 )) |
---|
199 | done |
---|
200 | echo "$i - ${IGCM_debug_Stack[$(( $IGCM_debug_LenStack-$i-1 ))]}" "(${IGCM_debug_StackArgs[$(( $IGCM_debug_LenStack-$i-1 ))]})" |
---|
201 | ((i = i + 1)) |
---|
202 | done |
---|
203 | fi |
---|
204 | } |
---|
205 | |
---|
206 | #D-#================================================================== |
---|
207 | #D-function IGCM_debug_PushStack |
---|
208 | #D-* Purpose: Push a function name in the stack |
---|
209 | #D- |
---|
210 | function IGCM_debug_PushStack { |
---|
211 | if ( $DEBUG_debug ) ; then |
---|
212 | typeset decal inputs startTime_ms |
---|
213 | |
---|
214 | # Only cosmetics : stack file |
---|
215 | echo >> ${StackFileLocation}/${StackFileName} |
---|
216 | decal=0 |
---|
217 | while [ ${decal} -lt ${IGCM_debug_LenStack} ]; do |
---|
218 | printf ' ' >> ${StackFileLocation}/${StackFileName} |
---|
219 | (( decal = decal + 1 )) |
---|
220 | done |
---|
221 | |
---|
222 | # Fill the stack file |
---|
223 | echo "> ${IGCM_debug_LenStack} : ${@}" >> ${StackFileLocation}/${StackFileName} |
---|
224 | |
---|
225 | # Save input list in an indexed array |
---|
226 | INPUTS=( $@ ) |
---|
227 | |
---|
228 | # Get timing information |
---|
229 | startTime_ms=$( IGCM_debug_getDate_ms ) |
---|
230 | |
---|
231 | # We add function call name on beginning of the stack |
---|
232 | set +A IGCM_debug_Stack -- ${1} ${IGCM_debug_Stack[*]} |
---|
233 | |
---|
234 | # Save timing in milliseconds in an indexed array |
---|
235 | set +A IGCM_debug_StackTiming -- ${startTime_ms} ${IGCM_debug_StackTiming[*]} |
---|
236 | |
---|
237 | # We include the "null" Args in the beginning of the StackArgs |
---|
238 | set +A IGCM_debug_StackArgs ${NULL_STR} ${IGCM_debug_StackArgs[*]} |
---|
239 | |
---|
240 | # Then, we shift StackArgs tabular |
---|
241 | if [ $# -gt 1 ]; then |
---|
242 | IGCM_debug_StackArgs[0]=$(echo ${INPUTS[*]:1} | sed -e "s/\ /,/g" ) |
---|
243 | fi |
---|
244 | |
---|
245 | if [ X${ActivateBigBro} = Xtrue ] ; then |
---|
246 | # RabbitMQ message code |
---|
247 | code=2000 |
---|
248 | # RabbitMQ message body |
---|
249 | Body=$( echo "{\"code\":\"${code}\",\"simuid\":\"${simuid}\",\"jobid\":\"${jobid}\",\"nesting\":\"${IGCM_debug_LenStack}\",\"command\":\"${INPUTS[*]}\",\"timestamp\":\"$( date +"%Y-%m-%d-%T" )\"}" ) |
---|
250 | # Fill the rabbitMQ queue |
---|
251 | IGCM_debug_sendAMQP |
---|
252 | fi |
---|
253 | |
---|
254 | # Increment LenStack |
---|
255 | (( IGCM_debug_LenStack = IGCM_debug_LenStack + 1 )) |
---|
256 | |
---|
257 | #IGCM_debug_CallStack |
---|
258 | fi |
---|
259 | } |
---|
260 | |
---|
261 | #D-#================================================================== |
---|
262 | #D-function IGCM_debug_PopStack |
---|
263 | #D-* Purpose: Pop a function name in the stack |
---|
264 | #D- |
---|
265 | function IGCM_debug_PopStack { |
---|
266 | if ( $DEBUG_debug ) ; then |
---|
267 | typeset i decal command arguments startTime_ms endTime_ms |
---|
268 | typeset instrumentation dest prefix |
---|
269 | # they are not typeset because they are send "by adress" to son functions |
---|
270 | # we unset them to avoid "memory effect" |
---|
271 | unset fileList source |
---|
272 | |
---|
273 | # INTRODUCE SIMPLE ERROR GENERATOR TO TEST SUPERVISOR |
---|
274 | # PROBABILITY ERROR IS 0.0001 PER COMMAND OR FUNCTION CALL |
---|
275 | # THERE ARE ~500 COMMAND OR FUNCTION CALL PER PERIOD |
---|
276 | if ( ${RandomError} ) ; then |
---|
277 | if [ $((RANDOM%10000)) -le 10 ] ; then |
---|
278 | IGCM_debug_Print 1 "Random error has been triggered" |
---|
279 | echo "RANDOM ERROR" >> ${StackFileLocation}/${StackFileName} |
---|
280 | ExitFlag=true |
---|
281 | fi |
---|
282 | fi |
---|
283 | |
---|
284 | if [ "${IGCM_debug_Stack[0]}" = "${1}" ]; then |
---|
285 | # Everything is cool |
---|
286 | |
---|
287 | # Get timing information |
---|
288 | endTime_ms=$( IGCM_debug_getDate_ms ) |
---|
289 | |
---|
290 | # Save Stack information before poping the stack |
---|
291 | command=${IGCM_debug_Stack[0]} |
---|
292 | |
---|
293 | # Go from comma separated (list) to space separated in an array |
---|
294 | set -A arguments $( echo ${IGCM_debug_StackArgs[0]} | sed -e "s/,/\ /g" ) |
---|
295 | |
---|
296 | # Save Stack information before poping the stack |
---|
297 | startTime_ms=${IGCM_debug_StackTiming[0]} |
---|
298 | |
---|
299 | # Pop the stack |
---|
300 | (( IGCM_debug_LenStack = IGCM_debug_LenStack - 1 )) |
---|
301 | set -A IGCM_debug_Stack -- ${IGCM_debug_Stack[*]:1} |
---|
302 | set -A IGCM_debug_StackArgs -- ${IGCM_debug_StackArgs[*]:1} |
---|
303 | set -A IGCM_debug_StackTiming -- ${IGCM_debug_StackTiming[*]:1} |
---|
304 | else |
---|
305 | echo 'IGCM_debug_Exit : stack is corrupted ! LenStack =' ${IGCM_debug_LenStack} |
---|
306 | IGCM_debug_Exit $@ |
---|
307 | fi |
---|
308 | |
---|
309 | # Special actions depending on command to prepare IGCM_debug_PrintInfosActions call |
---|
310 | # We are interested in: |
---|
311 | # 0. Which command performs the work |
---|
312 | # 1. Size of entity we are working with |
---|
313 | # 2. Where are we reading |
---|
314 | # 3. Where are we writing |
---|
315 | # 4. How long it took |
---|
316 | |
---|
317 | instrumentation=false |
---|
318 | |
---|
319 | case ${command} in |
---|
320 | # Classical copy (only files are given to IGCM_sys_Cp as options) |
---|
321 | IGCM_sys_Cp) |
---|
322 | instrumentation=true |
---|
323 | # All but the latest |
---|
324 | fileList=${arguments[*]:0:${#arguments[*]}-1} |
---|
325 | # just need the first file to get the directory |
---|
326 | source=${arguments[0]} |
---|
327 | # Nothing but the latest |
---|
328 | dest=${arguments[${#arguments[*]}-1]} |
---|
329 | # Size of file whose name are stored in a list |
---|
330 | entitySize=$( IGCM_debug_sizeOfTabContent fileList ${dest} ) |
---|
331 | ;; |
---|
332 | |
---|
333 | # Copy from archive machine or from buffer |
---|
334 | IGCM_sys_Get|IGCM_sys_GetBuffer) |
---|
335 | instrumentation=true |
---|
336 | if [ ${#arguments[*]} -eq 2 ] ; then |
---|
337 | source=${arguments[0]} |
---|
338 | dest=${arguments[1]} |
---|
339 | # Size of file whose name are stored in a variable |
---|
340 | entitySize=$( IGCM_debug_sizeOfTabContent source ${dest} ) |
---|
341 | elif ( [ ${#arguments[*]} -eq 3 ] && [ ${arguments[0]} = '/l' ] ) ; then |
---|
342 | # IGCM_sys_Get /l liste_file[*] /ccc/scratch/cont003/dsm/p86denv/RUN_DIR/985998_14754/ |
---|
343 | # Keep the array name hosting the all list |
---|
344 | eval set +A fileList \${${arguments[1]}} |
---|
345 | # just need the first file to get the directory |
---|
346 | source=${fileList[0]} |
---|
347 | dest=${arguments[2]} |
---|
348 | # Size of file whose name are stored in a list |
---|
349 | entitySize=$( IGCM_debug_sizeOfTabContent fileList[*] ${dest} ) |
---|
350 | elif [ [ ${#arguments[*]} -ge 3 ] ; then |
---|
351 | # All but the latest |
---|
352 | fileList=${arguments[*]:0:${#arguments[*]}-1} |
---|
353 | # just need the first file to get the directory |
---|
354 | source=${arguments[0]} |
---|
355 | # Nothing but the latest |
---|
356 | dest=${arguments[${#arguments[*]}-1]} |
---|
357 | # Size of file whose name are stored in a list |
---|
358 | entitySize=$( IGCM_debug_sizeOfTabContent fileList ${dest} ) |
---|
359 | fi |
---|
360 | ;; |
---|
361 | |
---|
362 | # Copy from compute node or copy to archive/buffer |
---|
363 | IGCM_sys_Get_Master|IGCM_sys_Get_Dir|IGCM_sys_Put_Out|IGCM_sys_PutBuffer_Out) |
---|
364 | instrumentation=true |
---|
365 | source=${arguments[0]} |
---|
366 | dest=${arguments[1]} |
---|
367 | # Size of file whose name are stored in a variable |
---|
368 | entitySize=$( IGCM_debug_sizeOfTabContent source ${dest} ) |
---|
369 | ;; |
---|
370 | |
---|
371 | # Rebuild command |
---|
372 | IGCM_sys_rebuild|IGCM_sys_rebuild_station) |
---|
373 | instrumentation=true |
---|
374 | # All but the first |
---|
375 | fileList=${arguments[*]:1:${#arguments[*]}-1} |
---|
376 | # just need a file to get the directory |
---|
377 | source=${arguments[1]} |
---|
378 | # Nothing but the first |
---|
379 | dest=${arguments[0]} |
---|
380 | # Size of file whose name are stored in a list |
---|
381 | entitySize=$( IGCM_debug_sizeOfTabContent fileList ${dest} ) |
---|
382 | ;; |
---|
383 | |
---|
384 | # NCO commands |
---|
385 | IGCM_sys_ncrcat|IGCM_sys_ncecat|IGCM_sys_ncra|IGCM_sys_ncks|IGCM_sys_cdo) |
---|
386 | # Example of what we want to catch : only filenames in those command lines |
---|
387 | # IGCM_sys_ncrcat -O -v ${list_var_final_ncrcat} ${OUT_SE[*]} ${RESULT_SE} |
---|
388 | # IGCM_sys_ncrcat --hst -v ${liste_coord}${var} ${file1} ${liste_file_tmp[*]} ${file_out} |
---|
389 | # IGCM_sys_ncrcat -p ${dir} ${liste_file_tmp} --output ${output} |
---|
390 | # IGCM_sys_ncrcat -x -v ${list_var} -p ${dir} ${liste_file_tmp} --output ${output} |
---|
391 | instrumentation=true |
---|
392 | keepGoing=true |
---|
393 | prefix=. |
---|
394 | i=0 |
---|
395 | while ( ${keepGoing} ) ; do |
---|
396 | # the last one is not interesting |
---|
397 | if [ ${i} -eq ${#arguments[*]}-1 ] ; then |
---|
398 | keepGoing=false |
---|
399 | # look after "-p" option. Path prefix is the following arguments |
---|
400 | elif [ ${arguments[${i}]} = "-p" ] ; then |
---|
401 | ((i = i + 1)) |
---|
402 | prefix=${arguments[${i}]} |
---|
403 | ((i = i + 1)) |
---|
404 | elif [ ${i} -eq ${#arguments[*]}-1 ] ; then |
---|
405 | keepGoing=false |
---|
406 | # looking for files |
---|
407 | elif [ -f ${prefix}/${arguments[${i}]} ] ; then |
---|
408 | fileList="${fileList} ${prefix}/${arguments[${i}]}" |
---|
409 | ((i = i + 1)) |
---|
410 | # other options are not interesting |
---|
411 | else |
---|
412 | ((i = i + 1)) |
---|
413 | fi |
---|
414 | done |
---|
415 | |
---|
416 | # i value is at least 1 |
---|
417 | # just need one file to get the directory |
---|
418 | source=$( echo ${fileList} | gawk '{print $1}' ) |
---|
419 | # Nothing but the latest |
---|
420 | dest=${arguments[${#arguments[*]}-1]} |
---|
421 | # Size of file whose name are stored in a list |
---|
422 | entitySize=$( IGCM_debug_sizeOfTabContent fileList ${dest} ) |
---|
423 | ;; |
---|
424 | esac |
---|
425 | |
---|
426 | # Print information related to instrumentation |
---|
427 | ( ${instrumentation} ) && IGCM_debug_PrintInfosActions ${command} ${entitySize} ${startTime_ms} ${endTime_ms} ${dest} ${source} |
---|
428 | |
---|
429 | # Only cosmetics : stack file |
---|
430 | decal=0 |
---|
431 | while [ ${decal} -lt ${IGCM_debug_LenStack} ]; do |
---|
432 | printf ' ' >> ${StackFileLocation}/${StackFileName} |
---|
433 | (( decal = decal + 1 )) |
---|
434 | done |
---|
435 | |
---|
436 | if ( ${ExitFlag} ) ; then |
---|
437 | # Inform the stack file |
---|
438 | echo '!!! ExitFlag has been activated !!!' >> ${StackFileLocation}/${StackFileName} |
---|
439 | |
---|
440 | if [ X${ActivateBigBro} = Xtrue ] ; then |
---|
441 | # RabbitMQ message code |
---|
442 | code=9000 |
---|
443 | # RabbitMQ message body |
---|
444 | Body=$( echo "{\"code\":\"${code}\",\"simuid\":\"${simuid}\",\"jobid\":\"${jobid}\",\"status\":\"NOK\",\"out\":\"true\",\"nesting\":\"${IGCM_debug_LenStack}\",\"command\":\"${INPUTS[*]}\",\"timestamp\":\"$( date +"%Y-%m-%d-%T" )\"}" ) |
---|
445 | # Fill the rabbitMQ queue |
---|
446 | IGCM_debug_sendAMQP |
---|
447 | fi |
---|
448 | else |
---|
449 | # Inform the stack file |
---|
450 | echo "< ${IGCM_debug_LenStack} : ${@}" >> ${StackFileLocation}/${StackFileName} |
---|
451 | if [ X${ActivateBigBro} = Xtrue ] ; then |
---|
452 | # RabbitMQ message code |
---|
453 | code=3000 |
---|
454 | # RabbitMQ message body |
---|
455 | Body=$( echo "{\"code\":\"${code}\",\"simuid\":\"${simuid}\",\"jobid\":\"${jobid}\",\"status\":\"OK\",\"out\":\"true\",\"nesting\":\"${IGCM_debug_LenStack}\",\"command\":\"${INPUTS[*]}\",\"timestamp\":\"$( date +"%Y-%m-%d-%T" )\"}" ) |
---|
456 | # Fill the rabbitMQ queue |
---|
457 | IGCM_debug_sendAMQP |
---|
458 | fi |
---|
459 | fi |
---|
460 | |
---|
461 | # Reset array if necessary |
---|
462 | if [ ${IGCM_debug_LenStack} = 0 ]; then |
---|
463 | #echo |
---|
464 | #IGCM_debug_Print 3 "Clean stack array" |
---|
465 | #echo |
---|
466 | unset IGCM_debug_Stack |
---|
467 | unset IGCM_debug_StackArgs |
---|
468 | unset IGCM_debug_StackTiming |
---|
469 | IGCM_debug_Stack[0]=${NULL_STR} |
---|
470 | IGCM_debug_StackArgs[0]=${NULL_STR} |
---|
471 | IGCM_debug_StackTiming[0]=${NULL_STR} |
---|
472 | fi |
---|
473 | fi |
---|
474 | #IGCM_debug_CallStack |
---|
475 | } |
---|
476 | |
---|
477 | #D-#================================================================== |
---|
478 | #D-function IGCM_debug_ActivateBigBro |
---|
479 | #D-* Purpose: switch rabbitMQ on |
---|
480 | #D- |
---|
481 | function IGCM_debug_ActivateBigBro { |
---|
482 | IGCM_debug_PushStack "IGCM_debug_ActivateBigBro" |
---|
483 | |
---|
484 | if [ X${BigBrother} = Xtrue ] ; then |
---|
485 | # ID to identify a simulation |
---|
486 | simuid=${config_UserChoices_JobName}.${config_UserChoices_ExperimentName}.${config_UserChoices_SpaceName}.${config_UserChoices_TagName}.p86denv.TGCC.CURIE |
---|
487 | |
---|
488 | # ID to identify a job. Several Jobs are needed to complete a simulation |
---|
489 | jobid=${config_UserChoices_JobName}.${config_UserChoices_ExperimentName}.${config_UserChoices_SpaceName}.${config_UserChoices_TagName}.p86denv.TGCC.CURIE.${CumulPeriod} |
---|
490 | |
---|
491 | # RabbitMQ message code |
---|
492 | if ( ${FirstInitialize} ) ; then |
---|
493 | code=0000 |
---|
494 | else |
---|
495 | code=1000 |
---|
496 | fi |
---|
497 | # RabbitMQ message body |
---|
498 | Body=$( echo "{\"code\":\"${code}\",\"simuid\":\"${simuid}\",\"jobid\":\"${jobid}\",\"status\":\"OK\",\"out\":\"false\",\"nesting\":\"${IGCM_debug_LenStack}\",\"timestamp\":\"$( date +"%Y-%m-%d-%T" )\"}" ) |
---|
499 | # Fill the rabbitMQ queue (specifying config.card must be send) |
---|
500 | IGCM_debug_sendAMQP activate |
---|
501 | |
---|
502 | # Turn the flag on |
---|
503 | ActivateBigBro=true |
---|
504 | fi |
---|
505 | IGCM_debug_PopStack "IGCM_debug_ActivateBigBro" |
---|
506 | } |
---|
507 | |
---|
508 | #D-#================================================================== |
---|
509 | #D-function IGCM_debug_Exit |
---|
510 | #D-* Purpose: Print Call Stack and set ExitFlag to true |
---|
511 | #D- |
---|
512 | function IGCM_debug_Exit { |
---|
513 | IGCM_debug_PushStack "IGCM_debug_Exit" |
---|
514 | echo "IGCM_debug_Exit : " "${@}" |
---|
515 | echo |
---|
516 | echo "!!!!!!!!!!!!!!!!!!!!!!!!!!" |
---|
517 | echo "!! ERROR TRIGGERED !!" |
---|
518 | echo "!! EXIT FLAG SET !!" |
---|
519 | echo "!------------------------!" |
---|
520 | echo |
---|
521 | IGCM_debug_CallStack |
---|
522 | ExitFlag=true |
---|
523 | IGCM_debug_PopStack "IGCM_debug_Exit" |
---|
524 | } |
---|
525 | |
---|
526 | #D-#================================================== |
---|
527 | #D-function IGCM_debug_Verif_Exit |
---|
528 | #D-* Purpose: exit with number 1 if ExitFlag is true |
---|
529 | #D- |
---|
530 | function IGCM_debug_Verif_Exit { |
---|
531 | if ( ${ExitFlag} ) ; then |
---|
532 | # Plan to send an email here with IGCM_sys_SendMail |
---|
533 | if [ X${TaskType} != Xchecking ] ; then |
---|
534 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Fatal" |
---|
535 | echo "IGCM_debug_Verif_Exit : Something wrong happened previously." |
---|
536 | echo "IGCM_debug_Verif_Exit : ERROR and EXIT keyword will help find out where." |
---|
537 | echo " EXIT THE JOB." |
---|
538 | echo |
---|
539 | IGCM_debug_CallStack |
---|
540 | fi |
---|
541 | |
---|
542 | if [ X${ActivateBigBro} = Xtrue ] ; then |
---|
543 | # RabbitMQ message code |
---|
544 | code=9999 |
---|
545 | # RabbitMQ message body |
---|
546 | Body=$( echo "{\"code\":\"${code}\",\"simuid\":\"${simuid}\",\"jobid\":\"${jobid}\",\"status\":\"FATAL\",\"timestamp\":\"$( date +"%Y-%m-%d-%T" )\"}" ) |
---|
547 | # Fill the rabbitMQ queue |
---|
548 | IGCM_debug_sendAMQP |
---|
549 | fi |
---|
550 | |
---|
551 | # Not sure about that one ... |
---|
552 | if ( $DEBUG_debug ) ; then |
---|
553 | echo "Your files on ${R_OUT} :" |
---|
554 | IGCM_sys_Tree ${R_SAVE} |
---|
555 | echo |
---|
556 | fi |
---|
557 | |
---|
558 | # Mail notification |
---|
559 | IGCM_sys_SendMail |
---|
560 | |
---|
561 | # And Good Bye |
---|
562 | date |
---|
563 | exit 1 |
---|
564 | fi |
---|
565 | } |
---|
566 | |
---|
567 | #D-#================================================== |
---|
568 | #D-function IGCM_debug_Verif_Exit_Post |
---|
569 | #D-* Purpose: exit with number 1 if ExitFlag is true for Post-treatment |
---|
570 | #D- |
---|
571 | function IGCM_debug_Verif_Exit_Post { |
---|
572 | if ( ${ExitFlag} ) ; then |
---|
573 | echo "IGCM_debug_Verif_Exit_Post : Something wrong happened." |
---|
574 | # If SpaceName is PROD then we stop if post_processing fails |
---|
575 | # Plan to send an email here with IGCM_sys_SendMail |
---|
576 | if [ X${config_UserChoices_SpaceName} = XPROD ] ; then |
---|
577 | echo " EXIT THE JOB." |
---|
578 | echo |
---|
579 | # Mail notification |
---|
580 | #IGCM_sys_SendMailPost |
---|
581 | # And Good Bye |
---|
582 | date |
---|
583 | exit 1 |
---|
584 | else |
---|
585 | echo "Either inside config.card the variable SpaceName is not in PROD" |
---|
586 | echo "or inside the main Job the variable JobType is not in RUN mode" |
---|
587 | echo " SO WE DO NOT EXIT THE JOB." |
---|
588 | echo |
---|
589 | date |
---|
590 | fi |
---|
591 | fi |
---|
592 | } |
---|
593 | |
---|
594 | #D-#================================================================== |
---|
595 | #D-function IGCM_debug_Print |
---|
596 | #D-* Purpose: Print arguments according to a level of verbosity. |
---|
597 | #D- |
---|
598 | function IGCM_debug_Print |
---|
599 | { |
---|
600 | typeset level=$1 |
---|
601 | shift |
---|
602 | |
---|
603 | if [ X"${1}" = X"-e" ]; then |
---|
604 | typeset cmd_echo="echo -e" |
---|
605 | shift |
---|
606 | else |
---|
607 | typeset cmd_echo="echo" |
---|
608 | fi |
---|
609 | |
---|
610 | if [ ${level} -le ${Verbosity} ] ; then |
---|
611 | typeset i |
---|
612 | case "${level}" in |
---|
613 | 1) for i in "$@" ; do |
---|
614 | ${cmd_echo} $(date +"%Y-%m-%d %T") "--Debug1-->" ${i} |
---|
615 | done ;; |
---|
616 | 2) for i in "$@" ; do |
---|
617 | ${cmd_echo} $(date +"%Y-%m-%d %T") "--------Debug2-->" ${i} |
---|
618 | done ;; |
---|
619 | 3) for i in "$@" ; do |
---|
620 | ${cmd_echo} $(date +"%Y-%m-%d %T") "--------------Debug3-->" ${i} |
---|
621 | done ;; |
---|
622 | esac |
---|
623 | fi |
---|
624 | } |
---|
625 | |
---|
626 | #D-#================================================================== |
---|
627 | #D-function IGCM_debug_PrintVariables |
---|
628 | #D-* Purpose: Print arguments when match a pattern |
---|
629 | #D- according to a level of verbosity. |
---|
630 | function IGCM_debug_PrintVariables |
---|
631 | { |
---|
632 | typeset level=$1 |
---|
633 | shift |
---|
634 | |
---|
635 | list=$( set | grep ^$1 | sed -e "s/'//g" ) |
---|
636 | |
---|
637 | if [ "X${list}" != X ] ; then |
---|
638 | IGCM_debug_Print ${level} ${list} |
---|
639 | fi |
---|
640 | } |
---|
641 | |
---|
642 | #D-#================================================================== |
---|
643 | #D-function IGCM_debug_PrintInfosActions |
---|
644 | #D-* Purpose: Print information related to instrumentation |
---|
645 | function IGCM_debug_PrintInfosActions |
---|
646 | { |
---|
647 | typeset actionType=$1 |
---|
648 | typeset entitySize=$2 |
---|
649 | typeset start_ms=$3 |
---|
650 | typeset end_ms=$4 |
---|
651 | |
---|
652 | typeset dest=$5 |
---|
653 | typeset source=$6 |
---|
654 | |
---|
655 | typeset diff_ms entitySizeKo entitySizeMo flux_Ko_ms flux_Ko_s flux_Mo_s |
---|
656 | typeset name dirOut dirSource |
---|
657 | |
---|
658 | name="doNotKnow" |
---|
659 | |
---|
660 | diff_ms=$(( $end_ms - $start_ms )) |
---|
661 | # echo "diff_ms=$diff_ms" |
---|
662 | |
---|
663 | entitySizeKo=$( echo ${entitySize} | gawk -F"|" '{print $1}' ) |
---|
664 | # echo "entitySizeKo=$entitySizeKo" |
---|
665 | entitySizeMo=$( echo ${entitySize} | gawk -F"|" '{print $2}' ) |
---|
666 | |
---|
667 | # flux en Ko / ms |
---|
668 | flux_Ko_ms=$( echo "scale=6;${entitySizeKo}/${diff_ms}" | bc ) |
---|
669 | # echo "flux_Ko_ms=$flux_Ko_ms" |
---|
670 | |
---|
671 | # flux en Ko / s |
---|
672 | flux_Ko_s=$(( $flux_Ko_ms * 1000 )) |
---|
673 | # echo "flux_Ko_s=$flux_Ko_s" |
---|
674 | |
---|
675 | # flux en Mo / s |
---|
676 | flux_Mo_s=$( echo "scale=6;${flux_Ko_s}/1024" | bc ) |
---|
677 | # echo "flux_Mo_s=$flux_Mo_s" |
---|
678 | |
---|
679 | if [ -d $dest ] ; then |
---|
680 | dirOut=$( readlink -f ${dest} ) |
---|
681 | else |
---|
682 | dirOut=$( readlink -f $( dirname ${dest} ) ) |
---|
683 | fi |
---|
684 | |
---|
685 | if [ -d $source ] ; then |
---|
686 | dirSource=$( readlink -f ${source} ) |
---|
687 | else |
---|
688 | dirSource=$( readlink -f $( dirname ${source} ) ) |
---|
689 | fi |
---|
690 | |
---|
691 | echo "==>act:${actionType}|sz:${entitySizeMo}|ms:${diff_ms}|fx(ko):${flux_Ko_s}|fx(mo):${flux_Mo_s}|nm:${name}|dirSource:${dirSource}|dirOut:${dirOut}" |
---|
692 | } |
---|
693 | |
---|
694 | #D-#================================================================== |
---|
695 | #D-function IGCM_debug_Check |
---|
696 | #D- * Purpose: Check the present file by comparison with a reference file |
---|
697 | function IGCM_debug_Check |
---|
698 | { |
---|
699 | #--------------------- |
---|
700 | if [ ! -n "${libIGCM}" ] ; then |
---|
701 | echo "Check libIGCM_debug ..........................................[ FAILED ]" |
---|
702 | echo "--Error--> libIGCM variable is not defined" |
---|
703 | exit 2 |
---|
704 | fi |
---|
705 | |
---|
706 | #--------------------- |
---|
707 | if [ ! -n "${Verbosity}" ] ; then |
---|
708 | echo "Check libIGCM_debug ..........................................[ FAILED ]" |
---|
709 | echo "--Error--> Verbosity variable is not defined" |
---|
710 | exit 3 |
---|
711 | fi |
---|
712 | |
---|
713 | #--------------------- |
---|
714 | ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ksh > /tmp/IGCM_debug_Test.$$.ref.failed 2>&1 |
---|
715 | sleep 2 |
---|
716 | |
---|
717 | # Remove date stamp. |
---|
718 | sed -e "s:[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]\:[0-9][0-9]\:[0-9][0-9] ::g" /tmp/IGCM_debug_Test.$$.ref.failed > /tmp/IGCM_debug_Test.$$.ref.failed.nodate |
---|
719 | mv /tmp/IGCM_debug_Test.$$.ref.failed.nodate /tmp/IGCM_debug_Test.$$.ref.failed |
---|
720 | |
---|
721 | if diff /tmp/IGCM_debug_Test.$$.ref.failed ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ref > /dev/null 2>&1 ; then |
---|
722 | echo "Check libIGCM_debug ..............................................[ OK ]" |
---|
723 | rm -f /tmp/IGCM_debug_Test.$$.ref.failed |
---|
724 | else |
---|
725 | echo "Check libIGCM_debug ..........................................[ FAILED ]" |
---|
726 | echo "--Error--> Execution of ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ksh" |
---|
727 | echo " has produced the file IGCM_debug_Test.ref.failed" |
---|
728 | echo " Please analyse differences with the reference file by typing:" |
---|
729 | echo " diff IGCM_debug_Test.ref.failed ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ref" |
---|
730 | echo " Report errors to the author: Patrick.Brockmann@cea.fr" |
---|
731 | cat /tmp/IGCM_debug_Test.$$.ref.failed |
---|
732 | exit 4 |
---|
733 | fi |
---|
734 | #--------------------- |
---|
735 | } |
---|