[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 | |
---|
[823] | 33 | # Where the stack file containing call tree will be stored. |
---|
| 34 | typeset StackFileLocation=${StackFileLocation:=${PWD}} |
---|
| 35 | |
---|
[2] | 36 | if ( $DEBUG_debug ) ; then |
---|
[823] | 37 | if [ -f ${StackFileLocation}/stack ] ; |
---|
[544] | 38 | then |
---|
[823] | 39 | echo "Stack of an libIGCM job :" >> ${StackFileLocation}/stack |
---|
[544] | 40 | else |
---|
[823] | 41 | echo "Stack of an libIGCM job :" > ${StackFileLocation}/stack |
---|
[544] | 42 | fi |
---|
[2] | 43 | fi |
---|
| 44 | |
---|
| 45 | #================================================== |
---|
| 46 | # NULL_STR |
---|
| 47 | # Default null string |
---|
[913] | 48 | typeset -r NULL_STR="_0_" |
---|
[2] | 49 | |
---|
| 50 | #================================================== |
---|
| 51 | # libIGCM_CurrentTag |
---|
| 52 | # Current libIGCM tag, check compatibilty with *.card |
---|
[915] | 53 | typeset -r libIGCM_CurrentTag="1.0" |
---|
[2] | 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 |
---|
[59] | 62 | unset IGCM_debug_Stack |
---|
| 63 | unset IGCM_debug_StackArgs |
---|
[913] | 64 | unset IGCM_debug_StackTiming |
---|
[54] | 65 | IGCM_debug_Stack[0]=${NULL_STR} |
---|
| 66 | IGCM_debug_StackArgs[0]=${NULL_STR} |
---|
[913] | 67 | IGCM_debug_StackTiming[0]=${NULL_STR} |
---|
[2] | 68 | IGCM_debug_LenStack=0 |
---|
| 69 | |
---|
| 70 | #D-#================================================================== |
---|
[913] | 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 | { |
---|
[917] | 90 | typeset dm_liste ifile sizeFile sizeKo sizeMo |
---|
[913] | 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]}" |
---|
[917] | 95 | # we want to compute the size from local path (not from archive ...) |
---|
[913] | 96 | # remove path /home/login/../ from dm_liste elements |
---|
[917] | 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'} ) |
---|
[913] | 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-#================================================================== |
---|
[2] | 154 | #D-function IGCM_debug_CallStack |
---|
[913] | 155 | #D-* Purpose: Print the call stack tree from the oldest to the youngest (opposite of the display standard) |
---|
[2] | 156 | #D- |
---|
| 157 | function IGCM_debug_CallStack { |
---|
[544] | 158 | if ( $DEBUG_debug ) ; then |
---|
[913] | 159 | # Cosmetics |
---|
[544] | 160 | typeset i decal |
---|
[823] | 161 | i=0 |
---|
[544] | 162 | until [ $i -eq ${IGCM_debug_LenStack} ]; do |
---|
| 163 | decal=0 |
---|
| 164 | until [ $decal -eq ${i} ]; do |
---|
[869] | 165 | printf -- ' ' |
---|
[823] | 166 | (( decal = decal + 1 )) |
---|
[544] | 167 | done |
---|
[869] | 168 | echo "$i - ${IGCM_debug_Stack[$(( $IGCM_debug_LenStack-$i-1 ))]}" "(${IGCM_debug_StackArgs[$(( $IGCM_debug_LenStack-$i-1 ))]})" |
---|
[823] | 169 | ((i = i + 1)) |
---|
[544] | 170 | done |
---|
| 171 | fi |
---|
[2] | 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 { |
---|
[544] | 179 | if ( $DEBUG_debug ) ; then |
---|
[913] | 180 | typeset decal inputs startTime_ms |
---|
[823] | 181 | echo >> ${StackFileLocation}/stack |
---|
[913] | 182 | |
---|
| 183 | # Only cosmetics : stack file |
---|
[544] | 184 | decal=0 |
---|
[823] | 185 | while [ ${decal} -lt ${IGCM_debug_LenStack} ]; do |
---|
| 186 | printf ' ' >> ${StackFileLocation}/stack |
---|
| 187 | (( decal = decal + 1 )) |
---|
[544] | 188 | done |
---|
[2] | 189 | |
---|
[913] | 190 | # Save input list in an indexed array |
---|
[823] | 191 | INPUTS=( $@ ) |
---|
[913] | 192 | |
---|
| 193 | # Get timing information |
---|
| 194 | startTime_ms=$( IGCM_debug_getDate_ms ) |
---|
| 195 | |
---|
[544] | 196 | # We add function call name on beginning of the stack |
---|
| 197 | set +A IGCM_debug_Stack -- ${1} ${IGCM_debug_Stack[*]} |
---|
[2] | 198 | |
---|
[913] | 199 | # Save timing in milliseconds in an indexed array |
---|
| 200 | set +A IGCM_debug_StackTiming -- ${startTime_ms} ${IGCM_debug_StackTiming[*]} |
---|
| 201 | |
---|
[544] | 202 | # We include the "null" Args in the beginning of the StackArgs |
---|
[913] | 203 | set +A IGCM_debug_StackArgs ${NULL_STR} ${IGCM_debug_StackArgs[*]} |
---|
| 204 | |
---|
[544] | 205 | # Then, we shift StackArgs tabular |
---|
[913] | 206 | if [ $# -gt 1 ]; then |
---|
| 207 | IGCM_debug_StackArgs[0]=$(echo ${INPUTS[*]:1} | sed -e "s/\ /,/g" ) |
---|
[544] | 208 | fi |
---|
[855] | 209 | |
---|
| 210 | # Fill the stack file |
---|
| 211 | echo "> ${IGCM_debug_LenStack} : ${@}" >> ${StackFileLocation}/stack |
---|
| 212 | |
---|
| 213 | if [ X${ActivateBigBro} = Xtrue ] ; then |
---|
[913] | 214 | # RabbitMQ message code |
---|
[855] | 215 | code=2000 |
---|
[913] | 216 | # RabbitMQ message body |
---|
[869] | 217 | Body=$( echo "{\"code\":\"${code}\",\"simuid\":\"${simuid}\",\"jobid\":\"${jobid}\",\"nesting\":\"${IGCM_debug_LenStack}\",\"command\":\"${INPUTS[*]}\",\"timestamp\":\"$( date +"%Y-%m-%d-%T" )\"}" ) |
---|
[913] | 218 | # Fill the rabbitMQ queue |
---|
| 219 | IGCM_debug_sendAMQP |
---|
[855] | 220 | fi |
---|
| 221 | |
---|
| 222 | # Increment LenStack |
---|
[544] | 223 | (( IGCM_debug_LenStack = IGCM_debug_LenStack + 1 )) |
---|
[2] | 224 | |
---|
[869] | 225 | #IGCM_debug_CallStack |
---|
[544] | 226 | fi |
---|
[2] | 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 { |
---|
[544] | 234 | if ( $DEBUG_debug ) ; then |
---|
[913] | 235 | typeset decal command arguments startTime_ms endTime_ms |
---|
[917] | 236 | typeset instrumentation source dest |
---|
[913] | 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 | |
---|
[544] | 249 | if [ "${IGCM_debug_Stack[0]}" = "${1}" ]; then |
---|
[913] | 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 |
---|
[823] | 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} |
---|
[913] | 268 | set -A IGCM_debug_StackTiming -- ${IGCM_debug_StackTiming[*]:1} |
---|
[544] | 269 | else |
---|
| 270 | echo 'IGCM_debug_Exit : stack is corrupted ! LenStack =' ${IGCM_debug_LenStack} |
---|
| 271 | IGCM_debug_Exit $@ |
---|
| 272 | fi |
---|
[913] | 273 | |
---|
[914] | 274 | # Special actions depending on command to prepare IGCM_debug_PrintInfosActions call |
---|
[913] | 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 | |
---|
[915] | 282 | instrumentation=false |
---|
| 283 | |
---|
[913] | 284 | case ${command} in |
---|
| 285 | # Copy from archive machine or from buffer |
---|
| 286 | IGCM_sys_Get|IGCM_sys_GetBuffer) |
---|
[915] | 287 | instrumentation=true |
---|
[913] | 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 |
---|
[917] | 292 | entitySize=$( IGCM_debug_sizeOfTabContent source ${dest} ) |
---|
[913] | 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 |
---|
[917] | 300 | entitySize=$( IGCM_debug_sizeOfTabContent fileList[*] ${dest} ) |
---|
[913] | 301 | elif [ [ ${#arguments[*]} -ge 3 ] ; then |
---|
| 302 | # All but the latest |
---|
[916] | 303 | fileList=${arguments[*]:0:${#arguments[*]}-1} |
---|
[913] | 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 |
---|
[917] | 309 | entitySize=$( IGCM_debug_sizeOfTabContent fileList ${dest} ) |
---|
[913] | 310 | fi |
---|
| 311 | ;; |
---|
| 312 | |
---|
[916] | 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 |
---|
[917] | 323 | entitySize=$( IGCM_debug_sizeOfTabContent fileList $dest ) |
---|
[916] | 324 | ;; |
---|
| 325 | |
---|
[913] | 326 | # Copy from compute node |
---|
| 327 | IGCM_sys_Get_Master|IGCM_sys_Get_Dir) |
---|
[915] | 328 | instrumentation=true |
---|
[913] | 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) |
---|
[915] | 339 | instrumentation=true |
---|
[913] | 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 |
---|
[917] | 347 | entitySize=$( IGCM_debug_sizeOfTabContent fileList ${dest} ) |
---|
[913] | 348 | ;; |
---|
| 349 | esac |
---|
| 350 | |
---|
| 351 | # Print information related to instrumentation |
---|
[915] | 352 | ( ${instrumentation} ) && IGCM_debug_PrintInfosActions ${command} ${entitySize} ${startTime_ms} ${endTime_ms} ${dest} ${source} |
---|
[913] | 353 | |
---|
| 354 | # Only cosmetics : stack file |
---|
[823] | 355 | decal=0 |
---|
| 356 | while [ ${decal} -lt ${IGCM_debug_LenStack} ]; do |
---|
| 357 | printf ' ' >> ${StackFileLocation}/stack |
---|
| 358 | (( decal = decal + 1 )) |
---|
[544] | 359 | done |
---|
[2] | 360 | |
---|
[855] | 361 | if ( ${ExitFlag} ) ; then |
---|
| 362 | # Inform the stack file |
---|
| 363 | echo '!!! ExitFlag has been activated !!!' >> ${StackFileLocation}/stack |
---|
[874] | 364 | |
---|
[855] | 365 | if [ X${ActivateBigBro} = Xtrue ] ; then |
---|
[913] | 366 | # RabbitMQ message code |
---|
[855] | 367 | code=9000 |
---|
[913] | 368 | # RabbitMQ message body |
---|
[869] | 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" )\"}" ) |
---|
[913] | 370 | # Fill the rabbitMQ queue |
---|
| 371 | IGCM_debug_sendAMQP |
---|
[855] | 372 | fi |
---|
| 373 | else |
---|
| 374 | # Inform the stack file |
---|
| 375 | echo "< ${IGCM_debug_LenStack} : ${@}" >> ${StackFileLocation}/stack |
---|
| 376 | if [ X${ActivateBigBro} = Xtrue ] ; then |
---|
[913] | 377 | # RabbitMQ message code |
---|
[855] | 378 | code=3000 |
---|
[913] | 379 | # RabbitMQ message body |
---|
[869] | 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" )\"}" ) |
---|
[913] | 381 | # Fill the rabbitMQ queue |
---|
| 382 | IGCM_debug_sendAMQP |
---|
[855] | 383 | fi |
---|
| 384 | fi |
---|
| 385 | |
---|
[913] | 386 | # Reset array if necessary |
---|
[544] | 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 |
---|
[913] | 393 | unset IGCM_debug_StackTiming |
---|
[544] | 394 | IGCM_debug_Stack[0]=${NULL_STR} |
---|
| 395 | IGCM_debug_StackArgs[0]=${NULL_STR} |
---|
[913] | 396 | IGCM_debug_StackTiming[0]=${NULL_STR} |
---|
[2] | 397 | fi |
---|
[544] | 398 | fi |
---|
[869] | 399 | #IGCM_debug_CallStack |
---|
[2] | 400 | } |
---|
| 401 | |
---|
| 402 | #D-#================================================================== |
---|
[855] | 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 | |
---|
[868] | 409 | if [ X${BigBrother} = Xtrue ] ; then |
---|
[869] | 410 | # ID to identify a simulation |
---|
| 411 | simuid=${config_UserChoices_JobName}.${config_UserChoices_ExperimentName}.${config_UserChoices_SpaceName}.${config_UserChoices_TagName}.p86denv.TGCC.CURIE |
---|
[913] | 412 | |
---|
[869] | 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} |
---|
[913] | 415 | |
---|
| 416 | # RabbitMQ message code |
---|
[855] | 417 | if ( ${FirstInitialize} ) ; then |
---|
| 418 | code=0000 |
---|
| 419 | else |
---|
| 420 | code=1000 |
---|
| 421 | fi |
---|
[913] | 422 | # RabbitMQ message body |
---|
[869] | 423 | Body=$( echo "{\"code\":\"${code}\",\"simuid\":\"${simuid}\",\"jobid\":\"${jobid}\",\"status\":\"OK\",\"out\":\"false\",\"nesting\":\"${IGCM_debug_LenStack}\",\"timestamp\":\"$( date +"%Y-%m-%d-%T" )\"}" ) |
---|
[913] | 424 | # Fill the rabbitMQ queue (specifying config.card must be send) |
---|
| 425 | IGCM_debug_sendAMQP activate |
---|
| 426 | |
---|
| 427 | # Turn the flag on |
---|
[855] | 428 | ActivateBigBro=true |
---|
| 429 | fi |
---|
| 430 | IGCM_debug_PopStack "IGCM_debug_ActivateBigBro" |
---|
| 431 | } |
---|
| 432 | |
---|
| 433 | #D-#================================================================== |
---|
[2] | 434 | #D-function IGCM_debug_Exit |
---|
| 435 | #D-* Purpose: Print Call Stack and set ExitFlag to true |
---|
| 436 | #D- |
---|
| 437 | function IGCM_debug_Exit { |
---|
[544] | 438 | IGCM_debug_PushStack "IGCM_debug_Exit" |
---|
| 439 | echo "IGCM_debug_Exit : " "${@}" |
---|
[913] | 440 | echo |
---|
[894] | 441 | echo "!!!!!!!!!!!!!!!!!!!!!!!!!!" |
---|
[913] | 442 | echo "!! ERROR TRIGGERED !!" |
---|
| 443 | echo "!! EXIT FLAG SET !!" |
---|
| 444 | echo "!------------------------!" |
---|
| 445 | echo |
---|
[894] | 446 | IGCM_debug_CallStack |
---|
[544] | 447 | ExitFlag=true |
---|
| 448 | IGCM_debug_PopStack "IGCM_debug_Exit" |
---|
[2] | 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 { |
---|
[544] | 456 | if ( ${ExitFlag} ) ; then |
---|
| 457 | # Plan to send an email here with IGCM_sys_SendMail |
---|
[775] | 458 | if [ X${TaskType} != Xchecking ] ; then |
---|
| 459 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Fatal" |
---|
[894] | 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." |
---|
[775] | 462 | echo " EXIT THE JOB." |
---|
| 463 | echo |
---|
[869] | 464 | IGCM_debug_CallStack |
---|
[775] | 465 | fi |
---|
[874] | 466 | |
---|
[855] | 467 | if [ X${ActivateBigBro} = Xtrue ] ; then |
---|
[913] | 468 | # RabbitMQ message code |
---|
[855] | 469 | code=9999 |
---|
[913] | 470 | # RabbitMQ message body |
---|
[869] | 471 | Body=$( echo "{\"code\":\"${code}\",\"simuid\":\"${simuid}\",\"jobid\":\"${jobid}\",\"status\":\"FATAL\",\"timestamp\":\"$( date +"%Y-%m-%d-%T" )\"}" ) |
---|
[913] | 472 | # Fill the rabbitMQ queue |
---|
| 473 | IGCM_debug_sendAMQP |
---|
[855] | 474 | fi |
---|
[874] | 475 | |
---|
[913] | 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 |
---|
[874] | 482 | |
---|
[544] | 483 | # Mail notification |
---|
| 484 | IGCM_sys_SendMail |
---|
[913] | 485 | |
---|
[544] | 486 | # And Good Bye |
---|
| 487 | date |
---|
| 488 | exit 1 |
---|
| 489 | fi |
---|
[2] | 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 { |
---|
[544] | 497 | if ( ${ExitFlag} ) ; then |
---|
[765] | 498 | echo "IGCM_debug_Verif_Exit_Post : Something wrong happened." |
---|
[544] | 499 | # If SpaceName is PROD then we stop if post_processing fails |
---|
| 500 | # Plan to send an email here with IGCM_sys_SendMail |
---|
[706] | 501 | if [ X${config_UserChoices_SpaceName} = XPROD ] ; then |
---|
[544] | 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" |
---|
[765] | 511 | echo "or inside the main Job the variable JobType is not in RUN mode" |
---|
[544] | 512 | echo " SO WE DO NOT EXIT THE JOB." |
---|
| 513 | echo |
---|
| 514 | date |
---|
[2] | 515 | fi |
---|
[544] | 516 | fi |
---|
[2] | 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 | { |
---|
[544] | 525 | typeset level=$1 |
---|
| 526 | shift |
---|
| 527 | |
---|
| 528 | if [ X"${1}" = X"-e" ]; then |
---|
| 529 | typeset cmd_echo="echo -e" |
---|
[2] | 530 | shift |
---|
[544] | 531 | else |
---|
| 532 | typeset cmd_echo="echo" |
---|
| 533 | fi |
---|
[2] | 534 | |
---|
[544] | 535 | if [ ${level} -le ${Verbosity} ] ; then |
---|
| 536 | typeset i |
---|
| 537 | case "${level}" in |
---|
| 538 | 1) for i in "$@" ; do |
---|
[734] | 539 | ${cmd_echo} $(date +"%Y-%m-%d %T") "--Debug1-->" ${i} |
---|
[913] | 540 | done ;; |
---|
[544] | 541 | 2) for i in "$@" ; do |
---|
[734] | 542 | ${cmd_echo} $(date +"%Y-%m-%d %T") "--------Debug2-->" ${i} |
---|
[913] | 543 | done ;; |
---|
[544] | 544 | 3) for i in "$@" ; do |
---|
[734] | 545 | ${cmd_echo} $(date +"%Y-%m-%d %T") "--------------Debug3-->" ${i} |
---|
[913] | 546 | done ;; |
---|
[544] | 547 | esac |
---|
| 548 | fi |
---|
[2] | 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 | { |
---|
[544] | 557 | typeset level=$1 |
---|
| 558 | shift |
---|
[2] | 559 | |
---|
[830] | 560 | list=$( set | grep ^$1 | sed -e "s/'//g" ) |
---|
[54] | 561 | |
---|
[544] | 562 | if [ "X${list}" != X ] ; then |
---|
| 563 | IGCM_debug_Print ${level} ${list} |
---|
| 564 | fi |
---|
[2] | 565 | } |
---|
| 566 | |
---|
| 567 | #D-#================================================================== |
---|
[914] | 568 | #D-function IGCM_debug_PrintInfosActions |
---|
[913] | 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 |
---|
[914] | 613 | dirSource=$( readlink -f $( dirname ${source} ) ) |
---|
[913] | 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-#================================================================== |
---|
[2] | 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 | { |
---|
[544] | 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 |
---|
[2] | 630 | |
---|
[544] | 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 |
---|
[2] | 637 | |
---|
[544] | 638 | #--------------------- |
---|
| 639 | ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ksh > IGCM_debug_Test.ref.failed 2>&1 |
---|
| 640 | sleep 2 |
---|
[2] | 641 | |
---|
[772] | 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 | |
---|
[544] | 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 | #--------------------- |
---|
[2] | 659 | } |
---|