source: TOOLS/SURPACK_IPSL/showPackProgress.sh @ 3624

Last change on this file since 3624 was 2173, checked in by omamce, 10 years ago

O.M. : replace one grep by a loop. Needed for big experiments with lot of files.

File size: 16.7 KB
Line 
1#!/bin/bash
2
3# On renseigne les variables d'environnement
4. load_ipslPack_env.sh
5
6export JOB_DIR=${TMP_MIGR_DATA}
7export EXE_DIR=${LS_SUBCWD:-${PWD}}
8
9SCRIPT_NAME=$(basename ${0} )
10
11export IGCM_TMP="${IGCM_DEM}/tmp"  # gpdebug : added
12
13export config_card=${IGCM_DEM}/config_card.liste
14
15source ${EXE_DIR}/DEM_utilities.sh
16
17export timeHandlingFile="${USER_OUTPUT_PROGRESS}/timeHandlingFile.txt"
18export timeLaunchStartFile="${USER_OUTPUT_PROGRESS}/timeLaunchStartFile.txt"
19export timeEndFile="${USER_OUTPUT_PROGRESS}/timeEndFile.txt"
20
21
22function getSimuName
23{   
24   config_card=$1
25   
26   dirSimu=$( dirname $config_card )
27   simuName=`echo ${dirSimu} | sed "s;${IGCM_DEM}/;;" `
28   echo $simuName
29
30}
31
32function getTimeTaken
33{
34   statFile=$1
35   if [ ! -e $statFile ]
36   then
37      echo "inconnu : pas de fichier status"
38      return
39   fi
40   
41   timeLine=`sed -n '1p' $statFile `
42   goodFormat=`echo $timeLine | grep -e '^meantime:[[:digit:]]*\.[[:digit:]]\{1,3\}$' | wc -l `
43   if [ "x$goodFormat" == "x0" ]
44   then
45       echo "inconnu : mauvais format du temps"
46       return
47   fi
48   
49   timeTaken=`echo $timeLine | sed 's;^meantime:;;' `
50   echo $timeTaken
51   
52}
53
54function progressStatus
55{
56   statFile=$1
57   echo "statFile=$1" >> ${JOB_DIR}/showPackProgress.log
58   if [ ! -e $statFile ]
59   then
60      echo "Non traitee"
61      return
62   fi
63   echo "blabla" >> ${JOB_DIR}/showPackProgress.log
64   echo "----------------------------------------------" >> ${JOB_DIR}/showPackProgress.log
65   # echo "progressStatus..." # gpdebug : a virer
66   
67   # ------------------------------------------------------------------------------------------------
68   listLineNumWithKey=`grep -n -E '(COMPLETED|FAILED|DELEGATE)' $statFile | awk -F":" '{print $1}' ` 
69   # echo "listLineNumWithKey=$listLineNumWithKey" # gpdebug : a virer
70   
71  if [ "x$listLineNumWithKey" == "x" ]
72  then
73     echo "Statut illisible"
74     return
75  fi
76
77   # On trouve la derniere ligne du fichier status comportant un mot cle
78   max=0
79   for lineNum in $listLineNumWithKey
80   do
81      if [ $lineNum -gt $max ]
82      then
83          max=$lineNum
84      fi
85   done
86
87   # echo "max=$max" # gpdebug : a virer
88
89   lastLineWithKey=`sed -n "${max}p" $statFile `
90   # echo "lastLineWithKey=$lastLineWithKey" # gpdebug : a virer   
91   # ------------------------------------------------------------------------------------------------
92     
93   # lastLine=`tail -1 $statFile ` # gpdebug : a virer
94   
95   completed=`echo $lastLineWithKey | grep COMPLETED | sed 's; (.*)$;;' `
96   if [ "x${completed}" != "x" ]
97   then
98      echo $completed
99      return
100   fi
101   
102  failed=`echo $lastLineWithKey | grep FAILED | cut -d";" -f1 `
103  if [ "x${failed}" != "x" ]
104  then
105     echo $failed
106     return         
107  fi
108 
109  delegate=`echo $lastLineWithKey | grep DELEGATE `
110  if [ "x${delegate}" != "x" ]
111  then
112     echo "DELEGATE"
113     return
114  fi
115 
116}
117
118
119function getWaitingTime
120{
121    timeNow_=$1
122    stillWaiting_=1
123   
124    launchTimeString=`cat $timeHandlingFile | grep -e 'launch time:[[:digit:].]*$' `
125    if [ "x${launchTimeString}" == "x" ]
126    then
127        echo "no launch time"
128        return
129    fi
130    launchTime_=`echo $launchTimeString | awk -F":" '{print $2}' `
131   
132   
133    startExecTimeString=`cat $timeHandlingFile | grep -e 'start time:[[:digit:].]*$' `
134    if [ "x${startExecTimeString}" == "x" ]
135    then
136        execTime_=${timeNow_}   
137    else
138        execTime_=`echo $startExecTimeString | awk -F":" '{print $2}' `
139        stillWaiting_=0
140    fi
141   
142    waitingTime_=$( awk 'BEGIN { print '${execTime_}'-'${launchTime_}' }' )
143    waitingTime_=$( awk 'BEGIN { print '${waitingTime_}'/'1000' }' )
144    if [ "x$stillWaiting_" == "x1" ]
145    then
146       waitingTime_="${waitingTime_}, still waiting..."
147    fi
148   
149    echo $waitingTime_
150}
151   
152   
153function getTimeSinceExecutionStart
154{ 
155   
156    timeNow_=$1
157    stillWaiting_=1   
158   
159    execTimeString=`cat $timeHandlingFile | grep -e 'start time:[[:digit:].]*$' `
160    if [ "x${execTimeString}" == "x" ]
161    then
162        echo "no start time"
163        return
164    fi
165    execTime_=`echo $execTimeString | awk -F":" '{print $2}' `
166   
167       
168    endTimeString=`cat $timeHandlingFile | grep -e 'end time:[[:digit:].]*$' `
169    if [ "x${endTimeString}" == "x" ]
170    then
171        endTime_=${timeNow_}
172    else
173        endTime_=`echo $endTimeString | awk -F":" '{print $2}' `
174        stillWaiting_=0
175    fi
176   
177    timeSinceExec_=$( awk 'BEGIN { print '${endTime_}'-'${execTime_}' }' )
178    timeSinceExec_=$( awk 'BEGIN { print '${timeSinceExec_}'/'1000' }' )
179    if [ "x$stillWaiting_" == "x1" ]
180    then
181       timeSinceExec_="${timeSinceExec_}, still executing..."
182    fi
183   
184    echo $timeSinceExec_
185}
186
187function getTimeSinceLaunchStart
188{
189    timeNow_=$1
190    stillWaiting_=1
191   
192    launchTimeString=`cat $timeLaunchStartFile | grep -e 'launch time:[[:digit:].]*$' `
193    if [ "x${launchTimeString}" == "x" ]
194    then
195        echo "no launch time"
196        return
197    fi
198    launchTime_=`echo $launchTimeString | awk -F":" '{print $2}' `
199   
200   
201    endTimeString=`cat $timeEndFile | grep -e 'end time:[[:digit:].]*$' `
202    if [ "x${endTimeString}" == "x" ]
203    then
204        endTime_=${timeNow_}
205    else
206        endTime_=`echo $endTimeString | awk -F":" '{print $2}' `
207        stillWaiting_=0
208    fi
209   
210    timeSinceLaunch_=$( awk 'BEGIN { print '${endTime_}'-'${launchTime_}' }' )
211    timeSinceLaunch_=$( awk 'BEGIN { print '${timeSinceLaunch_}'/'1000' }' )
212    if [ "x$stillWaiting_" == "x1" ]
213    then
214       timeSinceLaunch_="${timeSinceLaunch_}, still executing..."
215    fi
216   
217    echo $timeSinceLaunch_
218
219}
220
221
222function getListProgress
223{
224     set=$1     
225     
226     listName=`echo $(basename $set) | sed 's;\.list$;;' | sed 's;\.nc$;;' `
227
228     statusfile=${set%%.list}.status
229     status=$( progressStatus $statusfile ) # gpdebug : a retablir
230     timeTaken="???"
231
232     if [ -e ${statusfile} ]
233     then
234         
235         if [ -s $set ] ; then
236             if [[ "$listName" == *"_restart_"* ]] || [[ "$listName" == *"_debug_"* ]]
237             then
238                 purge_list=$( awk '{print $0}' $set | cut -c 5- )
239             else
240                 purge_list=$( awk '{print $0}' $set )
241             fi
242             for purge_keyword in ${purge_list} ; do
243                 grep -v ${purge_keyword} ${IGCM_DEM}/Listing_progress.txt > ${IGCM_DEM}/Listing_progress_tmp.txt
244                 mv ${IGCM_DEM}/Listing_progress_tmp.txt ${IGCM_DEM}/Listing_progress.txt
245             done
246         fi
247     fi
248
249     packFailed=`echo $status | grep -E '(DELEGATE|FAILED)' | wc -l `
250     if [ "x${packFailed}" != "x0" ]
251     then
252        nbOfListsFailed=$(( $nbOfListsFailed + 1 ))
253        simuOK=$(( $simuOK && 0 )) # marque une simu pas OK
254     fi
255 
256     packSuccess=`echo $status | grep "COMPLETED" | wc -l `
257     if [ "x${packSuccess}" != "x0" ]
258     then
259        timeTaken=$( getTimeTaken $statusfile )
260        nbOfListsPacked=$(( $nbOfListsPacked + 1 ))
261     fi
262     
263     packNottreated=`echo $status | grep -E '(Non traitee|illisible)' | wc -l `
264     if [ "x${packNottreated}" != "x0" ]
265     then
266         nbOfListsNottreated=$(( $nbOfListsNottreated + 1 ))
267         simuOK=$(( $simuOK && 0 )) # marque une simu pas OK
268         simutreated=$(( $simutreated && 0 )) # marque une simu non completement traitee
269     fi
270
271     echo "       $listName : $status | time : $timeTaken" >> ${JOB_DIR}/simuPrint.txt
272     
273     timeInSecondsOK=`echo $timeTaken | grep -e '^[[:digit:].]*$' | wc -l `
274     if [ "x${timeInSecondsOK}" != "x0" ]
275     then
276         totalTime=$(awk 'BEGIN { print '$totalTime'+'$timeTaken' }')
277     fi
278
279
280
281}
282
283#################################
284####### Main script #############
285#################################
286
287########  Options du script ########################################################
288focusOnSimu=
289outputFile=
290outputFile_simus=
291detailed_mode=1
292publish_mode=1
293while [ $# -gt 0 ]
294do
295   # echo "boucle sur les arguments du script ..."
296   # echo "@=$@"
297   case $1 in
298   -s)  echo "option -s selectionnee : afficher une simulation"
299        shift
300        focusOnSimu=$1
301        is_simu_an_option=`echo $focusOnSimu | grep -e '^-' | wc -l `
302        if [ "x${is_simu_an_option}" != "x0" ] || [ "x$focusOnSimu" == "x" ]
303        then
304           echo "L'option -s doit etre suivie d'une simulation !"
305           exit 1
306        fi
307        ;;
308   -o)  echo "option -o selectionnee : fichier d'output"
309        shift
310        outputFile=$1
311        is_output_an_option=`echo $outputFile | grep -e '^-' | wc -l `
312        if [ "x${is_output_an_option}" != "x0" ] || [ "x$outputFile" == "x" ]
313        then
314           echo "L'option -o doit etre suivie d'un fichier d'output !"
315           exit 1
316        fi
317        ;;
318   --not-detailled)  echo "option '--not-detailled' selectionnee"
319                     detailed_mode=0
320                     ;;
321   -p) echo "option -p selectionnee : publication"
322       publish_mode=0
323       outputFile="${MONIT_DIR}/monit_${USER}.txt"
324       outputFile_simus="${MONIT_DIR}/${USER}_SIMUS/monit_${USER}_simus.txt"
325       if [ -d ${MONIT_DIR}/${USER}_SIMUS ]
326       then
327           rm -f ${MONIT_DIR}/${USER}_SIMUS/*
328       else
329           mkdir -p ${MONIT_DIR}/${USER}_SIMUS
330       fi
331       echo "Simulation;Status" > ${outputFile_simus}
332   esac
333   shift
334done
335
336# echo "focusOnSimu=$focusOnSimu"
337# echo "outputFile=$outputFile"
338# echo "detailed_mode=$detailed_mode"
339######################################################################################
340# exit 0 # gpdebug : a virer
341
342
343
344> ${JOB_DIR}/showPackProgress.log # vider le fichier de log
345
346
347# Recuperation des temps d'attente et ecoule depuis de demarrage des traitements en batch
348if [ -e $timeLaunchStartFile ]
349then
350    timeNow=$( getDateMilliSeconds )
351    # waitingTime=$( getWaitingTime $timeNow ) # supprime pour le moment : pb si +sieurs instances ==> on simplifie
352    # timeSinceExecutionStart=$( getTimeSinceExecutionStart $timeNow ) # supprime pour le moment : pb si +sieurs instances ==> on simplifie
353    timeSinceLaunchStart=$( getTimeSinceLaunchStart $timeNow ) # added
354else
355    # waitingTime="no handling time file available." # supprime pour le moment : pb si +sieurs instances ==> on simplifie
356    # timeFromExecutionStart="no handling time file available." # supprime pour le moment : pb si +sieurs instances ==> on simplifie
357    timeSinceLaunchStart="no launch time file available."
358fi
359
360
361totalNbOfList=0
362for CONFIG in $( awk '{print $1}' ${IGCM_DEM}/config_card.liste )
363do
364   PATH_SIMU=$( dirname $CONFIG )
365   nbListInConfig=`find $PATH_SIMU -name "*list" | wc -l `
366   totalNbOfList=$(( $totalNbOfList + $nbListInConfig ))
367done
368
369# echo "totalNbOfList=$totalNbOfList"
370# exit 0 # gpdebug : a virer
371
372TotalNbSimu=0
373nbOfSimuPacked=0
374nbOfSimuFailed=0
375nbOfSimuNottreated=0
376nbOfListsPacked=0
377nbOfListsFailed=0
378nbOfListsNottreated=0
379TotalNbInodes=0
380TotalSimuTar=0
381totalTime=0
382cp ${IGCM_DEM}/Listing.txt ${IGCM_DEM}/Listing_progress.txt
383TotalNbSimu=`cat ${IGCM_DEM}/config_card.liste |wc -l`
384
385if [ "x${outputFile}" == "x" ] && [ "x${publish_mode}" == "x0" ]
386then
387# Publication
388echo "Simulation;Status" > ${outputFile}_${USER}
389fi
390
391for CONFIG in $( awk '{print $1}' ${IGCM_DEM}/config_card.liste ) ; do
392
393    DEM_state=$( DEM_read_state ${IGCM_DEM}/config_card.liste ${CONFIG} )
394   
395    # Eviter les simus autre que celle selectionnee par l'option -s
396    showCurrentSimu=`echo $CONFIG | grep "${focusOnSimu}" | wc -l `
397    if [ "x${showCurrentSimu}" == "x0" ]
398    then
399        continue
400    fi
401
402    simuName=$( getSimuName $CONFIG )
403   
404    > ${JOB_DIR}/simuPrint.txt
405
406    export PATH_SIMU=$( dirname $CONFIG )
407    # echo "PATH_SIMU = $PATH_SIMU"
408   
409    simuOK=1
410    simutreated=1
411 
412    if [ ! -e "${PATH_SIMU}/tar_full_simul.list" ]
413    then
414       
415         listOfDir="output_ncrcat output_tar restart_tar debug_tar store_cp work_cp"
416         for dir in $listOfDir
417         do
418             echo "   ${dir} :" >> ${JOB_DIR}/simuPrint.txt
419             if [ ! -d $PATH_SIMU/${dir} ]
420             then
421                echo "      ${dir} n'existe pas pour cette simu" >> ${JOB_DIR}/simuPrint.txt
422#               simuOK=$(( $simuOK && 0 )) # marque une simu pas OK
423                continue
424             fi
425           
426             listFilesInDir=`find $PATH_SIMU/${dir} -name "*list" | wc -l `
427             if [ "x$listFilesInDir" == "x0" ]
428             then
429                echo "       -- no list --" >> ${JOB_DIR}/simuPrint.txt
430                continue           
431             fi
432           
433             setList=$( ls $PATH_SIMU/${dir}/*list )
434
435             for set in $setList
436             do
437                  getListProgress $set
438             done
439         done
440    else         
441         getListProgress ${PATH_SIMU}/tar_full_simul.list
442         TotalSimuTar=$(( $TotalSimuTar + 1 ))
443    fi
444   
445    resSimu="OK"
446    if [ "x${simuOK}" == "x0" ]
447    then
448        resSimu="not OK"
449    fi
450
451    if [ "x${simutreated}" == "x0" ]
452    then
453        resSimu="not treated"
454    fi
455
456    if [ "x${resSimu}" == "xnot OK" ]
457    then
458       nbOfSimuFailed=$(( $nbOfSimuFailed + 1 )) 
459    elif [ "x${resSimu}" == "xnot treated" ]
460    then
461       nbOfSimuNottreated=$(( $nbOfSimuNottreated + 1 ))
462    else
463        nbOfSimuPacked=$(( $nbOfSimuPacked + 1 ))
464    fi
465
466    if [ "x${outputFile}" == "x" ]
467    then
468        echo "***************************************************"
469        echo "simulation : $simuName  ===> $resSimu"
470        echo "***************************************************"
471        if [ "x${detailed_mode}" == "x1" ]
472        then
473            cat ${JOB_DIR}/simuPrint.txt  $outRedirectStatement
474        fi
475    else
476        if [ "x${publish_mode}" == "x1" ]
477        then
478        echo "***************************************************" >> ${outputFile}
479        echo "simulation : $simuName  ===> $resSimu"               >> ${outputFile}
480        echo "***************************************************" >> ${outputFile}
481        if [ "x${detailed_mode}" == "x1" ]
482        then
483            cat ${JOB_DIR}/simuPrint.txt  $outRedirectStatement               >> ${outputFile}
484        fi     
485        else
486# Publication
487            echo "$simuName;$resSimu" >> ${outputFile_simus}
488            if [ "x${resSimu}" == "xnot OK" ]
489            then
490                simuName_modif=$( echo $simuName | sed s%"/"%"_"%g )
491                cat ${JOB_DIR}/simuPrint.txt $outRedirectStatemen > ${MONIT_DIR}/${USER}_SIMUS/${simuName_modif}".log"
492            fi
493        fi
494    fi
495    rm ${JOB_DIR}/simuPrint.txt
496done
497NbInodeBefore=`cat ${IGCM_DEM}/Listing.txt | grep "f " | wc -l`
498#NbInodeBefore=`cat ${IGCM_DEM}/Listing.txt  | wc -l`
499 NbInodeAfterStore=0
500 if [ -d "${OUTPUT_STORE}" ]
501 then
502     NbInodeAfterStore=$( find $OUTPUT_STORE -type f -printf "%y %s %p \n" | wc -l )
503 fi
504 NbInodeAfterWork=0
505 if [ -d "${OUTPUT_WORK}" ]
506 then
507     NbInodeAfterWork=$( find $OUTPUT_WORK -type f -printf "%y %s %p \n" | wc -l )
508 fi
509
510# NbInodeAfter=`cat ${IGCM_DEM}/ListingEnd.txt | grep "f " | wc -l`
511 NbInodeAfter=$(( $NbInodeAfterStore + $NbInodeAfterWork ))
512
513if [ -e ${IGCM_DEM}/Listing_progress.txt ]
514then
515    NbInodesprogressed=`cat ${IGCM_DEM}/Listing_progress.txt | grep "f " | wc -l`
516#    NbInodesprogressed=`cat ${IGCM_DEM}/Listing_progress.txt | wc -l`
517fi
518TotalNbInodes=$(( $NbInodeBefore - $NbInodesprogressed ))
519
520
521if [ "x${outputFile}" == "x" ]
522then
523    echo
524    echo "##################"
525    echo "#####  BILAN #####"
526    echo "##################"
527    echo "nb of Simulations packed with success : ${nbOfSimuPacked} / ${TotalNbSimu}"
528    echo "nb of Simus failed : ${nbOfSimuFailed}"
529    echo "nb of Simus not treated : ${nbOfSimuNottreated}"
530    echo "nb of Lists packed with success : ${nbOfListsPacked} / ${totalNbOfList}"
531    echo "nb of fails : $nbOfListsFailed"
532    echo "nb of not treated : ${nbOfListsNottreated}"
533    echo "nb of inodes packed : $TotalNbInodes"
534    echo "nb simul full tared : $TotalSimuTar"
535    echo "nb inode before : $NbInodeBefore"
536    echo "nb inode after WORK : $NbInodeAfterWork"
537    echo "nb inode after STORE : $NbInodeAfterStore"
538    echo "Total time for elementary operations : $totalTime" 
539    echo "Time since launch start : $timeSinceLaunchStart"
540
541else
542    if [ "x${publish_mode}" == "x1" ]
543        then
544    echo
545    echo "##################" >> ${outputFile}
546    echo "#####  BILAN #####" >> ${outputFile}
547    echo "##################" >> ${outputFile}
548    echo "nb of Simulations packed with success : ${nbOfSimuPacked} / ${TotalNbSimu}" >> ${outputFile}
549    echo "nb of Simus failed : ${nbOfSimuFailed}" >> ${outputFile}
550    echo "nb of Simus not treated : ${nbOfSimuNottreated}" >> ${outputFile}
551    echo "nb of Lists packed with success : ${nbOfListsPacked} / ${totalNbOfList}" >> ${outputFile}
552    echo "nb of fails : $nbOfListsFailed" >> ${outputFile}
553    echo "nb of not treated : ${nbOfListsNottreated}" >> ${outputFile}
554    echo "nb of inodes packed : $TotalNbInodes" >> ${outputFile}
555    echo "nb simul full tared : $TotalSimuTar" >> ${outputFile}
556    echo "nb inode before : $NbInodeBefore" >> ${outputFile}
557    echo "nb inode after : $NbInodeAfter" >> ${outputFile}
558    echo "Total time for elementary operations : $totalTime" >> ${outputFile}
559    echo "Time since launch start : $timeSinceLaunchStart" >> ${outputFile}
560    else
561# Publication
562    echo "User;Inode NB;Inode Processed;Inode Treatment Percentage;Inode After;Inode store;Inode percentage STORE-WORK;Simu NB;Simu OK; Simu FAILED;Simu Percentage;List NB;List OK;List FAILED;List Percentage" > ${outputFile}
563        echo "${USER};$NbInodeBefore;$TotalNbInodes;PIE2;$NbInodeAfter;$NbInodeAfterStore;PIE2;${TotalNbSimu};${nbOfSimuPacked};${nbOfSimuFailed};PIE3;${totalNbOfList};${nbOfListsPacked};$nbOfListsFailed;PIE3" >> ${outputFile}
564    fi
565fi
Note: See TracBrowser for help on using the repository browser.