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

Last change on this file since 916 was 916, checked in by sdipsl, 11 years ago

add IGCM_sys_Cp to the instrumented functions list
fix a bug. In this syntax, length is a length not an indice ${variable:start:length}

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