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