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

Last change on this file since 983 was 983, checked in by sdipsl, 10 years ago

bypass firewalling difficulties. use mailing system to send AMQP message
see #176

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