source: trunk/libIGCM/libIGCM_debug/libIGCM_debug.ksh @ 1517

Last change on this file since 1517 was 1478, checked in by mafoipsl, 5 years ago

Consolidation of AA_pack_restart and AA_pack_debug to stop when tar failed.
Consolidation of libIGCM_debug IGCM_debug_Verif_Exit : initialisation of !postProcessingName added.

  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

    The fact that you are presently reading this means that you have had
    knowledge of the CeCILL license and that you accept its terms.
  • Property svn:keywords set to Revision Author Date
File size: 40.9 KB
RevLine 
[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
22typeset -i Verbosity=${Verbosity:=3}
23
24#==================================================
25# DEBUG_debug
26# Add low level verbosity
[1083]27DEBUG_debug=${DEBUG_debug:=false}
[2]28
[1290]29#D- postProcessingStopLevel (0,1,2,3)
30#D- 3 stop if any post-processing went wrong
31#D- 2 dont stop if atlas, monitoring or metrics failed
32#D- 1 dont stop if atlas, monitoring, metrics, create_ts or create_se failed
33#D- 0 dont stop if atlas, monitoring, metrics, create_ts, create_se, rebuild or pack_* failed
34postProcessingStopLevel=${postProcessingStopLevel:=0}
35
[872]36#==================================================
37# GENERATE RANDOM ERROR ; only apply if ( ${DEBUG_debug} )
[1244]38typeset -r RandomError=false
[872]39
[2]40#==================================================
41# NULL_STR
42# Default null string
[913]43typeset -r NULL_STR="_0_"
[2]44
45#==================================================
46# libIGCM_CurrentTag
47# Current libIGCM tag, check compatibilty with *.card
[1404]48typeset -r libIGCMVersion="2.8.3"
[2]49
50#==================================================
51# Exit Flag (internal debug)
52# When true, end the master loop AFTER SAVES FILES
53ExitFlag=false
54
55#==================================================
[1243]56# When we start to run the simulation is not finished
57simulationIsOver=false
58
59#==================================================
[1268]60# When we start to run we dont flush AMQP messages
61FlushAMQP=false
62
63#==================================================
[2]64# Declare a stack of functions calls
[59]65unset IGCM_debug_Stack
66unset IGCM_debug_StackArgs
[913]67unset IGCM_debug_StackTiming
[54]68IGCM_debug_Stack[0]=${NULL_STR}
69IGCM_debug_StackArgs[0]=${NULL_STR}
[913]70IGCM_debug_StackTiming[0]=${NULL_STR}
[2]71IGCM_debug_LenStack=0
72
73#D-#==================================================================
[913]74#D-function IGCM_debug_getDate_ms
75#D- * Purpose: Give number of milliseconds since 01-jan-1970
76function IGCM_debug_getDate_ms
77{
[926]78  typeset nanosecs ms
[913]79  # nano secondes since 01-jan-1970
80  nanosecs=$( date +%s%N )
81
82  # truncate the last 6 digits to get milliseconds since 01-jan-1970
83  ms=${nanosecs:0:${#nanosecs}-6}
84
85  echo "$ms"
86}
87
88#D-#==================================================================
89#D-function IGCM_debug_sizeOfTabContent
90#D- * Purpose: Give sumed size of a list of files
[924]91#D- * Usage: IGCM_debug_sizeOfTabContent entityList destination
92#D- *        where entityList is a list of files or directory
93#D- *        where dest is either a directory or a file name
[913]94function IGCM_debug_sizeOfTabContent
95{
[924]96  typeset entityListe destination iEntity sizeKo sumSizeKo sumSizeMo
97
98  eval set +A entityListe \${${1}}
[941]99  destination=${2}
[924]100  sumSizeKo=0
101
102  # Here we will try to compute size (file or directory size) from local path and not from archive.
[941]103  for ((i = 0; i < ${#entityListe[*]}; i += 1)) ; do
104    if [ -f ${entityListe[$i]} ] ; then
105      # One file or a bunch of files has been copied without renaming from a visible filesystem
106      iEntity=${entityListe[$i]}
107    elif [ -f ${entityListe[$i]##/*/} ] ; then
108      # One file or a bunch of files has been copied without renaming from an non visible filesystem
[924]109      # remove path /home/login/../ from entityListe elements
110      iEntity=${entityListe[$i]##/*/}
111    elif [ -f ${destination} ] ; then
[941]112      # a file has been copied and renamed
[924]113      iEntity=${destination}
114    elif [ -f ${destination}/${entityListe[$i]##/*/} ] ; then
115      # a copy in a directory but not in ${PWD}
116      iEntity=${destination}/${entityListe[$i]##/*/}
117    elif [ -d ${entityListe[$i]} ] ; then
[941]118      # a directory has been copied from a non remote place
[924]119      iEntity=${entityListe[$i]}
120    elif [ -d ${destination}/${entityListe[$i]##/*/} ] ; then
[941]121      # a directory has been copied from a remote archive and not renamed
[924]122      iEntity=${destination}/${entityListe[$i]##/*/}
123    elif [ -d ${destination} ] ; then
[941]124      # a directory has been copied from a remote archive and renamed
[924]125      iEntity=${destination}
[917]126    fi
[1083]127    sizeKo=$( du --apparent-size -skL ${iEntity} | gawk '{print $1}' )
[924]128    sumSizeKo=$(( $sumSizeKo + $sizeKo ))
[913]129  done
[924]130  sumSizeMo=$( echo "scale=6;${sumSizeKo}/1024" | bc )
131  echo "${sumSizeKo}|${sumSizeMo}"
[913]132}
133
134#D-#==================================================================
[983]135#D-function IGCM_debug_send_AMQP_msg__MAILTUNNEL
136#D- * Purpose: Take over AMQP C client using mail as a message recipient
137#D- * One argument : base64 encoded message
[1051]138#D- * Attach encoded config.card when starting the simulation
139
[983]140function IGCM_debug_send_AMQP_msg__MAILTUNNEL {
141
[987]142  typeset b64_encoded_msg mail_recipient
[1076]143  typeset buffer send_messages mail_frequency
[987]144  typeset last_mail_date__file
[1234]145  typeset secondsBetweenRefAndLastMail secondsSinceLastMail
[987]146
[983]147  b64_encoded_msg=$1
148
[1398]149  mail_recipient="superviseur@mail.ipsl.upmc.fr"
[983]150  send_messages=0
151  mail_frequency=3600 # in seconds
152  # use to keep track when was last mail sent (maybe to be replaced with global variable)
[1150]153  last_mail_date__file=${R_BUF}/.stamp.${config_UserChoices_TagName}.${config_UserChoices_JobName}
154  # use to accumulate messages before sending them
155  buffer=${R_BUF}/.buffer.${config_UserChoices_TagName}.${config_UserChoices_JobName}
[983]156
157  # init
158  if [ ! -f "${buffer}" ]; then
[1150]159    touch ${buffer}
[983]160  fi
161
162  if [ ! -f "${last_mail_date__file}" ]; then
[1150]163    touch ${last_mail_date__file}
[983]164  else
[1150]165    # compute last time the file was changed (in seconds)
[1234]166    secondsBetweenRefAndLastMail=$(stat -c %Y ${last_mail_date__file})
167    status=$?
168    #
[1275]169    # Only execute this block when the stat command succeeded.
170    # The stat command might fail in some circumstance but we consider it is ok to continue anyway.
171    if [ ${status} -eq 0 ] ; then
172      secondsSinceLastMail=$(( $(date +%s) - ${secondsBetweenRefAndLastMail} ))
173      # send message when exceeding threshold
174      [ ${secondsSinceLastMail} -gt ${mail_frequency} ] && send_messages=1
[1234]175    fi
[983]176  fi
177
[997]178  # queue messages in the buffer
179  echo ${b64_encoded_msg} >> ${buffer}
180
181  # send mail
[1051]182
[1053]183  if [ X${initBigBro} = Xtrue ] ; then
[1087]184    #echo $(date +"%Y-%m-%dT%H:%M:%S.%N%z") > ${SUBMIT_DIR}/mail.txt
[1051]185    mailx -s "[TEMPORARY AMQP CHANNEL]" -a ${SUBMIT_DIR}/config.card.base64 ${mail_recipient} < ${buffer} # send buffer
186    rm -f $buffer ; touch ${buffer}                                    # clear buffer
187    touch ${last_mail_date__file}                                      # memorize last mail date
[1293]188    rm -f ${SUBMIT_DIR}/config.card.base64                             # remove temporary file
[1051]189    initBigBro=false
[1150]190  elif [ ${send_messages} -eq 1 ] ; then
[1087]191    #echo $(date +"%Y-%m-%dT%H:%M:%S.%N%z") >> ${SUBMIT_DIR}/mail.txt
[1051]192    mailx -s "[TEMPORARY AMQP CHANNEL]" ${mail_recipient}  < ${buffer} # send buffer
[1150]193    rm -f ${buffer} ; touch ${buffer}                                  # flush the buffer
[1051]194    touch ${last_mail_date__file}                                      # memorize last mail date
[983]195  fi
[987]196
[1189]197  if ( ${FlushAMQP} ) ; then
[1150]198    mailx -s "[TEMPORARY AMQP CHANNEL]" ${mail_recipient}  < ${buffer} # send buffer
199    rm -f ${buffer}                                                    # cleaning behind us
200    rm -f ${last_mail_date__file}                                      # cleaning behind us
201  fi
202
[983]203  # Allways all good for now.
204  return 0
205}
206
207#D-#==================================================================
[1355]208#D-function IGCM_debug_sendAMQP_Purge
209#D- * Purpose: Take over AMQP C client using mail as a message recipient
210#D- * No argument : send a message indicating a simulation has been purged
211
212function IGCM_debug_sendAMQP_Purge {
213
214  typeset mail_recipient encodedBody
215  if [ X${ActivateBigBro} = Xtrue ] ; then
[1418]216    mail_recipient="superviseur@mail.ipsl.upmc.fr"
[1355]217    # Clea nup tag on server side
218    code=8888
219    # Usual AMQP message to route messages on server side
220    encodedBody=$( echo "{${genericSimulationID},\"msgCode\":\"${code}\",\"msgUID\":\"$(uuidgen)\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" |  base64 -w 0 )
221    # send mail
222
223    IGCM_debug_Print 2 "IGCM_debug_sendAMQP_Purge"
224    echo ${encodedBody}|mailx -s "[TEMPORARY AMQP CHANNEL]" ${mail_recipient}
225  fi
226
227  # Allways all good for now.
228  return 0
229}
230
231#D-#==================================================================
[1162]232#D-function IGCM_debug_sendAMQP_Metrics
233#D- * Purpose: Take over AMQP C client using mail as a message recipient
[1202]234#D- * Two arguments : - Directory where metrics.json files can be found
235#D- *                 - Metrics Group Name. metrics will be added to this group
[1162]236#D- * Attach encoded metrics.json files.
237
238function IGCM_debug_sendAMQP_Metrics {
239
240  typeset mail_recipient encodedBody
241  if [ X${ActivateBigBro} = Xtrue ] ; then
[1418]242    mail_recipient="superviseur@mail.ipsl.upmc.fr"
[1162]243    # Metrics tag on server side
244    code=7100
245    # Usual AMQP message to route messages on server side
[1202]246    encodedBody=$( echo "{${genericSimulationID},\"msgCode\":\"${code}\",\"msgUID\":\"$(uuidgen)\",\"metricsGroupName\":\"${2}\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" |  base64 -w 0 )
[1162]247    # send mail
248    attachmentsOptions=""
249    for metricsFile in $( ls $1/*json ) ; do
250      attachmentsOptions="-a ${metricsFile} ${attachmentsOptions}"
251    done
[1355]252    IGCM_debug_Print 2 "IGCM_debug_sendAMQP_Metrics"
[1162]253    echo ${encodedBody}|mailx -s "[TEMPORARY AMQP CHANNEL]" ${attachmentsOptions} ${mail_recipient}
254  fi
255
256  # Allways all good for now.
257  return 0
258}
259
260#D-#==================================================================
[1285]261#D-function IGCM_debug_sendAMQP_projectAccounting
262#D- * Purpose: Take over AMQP C client using mail as a message recipient
263#D- * One argument : - File name where project accounting details are stored
264#D- * Attach encoded accounting file.
265
266function IGCM_debug_sendAMQP_projectAccounting {
267
268  typeset mail_recipient encodedBody
269  if [ X${ActivateBigBro} = Xtrue ] ; then
[1418]270    mail_recipient="superviseur@mail.ipsl.upmc.fr"
[1285]271    # Metrics tag on server side
272    code=7010
273    # Usual AMQP message to route messages on server side
274    encodedBody=$( echo "{${genericSimulationID},\"msgCode\":\"${code}\",\"msgUID\":\"$(uuidgen)\",\"accountingProject\":\"${PROJECT}\",\"centre\":\"${CENTER}\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" |  base64 -w 0 )
275    # send mail
276    attachmentsOptions="-a ${1}"
277    IGCM_debug_Print 2 "IGCM_debug_sendAMQP_projectAccounting"
278    echo ${encodedBody}|mailx -s "[TEMPORARY AMQP CHANNEL]" ${attachmentsOptions} ${mail_recipient}
[1290]279    # clean behind
280    rm -f $1
[1285]281  fi
282
283  # Allways all good for now.
284  return 0
285}
286
287#D-#==================================================================
[913]288#D-function IGCM_debug_SendAMQP
289#D- * Purpose: Send body; encoded body and config.card to rabbitMQ
[1053]290function IGCM_debug_sendAMQP {
291
[913]292  typeset decal first additionnalOption encodedBody
293
294  # Encode message Body
295  encodedBody=$( echo "${Body}" | base64 -w 0 )
296
297  # Send config.card ?
298  if [ X${1} = Xactivate ] ; then
299    # Encode config.card
300    cat ${SUBMIT_DIR}/config.card | base64 -w 0 > ${SUBMIT_DIR}/config.card.base64
301    # Prepare additionnal option
302    additionnalOption="-f ${SUBMIT_DIR}/config.card.base64"
[1076]303    #
[1051]304    initBigBro=true
[913]305  else
306    additionnalOption=
[1051]307    #
308    initBigBro=false
[913]309  fi
310
311  # Only cosmetics : stack file
[1115]312  if [ X${ActivateStackFilling} = Xtrue ] ; then
313    decal=0
314    while [ ${decal} -lt ${IGCM_debug_LenStack} ]; do
315      printf ' ' >> ${StackFileLocation}/${StackFileName}
316      (( decal = decal + 1 ))
317    done
318    # Log to stack file using human readable format
319    echo "${Body}" >> ${StackFileLocation}/${StackFileName}
320  fi
[913]321
[983]322  # Log separately encoded AMQP message command for reuse in a mock up
[1120]323  #echo sendAMQPMsg -h localhost -p 5672 ${additionnalOption} -b ${encodedBody} >> ${RUN_DIR_PATH}/send.AMQP.${config_UserChoices_JobName}.${config_UserChoices_ExperimentName}.${config_UserChoices_SpaceName}.${config_UserChoices_TagName}.${CumulPeriod}.history.txt
[913]324
325  # Send the message
[983]326  if [ X${BigBrotherChannel} = XMAIL ] ; then
327    IGCM_debug_send_AMQP_msg__MAILTUNNEL "${encodedBody}"
328    status=$?
329  else
330    sendAMQPMsg -h localhost -p 5672 ${additionnalOption} -b ${encodedBody}
331    status=$?
332  fi
333
[913]334  if [ ${status} -gt 0 ] ; then
335    IGCM_debug_Print 2 "IGCM_debug_Push/PopStack/ActivateBigBro : command sendAMQPMsg failed error code ${status}"
[1051]336    echo sendAMQPMsg -h localhost -p 5672 -b "${Body}"
[1090]337    exit 1
[913]338  fi
339}
340
341#D-#==================================================================
[2]342#D-function IGCM_debug_CallStack
[913]343#D-* Purpose: Print the call stack tree from the oldest to the youngest (opposite of the display standard)
[2]344#D-
345function IGCM_debug_CallStack {
[544]346  if ( $DEBUG_debug ) ; then
[913]347    # Cosmetics
[544]348    typeset i decal
[823]349    i=0
[544]350    until [ $i -eq ${IGCM_debug_LenStack} ]; do
351      decal=0
352      until [ $decal -eq ${i} ]; do
[869]353        printf -- ' '
[823]354        (( decal = decal + 1 ))
[544]355      done
[869]356      echo "$i - ${IGCM_debug_Stack[$(( $IGCM_debug_LenStack-$i-1 ))]}" "(${IGCM_debug_StackArgs[$(( $IGCM_debug_LenStack-$i-1 ))]})"
[823]357      ((i = i + 1))
[544]358    done
359  fi
[2]360}
361
362#D-#==================================================================
363#D-function IGCM_debug_PushStack
364#D-* Purpose: Push a function name in the stack
365#D-
366function IGCM_debug_PushStack {
[544]367  if ( $DEBUG_debug ) ; then
[913]368    typeset decal inputs startTime_ms
369
370    # Only cosmetics : stack file
[1115]371    if [ X${ActivateStackFilling} = Xtrue ] ; then
372      echo >> ${StackFileLocation}/${StackFileName}
373      decal=0
374      while [ ${decal} -lt ${IGCM_debug_LenStack} ]; do
375        printf ' ' >> ${StackFileLocation}/${StackFileName}
376        (( decal = decal + 1 ))
377      done
[2]378
[1115]379      # Fill the stack file
380      echo "> ${IGCM_debug_LenStack} : ${@}" >> ${StackFileLocation}/${StackFileName}
381    fi
[926]382
[913]383    # Save input list in an indexed array
[823]384    INPUTS=( $@ )
[913]385
386    # Get timing information
387    startTime_ms=$( IGCM_debug_getDate_ms )
388
[544]389    # We add function call name on beginning of the stack
390    set +A IGCM_debug_Stack -- ${1} ${IGCM_debug_Stack[*]}
[2]391
[913]392    # Save timing in milliseconds in an indexed array
393    set +A IGCM_debug_StackTiming -- ${startTime_ms} ${IGCM_debug_StackTiming[*]}
394
[544]395    # We include the "null" Args in the beginning of the StackArgs
[913]396    set +A IGCM_debug_StackArgs ${NULL_STR} ${IGCM_debug_StackArgs[*]}
397
[544]398    # Then, we shift StackArgs tabular
[1065]399    # Replacing blank separated list by comma separated list of quoted elements (except the first and last element)
[913]400    if [ $# -gt 1 ]; then
[1065]401      IGCM_debug_StackArgs[0]=$(echo ${INPUTS[*]:1} | sed -e "s/\ /\",\"/g" )
[544]402    fi
[855]403
404    # Increment LenStack
[544]405    (( IGCM_debug_LenStack = IGCM_debug_LenStack + 1 ))
[2]406
[869]407    #IGCM_debug_CallStack
[544]408  fi
[2]409}
410
411#D-#==================================================================
412#D-function IGCM_debug_PopStack
413#D-* Purpose: Pop a function name in the stack
414#D-
415function IGCM_debug_PopStack {
[544]416  if ( $DEBUG_debug ) ; then
[926]417    typeset i decal command arguments startTime_ms endTime_ms
[941]418    typeset instrumentation dest prefix
[926]419    # they are not typeset because they are send "by adress" to son functions
420    # we unset them to avoid "memory effect"
421    unset fileList source
[913]422
423    # INTRODUCE SIMPLE ERROR GENERATOR TO TEST SUPERVISOR
424    # PROBABILITY ERROR IS 0.0001 PER COMMAND OR FUNCTION CALL
425    # THERE ARE ~500 COMMAND OR FUNCTION CALL PER PERIOD
[1277]426    # ONLY WHEN TaskType is "computing".
427    if [ X${ActivateBigBro} = Xtrue ] ; then
428      if [ X${TaskType} = Xcomputing ]; then
429        if ( ${RandomError} ) ; then
430          if [ $((RANDOM%10000)) -le 10 ] ; then
431            IGCM_debug_Print 1 "Random error has been triggered"
432            if [ X${ActivateStackFilling} = Xtrue ] ; then
433              echo "RANDOM ERROR" >> ${StackFileLocation}/${StackFileName}
434            fi
435            ExitFlag=true
436          fi
[1115]437        fi
[913]438      fi
439    fi
440
[544]441    if [ "${IGCM_debug_Stack[0]}" = "${1}" ]; then
[913]442      # Everything is cool
443
444      # Get timing information
445      endTime_ms=$( IGCM_debug_getDate_ms )
446
447      # Save Stack information before poping the stack
448      command=${IGCM_debug_Stack[0]}
449
[1084]450      # Go from comma separated list of quoted elements (except the first and the last element)
451      # to unquoted space separated elements in an array
[1083]452      set -A arguments -- $( echo ${IGCM_debug_StackArgs[0]} | sed -e "s/\",\"/\ /g" )
[913]453
454      # Save Stack information before poping the stack
455      startTime_ms=${IGCM_debug_StackTiming[0]}
456
457      # Pop the stack
[823]458      (( IGCM_debug_LenStack = IGCM_debug_LenStack - 1 ))
459      set -A IGCM_debug_Stack -- ${IGCM_debug_Stack[*]:1}
460      set -A IGCM_debug_StackArgs -- ${IGCM_debug_StackArgs[*]:1}
[913]461      set -A IGCM_debug_StackTiming -- ${IGCM_debug_StackTiming[*]:1}
[544]462    else
463      echo 'IGCM_debug_Exit : stack is corrupted ! LenStack =' ${IGCM_debug_LenStack}
464      IGCM_debug_Exit $@
465    fi
[913]466
[914]467    # Special actions depending on command to prepare IGCM_debug_PrintInfosActions call
[913]468    # We are interested in:
469    #  0. Which command performs the work
470    #  1. Size of entity we are working with
471    #  2. Where are we reading
472    #  3. Where are we writing
473    #  4. How long it took
474
[915]475    instrumentation=false
476
[913]477    case ${command} in
[925]478    # Classical copy (only files are given to IGCM_sys_Cp as options)
479    IGCM_sys_Cp)
480      instrumentation=true
481      # All but the latest
482      fileList=${arguments[*]:0:${#arguments[*]}-1}
483      # just need the first file to get the directory
484      source=${arguments[0]}
485      # Nothing but the latest
486      dest=${arguments[${#arguments[*]}-1]}
487      # Size of file whose name are stored in a list
488      entitySize=$( IGCM_debug_sizeOfTabContent fileList ${dest} )
489      ;;
490
[913]491    # Copy from archive machine or from buffer
492    IGCM_sys_Get|IGCM_sys_GetBuffer)
[915]493      instrumentation=true
[913]494      if [ ${#arguments[*]} -eq 2 ] ; then
495        source=${arguments[0]}
496        dest=${arguments[1]}
497        # Size of file whose name are stored in a variable
[917]498        entitySize=$( IGCM_debug_sizeOfTabContent source ${dest} )
[913]499      elif ( [ ${#arguments[*]} -eq 3 ] && [ ${arguments[0]} = '/l' ] ) ; then
[936]500        # IGCM_sys_Get /l liste_file[*] /ccc/scratch/cont003/dsm/p86denv/RUN_DIR/985998_14754/
[913]501        # Keep the array name hosting the all list
[936]502        eval set +A fileList \${${arguments[1]}}
[913]503        # just need the first file to get the directory
[936]504        source=${fileList[0]}
[931]505        dest=${arguments[2]}
[934]506        # Size of file whose name are stored in a list
[936]507        entitySize=$( IGCM_debug_sizeOfTabContent fileList[*] ${dest} )
[913]508      elif [ [ ${#arguments[*]} -ge 3 ] ; then
509       # All but the latest
[916]510        fileList=${arguments[*]:0:${#arguments[*]}-1}
[913]511        # just need the first file to get the directory
512        source=${arguments[0]}
513        # Nothing but the latest
514        dest=${arguments[${#arguments[*]}-1]}
515        # Size of file whose name are stored in a list
[917]516        entitySize=$( IGCM_debug_sizeOfTabContent fileList ${dest} )
[913]517      fi
518      ;;
519
[925]520    # Copy from compute node or copy to archive/buffer
521    IGCM_sys_Get_Master|IGCM_sys_Get_Dir|IGCM_sys_Put_Out|IGCM_sys_PutBuffer_Out)
[924]522      instrumentation=true
[916]523      source=${arguments[0]}
[924]524      dest=${arguments[1]}
525      # Size of file whose name are stored in a variable
526      entitySize=$( IGCM_debug_sizeOfTabContent source ${dest} )
[913]527      ;;
528
529    # Rebuild command
530    IGCM_sys_rebuild|IGCM_sys_rebuild_station)
[915]531      instrumentation=true
[913]532      # All but the first
533      fileList=${arguments[*]:1:${#arguments[*]}-1}
534      # just need a file to get the directory
535      source=${arguments[1]}
536      # Nothing but the first
537      dest=${arguments[0]}
538      # Size of file whose name are stored in a list
[917]539      entitySize=$( IGCM_debug_sizeOfTabContent fileList ${dest} )
[913]540      ;;
[941]541
[926]542    # NCO commands
543    IGCM_sys_ncrcat|IGCM_sys_ncecat|IGCM_sys_ncra|IGCM_sys_ncks|IGCM_sys_cdo)
544      # Example of what we want to catch : only filenames in those command lines
545      # IGCM_sys_ncrcat -O -v ${list_var_final_ncrcat} ${OUT_SE[*]} ${RESULT_SE}
546      # IGCM_sys_ncrcat --hst -v ${liste_coord}${var} ${file1} ${liste_file_tmp[*]} ${file_out}
547      # IGCM_sys_ncrcat -p ${dir} ${liste_file_tmp} --output ${output}
548      # IGCM_sys_ncrcat -x -v ${list_var} -p ${dir} ${liste_file_tmp} --output ${output}
549      instrumentation=true
[941]550      keepGoing=true
551      prefix=.
[926]552      i=0
553      while ( ${keepGoing} ) ; do
[941]554        # the last one is not interesting
555        if [ ${i} -eq ${#arguments[*]}-1 ] ; then
556          keepGoing=false
557        # look after "-p" option. Path prefix is the following arguments
558        elif [ ${arguments[${i}]} = "-p" ] ; then
[926]559          ((i = i + 1))
[941]560          prefix=${arguments[${i}]}
561          ((i = i + 1))
562        elif [ ${i} -eq ${#arguments[*]}-1 ] ; then
[926]563          keepGoing=false
[941]564        # looking for files
565        elif [ -f ${prefix}/${arguments[${i}]} ] ; then
566          fileList="${fileList} ${prefix}/${arguments[${i}]}"
567          ((i = i + 1))
568        # other options are not interesting
[926]569        else
570          ((i = i + 1))
571        fi
572      done
[941]573
[926]574      # i value is at least 1
575      # just need one file to get the directory
[941]576      source=$( echo ${fileList} | gawk '{print $1}' )
[926]577      # Nothing but the latest
578      dest=${arguments[${#arguments[*]}-1]}
579      # Size of file whose name are stored in a list
580      entitySize=$( IGCM_debug_sizeOfTabContent fileList ${dest} )
581      ;;
[913]582    esac
583
584    # Print information related to instrumentation
[915]585    ( ${instrumentation} ) && IGCM_debug_PrintInfosActions ${command} ${entitySize} ${startTime_ms} ${endTime_ms} ${dest} ${source}
[913]586
587    # Only cosmetics : stack file
[1115]588    if [ X${ActivateStackFilling} = Xtrue ] ; then
589      decal=0
590      while [ ${decal} -lt ${IGCM_debug_LenStack} ]; do
591        printf ' ' >> ${StackFileLocation}/${StackFileName}
592        (( decal = decal + 1 ))
593      done
594    fi
[2]595
[855]596    if ( ${ExitFlag} ) ; then
597      # Inform the stack file
[1115]598      if [ X${ActivateStackFilling} = Xtrue ] ; then
599        echo '!!! ExitFlag has been activated !!!' >> ${StackFileLocation}/${StackFileName}
600      fi
[874]601
[1216]602      # Unplugged message 4900 handling for now. To ease downstream treatment.
[1244]603      if [ X${ActivateBigBro} = Xtrue ] ; then
604        if [ X${TaskType} = Xcomputing ]; then
605          # RabbitMQ message code "COMPUTING JOBs COMMAND FAILURE"
606          code=1900
607        elif [ X${TaskType} = Xpost-processing ]; then
608          # RabbitMQ message code "POST-PROCESSING JOBs COMMAND FAILURE"
609          code=2900
610        elif [ X${TaskType} = Xchecking ]; then
611          # RabbitMQ message code "POST-PROCESSING FROM CHECKER JOBs COMMAND FAILURE"
612          code=3900
613        fi
614        # RabbitMQ message body
615        Body=$( echo "{${genericSimulationID},\"msgCode\":\"${code}\",\"msgUID\":\"$(uuidgen)\",\"command\":\"${command}\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" )
616
617        # Fill the rabbitMQ queue
618        IGCM_debug_sendAMQP
619      fi
[855]620    else
621      # Inform the stack file
[1115]622      if [ X${ActivateStackFilling} = Xtrue ] ; then
623        echo "< ${IGCM_debug_LenStack} : ${@}" >> ${StackFileLocation}/${StackFileName}
624      fi
[855]625    fi
626
[913]627    # Reset array if necessary
[544]628    if [ ${IGCM_debug_LenStack} = 0 ]; then
629      #echo
630      #IGCM_debug_Print 3 "Clean stack array"
631      #echo
632      unset IGCM_debug_Stack
633      unset IGCM_debug_StackArgs
[913]634      unset IGCM_debug_StackTiming
[544]635      IGCM_debug_Stack[0]=${NULL_STR}
636      IGCM_debug_StackArgs[0]=${NULL_STR}
[913]637      IGCM_debug_StackTiming[0]=${NULL_STR}
[2]638    fi
[544]639  fi
[869]640  #IGCM_debug_CallStack
[2]641}
642
643#D-#==================================================================
[1189]644#D-function IGCM_debug_BigBro_Initialize
[855]645#D-* Purpose: switch rabbitMQ on
646#D-
[1189]647function IGCM_debug_BigBro_Initialize {
648  IGCM_debug_PushStack "IGCM_debug_BigBro_Initialize"
[855]649
[1347]650  typeset postProcessingIDLength postProcessingName postProcessingDate postProcessingDimn postProcessingComp postProcessingFile accountingFile
[1229]651
[1051]652# Message type standard fields:
653# https://github.com/Prodiguer/prodiguer-docs/wiki/MQ-Standard-Message-Fields
654
655# Message type dictionnary and custom fields:
656# https://github.com/Prodiguer/prodiguer-docs/wiki/Monitoring-Message-Dictionary
657
[868]658  if [ X${BigBrother} = Xtrue ] ; then
[1051]659    # create a unique ID for this specific job
660    jobuid=$(uuidgen)
[913]661
[1244]662    # get the assigned id by the scheduler for that job
663    IGCM_sys_getJobSchedulerID jobSchedulerID
664
[1189]665    if [ X${TaskType} = Xcomputing ]; then
666      if ( ${FirstInitialize} ) ; then
667        # RabbitMQ message code "BEGIN A SIMULATION"
668        code=0000
669        # create and persist a unique id for this simulation
670        simuid=$(uuidgen)
671        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration simuid ${simuid}
672        # Standard fields for the first message
[1244]673        genericSimulationID=$( echo "\"msgApplication\":\"monitoring\",\"msgProducer\":\"libigcm\",\"msgProducerVersion\":\"${libIGCMVersion}\",\"activity\":\"IPSL\",\"name\":\"${config_UserChoices_JobName}\",\"experiment\":\"${config_UserChoices_ExperimentName}\",\"space\":\"${config_UserChoices_SpaceName}\",\"model\":\"${config_UserChoices_TagName}\",\"startDate\":\"${config_UserChoices_DateBegin}\",\"endDate\":\"${config_UserChoices_DateEnd}\",\"login\":\"${LOGIN}\",\"centre\":\"${CENTER}\",\"machine\":\"${MASTER}\",\"simuid\":\"${simuid}\",\"jobuid\":\"${jobuid}\"" )
[1189]674        # RabbitMQ message body with specific fields associated message codes treated here
[1353]675        Body=$( echo "{${genericSimulationID},\"msgCode\":\"${code}\",\"accountingProject\":\"${PROJECT}\",\"jobWarningDelay\":\"${jobWarningDelay}\",\"jobSchedulerID\":\"${jobSchedulerID}\",\"jobSubmissionPath\":\"${SUBMIT_DIR}\",\"archivePath\":\"${R_SAVE}\",\"storagePath\":\"${R_BUFR}\",\"storageSmallPath\":\"${R_FIGR}\",\"msgUID\":\"$(uuidgen)\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" )
[1189]676        # Fill the rabbitMQ queue (the config.card in use will be sent)
677        IGCM_debug_sendAMQP activate
678      else
679        # RabbitMQ message code "A NEW COMPUTING JOB IS RUNNING PART OF A SIMULATION"
680        code=1000
681        # retrieve this simulation's unique id
682        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration simuid
683        simuid=${run_Configuration_simuid}
684        # Using standard fields for message others than the first one. Still subject to change
[1244]685        genericSimulationID=$( echo "\"msgApplication\":\"monitoring\",\"msgProducer\":\"libigcm\",\"msgProducerVersion\":\"${libIGCMVersion}\",\"simuid\":\"${simuid}\",\"jobuid\":\"${jobuid}\"" )
[1189]686        # RabbitMQ message body with specific fields associated message codes treated here
[1353]687        Body=$( echo "{${genericSimulationID},\"msgCode\":\"${code}\",\"accountingProject\":\"${PROJECT}\",\"jobWarningDelay\":\"${jobWarningDelay}\",\"jobSchedulerID\":\"${jobSchedulerID}\",\"jobSubmissionPath\":\"${SUBMIT_DIR}\",\"archivePath\":\"${R_SAVE}\",\"storagePath\":\"${R_BUFR}\",\"storageSmallPath\":\"${R_FIGR}\",\"msgUID\":\"$(uuidgen)\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" )
[1189]688        # Fill the rabbitMQ queue
689        IGCM_debug_sendAMQP
690      fi
691
692      # NOT VERY NICE BUT ... IT WORKS
693      # Be sure that the genericSimulationID will be small from now on
694      # Using standard fields for messages others than the first one. Still subject to change
[1244]695      genericSimulationID=$( echo "\"msgApplication\":\"monitoring\",\"msgProducer\":\"libigcm\",\"msgProducerVersion\":\"${libIGCMVersion}\",\"simuid\":\"${simuid}\",\"jobuid\":\"${jobuid}\"" )
[1189]696
697    elif [ X${TaskType} = Xpost-processing ]; then
698      # RabbitMQ message code "A NEW POST-PROCESSING JOB IS RUNNING PART OF A SIMULATION"
699      code=2000
[1076]700      # retrieve this simulation's unique id
[1051]701      IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration simuid
[1086]702      simuid=${run_Configuration_simuid}
[1076]703      # Using standard fields for message others than the first one. Still subject to change
[1244]704      genericSimulationID=$( echo "\"msgApplication\":\"monitoring\",\"msgProducer\":\"libigcm\",\"msgProducerVersion\":\"${libIGCMVersion}\",\"simuid\":\"${simuid}\",\"jobuid\":\"${jobuid}\"" )
[1229]705     
706      # Specify the post-processing task we are dealing with
[1244]707      postProcessingIDLength=$( echo "${Script_Post_Output}" | tr -d -c "\." | wc -c )
[1229]708      postProcessingName=$( echo "${Script_Post_Output}" | gawk -F. '{print $1}' )
709      postProcessingDate=$( echo "${Script_Post_Output}" | gawk -F. '{print $2}' )
[1231]710      postProcessingDimn="null"
711      postProcessingComp="null"
712      postProcessingFile="null"
[1254]713      if [ ${postProcessingIDLength} -eq 2 ] ; then
[1231]714        postProcessingDimn=$( echo "${Script_Post_Output}" | gawk -F. '{print $3}' )
[1254]715      elif [ ${postProcessingIDLength} -eq 4 ] ; then
[1229]716        postProcessingComp=$( echo "${Script_Post_Output}" | gawk -F. '{print $4}' )
717        postProcessingFile=$( echo "${Script_Post_Output}" | gawk -F. '{print $5}' )
718      fi
719
[1087]720      # RabbitMQ message body with specific fields associated message codes treated here
[1244]721      Body=$( echo "{${genericSimulationID},\"msgCode\":\"${code}\",\"accountingProject\":\"${PROJECT}\",\"jobWarningDelay\":\"${jobWarningDelay}\",\"jobSchedulerID\":\"${jobSchedulerID}\",\"jobSubmissionPath\":\"${SUBMIT_DIR}\",\"msgUID\":\"$(uuidgen)\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\",\"postProcessingName\":\"${postProcessingName}\",\"postProcessingDate\":\"${postProcessingDate}\",\"postProcessingDimn\":\"${postProcessingDimn}\",\"postProcessingComp\":\"${postProcessingComp}\",\"postProcessingFile\":\"${postProcessingFile}\"}" )
[1087]722      # Fill the rabbitMQ queue
723      IGCM_debug_sendAMQP
[1355]724
725    elif [ X${TaskType} = Xchecking ]; then
726      # retrieve this simulation's unique id
727      IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration simuid
728      simuid=${run_Configuration_simuid}
729      # Using standard fields for message others than the first one. Still subject to change
730      genericSimulationID=$( echo "\"msgApplication\":\"monitoring\",\"msgProducer\":\"libigcm\",\"msgProducerVersion\":\"${libIGCMVersion}\",\"simuid\":\"${simuid}\",\"jobuid\":\"N\/A\"" )
[855]731    fi
[1285]732
[1295]733    # Turn the flag on
734    ActivateBigBro=true
735
[1354]736    if [ X${TaskType} = Xcomputing ]; then
737      # Save project accounting details in a file
738      accountingFile=cpt_${CENTER}_${PROJECT}_$( date +"%Y%m%d_%H%M" ).dat
739      IGCM_sys_projectAccounting ${accountingFile}
[1285]740
[1354]741      # And send it
742      IGCM_debug_sendAMQP_projectAccounting ${accountingFile}
743    fi
[855]744  fi
[1189]745  IGCM_debug_PopStack "IGCM_debug_BigBro_Initialize"
[855]746}
747
748#D-#==================================================================
[1332]749#D-function IGCM_debug_BigBro_Update
750#D-* Purpose: Update rabbitMQ messages exchanges during the run
751#D-
752function IGCM_debug_BigBro_Update {
753  IGCM_debug_PushStack "IGCM_debug_BigBro_Update"
754
755  # Message type standard fields:
756  # https://github.com/Prodiguer/prodiguer-docs/wiki/MQ-Standard-Message-Fields
757
758  # Message type dictionnary and custom fields:
759  # https://github.com/Prodiguer/prodiguer-docs/wiki/Monitoring-Message-Dictionary
760
761  if [ X${ActivateBigBro} = Xtrue ] ; then
[1354]762    if [ X${TaskType} = Xcomputing ]; then
763      # Send ${PeriodDateBegin}, ${PeriodDateEnd} and ${CumulPeriod}
764      # RabbitMQ message body
765      Body=$( echo "{${genericSimulationID},\"msgCode\":\"1001\",\"PeriodDateBegin\":\"${PeriodDateBegin}\",\"PeriodDateEnd\":\"${PeriodDateEnd}\",\"CumulPeriod\":\"${CumulPeriod}\",\"msgUID\":\"$(uuidgen)\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" )
766      # Fill the rabbitMQ queue
767      IGCM_debug_sendAMQP
768    fi
[1332]769  fi
770  IGCM_debug_PopStack "IGCM_debug_BigBro_Update"
771}
772
773#D-#==================================================================
[1189]774#D-function IGCM_debug_BigBro_Finalize
775#D-* Purpose: Finalize rabbitMQ messages exchanges
776#D-
777function IGCM_debug_BigBro_Finalize {
778  IGCM_debug_PushStack "IGCM_debug_BigBro_Finalize"
779
780  # Message type standard fields:
781  # https://github.com/Prodiguer/prodiguer-docs/wiki/MQ-Standard-Message-Fields
782
783  # Message type dictionnary and custom fields:
784  # https://github.com/Prodiguer/prodiguer-docs/wiki/Monitoring-Message-Dictionary
785
786  if ( $DEBUG_debug ) ; then
787    if [ X${ActivateBigBro} = Xtrue ] ; then
788      if [ X${TaskType} = Xcomputing ]; then
789        if ( ${simulationIsOver} ) ; then
790          # RabbitMQ message code "SIMULATION ENDS"
791          code=0100
792          FlushAMQP=true
[1207]793        elif ( ${ExitFlag} ) ; then
794          # RabbitMQ message code "EXIT THE JOBS BECAUSE ERROR(S) HAS BEEN TRIGGERED"
[1244]795          code=1999
[1207]796          FlushAMQP=true
[1189]797        else
798          # RabbitMQ message code "COMPUTING JOB ENDS"
799          code=1100
800        fi
801      elif [ X${TaskType} = Xpost-processing ]; then
[1207]802        if ( ${ExitFlag} ) ; then
803          # RabbitMQ message code "POST-PROCESSING JOB FAILS"
[1244]804          code=2999
[1207]805          FlushAMQP=true
[1244]806        else
[1207]807          # RabbitMQ message code "POST-PROCESSING JOB ENDS"
808          code=2100
809          FlushAMQP=true
810        fi
[1244]811      elif [ X${TaskType} = Xchecking ]; then
812        if ( ${ExitFlag} ) ; then
813          # RabbitMQ message code "POST-PROCESSING JOB FAILS"
814          code=3999
815          FlushAMQP=true
816        else
817          # RabbitMQ message code "POST-PROCESSING JOB ENDS"
818          code=3100
819          FlushAMQP=true
820        fi
[1189]821      fi
822      # RabbitMQ message body
823      Body=$( echo "{${genericSimulationID},\"msgCode\":\"${code}\",\"msgUID\":\"$(uuidgen)\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" )
824      # Fill the rabbitMQ queue
825      IGCM_debug_sendAMQP
826    fi
827  fi
828 
829  IGCM_debug_PopStack "IGCM_debug_BigBro_Finalize"
830}
831
832#D-#==================================================================
[2]833#D-function IGCM_debug_Exit
834#D-* Purpose: Print Call Stack and set ExitFlag to true
835#D-
836function IGCM_debug_Exit {
[544]837  IGCM_debug_PushStack "IGCM_debug_Exit"
838  echo "IGCM_debug_Exit : " "${@}"
[913]839  echo
[894]840  echo "!!!!!!!!!!!!!!!!!!!!!!!!!!"
[913]841  echo "!!   ERROR TRIGGERED    !!"
842  echo "!!   EXIT FLAG SET      !!"
843  echo "!------------------------!"
844  echo
[894]845  IGCM_debug_CallStack
[544]846  ExitFlag=true
847  IGCM_debug_PopStack "IGCM_debug_Exit"
[2]848}
849
850#D-#==================================================
851#D-function IGCM_debug_Verif_Exit
852#D-* Purpose: exit with number 1 if ExitFlag is true
853#D-
854function IGCM_debug_Verif_Exit {
[544]855  if ( ${ExitFlag} ) ; then
[1206]856    echo "IGCM_debug_Verif_Exit : Something wrong happened previously."
[1207]857    echo "IGCM_debug_Verif_Exit : ERROR and EXIT keyword will help find out where."
[1206]858    # Only computing TaskType stops the job for now.
859    if [ X${TaskType} = Xcomputing ] ; then
[775]860      IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Fatal"
861      echo "                        EXIT THE JOB."
862      echo
[869]863      IGCM_debug_CallStack
[874]864
[1206]865      # Mail notification
866      IGCM_sys_SendMail
[913]867
[1207]868      # Inform the rabbitMQ queue
869      IGCM_debug_BigBro_Finalize
870
[544]871      # And Good Bye
872      date
873      exit 1
[1206]874
875    elif [ X${TaskType} = Xpost-processing ] ; then
[1302]876      StopAll=false
[1478]877      typeset postProcessingName
878      postProcessingName=$( echo "${Script_Post_Output}" | gawk -F. '{print $1}' )
[1282]879      # Test if we need to stop the computing job
880      case ${postProcessingName} in
881      atlas*|monitoring*|metrics*)
882        [ ${postProcessingStopLevel} -gt 2 ] && StopAll=true ;;
883      create_*)
884        [ ${postProcessingStopLevel} -gt 1 ] && StopAll=true ;;
885      rebuild*|pack_*)
886        [ ${postProcessingStopLevel} -gt 0 ] && StopAll=true ;;
887      esac
888      # Notify the computing job that something wrong happened and stop it.
[1302]889      ( ${StopAll} ) && IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Fatal.${Script_Post_Output}"
[1282]890
891      # If SpaceName is PROD we stop when post_processing failed
[1206]892      if [ X${config_UserChoices_SpaceName} = XPROD ] ; then
[1220]893        echo "                        EXIT THE POST-PROCESSING JOB."
[1206]894        echo
[1207]895        IGCM_debug_CallStack
896
897        # Inform the rabbitMQ queue
898        IGCM_debug_BigBro_Finalize
899
[1206]900        # And Good Bye
901        date
902        exit 1
903      else
[1207]904        echo "In config.card the variable SpaceName is not in PROD"
[1206]905        echo "              SO WE DO NOT EXIT THE JOB."
906        echo
907        date
908      fi
909    elif [ X${TaskType} = Xchecking ] ; then
[1207]910      echo "Nothing will happen for now"
[2]911    fi
[544]912  fi
[2]913}
914
915#D-#==================================================================
916#D-function IGCM_debug_Print
917#D-* Purpose: Print arguments according to a level of verbosity.
918#D-
919function IGCM_debug_Print
920{
[544]921  typeset level=$1
922  shift
923
924  if [ X"${1}" = X"-e" ]; then
925    typeset cmd_echo="echo -e"
[2]926    shift
[544]927  else
928    typeset cmd_echo="echo"
929  fi
[2]930
[544]931  if [ ${level} -le ${Verbosity} ] ; then
932    typeset i
933    case "${level}" in
934    1) for i in "$@" ; do
[734]935      ${cmd_echo} $(date +"%Y-%m-%d %T") "--Debug1-->" ${i}
[913]936      done ;;
[544]937    2) for i in "$@" ; do
[734]938      ${cmd_echo} $(date +"%Y-%m-%d %T") "--------Debug2-->" ${i}
[913]939      done ;;
[544]940    3) for i in "$@" ; do
[734]941      ${cmd_echo} $(date +"%Y-%m-%d %T") "--------------Debug3-->" ${i}
[913]942      done ;;
[544]943    esac
944  fi
[2]945}
946
947#D-#==================================================================
948#D-function IGCM_debug_PrintVariables
949#D-* Purpose: Print arguments when match a pattern
950#D-           according to a level of verbosity.
951function IGCM_debug_PrintVariables
952{
[544]953  typeset level=$1
954  shift
[2]955
[830]956  list=$( set | grep ^$1 | sed -e "s/'//g" )
[54]957
[544]958  if [ "X${list}" != X ]  ; then
959    IGCM_debug_Print ${level} ${list}
960  fi
[2]961}
962
963#D-#==================================================================
[914]964#D-function IGCM_debug_PrintInfosActions
[913]965#D-* Purpose: Print information related to instrumentation
966function IGCM_debug_PrintInfosActions
967{
968  typeset actionType=$1
969  typeset entitySize=$2
970  typeset start_ms=$3
971  typeset end_ms=$4
972
973  typeset dest=$5
974  typeset source=$6
975
976  typeset diff_ms entitySizeKo entitySizeMo flux_Ko_ms flux_Ko_s flux_Mo_s
[1090]977  typeset dirFrom dirTo
[913]978
979  diff_ms=$(( $end_ms - $start_ms ))
980  # echo "diff_ms=$diff_ms"
981
982  entitySizeKo=$( echo ${entitySize} | gawk -F"|" '{print $1}' )
983  # echo "entitySizeKo=$entitySizeKo"
984  entitySizeMo=$( echo ${entitySize} | gawk -F"|" '{print $2}' )
985
986  # flux en Ko / ms
987  flux_Ko_ms=$( echo "scale=6;${entitySizeKo}/${diff_ms}" | bc )
988  # echo "flux_Ko_ms=$flux_Ko_ms"
989
990  # flux en Ko / s
991  flux_Ko_s=$(( $flux_Ko_ms * 1000 ))
992  # echo "flux_Ko_s=$flux_Ko_s"
993
994  # flux en Mo / s
995  flux_Mo_s=$( echo "scale=6;${flux_Ko_s}/1024" | bc )
996  # echo "flux_Mo_s=$flux_Mo_s"
997
998  if [ -d $dest ] ; then
[1090]999    dirTo=$( readlink -f ${dest} )
[913]1000  else
[1090]1001    dirTo=$( readlink -f $( dirname ${dest} ) )
[913]1002  fi
1003
1004  if [ -d $source ] ; then
[1090]1005    dirFrom=$( readlink -f ${source} )
[913]1006  else
[1090]1007    dirFrom=$( readlink -f $( dirname ${source} ) )
[913]1008  fi
1009
[1094]1010  instrumentationContent=$( echo "\"actionName\":\"${actionType}\",\"size_Mo\":\"${entitySizeMo}\",\"duration_ms\":\"${diff_ms}\",\"throughput_Mo_s\":\"${flux_Mo_s}\",\"dirFrom\":\"${dirFrom}\",\"dirTo\":\"${dirTo}\"" )
[1050]1011
[1115]1012  if [ X${ActivateStackFilling} = Xtrue ] ; then
1013    echo "{${instrumentationContent}}" >> ${StackFileLocation}/${StackFileName}
1014  fi
[1050]1015
1016  # Inform the rabbitMQ queue
1017  if [ X${ActivateBigBro} = Xtrue ] ; then
1018    # RabbitMQ message body
[1065]1019    Body=$( echo "{${genericSimulationID},\"msgCode\":\"7000\",\"msgUID\":\"$(uuidgen)\",${instrumentationContent},\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" )
[1050]1020    # Fill the rabbitMQ queue
1021    IGCM_debug_sendAMQP
1022  fi
[913]1023}
1024
1025#D-#==================================================================
[2]1026#D-function IGCM_debug_Check
1027#D- * Purpose: Check the present file by comparison with a reference file
1028function IGCM_debug_Check
1029{
[544]1030  #---------------------
1031  if [ ! -n "${libIGCM}" ] ; then
1032    echo "Check libIGCM_debug ..........................................[ FAILED ]"
1033    echo "--Error--> libIGCM variable is not defined"
1034    exit 2
1035  fi
[2]1036
[544]1037  #---------------------
1038  if [ ! -n "${Verbosity}" ] ; then
1039    echo "Check libIGCM_debug ..........................................[ FAILED ]"
1040    echo "--Error--> Verbosity variable is not defined"
1041    exit 3
1042  fi
[2]1043
[544]1044  #---------------------
[1118]1045  # Need to remove timestamps here
1046  diff ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ref <(${libIGCM}/libIGCM_debug/IGCM_debug_Test.ksh | 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") > /dev/null 2>&1
[1106]1047  status=$?
[2]1048
[1118]1049  if [ ${status} -eq 0 ] ; then
[544]1050    echo "Check libIGCM_debug ..............................................[ OK ]"
1051  else
1052    echo "Check libIGCM_debug ..........................................[ FAILED ]"
1053    echo "--Error--> Execution of ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ksh"
1054    echo "           has produced the file IGCM_debug_Test.ref.failed"
1055    echo "           Please analyse differences with the reference file by typing:"
1056    echo "           diff IGCM_debug_Test.ref.failed ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ref"
1057    echo "           Report errors to the author: Patrick.Brockmann@cea.fr"
[1118]1058    diff ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ref <(${libIGCM}/libIGCM_debug/IGCM_debug_Test.ksh | 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")
[544]1059    exit 4
1060  fi
1061  #---------------------
[2]1062}
Note: See TracBrowser for help on using the repository browser.