diff --git a/common/create-sbu_du-report.sh b/common/create-sbu_du-report.sh index 5c505c5..1e08bf4 100755 --- a/common/create-sbu_du-report.sh +++ b/common/create-sbu_du-report.sh @@ -6,6 +6,8 @@ set -e LOGSDIR=$1 VERSION=$2 +LINE="================================================================================" + # Make sure that we have a directory as first argument [[ ! -d "$LOGSDIR" ]] && \ echo -e "\nUSAGE: create-sbu_du-report.sh logs_directory [book_version]\n" && exit @@ -25,6 +27,8 @@ VERSION=$2 # Set the report file REPORT="$VERSION"-SBU_DU-$(date --iso-8601).report +[ -f $REPORT ] && : >$REPORT + # Dump generation time stamp and book version echo -e "\n`date`\n" > "$REPORT" echo -e "Book version is:\t$VERSION\n" >> "$REPORT" @@ -44,82 +48,74 @@ echo -e "\n\t\tMemory info:\n" >> "$REPORT" free >> "$REPORT" # Parse only that logs that have time data -BUILDLOGS=`grep -l "^real\>" $LOGSDIR/*` +BUILDLOGS="`grep -l "^Totalseconds:" ${LOGSDIR}/*`" # Match the first timed log to extract the SBU unit value from it -BASELOG=`grep -l "^real\>" $LOGSDIR/* | head -n1` -echo -e "\n\nUsing $BASELOG to obtain the SBU unit value." >> "$REPORT" -BASEMINUTES=`grep "^real\>" $BASELOG | cut -f2 | sed -e 's/m.*//'` -BASESECONDS=`grep "^real\>" $BASELOG | cut -f2 | sed -e 's/.*m//;s/s//'` -SBU_UNIT=`echo "scale=3; $BASEMINUTES * 60 + $BASESECONDS" | bc` -echo -e "The SBU unit value is equal to $SBU_UNIT seconds.\n" >> "$REPORT" +BASELOG=`grep -l "^Totalseconds:" $LOGSDIR/* | head -n1` +echo -e "\nUsing ${BASELOG#*[[:digit:]]-} to obtain the SBU unit value." +SBU_UNIT=`sed -n 's/^Totalseconds:\s\([[:digit:]]*.[[:digit:]]*\)$/\1/p' $BASELOG` +echo -e "\nThe SBU unit value is equal to $SBU_UNIT seconds.\n" +echo -e "\n\n$LINE\n\nThe SBU unit value is equal to $SBU_UNIT seconds.\n" >> "$REPORT" # Set the first value to 0 for grand totals calculation SBU2=0 INSTALL2=0 INSTALLMB2=0 +# Start the loop for log in $BUILDLOGS ; do -#Start SBU calculation - # Build time - BUILDTIME=`grep "^real\>" $log | cut -f2` - # Build time in seconds - MINUTES=`grep "^real\>" $log | cut -f2 | sed -e 's/m.*//'` - SECS=`grep "^real\>" $log | cut -f2 | sed -e 's/.*m//;s/s//'` - TIME=`echo "scale=3; $MINUTES * 60 + $SECS" | bc` - # Calculate build time in SBU - SBU=`echo "scale=3; $TIME / $SBU_UNIT" | bc` - # Append SBU value to SBU2 for grand total - SBU2="$SBU2 + $SBU" +# Strip the filename + PACKAGE="${log#*[[:digit:]]*-}" -#Start disk usage calculation - # Disk usage before unpacking the package +# Start SBU calculation +# Build time + TIME=`sed -n 's/^Totalseconds:\s\([[:digit:]]*.[[:digit:]]*\)$/\1/p' $log` + SECS=`perl -e 'print ('$TIME' % '60')';` + MINUTES=`perl -e 'printf "%.0f" , (('$TIME' - '$SECS') / '60')';` + SBU=`perl -e 'printf "%.3f" , ('$TIME' / '$SBU_UNIT')';` + +# Append SBU value to SBU2 for grand total + SBU2=`perl -e 'printf "%.3f" , ('$SBU2' + '$SBU')';` + +# Start disk usage calculation +# Disk usage before unpacking the package DU1=`grep "^KB: " $log | head -n1 | cut -f1 | sed -e 's/KB: //'` - DU1MB=`echo "scale=2; $DU1 / 1024" | bc` - # Disk usage before deleting the source and build dirs + DU1MB=`perl -e 'printf "%.3f" , ('$DU1' / '1024')';` +# Disk usage before deleting the source and build dirs DU2=`grep "^KB: " $log | tail -n1 | cut -f1 | sed -e 's/KB: //'` - DU2MB=`echo "scale=2; $DU2 / 1024" | bc` - # Calculate disk space required to do the build - REQUIRED1=`echo "$DU2 - $DU1" | bc` - REQUIRED2=`echo "scale=2; $DU2MB - $DU1MB" | bc` + DU2MB=`perl -e 'printf "%.3f" , ('$DU2' / '1024')';` +# Calculate disk space required to do the build + REQUIRED1=`perl -e 'print ('$DU2' - '$DU1')';` + REQUIRED2=`perl -e 'printf "%.3f" , ('$DU2MB' - '$DU1MB')';` - # Append installed files disk usage to the previous entry, - # except for the first parsed log +# Append installed files disk usage to the previous entry, +# except for the first parsed log if [ "$log" != "$BASELOG" ] ; then - INSTALL=`echo "$DU1 - $DU1PREV" | bc` - INSTALLMB=`echo "scale=2; $DU1MB - $DU1MBPREV" | bc` - echo -e "Installed files disk usage:\t\t\t\t$INSTALL KB or $INSTALLMB MB\n" >> "$REPORT" + INSTALL=`perl -e 'print ('$DU1' - '$DU1PREV')';` + INSTALLMB=`perl -e 'printf "%.3f" , ('$DU1MB' - '$DU1MBPREV')';` + echo -e "Installed files disk usage:\t\t\t\t$INSTALL KB or $INSTALLMB MB\n" >> $REPORT # Append install values for grand total - INSTALL2="$INSTALL2 + $INSTALL" - INSTALLMB2="$INSTALLMB2 + $INSTALLMB" + INSTALL2=`perl -e 'printf "%.3f" , ('$INSTALL2' + '$INSTALL')';` + INSTALLMB2=`perl -e 'printf "%.3f" , ('$INSTALLMB2' + '$INSTALLMB')';` fi - # Set variables to calculate installed files disk usage +# Set variables to calculate installed files disk usage DU1PREV=$DU1 DU1MBPREV=$DU1MB - # Append log name - echo -e "\n\t$log" >> "$REPORT" - - # Dump time values - echo -e "Build time is:\t\t\t$BUILDTIME" >> "$REPORT" - echo -e "Build time in seconds is\t$TIME" >> "$REPORT" - echo -e "Approximate SBU time is:\t$SBU" >> "$REPORT" - - # Dump disk usage values - echo -e "\nDisk usage before unpacking the package:\t\t$DU1 KB or $DU1MB MB" >> "$REPORT" - echo -e "Disk usage before deleting the source and build dirs:\t$DU2 KB or $DU2MB MB" >> "$REPORT" - echo -e "Required space to build the package:\t\t\t$REQUIRED1 KB or $REQUIRED2 MB\n" >> "$REPORT" +# Dump time and disk usage values + echo -e "$LINE\n\t\t\t\t[$PACKAGE]\n" >> $REPORT + echo -e "Build time is:\t\t\t\t\t\t$MINUTES minutes and $SECS seconds" >> $REPORT + echo -e "Build time in seconds is:\t\t\t\t$TIME" >> $REPORT + echo -e "Approximate SBU time is:\t\t\t\t$SBU" >> $REPORT + echo -e "Disk usage before unpacking the package:\t\t$DU1 KB or $DU1MB MB" >> $REPORT + echo -e "Disk usage before deleting the source and build dirs:\t$DU2 KB or $DU2MB MB" >> $REPORT + echo -e "Required space to build the package:\t\t\t$REQUIRED1 KB or $REQUIRED2 MB" >> $REPORT done # Dump grand totals -TOTALSBU=`echo "scale=3; ${SBU2}" | bc` -echo -e "\nTotal time required to build the systen:\t$TOTALSBU SBU\n" >> "$REPORT" -TOTALINSTALL=`echo "${INSTALL2}" | bc` -TOTALINSTALLMB=`echo "scale=2; ${INSTALLMB2}" | bc` -echo -e "Total Installed files disk usage - (including /tools but not /sources):\t$TOTALINSTALL KB or $TOTALINSTALLMB MB\n" >> "$REPORT" - - +echo -e "\n$LINE\n\nTotal time required to build the systen:\t\t$SBU2 SBU" >> $REPORT +# Total disk usage: including /tools but not /sources. +echo -e "Total Installed files disk usage:\t\t\t$INSTALL2 KB or $INSTALLMB2 MB" >> $REPORT diff --git a/common/libs/func_validate_configs.sh b/common/libs/func_validate_configs.sh index 4c74ee8..84a2bf7 100644 --- a/common/libs/func_validate_configs.sh +++ b/common/libs/func_validate_configs.sh @@ -117,6 +117,7 @@ inline_doc TIMEZONE | \ PAGE | \ INSTALL_LOG | \ + REPORT | \ REBUILD_MAKEFILE ) echo -e "`eval echo $PARAM_VALS`" ;; # Envvars that depend on other settings to be displayed @@ -138,25 +139,13 @@ inline_doc LGROUP) echo -e "`eval echo $PARAM_VALS`" [[ "${!config_param}" = "**EDIT ME**" ]] && write_error_and_die ;; - REPORT) echo -e "`eval echo $PARAM_VALS`" - if [[ "${!config_param}" = "y" ]]; then - if [[ `type -p bc` ]]; then - continue - else - echo -e " ${BOLD}The bc binary was not found${OFF}" - echo -e " The SBU and disk usage report creation will be skiped" - REPORT=n - continue - fi - fi ;; - # BOOK validation. Very ugly, need be fixed BOOK) if [[ "${WORKING_COPY}" = "y" ]] ; then validate_dir -z -d else echo -e "`eval echo $PARAM_VALS`" - fi ;; - + fi + ;; # Validate directories, testable states: # fatal -z -d -w, # warning -z+ -w+ diff --git a/common/libs/func_wrt_Makefile b/common/libs/func_wrt_Makefile index 4ce3f09..7bbec93 100644 --- a/common/libs/func_wrt_Makefile +++ b/common/libs/func_wrt_Makefile @@ -40,6 +40,8 @@ SU_LUSER = su - \$(LUSER) -c LUSER_HOME = \$(LHOME)/\$(LUSER) PRT_DU = echo -e "\nKB: \`du -skx --exclude=\$(SCRIPT_ROOT) --exclude=lost+found \$(MOUNT_PT) \`\n" PRT_DU_CR = echo -e "\nKB: \`du -skx --exclude=\$(SCRIPT_ROOT) --exclude=lost+found / \`\n" +TIME_MARK = \`date +%s.%N\` +BUILD_TIME = perl -e "printf \"\nTotalseconds: %.3f\", ('\$\$end' - '\$\$start')" ADD_REPORT = $REPORT ADD_CUSTOM_TOOLS = $CUSTOM_TOOLS @@ -230,21 +232,27 @@ wrt_RunAsRoot() { # Some scripts must be run as root.. ( cat << EOF - @( time { export ${MOUNT_ENV}=\$(MOUNT_PT) && ${PROGNAME}-commands/`dirname $file`/\$@ >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ && \\ + @start=\$(TIME_MARK) && \\ + export ${MOUNT_ENV}=\$(MOUNT_PT) && \\ + ${PROGNAME}-commands/`dirname $file`/\$@ >>logs/\$@ 2>&1 && \\ + end=\$(TIME_MARK) && \$(BUILD_TIME) >>logs/\$@ && \\ \$(PRT_DU) >>logs/\$@ EOF ) >> $MKFILE.tmp } #----------------------------------# -LUSER_wrt_RunAsUser() { # Execute script inside time { }, footer to log file +LUSER_wrt_RunAsUser() { # Calculate time with perl, footer to log file #----------------------------------# local file=$1 ( cat << EOF - @( time { source ~/.bashrc && \$(CMDSDIR)/`dirname $file`/\$@ >> logs/\$@ 2>&1; } ) 2>> logs/\$@ && \\ - \$(PRT_DU) >> logs/\$@ + @start=\$(TIME_MARK) && \\ + source ~/.bashrc && \\ + \$(CMDSDIR)/`dirname $file`/\$@ >> logs/\$@ 2>&1 && \\ + end=\$(TIME_MARK) && \$(BUILD_TIME) >>logs/\$@ && \\ + \$(PRT_DU) >>logs/\$@ EOF ) >> $MKFILE.tmp } @@ -255,7 +263,10 @@ CHROOT_wrt_RunAsRoot() { # local file=$1 ( cat << EOF - @( time { source envars && \$(crCMDSDIR)/`dirname $file`/\$@ >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ && \\ + @start=\$(TIME_MARK) && \\ + source envars && \\ + \$(crCMDSDIR)/`dirname $file`/\$@ >>logs/\$@ 2>&1 && \\ + end=\$(TIME_MARK) && \$(BUILD_TIME) >>logs/\$@ && \\ \$(PRT_DU_CR) >>logs/\$@ EOF ) >> $MKFILE.tmp @@ -272,7 +283,10 @@ LUSER_wrt_CopyFstab() { # #----------------------------------# ( cat << EOF - @( time { cp -v \$(MOUNT_PT)/sources/fstab \$(MOUNT_PT)/etc/fstab >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ + @start=\$(TIME_MARK) && \\ + cp -v \$(MOUNT_PT)/sources/fstab \$(MOUNT_PT)/etc/fstab >>logs/\$@ 2>&1 && \\ + end=\$(TIME_MARK) && \$(BUILD_TIME) >>logs/\$@ && \\ + \$(PRT_DU) >>logs/\$@ EOF ) >> $MKFILE.tmp } @@ -282,7 +296,10 @@ CHROOT_wrt_CopyFstab() { # #----------------------------------# ( cat << EOF - @( time { cp -v /sources/fstab /etc/fstab >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ + @start=\$(TIME_MARK) && \\ + cp -v /sources/fstab /etc/fstab >>logs/\$@ 2>&1 && \\ + end=\$(TIME_MARK) && \$(BUILD_TIME) >>logs/\$@ && \\ + \$(PRT_DU_CR) >>logs/\$@ EOF ) >> $MKFILE.tmp } @@ -295,7 +312,6 @@ EOF #----------------------------------# CHROOT_wrt_TouchTimestamp() { # #----------------------------------# - local name=$1 ( cat << EOF @\$(call touch_timestamp)