source: TOOLS/PACK_IPSL/showPackProgress.sh @ 2010

Last change on this file since 2010 was 1978, checked in by aclsce, 11 years ago

Fixed bbugs

  • Property svn:executable set to *
File size: 16.6 KB
RevLine 
[1822]1#!/bin/bash
2
[1853]3# On renseigne les variables d'environnement
4. load_ipslPack_env.sh
[1822]5
[1900]6export JOB_DIR=${TMP_MIGR_DATA}
7export EXE_DIR=${LS_SUBCWD:-${PWD}}
8
[1822]9SCRIPT_NAME=$(basename ${0} )
10
[1853]11export IGCM_TMP="${IGCM_DEM}/tmp"  # gpdebug : added
[1822]12
13export config_card=${IGCM_DEM}/config_card.liste
14
15source ${EXE_DIR}/DEM_utilities.sh
16
[1853]17export timeHandlingFile="${USER_OUTPUT_PROGRESS}/timeHandlingFile.txt"
[1862]18export timeLaunchStartFile="${USER_OUTPUT_PROGRESS}/timeLaunchStartFile.txt"
19export timeEndFile="${USER_OUTPUT_PROGRESS}/timeEndFile.txt"
[1822]20
[1849]21
[1822]22function getSimuName
23{   
24   config_card=$1
25   
[1853]26   dirSimu=$( dirname $config_card )
27   simuName=`echo ${dirSimu} | sed "s;${IGCM_DEM}/;;" `
[1822]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
[1911]57   echo "statFile=$1" >> ${JOB_DIR}/showPackProgress.log
[1822]58   if [ ! -e $statFile ]
59   then
60      echo "Non traitee"
61      return
62   fi
[1911]63   echo "blabla" >> ${JOB_DIR}/showPackProgress.log
64   echo "----------------------------------------------" >> ${JOB_DIR}/showPackProgress.log
[1822]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
[1849]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
[1862]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_
[1853]218
[1862]219}
[1853]220
[1862]221
[1853]222function getListProgress
223{
224     set=$1     
225     
226     listName=`echo $(basename $set) | sed 's;\.list$;;' | sed 's;\.nc$;;' `
[1899]227
[1853]228     statusfile=${set%%.list}.status
229     status=$( progressStatus $statusfile ) # gpdebug : a retablir
230     timeTaken="???"
[1899]231
232     if [ -e ${statusfile} ]
233     then
234         for file in `awk '{print $0}' $set` ; do
235         if [[ "$listName" == *"_restart_"* ]] || [[ "$listName" == *"_debug_"* ]] 
236         then
237             file_tmp=$( echo $file | cut -c 5- )
238         else
239             file_tmp=$file
240         fi
241         grep -v $file_tmp ${IGCM_DEM}/Listing_progress.txt > ${IGCM_DEM}/Listing_progress_tmp.txt
242         mv ${IGCM_DEM}/Listing_progress_tmp.txt ${IGCM_DEM}/Listing_progress.txt
243         done
244     fi
245
[1868]246     packFailed=`echo $status | grep -E '(DELEGATE|FAILED)' | wc -l `
[1853]247     if [ "x${packFailed}" != "x0" ]
248     then
249        nbOfListsFailed=$(( $nbOfListsFailed + 1 ))
250        simuOK=$(( $simuOK && 0 )) # marque une simu pas OK
251     fi
252 
253     packSuccess=`echo $status | grep "COMPLETED" | wc -l `
254     if [ "x${packSuccess}" != "x0" ]
255     then
256        timeTaken=$( getTimeTaken $statusfile )
257        nbOfListsPacked=$(( $nbOfListsPacked + 1 ))
258     fi
259     
[1868]260     packNottreated=`echo $status | grep -E '(Non traitee|illisible)' | wc -l `
[1864]261     if [ "x${packNottreated}" != "x0" ]
262     then
263         nbOfListsNottreated=$(( $nbOfListsNottreated + 1 ))
[1868]264         simuOK=$(( $simuOK && 0 )) # marque une simu pas OK
[1876]265         simutreated=$(( $simutreated && 0 )) # marque une simu non completement traitee
[1864]266     fi
267
[1911]268     echo "       $listName : $status | time : $timeTaken" >> ${JOB_DIR}/simuPrint.txt
[1853]269     
270     timeInSecondsOK=`echo $timeTaken | grep -e '^[[:digit:].]*$' | wc -l `
271     if [ "x${timeInSecondsOK}" != "x0" ]
272     then
273         totalTime=$(awk 'BEGIN { print '$totalTime'+'$timeTaken' }')
274     fi
275
276
277
278}
279
[1822]280#################################
281####### Main script #############
282#################################
[1853]283
284########  Options du script ########################################################
285focusOnSimu=
286outputFile=
[1899]287outputFile_simus=
[1853]288detailed_mode=1
[1871]289publish_mode=1
[1853]290while [ $# -gt 0 ]
291do
292   # echo "boucle sur les arguments du script ..."
293   # echo "@=$@"
294   case $1 in
295   -s)  echo "option -s selectionnee : afficher une simulation"
296        shift
297        focusOnSimu=$1
298        is_simu_an_option=`echo $focusOnSimu | grep -e '^-' | wc -l `
299        if [ "x${is_simu_an_option}" != "x0" ] || [ "x$focusOnSimu" == "x" ]
300        then
301           echo "L'option -s doit etre suivie d'une simulation !"
302           exit 1
303        fi
304        ;;
305   -o)  echo "option -o selectionnee : fichier d'output"
306        shift
307        outputFile=$1
308        is_output_an_option=`echo $outputFile | grep -e '^-' | wc -l `
309        if [ "x${is_output_an_option}" != "x0" ] || [ "x$outputFile" == "x" ]
310        then
311           echo "L'option -o doit etre suivie d'un fichier d'output !"
312           exit 1
313        fi
314        ;;
315   --not-detailled)  echo "option '--not-detailled' selectionnee"
316                     detailed_mode=0
317                     ;;
[1871]318   -p) echo "option -p selectionnee : publication"
[1899]319       publish_mode=0
[1978]320       outputFile="${MONIT_DIR}/monit_${USER}.txt"
321       outputFile_simus="${MONIT_DIR}/${USER}_SIMUS/monit_${USER}_simus.txt"
322       if [ -d ${MONIT_DIR}/${USER}_SIMUS ]
[1899]323       then
[1978]324           rm -f ${MONIT_DIR}/${USER}_SIMUS/*
[1899]325       else
[1978]326           mkdir -p ${MONIT_DIR}/${USER}_SIMUS
[1899]327       fi
328       echo "Simulation;Status" > ${outputFile_simus}
[1853]329   esac
330   shift
331done
332
333# echo "focusOnSimu=$focusOnSimu"
334# echo "outputFile=$outputFile"
335# echo "detailed_mode=$detailed_mode"
336######################################################################################
337# exit 0 # gpdebug : a virer
338
339
340
[1911]341> ${JOB_DIR}/showPackProgress.log # vider le fichier de log
[1822]342
[1853]343
[1849]344# Recuperation des temps d'attente et ecoule depuis de demarrage des traitements en batch
[1862]345if [ -e $timeLaunchStartFile ]
[1849]346then
347    timeNow=$( getDateMilliSeconds )
[1862]348    # waitingTime=$( getWaitingTime $timeNow ) # supprime pour le moment : pb si +sieurs instances ==> on simplifie
349    # timeSinceExecutionStart=$( getTimeSinceExecutionStart $timeNow ) # supprime pour le moment : pb si +sieurs instances ==> on simplifie
350    timeSinceLaunchStart=$( getTimeSinceLaunchStart $timeNow ) # added
[1849]351else
[1862]352    # waitingTime="no handling time file available." # supprime pour le moment : pb si +sieurs instances ==> on simplifie
353    # timeFromExecutionStart="no handling time file available." # supprime pour le moment : pb si +sieurs instances ==> on simplifie
354    timeSinceLaunchStart="no launch time file available."
[1849]355fi
356
357
[1822]358totalNbOfList=0
359for CONFIG in $( awk '{print $1}' ${IGCM_DEM}/config_card.liste )
360do
361   PATH_SIMU=$( dirname $CONFIG )
362   nbListInConfig=`find $PATH_SIMU -name "*list" | wc -l `
363   totalNbOfList=$(( $totalNbOfList + $nbListInConfig ))
364done
365
366# echo "totalNbOfList=$totalNbOfList"
367# exit 0 # gpdebug : a virer
368
[1871]369TotalNbSimu=0
370nbOfSimuPacked=0
371nbOfSimuFailed=0
372nbOfSimuNottreated=0
[1822]373nbOfListsPacked=0
374nbOfListsFailed=0
[1864]375nbOfListsNottreated=0
[1899]376TotalNbInodes=0
[1848]377TotalSimuTar=0
[1849]378totalTime=0
[1899]379cp ${IGCM_DEM}/Listing.txt ${IGCM_DEM}/Listing_progress.txt
[1871]380TotalNbSimu=`cat ${IGCM_DEM}/config_card.liste |wc -l`
[1853]381
[1871]382if [ "x${outputFile}" == "x" ] && [ "x${publish_mode}" == "x0" ]
383then
384# Publication
385echo "Simulation;Status" > ${outputFile}_${USER}
386fi
387
[1822]388for CONFIG in $( awk '{print $1}' ${IGCM_DEM}/config_card.liste ) ; do
389
390    DEM_state=$( DEM_read_state ${IGCM_DEM}/config_card.liste ${CONFIG} )
[1853]391   
392    # Eviter les simus autre que celle selectionnee par l'option -s
393    showCurrentSimu=`echo $CONFIG | grep "${focusOnSimu}" | wc -l `
394    if [ "x${showCurrentSimu}" == "x0" ]
395    then
396        continue
397    fi
[1822]398
[1853]399    simuName=$( getSimuName $CONFIG )
400   
[1911]401    > ${JOB_DIR}/simuPrint.txt
[1822]402
[1853]403    export PATH_SIMU=$( dirname $CONFIG )
404    # echo "PATH_SIMU = $PATH_SIMU"
405   
406    simuOK=1
[1871]407    simutreated=1
408 
[1853]409    if [ ! -e "${PATH_SIMU}/tar_full_simul.list" ]
410    then
411       
[1822]412         listOfDir="output_ncrcat output_tar restart_tar debug_tar store_cp work_cp"
413         for dir in $listOfDir
414         do
[1911]415             echo "   ${dir} :" >> ${JOB_DIR}/simuPrint.txt
[1822]416             if [ ! -d $PATH_SIMU/${dir} ]
417             then
[1911]418                echo "      ${dir} n'existe pas pour cette simu" >> ${JOB_DIR}/simuPrint.txt
[1871]419#               simuOK=$(( $simuOK && 0 )) # marque une simu pas OK
[1822]420                continue
421             fi
422           
423             listFilesInDir=`find $PATH_SIMU/${dir} -name "*list" | wc -l `
424             if [ "x$listFilesInDir" == "x0" ]
425             then
[1911]426                echo "       -- no list --" >> ${JOB_DIR}/simuPrint.txt
[1822]427                continue           
428             fi
429           
430             setList=$( ls $PATH_SIMU/${dir}/*list )
431
432             for set in $setList
433             do
[1853]434                  getListProgress $set
[1822]435             done
436         done
[1853]437    else         
438         getListProgress ${PATH_SIMU}/tar_full_simul.list
[1848]439         TotalSimuTar=$(( $TotalSimuTar + 1 ))
[1822]440    fi
[1853]441   
442    resSimu="OK"
443    if [ "x${simuOK}" == "x0" ]
444    then
445        resSimu="not OK"
446    fi
[1871]447
448    if [ "x${simutreated}" == "x0" ]
449    then
450        resSimu="not treated"
451    fi
452
453    if [ "x${resSimu}" == "xnot OK" ]
454    then
455       nbOfSimuFailed=$(( $nbOfSimuFailed + 1 )) 
456    elif [ "x${resSimu}" == "xnot treated" ]
457    then
458       nbOfSimuNottreated=$(( $nbOfSimuNottreated + 1 ))
459    else
460        nbOfSimuPacked=$(( $nbOfSimuPacked + 1 ))
461    fi
462
[1853]463    if [ "x${outputFile}" == "x" ]
464    then
465        echo "***************************************************"
466        echo "simulation : $simuName  ===> $resSimu"
467        echo "***************************************************"
468        if [ "x${detailed_mode}" == "x1" ]
469        then
[1911]470            cat ${JOB_DIR}/simuPrint.txt  $outRedirectStatement
[1853]471        fi
472    else
[1871]473        if [ "x${publish_mode}" == "x1" ]
474        then
[1853]475        echo "***************************************************" >> ${outputFile}
476        echo "simulation : $simuName  ===> $resSimu"               >> ${outputFile}
477        echo "***************************************************" >> ${outputFile}
478        if [ "x${detailed_mode}" == "x1" ]
479        then
[1911]480            cat ${JOB_DIR}/simuPrint.txt  $outRedirectStatement               >> ${outputFile}
[1853]481        fi     
[1871]482        else
483# Publication
[1899]484            echo "$simuName;$resSimu" >> ${outputFile_simus}
485            if [ "x${resSimu}" == "xnot OK" ]
486            then
487                simuName_modif=$( echo $simuName | sed s%"/"%"_"%g )
[1978]488                cat ${JOB_DIR}/simuPrint.txt $outRedirectStatemen > ${MONIT_DIR}/${USER}_SIMUS/${simuName_modif}".log"
[1899]489            fi
[1871]490        fi
[1853]491    fi
[1911]492    rm ${JOB_DIR}/simuPrint.txt
[1822]493done
[1899]494NbInodeBefore=`cat ${IGCM_DEM}/Listing.txt | grep "f " | wc -l`
495#NbInodeBefore=`cat ${IGCM_DEM}/Listing.txt  | wc -l`
[1913]496 NbInodeAfterStore=0
[1863]497 if [ -d "${OUTPUT_STORE}" ]
498 then
[1899]499     NbInodeAfterStore=$( find $OUTPUT_STORE -type f -printf "%y %s %p \n" | wc -l )
[1863]500 fi
[1913]501 NbInodeAfterWork=0
[1863]502 if [ -d "${OUTPUT_WORK}" ]
503 then
[1899]504     NbInodeAfterWork=$( find $OUTPUT_WORK -type f -printf "%y %s %p \n" | wc -l )
[1863]505 fi
[1822]506
[1899]507# NbInodeAfter=`cat ${IGCM_DEM}/ListingEnd.txt | grep "f " | wc -l`
508 NbInodeAfter=$(( $NbInodeAfterStore + $NbInodeAfterWork ))
509
510if [ -e ${IGCM_DEM}/Listing_progress.txt ]
511then
512    NbInodesprogressed=`cat ${IGCM_DEM}/Listing_progress.txt | grep "f " | wc -l`
513#    NbInodesprogressed=`cat ${IGCM_DEM}/Listing_progress.txt | wc -l`
[1885]514fi
[1899]515TotalNbInodes=$(( $NbInodeBefore - $NbInodesprogressed ))
[1885]516
[1899]517
[1863]518if [ "x${outputFile}" == "x" ]
519then
520    echo
521    echo "##################"
522    echo "#####  BILAN #####"
523    echo "##################"
[1871]524    echo "nb of Simulations packed with success : ${nbOfSimuPacked} / ${TotalNbSimu}"
525    echo "nb of Simus failed : ${nbOfSimuFailed}"
526    echo "nb of Simus not treated : ${nbOfSimuNottreated}"
[1863]527    echo "nb of Lists packed with success : ${nbOfListsPacked} / ${totalNbOfList}"
528    echo "nb of fails : $nbOfListsFailed"
[1864]529    echo "nb of not treated : ${nbOfListsNottreated}"
[1899]530    echo "nb of inodes packed : $TotalNbInodes"
[1863]531    echo "nb simul full tared : $TotalSimuTar"
532    echo "nb inode before : $NbInodeBefore"
[1899]533    echo "nb inode after WORK : $NbInodeAfterWork"
534    echo "nb inode after STORE : $NbInodeAfterStore"
[1863]535    echo "Total time for elementary operations : $totalTime" 
536    echo "Time since launch start : $timeSinceLaunchStart"
[1822]537
[1863]538else
[1871]539    if [ "x${publish_mode}" == "x1" ]
540        then
[1863]541    echo
542    echo "##################" >> ${outputFile}
543    echo "#####  BILAN #####" >> ${outputFile}
544    echo "##################" >> ${outputFile}
[1871]545    echo "nb of Simulations packed with success : ${nbOfSimuPacked} / ${TotalNbSimu}" >> ${outputFile}
546    echo "nb of Simus failed : ${nbOfSimuFailed}" >> ${outputFile}
547    echo "nb of Simus not treated : ${nbOfSimuNottreated}" >> ${outputFile}
[1863]548    echo "nb of Lists packed with success : ${nbOfListsPacked} / ${totalNbOfList}" >> ${outputFile}
549    echo "nb of fails : $nbOfListsFailed" >> ${outputFile}
[1864]550    echo "nb of not treated : ${nbOfListsNottreated}" >> ${outputFile}
[1899]551    echo "nb of inodes packed : $TotalNbInodes" >> ${outputFile}
[1863]552    echo "nb simul full tared : $TotalSimuTar" >> ${outputFile}
553    echo "nb inode before : $NbInodeBefore" >> ${outputFile}
554    echo "nb inode after : $NbInodeAfter" >> ${outputFile}
555    echo "Total time for elementary operations : $totalTime" >> ${outputFile}
556    echo "Time since launch start : $timeSinceLaunchStart" >> ${outputFile}
[1871]557    else
558# Publication
[1899]559    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}
560        echo "${USER};$NbInodeBefore;$TotalNbInodes;PIE2;$NbInodeAfter;$NbInodeAfterStore;PIE2;${TotalNbSimu};${nbOfSimuPacked};${nbOfSimuFailed};PIE3;${totalNbOfList};${nbOfListsPacked};$nbOfListsFailed;PIE3" >> ${outputFile}
[1871]561    fi
[1863]562fi
Note: See TracBrowser for help on using the repository browser.