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

Last change on this file since 1332 was 1332, checked in by sdipsl, 8 years ago
  • 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: 39.2 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
[1325]48typeset -r libIGCMVersion="2.8.1"
[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
[1072]149  mail_recipient="superviseur@ipsl.jussieu.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-#==================================================================
[1162]208#D-function IGCM_debug_sendAMQP_Metrics
209#D- * Purpose: Take over AMQP C client using mail as a message recipient
[1202]210#D- * Two arguments : - Directory where metrics.json files can be found
211#D- *                 - Metrics Group Name. metrics will be added to this group
[1162]212#D- * Attach encoded metrics.json files.
213
214function IGCM_debug_sendAMQP_Metrics {
215
216  typeset mail_recipient encodedBody
217  if [ X${ActivateBigBro} = Xtrue ] ; then
218    mail_recipient="superviseur@ipsl.jussieu.fr"
219    # Metrics tag on server side
220    code=7100
221    # Usual AMQP message to route messages on server side
[1202]222    encodedBody=$( echo "{${genericSimulationID},\"msgCode\":\"${code}\",\"msgUID\":\"$(uuidgen)\",\"metricsGroupName\":\"${2}\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" |  base64 -w 0 )
[1162]223    # send mail
224    attachmentsOptions=""
225    for metricsFile in $( ls $1/*json ) ; do
226      attachmentsOptions="-a ${metricsFile} ${attachmentsOptions}"
227    done
[1204]228    IGCM_debug_Print 2 "IGCM_debug_sendAMQP_Metrics "
[1162]229    echo ${encodedBody}|mailx -s "[TEMPORARY AMQP CHANNEL]" ${attachmentsOptions} ${mail_recipient}
230  fi
231
232  # Allways all good for now.
233  return 0
234}
235
236#D-#==================================================================
[1285]237#D-function IGCM_debug_sendAMQP_projectAccounting
238#D- * Purpose: Take over AMQP C client using mail as a message recipient
239#D- * One argument : - File name where project accounting details are stored
240#D- * Attach encoded accounting file.
241
242function IGCM_debug_sendAMQP_projectAccounting {
243
244  typeset mail_recipient encodedBody
245  if [ X${ActivateBigBro} = Xtrue ] ; then
246    mail_recipient="superviseur@ipsl.jussieu.fr"
247    # Metrics tag on server side
248    code=7010
249    # Usual AMQP message to route messages on server side
250    encodedBody=$( echo "{${genericSimulationID},\"msgCode\":\"${code}\",\"msgUID\":\"$(uuidgen)\",\"accountingProject\":\"${PROJECT}\",\"centre\":\"${CENTER}\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" |  base64 -w 0 )
251    # send mail
252    attachmentsOptions="-a ${1}"
253    IGCM_debug_Print 2 "IGCM_debug_sendAMQP_projectAccounting"
254    echo ${encodedBody}|mailx -s "[TEMPORARY AMQP CHANNEL]" ${attachmentsOptions} ${mail_recipient}
[1290]255    # clean behind
256    rm -f $1
[1285]257  fi
258
259  # Allways all good for now.
260  return 0
261}
262
263#D-#==================================================================
[913]264#D-function IGCM_debug_SendAMQP
265#D- * Purpose: Send body; encoded body and config.card to rabbitMQ
[1053]266function IGCM_debug_sendAMQP {
267
[913]268  typeset decal first additionnalOption encodedBody
269
270  # Encode message Body
271  encodedBody=$( echo "${Body}" | base64 -w 0 )
272
273  # Send config.card ?
274  if [ X${1} = Xactivate ] ; then
275    # Encode config.card
276    cat ${SUBMIT_DIR}/config.card | base64 -w 0 > ${SUBMIT_DIR}/config.card.base64
277    # Prepare additionnal option
278    additionnalOption="-f ${SUBMIT_DIR}/config.card.base64"
[1076]279    #
[1051]280    initBigBro=true
[913]281  else
282    additionnalOption=
[1051]283    #
284    initBigBro=false
[913]285  fi
286
287  # Only cosmetics : stack file
[1115]288  if [ X${ActivateStackFilling} = Xtrue ] ; then
289    decal=0
290    while [ ${decal} -lt ${IGCM_debug_LenStack} ]; do
291      printf ' ' >> ${StackFileLocation}/${StackFileName}
292      (( decal = decal + 1 ))
293    done
294    # Log to stack file using human readable format
295    echo "${Body}" >> ${StackFileLocation}/${StackFileName}
296  fi
[913]297
[983]298  # Log separately encoded AMQP message command for reuse in a mock up
[1120]299  #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]300
301  # Send the message
[983]302  if [ X${BigBrotherChannel} = XMAIL ] ; then
303    IGCM_debug_send_AMQP_msg__MAILTUNNEL "${encodedBody}"
304    status=$?
305  else
306    sendAMQPMsg -h localhost -p 5672 ${additionnalOption} -b ${encodedBody}
307    status=$?
308  fi
309
[913]310  if [ ${status} -gt 0 ] ; then
311    IGCM_debug_Print 2 "IGCM_debug_Push/PopStack/ActivateBigBro : command sendAMQPMsg failed error code ${status}"
[1051]312    echo sendAMQPMsg -h localhost -p 5672 -b "${Body}"
[1090]313    exit 1
[913]314  fi
315}
316
317#D-#==================================================================
[2]318#D-function IGCM_debug_CallStack
[913]319#D-* Purpose: Print the call stack tree from the oldest to the youngest (opposite of the display standard)
[2]320#D-
321function IGCM_debug_CallStack {
[544]322  if ( $DEBUG_debug ) ; then
[913]323    # Cosmetics
[544]324    typeset i decal
[823]325    i=0
[544]326    until [ $i -eq ${IGCM_debug_LenStack} ]; do
327      decal=0
328      until [ $decal -eq ${i} ]; do
[869]329        printf -- ' '
[823]330        (( decal = decal + 1 ))
[544]331      done
[869]332      echo "$i - ${IGCM_debug_Stack[$(( $IGCM_debug_LenStack-$i-1 ))]}" "(${IGCM_debug_StackArgs[$(( $IGCM_debug_LenStack-$i-1 ))]})"
[823]333      ((i = i + 1))
[544]334    done
335  fi
[2]336}
337
338#D-#==================================================================
339#D-function IGCM_debug_PushStack
340#D-* Purpose: Push a function name in the stack
341#D-
342function IGCM_debug_PushStack {
[544]343  if ( $DEBUG_debug ) ; then
[913]344    typeset decal inputs startTime_ms
345
346    # Only cosmetics : stack file
[1115]347    if [ X${ActivateStackFilling} = Xtrue ] ; then
348      echo >> ${StackFileLocation}/${StackFileName}
349      decal=0
350      while [ ${decal} -lt ${IGCM_debug_LenStack} ]; do
351        printf ' ' >> ${StackFileLocation}/${StackFileName}
352        (( decal = decal + 1 ))
353      done
[2]354
[1115]355      # Fill the stack file
356      echo "> ${IGCM_debug_LenStack} : ${@}" >> ${StackFileLocation}/${StackFileName}
357    fi
[926]358
[913]359    # Save input list in an indexed array
[823]360    INPUTS=( $@ )
[913]361
362    # Get timing information
363    startTime_ms=$( IGCM_debug_getDate_ms )
364
[544]365    # We add function call name on beginning of the stack
366    set +A IGCM_debug_Stack -- ${1} ${IGCM_debug_Stack[*]}
[2]367
[913]368    # Save timing in milliseconds in an indexed array
369    set +A IGCM_debug_StackTiming -- ${startTime_ms} ${IGCM_debug_StackTiming[*]}
370
[544]371    # We include the "null" Args in the beginning of the StackArgs
[913]372    set +A IGCM_debug_StackArgs ${NULL_STR} ${IGCM_debug_StackArgs[*]}
373
[544]374    # Then, we shift StackArgs tabular
[1065]375    # Replacing blank separated list by comma separated list of quoted elements (except the first and last element)
[913]376    if [ $# -gt 1 ]; then
[1065]377      IGCM_debug_StackArgs[0]=$(echo ${INPUTS[*]:1} | sed -e "s/\ /\",\"/g" )
[544]378    fi
[855]379
380    # Increment LenStack
[544]381    (( IGCM_debug_LenStack = IGCM_debug_LenStack + 1 ))
[2]382
[869]383    #IGCM_debug_CallStack
[544]384  fi
[2]385}
386
387#D-#==================================================================
388#D-function IGCM_debug_PopStack
389#D-* Purpose: Pop a function name in the stack
390#D-
391function IGCM_debug_PopStack {
[544]392  if ( $DEBUG_debug ) ; then
[926]393    typeset i decal command arguments startTime_ms endTime_ms
[941]394    typeset instrumentation dest prefix
[926]395    # they are not typeset because they are send "by adress" to son functions
396    # we unset them to avoid "memory effect"
397    unset fileList source
[913]398
399    # INTRODUCE SIMPLE ERROR GENERATOR TO TEST SUPERVISOR
400    # PROBABILITY ERROR IS 0.0001 PER COMMAND OR FUNCTION CALL
401    # THERE ARE ~500 COMMAND OR FUNCTION CALL PER PERIOD
[1277]402    # ONLY WHEN TaskType is "computing".
403    if [ X${ActivateBigBro} = Xtrue ] ; then
404      if [ X${TaskType} = Xcomputing ]; then
405        if ( ${RandomError} ) ; then
406          if [ $((RANDOM%10000)) -le 10 ] ; then
407            IGCM_debug_Print 1 "Random error has been triggered"
408            if [ X${ActivateStackFilling} = Xtrue ] ; then
409              echo "RANDOM ERROR" >> ${StackFileLocation}/${StackFileName}
410            fi
411            ExitFlag=true
412          fi
[1115]413        fi
[913]414      fi
415    fi
416
[544]417    if [ "${IGCM_debug_Stack[0]}" = "${1}" ]; then
[913]418      # Everything is cool
419
420      # Get timing information
421      endTime_ms=$( IGCM_debug_getDate_ms )
422
423      # Save Stack information before poping the stack
424      command=${IGCM_debug_Stack[0]}
425
[1084]426      # Go from comma separated list of quoted elements (except the first and the last element)
427      # to unquoted space separated elements in an array
[1083]428      set -A arguments -- $( echo ${IGCM_debug_StackArgs[0]} | sed -e "s/\",\"/\ /g" )
[913]429
430      # Save Stack information before poping the stack
431      startTime_ms=${IGCM_debug_StackTiming[0]}
432
433      # Pop the stack
[823]434      (( IGCM_debug_LenStack = IGCM_debug_LenStack - 1 ))
435      set -A IGCM_debug_Stack -- ${IGCM_debug_Stack[*]:1}
436      set -A IGCM_debug_StackArgs -- ${IGCM_debug_StackArgs[*]:1}
[913]437      set -A IGCM_debug_StackTiming -- ${IGCM_debug_StackTiming[*]:1}
[544]438    else
439      echo 'IGCM_debug_Exit : stack is corrupted ! LenStack =' ${IGCM_debug_LenStack}
440      IGCM_debug_Exit $@
441    fi
[913]442
[914]443    # Special actions depending on command to prepare IGCM_debug_PrintInfosActions call
[913]444    # We are interested in:
445    #  0. Which command performs the work
446    #  1. Size of entity we are working with
447    #  2. Where are we reading
448    #  3. Where are we writing
449    #  4. How long it took
450
[915]451    instrumentation=false
452
[913]453    case ${command} in
[925]454    # Classical copy (only files are given to IGCM_sys_Cp as options)
455    IGCM_sys_Cp)
456      instrumentation=true
457      # All but the latest
458      fileList=${arguments[*]:0:${#arguments[*]}-1}
459      # just need the first file to get the directory
460      source=${arguments[0]}
461      # Nothing but the latest
462      dest=${arguments[${#arguments[*]}-1]}
463      # Size of file whose name are stored in a list
464      entitySize=$( IGCM_debug_sizeOfTabContent fileList ${dest} )
465      ;;
466
[913]467    # Copy from archive machine or from buffer
468    IGCM_sys_Get|IGCM_sys_GetBuffer)
[915]469      instrumentation=true
[913]470      if [ ${#arguments[*]} -eq 2 ] ; then
471        source=${arguments[0]}
472        dest=${arguments[1]}
473        # Size of file whose name are stored in a variable
[917]474        entitySize=$( IGCM_debug_sizeOfTabContent source ${dest} )
[913]475      elif ( [ ${#arguments[*]} -eq 3 ] && [ ${arguments[0]} = '/l' ] ) ; then
[936]476        # IGCM_sys_Get /l liste_file[*] /ccc/scratch/cont003/dsm/p86denv/RUN_DIR/985998_14754/
[913]477        # Keep the array name hosting the all list
[936]478        eval set +A fileList \${${arguments[1]}}
[913]479        # just need the first file to get the directory
[936]480        source=${fileList[0]}
[931]481        dest=${arguments[2]}
[934]482        # Size of file whose name are stored in a list
[936]483        entitySize=$( IGCM_debug_sizeOfTabContent fileList[*] ${dest} )
[913]484      elif [ [ ${#arguments[*]} -ge 3 ] ; then
485       # All but the latest
[916]486        fileList=${arguments[*]:0:${#arguments[*]}-1}
[913]487        # just need the first file to get the directory
488        source=${arguments[0]}
489        # Nothing but the latest
490        dest=${arguments[${#arguments[*]}-1]}
491        # Size of file whose name are stored in a list
[917]492        entitySize=$( IGCM_debug_sizeOfTabContent fileList ${dest} )
[913]493      fi
494      ;;
495
[925]496    # Copy from compute node or copy to archive/buffer
497    IGCM_sys_Get_Master|IGCM_sys_Get_Dir|IGCM_sys_Put_Out|IGCM_sys_PutBuffer_Out)
[924]498      instrumentation=true
[916]499      source=${arguments[0]}
[924]500      dest=${arguments[1]}
501      # Size of file whose name are stored in a variable
502      entitySize=$( IGCM_debug_sizeOfTabContent source ${dest} )
[913]503      ;;
504
505    # Rebuild command
506    IGCM_sys_rebuild|IGCM_sys_rebuild_station)
[915]507      instrumentation=true
[913]508      # All but the first
509      fileList=${arguments[*]:1:${#arguments[*]}-1}
510      # just need a file to get the directory
511      source=${arguments[1]}
512      # Nothing but the first
513      dest=${arguments[0]}
514      # Size of file whose name are stored in a list
[917]515      entitySize=$( IGCM_debug_sizeOfTabContent fileList ${dest} )
[913]516      ;;
[941]517
[926]518    # NCO commands
519    IGCM_sys_ncrcat|IGCM_sys_ncecat|IGCM_sys_ncra|IGCM_sys_ncks|IGCM_sys_cdo)
520      # Example of what we want to catch : only filenames in those command lines
521      # IGCM_sys_ncrcat -O -v ${list_var_final_ncrcat} ${OUT_SE[*]} ${RESULT_SE}
522      # IGCM_sys_ncrcat --hst -v ${liste_coord}${var} ${file1} ${liste_file_tmp[*]} ${file_out}
523      # IGCM_sys_ncrcat -p ${dir} ${liste_file_tmp} --output ${output}
524      # IGCM_sys_ncrcat -x -v ${list_var} -p ${dir} ${liste_file_tmp} --output ${output}
525      instrumentation=true
[941]526      keepGoing=true
527      prefix=.
[926]528      i=0
529      while ( ${keepGoing} ) ; do
[941]530        # the last one is not interesting
531        if [ ${i} -eq ${#arguments[*]}-1 ] ; then
532          keepGoing=false
533        # look after "-p" option. Path prefix is the following arguments
534        elif [ ${arguments[${i}]} = "-p" ] ; then
[926]535          ((i = i + 1))
[941]536          prefix=${arguments[${i}]}
537          ((i = i + 1))
538        elif [ ${i} -eq ${#arguments[*]}-1 ] ; then
[926]539          keepGoing=false
[941]540        # looking for files
541        elif [ -f ${prefix}/${arguments[${i}]} ] ; then
542          fileList="${fileList} ${prefix}/${arguments[${i}]}"
543          ((i = i + 1))
544        # other options are not interesting
[926]545        else
546          ((i = i + 1))
547        fi
548      done
[941]549
[926]550      # i value is at least 1
551      # just need one file to get the directory
[941]552      source=$( echo ${fileList} | gawk '{print $1}' )
[926]553      # Nothing but the latest
554      dest=${arguments[${#arguments[*]}-1]}
555      # Size of file whose name are stored in a list
556      entitySize=$( IGCM_debug_sizeOfTabContent fileList ${dest} )
557      ;;
[913]558    esac
559
560    # Print information related to instrumentation
[915]561    ( ${instrumentation} ) && IGCM_debug_PrintInfosActions ${command} ${entitySize} ${startTime_ms} ${endTime_ms} ${dest} ${source}
[913]562
563    # Only cosmetics : stack file
[1115]564    if [ X${ActivateStackFilling} = Xtrue ] ; then
565      decal=0
566      while [ ${decal} -lt ${IGCM_debug_LenStack} ]; do
567        printf ' ' >> ${StackFileLocation}/${StackFileName}
568        (( decal = decal + 1 ))
569      done
570    fi
[2]571
[855]572    if ( ${ExitFlag} ) ; then
573      # Inform the stack file
[1115]574      if [ X${ActivateStackFilling} = Xtrue ] ; then
575        echo '!!! ExitFlag has been activated !!!' >> ${StackFileLocation}/${StackFileName}
576      fi
[874]577
[1216]578      # Unplugged message 4900 handling for now. To ease downstream treatment.
[1244]579      if [ X${ActivateBigBro} = Xtrue ] ; then
580        if [ X${TaskType} = Xcomputing ]; then
581          # RabbitMQ message code "COMPUTING JOBs COMMAND FAILURE"
582          code=1900
583        elif [ X${TaskType} = Xpost-processing ]; then
584          # RabbitMQ message code "POST-PROCESSING JOBs COMMAND FAILURE"
585          code=2900
586        elif [ X${TaskType} = Xchecking ]; then
587          # RabbitMQ message code "POST-PROCESSING FROM CHECKER JOBs COMMAND FAILURE"
588          code=3900
589        fi
590        # RabbitMQ message body
591        Body=$( echo "{${genericSimulationID},\"msgCode\":\"${code}\",\"msgUID\":\"$(uuidgen)\",\"command\":\"${command}\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" )
592
593        # Fill the rabbitMQ queue
594        IGCM_debug_sendAMQP
595      fi
[855]596    else
597      # Inform the stack file
[1115]598      if [ X${ActivateStackFilling} = Xtrue ] ; then
599        echo "< ${IGCM_debug_LenStack} : ${@}" >> ${StackFileLocation}/${StackFileName}
600      fi
[855]601    fi
602
[913]603    # Reset array if necessary
[544]604    if [ ${IGCM_debug_LenStack} = 0 ]; then
605      #echo
606      #IGCM_debug_Print 3 "Clean stack array"
607      #echo
608      unset IGCM_debug_Stack
609      unset IGCM_debug_StackArgs
[913]610      unset IGCM_debug_StackTiming
[544]611      IGCM_debug_Stack[0]=${NULL_STR}
612      IGCM_debug_StackArgs[0]=${NULL_STR}
[913]613      IGCM_debug_StackTiming[0]=${NULL_STR}
[2]614    fi
[544]615  fi
[869]616  #IGCM_debug_CallStack
[2]617}
618
619#D-#==================================================================
[1189]620#D-function IGCM_debug_BigBro_Initialize
[855]621#D-* Purpose: switch rabbitMQ on
622#D-
[1189]623function IGCM_debug_BigBro_Initialize {
624  IGCM_debug_PushStack "IGCM_debug_BigBro_Initialize"
[855]625
[1244]626  typeset postProcessingIDLength postProcessingName postProcessingDate postProcessingDimn postProcessingComp postProcessingFile
[1229]627
[1051]628# Message type standard fields:
629# https://github.com/Prodiguer/prodiguer-docs/wiki/MQ-Standard-Message-Fields
630
631# Message type dictionnary and custom fields:
632# https://github.com/Prodiguer/prodiguer-docs/wiki/Monitoring-Message-Dictionary
633
[868]634  if [ X${BigBrother} = Xtrue ] ; then
[1051]635    # create a unique ID for this specific job
636    jobuid=$(uuidgen)
[913]637
[1244]638    # get the assigned id by the scheduler for that job
639    IGCM_sys_getJobSchedulerID jobSchedulerID
640
[1189]641    if [ X${TaskType} = Xcomputing ]; then
642      if ( ${FirstInitialize} ) ; then
643        # RabbitMQ message code "BEGIN A SIMULATION"
644        code=0000
645        # create and persist a unique id for this simulation
646        simuid=$(uuidgen)
647        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration simuid ${simuid}
648        # Standard fields for the first message
[1244]649        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]650        # RabbitMQ message body with specific fields associated message codes treated here
[1277]651        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" )\"}" )
[1189]652        # Fill the rabbitMQ queue (the config.card in use will be sent)
653        IGCM_debug_sendAMQP activate
654      else
655        # RabbitMQ message code "A NEW COMPUTING JOB IS RUNNING PART OF A SIMULATION"
656        code=1000
657        # retrieve this simulation's unique id
658        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration simuid
659        simuid=${run_Configuration_simuid}
660        # Using standard fields for message others than the first one. Still subject to change
[1244]661        genericSimulationID=$( echo "\"msgApplication\":\"monitoring\",\"msgProducer\":\"libigcm\",\"msgProducerVersion\":\"${libIGCMVersion}\",\"simuid\":\"${simuid}\",\"jobuid\":\"${jobuid}\"" )
[1189]662        # RabbitMQ message body with specific fields associated message codes treated here
[1244]663        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" )\"}" )
[1189]664        # Fill the rabbitMQ queue
665        IGCM_debug_sendAMQP
666      fi
667
668      # NOT VERY NICE BUT ... IT WORKS
669      # Be sure that the genericSimulationID will be small from now on
670      # Using standard fields for messages others than the first one. Still subject to change
[1244]671      genericSimulationID=$( echo "\"msgApplication\":\"monitoring\",\"msgProducer\":\"libigcm\",\"msgProducerVersion\":\"${libIGCMVersion}\",\"simuid\":\"${simuid}\",\"jobuid\":\"${jobuid}\"" )
[1189]672
673    elif [ X${TaskType} = Xpost-processing ]; then
674      # RabbitMQ message code "A NEW POST-PROCESSING JOB IS RUNNING PART OF A SIMULATION"
675      code=2000
[1076]676      # retrieve this simulation's unique id
[1051]677      IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration simuid
[1086]678      simuid=${run_Configuration_simuid}
[1076]679      # Using standard fields for message others than the first one. Still subject to change
[1244]680      genericSimulationID=$( echo "\"msgApplication\":\"monitoring\",\"msgProducer\":\"libigcm\",\"msgProducerVersion\":\"${libIGCMVersion}\",\"simuid\":\"${simuid}\",\"jobuid\":\"${jobuid}\"" )
[1229]681     
682      # Specify the post-processing task we are dealing with
[1244]683      postProcessingIDLength=$( echo "${Script_Post_Output}" | tr -d -c "\." | wc -c )
[1229]684      postProcessingName=$( echo "${Script_Post_Output}" | gawk -F. '{print $1}' )
685      postProcessingDate=$( echo "${Script_Post_Output}" | gawk -F. '{print $2}' )
[1231]686      postProcessingDimn="null"
687      postProcessingComp="null"
688      postProcessingFile="null"
[1254]689      if [ ${postProcessingIDLength} -eq 2 ] ; then
[1231]690        postProcessingDimn=$( echo "${Script_Post_Output}" | gawk -F. '{print $3}' )
[1254]691      elif [ ${postProcessingIDLength} -eq 4 ] ; then
[1229]692        postProcessingComp=$( echo "${Script_Post_Output}" | gawk -F. '{print $4}' )
693        postProcessingFile=$( echo "${Script_Post_Output}" | gawk -F. '{print $5}' )
694      fi
695
[1087]696      # RabbitMQ message body with specific fields associated message codes treated here
[1244]697      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]698      # Fill the rabbitMQ queue
699      IGCM_debug_sendAMQP
[855]700    fi
[1285]701
[1295]702    # Turn the flag on
703    ActivateBigBro=true
704
[1285]705    # Save project accounting details in a file
706    IGCM_sys_projectAccounting cpt_${CENTER}_${PROJECT}_$( date +"%Y%m%d_%H%M" ).dat
707
708    # And send it
709    IGCM_debug_sendAMQP_projectAccounting cpt_${CENTER}_${PROJECT}_$( date +"%Y%m%d_%H%M" ).dat
710
[855]711  fi
[1189]712  IGCM_debug_PopStack "IGCM_debug_BigBro_Initialize"
[855]713}
714
715#D-#==================================================================
[1332]716#D-function IGCM_debug_BigBro_Update
717#D-* Purpose: Update rabbitMQ messages exchanges during the run
718#D-
719function IGCM_debug_BigBro_Update {
720  IGCM_debug_PushStack "IGCM_debug_BigBro_Update"
721
722  # Message type standard fields:
723  # https://github.com/Prodiguer/prodiguer-docs/wiki/MQ-Standard-Message-Fields
724
725  # Message type dictionnary and custom fields:
726  # https://github.com/Prodiguer/prodiguer-docs/wiki/Monitoring-Message-Dictionary
727
728  if [ X${ActivateBigBro} = Xtrue ] ; then
729      if [ X${TaskType} = Xcomputing ]; then
730        # Send ${PeriodDateBegin}, ${PeriodDateEnd} and ${CumulPeriod}
731        # RabbitMQ message body
732        Body=$( echo "{${genericSimulationID},\"msgCode\":\"1001\",\"PeriodDateBegin\":\"${PeriodDateBegin}\",\"PeriodDateEnd\":\"${PeriodDateEnd}\",\"CumulPeriod\":\"${cumulPeriod}\",\"msgUID\":\"$(uuidgen)\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" )
733        # Fill the rabbitMQ queue
734        IGCM_debug_sendAMQP
735      fi
736  fi
737  IGCM_debug_PopStack "IGCM_debug_BigBro_Update"
738}
739
740#D-#==================================================================
[1189]741#D-function IGCM_debug_BigBro_Finalize
742#D-* Purpose: Finalize rabbitMQ messages exchanges
743#D-
744function IGCM_debug_BigBro_Finalize {
745  IGCM_debug_PushStack "IGCM_debug_BigBro_Finalize"
746
747  # Message type standard fields:
748  # https://github.com/Prodiguer/prodiguer-docs/wiki/MQ-Standard-Message-Fields
749
750  # Message type dictionnary and custom fields:
751  # https://github.com/Prodiguer/prodiguer-docs/wiki/Monitoring-Message-Dictionary
752
753  if ( $DEBUG_debug ) ; then
754    if [ X${ActivateBigBro} = Xtrue ] ; then
755      if [ X${TaskType} = Xcomputing ]; then
756        if ( ${simulationIsOver} ) ; then
757          # RabbitMQ message code "SIMULATION ENDS"
758          code=0100
759          FlushAMQP=true
[1207]760        elif ( ${ExitFlag} ) ; then
761          # RabbitMQ message code "EXIT THE JOBS BECAUSE ERROR(S) HAS BEEN TRIGGERED"
[1244]762          code=1999
[1207]763          FlushAMQP=true
[1189]764        else
765          # RabbitMQ message code "COMPUTING JOB ENDS"
766          code=1100
767        fi
768      elif [ X${TaskType} = Xpost-processing ]; then
[1207]769        if ( ${ExitFlag} ) ; then
770          # RabbitMQ message code "POST-PROCESSING JOB FAILS"
[1244]771          code=2999
[1207]772          FlushAMQP=true
[1244]773        else
[1207]774          # RabbitMQ message code "POST-PROCESSING JOB ENDS"
775          code=2100
776          FlushAMQP=true
777        fi
[1244]778      elif [ X${TaskType} = Xchecking ]; then
779        if ( ${ExitFlag} ) ; then
780          # RabbitMQ message code "POST-PROCESSING JOB FAILS"
781          code=3999
782          FlushAMQP=true
783        else
784          # RabbitMQ message code "POST-PROCESSING JOB ENDS"
785          code=3100
786          FlushAMQP=true
787        fi
[1189]788      fi
789      # RabbitMQ message body
790      Body=$( echo "{${genericSimulationID},\"msgCode\":\"${code}\",\"msgUID\":\"$(uuidgen)\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" )
791      # Fill the rabbitMQ queue
792      IGCM_debug_sendAMQP
793    fi
794  fi
795 
796  IGCM_debug_PopStack "IGCM_debug_BigBro_Finalize"
797}
798
799#D-#==================================================================
[2]800#D-function IGCM_debug_Exit
801#D-* Purpose: Print Call Stack and set ExitFlag to true
802#D-
803function IGCM_debug_Exit {
[544]804  IGCM_debug_PushStack "IGCM_debug_Exit"
805  echo "IGCM_debug_Exit : " "${@}"
[913]806  echo
[894]807  echo "!!!!!!!!!!!!!!!!!!!!!!!!!!"
[913]808  echo "!!   ERROR TRIGGERED    !!"
809  echo "!!   EXIT FLAG SET      !!"
810  echo "!------------------------!"
811  echo
[894]812  IGCM_debug_CallStack
[544]813  ExitFlag=true
814  IGCM_debug_PopStack "IGCM_debug_Exit"
[2]815}
816
817#D-#==================================================
818#D-function IGCM_debug_Verif_Exit
819#D-* Purpose: exit with number 1 if ExitFlag is true
820#D-
821function IGCM_debug_Verif_Exit {
[544]822  if ( ${ExitFlag} ) ; then
[1206]823    echo "IGCM_debug_Verif_Exit : Something wrong happened previously."
[1207]824    echo "IGCM_debug_Verif_Exit : ERROR and EXIT keyword will help find out where."
[1206]825    # Only computing TaskType stops the job for now.
826    if [ X${TaskType} = Xcomputing ] ; then
[775]827      IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Fatal"
828      echo "                        EXIT THE JOB."
829      echo
[869]830      IGCM_debug_CallStack
[874]831
[1206]832      # Mail notification
833      IGCM_sys_SendMail
[913]834
[1207]835      # Inform the rabbitMQ queue
836      IGCM_debug_BigBro_Finalize
837
[544]838      # And Good Bye
839      date
840      exit 1
[1206]841
842    elif [ X${TaskType} = Xpost-processing ] ; then
[1302]843      StopAll=false
[1282]844      # Test if we need to stop the computing job
845      case ${postProcessingName} in
846      atlas*|monitoring*|metrics*)
847        [ ${postProcessingStopLevel} -gt 2 ] && StopAll=true ;;
848      create_*)
849        [ ${postProcessingStopLevel} -gt 1 ] && StopAll=true ;;
850      rebuild*|pack_*)
851        [ ${postProcessingStopLevel} -gt 0 ] && StopAll=true ;;
852      esac
853      # Notify the computing job that something wrong happened and stop it.
[1302]854      ( ${StopAll} ) && IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Fatal.${Script_Post_Output}"
[1282]855
856      # If SpaceName is PROD we stop when post_processing failed
[1206]857      if [ X${config_UserChoices_SpaceName} = XPROD ] ; then
[1220]858        echo "                        EXIT THE POST-PROCESSING JOB."
[1206]859        echo
[1207]860        IGCM_debug_CallStack
861
862        # Inform the rabbitMQ queue
863        IGCM_debug_BigBro_Finalize
864
[1206]865        # And Good Bye
866        date
867        exit 1
868      else
[1207]869        echo "In config.card the variable SpaceName is not in PROD"
[1206]870        echo "              SO WE DO NOT EXIT THE JOB."
871        echo
872        date
873      fi
874    elif [ X${TaskType} = Xchecking ] ; then
[1207]875      echo "Nothing will happen for now"
[2]876    fi
[544]877  fi
[2]878}
879
880#D-#==================================================================
881#D-function IGCM_debug_Print
882#D-* Purpose: Print arguments according to a level of verbosity.
883#D-
884function IGCM_debug_Print
885{
[544]886  typeset level=$1
887  shift
888
889  if [ X"${1}" = X"-e" ]; then
890    typeset cmd_echo="echo -e"
[2]891    shift
[544]892  else
893    typeset cmd_echo="echo"
894  fi
[2]895
[544]896  if [ ${level} -le ${Verbosity} ] ; then
897    typeset i
898    case "${level}" in
899    1) for i in "$@" ; do
[734]900      ${cmd_echo} $(date +"%Y-%m-%d %T") "--Debug1-->" ${i}
[913]901      done ;;
[544]902    2) for i in "$@" ; do
[734]903      ${cmd_echo} $(date +"%Y-%m-%d %T") "--------Debug2-->" ${i}
[913]904      done ;;
[544]905    3) for i in "$@" ; do
[734]906      ${cmd_echo} $(date +"%Y-%m-%d %T") "--------------Debug3-->" ${i}
[913]907      done ;;
[544]908    esac
909  fi
[2]910}
911
912#D-#==================================================================
913#D-function IGCM_debug_PrintVariables
914#D-* Purpose: Print arguments when match a pattern
915#D-           according to a level of verbosity.
916function IGCM_debug_PrintVariables
917{
[544]918  typeset level=$1
919  shift
[2]920
[830]921  list=$( set | grep ^$1 | sed -e "s/'//g" )
[54]922
[544]923  if [ "X${list}" != X ]  ; then
924    IGCM_debug_Print ${level} ${list}
925  fi
[2]926}
927
928#D-#==================================================================
[914]929#D-function IGCM_debug_PrintInfosActions
[913]930#D-* Purpose: Print information related to instrumentation
931function IGCM_debug_PrintInfosActions
932{
933  typeset actionType=$1
934  typeset entitySize=$2
935  typeset start_ms=$3
936  typeset end_ms=$4
937
938  typeset dest=$5
939  typeset source=$6
940
941  typeset diff_ms entitySizeKo entitySizeMo flux_Ko_ms flux_Ko_s flux_Mo_s
[1090]942  typeset dirFrom dirTo
[913]943
944  diff_ms=$(( $end_ms - $start_ms ))
945  # echo "diff_ms=$diff_ms"
946
947  entitySizeKo=$( echo ${entitySize} | gawk -F"|" '{print $1}' )
948  # echo "entitySizeKo=$entitySizeKo"
949  entitySizeMo=$( echo ${entitySize} | gawk -F"|" '{print $2}' )
950
951  # flux en Ko / ms
952  flux_Ko_ms=$( echo "scale=6;${entitySizeKo}/${diff_ms}" | bc )
953  # echo "flux_Ko_ms=$flux_Ko_ms"
954
955  # flux en Ko / s
956  flux_Ko_s=$(( $flux_Ko_ms * 1000 ))
957  # echo "flux_Ko_s=$flux_Ko_s"
958
959  # flux en Mo / s
960  flux_Mo_s=$( echo "scale=6;${flux_Ko_s}/1024" | bc )
961  # echo "flux_Mo_s=$flux_Mo_s"
962
963  if [ -d $dest ] ; then
[1090]964    dirTo=$( readlink -f ${dest} )
[913]965  else
[1090]966    dirTo=$( readlink -f $( dirname ${dest} ) )
[913]967  fi
968
969  if [ -d $source ] ; then
[1090]970    dirFrom=$( readlink -f ${source} )
[913]971  else
[1090]972    dirFrom=$( readlink -f $( dirname ${source} ) )
[913]973  fi
974
[1094]975  instrumentationContent=$( echo "\"actionName\":\"${actionType}\",\"size_Mo\":\"${entitySizeMo}\",\"duration_ms\":\"${diff_ms}\",\"throughput_Mo_s\":\"${flux_Mo_s}\",\"dirFrom\":\"${dirFrom}\",\"dirTo\":\"${dirTo}\"" )
[1050]976
[1115]977  if [ X${ActivateStackFilling} = Xtrue ] ; then
978    echo "{${instrumentationContent}}" >> ${StackFileLocation}/${StackFileName}
979  fi
[1050]980
981  # Inform the rabbitMQ queue
982  if [ X${ActivateBigBro} = Xtrue ] ; then
983    # RabbitMQ message body
[1065]984    Body=$( echo "{${genericSimulationID},\"msgCode\":\"7000\",\"msgUID\":\"$(uuidgen)\",${instrumentationContent},\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" )
[1050]985    # Fill the rabbitMQ queue
986    IGCM_debug_sendAMQP
987  fi
[913]988}
989
990#D-#==================================================================
[2]991#D-function IGCM_debug_Check
992#D- * Purpose: Check the present file by comparison with a reference file
993function IGCM_debug_Check
994{
[544]995  #---------------------
996  if [ ! -n "${libIGCM}" ] ; then
997    echo "Check libIGCM_debug ..........................................[ FAILED ]"
998    echo "--Error--> libIGCM variable is not defined"
999    exit 2
1000  fi
[2]1001
[544]1002  #---------------------
1003  if [ ! -n "${Verbosity}" ] ; then
1004    echo "Check libIGCM_debug ..........................................[ FAILED ]"
1005    echo "--Error--> Verbosity variable is not defined"
1006    exit 3
1007  fi
[2]1008
[544]1009  #---------------------
[1118]1010  # Need to remove timestamps here
1011  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]1012  status=$?
[2]1013
[1118]1014  if [ ${status} -eq 0 ] ; then
[544]1015    echo "Check libIGCM_debug ..............................................[ OK ]"
1016  else
1017    echo "Check libIGCM_debug ..........................................[ FAILED ]"
1018    echo "--Error--> Execution of ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ksh"
1019    echo "           has produced the file IGCM_debug_Test.ref.failed"
1020    echo "           Please analyse differences with the reference file by typing:"
1021    echo "           diff IGCM_debug_Test.ref.failed ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ref"
1022    echo "           Report errors to the author: Patrick.Brockmann@cea.fr"
[1118]1023    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]1024    exit 4
1025  fi
1026  #---------------------
[2]1027}
Note: See TracBrowser for help on using the repository browser.