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