Replaced "time" and "du" by "perl" fot timming and SBU-DU report calculations.

Thanks to Dan Nicholson and Ag. D. Hatzimanikas for the sugestions and patches.
This commit is contained in:
Manuel Canales Esparcia 2007-05-26 21:16:18 +00:00
parent 81fca3136b
commit 02100141e4
3 changed files with 77 additions and 76 deletions

View file

@ -6,6 +6,8 @@ set -e
LOGSDIR=$1 LOGSDIR=$1
VERSION=$2 VERSION=$2
LINE="================================================================================"
# Make sure that we have a directory as first argument # Make sure that we have a directory as first argument
[[ ! -d "$LOGSDIR" ]] && \ [[ ! -d "$LOGSDIR" ]] && \
echo -e "\nUSAGE: create-sbu_du-report.sh logs_directory [book_version]\n" && exit echo -e "\nUSAGE: create-sbu_du-report.sh logs_directory [book_version]\n" && exit
@ -25,6 +27,8 @@ VERSION=$2
# Set the report file # Set the report file
REPORT="$VERSION"-SBU_DU-$(date --iso-8601).report REPORT="$VERSION"-SBU_DU-$(date --iso-8601).report
[ -f $REPORT ] && : >$REPORT
# Dump generation time stamp and book version # Dump generation time stamp and book version
echo -e "\n`date`\n" > "$REPORT" echo -e "\n`date`\n" > "$REPORT"
echo -e "Book version is:\t$VERSION\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" free >> "$REPORT"
# Parse only that logs that have time data # 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 # Match the first timed log to extract the SBU unit value from it
BASELOG=`grep -l "^real\>" $LOGSDIR/* | head -n1` BASELOG=`grep -l "^Totalseconds:" $LOGSDIR/* | head -n1`
echo -e "\n\nUsing $BASELOG to obtain the SBU unit value." >> "$REPORT" echo -e "\nUsing ${BASELOG#*[[:digit:]]-} to obtain the SBU unit value."
BASEMINUTES=`grep "^real\>" $BASELOG | cut -f2 | sed -e 's/m.*//'` SBU_UNIT=`sed -n 's/^Totalseconds:\s\([[:digit:]]*.[[:digit:]]*\)$/\1/p' $BASELOG`
BASESECONDS=`grep "^real\>" $BASELOG | cut -f2 | sed -e 's/.*m//;s/s//'` echo -e "\nThe SBU unit value is equal to $SBU_UNIT seconds.\n"
SBU_UNIT=`echo "scale=3; $BASEMINUTES * 60 + $BASESECONDS" | bc` echo -e "\n\n$LINE\n\nThe SBU unit value is equal to $SBU_UNIT seconds.\n" >> "$REPORT"
echo -e "The SBU unit value is equal to $SBU_UNIT seconds.\n" >> "$REPORT"
# Set the first value to 0 for grand totals calculation # Set the first value to 0 for grand totals calculation
SBU2=0 SBU2=0
INSTALL2=0 INSTALL2=0
INSTALLMB2=0 INSTALLMB2=0
# Start the loop
for log in $BUILDLOGS ; do for log in $BUILDLOGS ; do
# Strip the filename
PACKAGE="${log#*[[:digit:]]*-}"
# Start SBU calculation # Start SBU calculation
# Build time # Build time
BUILDTIME=`grep "^real\>" $log | cut -f2` TIME=`sed -n 's/^Totalseconds:\s\([[:digit:]]*.[[:digit:]]*\)$/\1/p' $log`
# Build time in seconds SECS=`perl -e 'print ('$TIME' % '60')';`
MINUTES=`grep "^real\>" $log | cut -f2 | sed -e 's/m.*//'` MINUTES=`perl -e 'printf "%.0f" , (('$TIME' - '$SECS') / '60')';`
SECS=`grep "^real\>" $log | cut -f2 | sed -e 's/.*m//;s/s//'` SBU=`perl -e 'printf "%.3f" , ('$TIME' / '$SBU_UNIT')';`
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 # Append SBU value to SBU2 for grand total
SBU2="$SBU2 + $SBU" SBU2=`perl -e 'printf "%.3f" , ('$SBU2' + '$SBU')';`
# Start disk usage calculation # Start disk usage calculation
# Disk usage before unpacking the package # Disk usage before unpacking the package
DU1=`grep "^KB: " $log | head -n1 | cut -f1 | sed -e 's/KB: //'` DU1=`grep "^KB: " $log | head -n1 | cut -f1 | sed -e 's/KB: //'`
DU1MB=`echo "scale=2; $DU1 / 1024" | bc` DU1MB=`perl -e 'printf "%.3f" , ('$DU1' / '1024')';`
# Disk usage before deleting the source and build dirs # Disk usage before deleting the source and build dirs
DU2=`grep "^KB: " $log | tail -n1 | cut -f1 | sed -e 's/KB: //'` DU2=`grep "^KB: " $log | tail -n1 | cut -f1 | sed -e 's/KB: //'`
DU2MB=`echo "scale=2; $DU2 / 1024" | bc` DU2MB=`perl -e 'printf "%.3f" , ('$DU2' / '1024')';`
# Calculate disk space required to do the build # Calculate disk space required to do the build
REQUIRED1=`echo "$DU2 - $DU1" | bc` REQUIRED1=`perl -e 'print ('$DU2' - '$DU1')';`
REQUIRED2=`echo "scale=2; $DU2MB - $DU1MB" | bc` REQUIRED2=`perl -e 'printf "%.3f" , ('$DU2MB' - '$DU1MB')';`
# Append installed files disk usage to the previous entry, # Append installed files disk usage to the previous entry,
# except for the first parsed log # except for the first parsed log
if [ "$log" != "$BASELOG" ] ; then if [ "$log" != "$BASELOG" ] ; then
INSTALL=`echo "$DU1 - $DU1PREV" | bc` INSTALL=`perl -e 'print ('$DU1' - '$DU1PREV')';`
INSTALLMB=`echo "scale=2; $DU1MB - $DU1MBPREV" | bc` INSTALLMB=`perl -e 'printf "%.3f" , ('$DU1MB' - '$DU1MBPREV')';`
echo -e "Installed files disk usage:\t\t\t\t$INSTALL KB or $INSTALLMB MB\n" >> "$REPORT" echo -e "Installed files disk usage:\t\t\t\t$INSTALL KB or $INSTALLMB MB\n" >> $REPORT
# Append install values for grand total # Append install values for grand total
INSTALL2="$INSTALL2 + $INSTALL" INSTALL2=`perl -e 'printf "%.3f" , ('$INSTALL2' + '$INSTALL')';`
INSTALLMB2="$INSTALLMB2 + $INSTALLMB" INSTALLMB2=`perl -e 'printf "%.3f" , ('$INSTALLMB2' + '$INSTALLMB')';`
fi fi
# Set variables to calculate installed files disk usage # Set variables to calculate installed files disk usage
DU1PREV=$DU1 DU1PREV=$DU1
DU1MBPREV=$DU1MB DU1MBPREV=$DU1MB
# Append log name # Dump time and disk usage values
echo -e "\n\t$log" >> "$REPORT" 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
# Dump time values echo -e "Build time in seconds is:\t\t\t\t$TIME" >> $REPORT
echo -e "Build time is:\t\t\t$BUILDTIME" >> "$REPORT" echo -e "Approximate SBU time is:\t\t\t\t$SBU" >> $REPORT
echo -e "Build time in seconds is\t$TIME" >> "$REPORT" echo -e "Disk usage before unpacking the package:\t\t$DU1 KB or $DU1MB MB" >> $REPORT
echo -e "Approximate SBU time is:\t$SBU" >> "$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
# 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"
done done
# Dump grand totals # Dump grand totals
TOTALSBU=`echo "scale=3; ${SBU2}" | bc` echo -e "\n$LINE\n\nTotal time required to build the systen:\t\t$SBU2 SBU" >> $REPORT
echo -e "\nTotal time required to build the systen:\t$TOTALSBU SBU\n" >> "$REPORT" # Total disk usage: including /tools but not /sources.
TOTALINSTALL=`echo "${INSTALL2}" | bc` echo -e "Total Installed files disk usage:\t\t\t$INSTALL2 KB or $INSTALLMB2 MB" >> $REPORT
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"

View file

@ -117,6 +117,7 @@ inline_doc
TIMEZONE | \ TIMEZONE | \
PAGE | \ PAGE | \
INSTALL_LOG | \ INSTALL_LOG | \
REPORT | \
REBUILD_MAKEFILE ) echo -e "`eval echo $PARAM_VALS`" ;; REBUILD_MAKEFILE ) echo -e "`eval echo $PARAM_VALS`" ;;
# Envvars that depend on other settings to be displayed # Envvars that depend on other settings to be displayed
@ -138,25 +139,13 @@ inline_doc
LGROUP) echo -e "`eval echo $PARAM_VALS`" LGROUP) echo -e "`eval echo $PARAM_VALS`"
[[ "${!config_param}" = "**EDIT ME**" ]] && write_error_and_die [[ "${!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 validation. Very ugly, need be fixed
BOOK) if [[ "${WORKING_COPY}" = "y" ]] ; then BOOK) if [[ "${WORKING_COPY}" = "y" ]] ; then
validate_dir -z -d validate_dir -z -d
else else
echo -e "`eval echo $PARAM_VALS`" echo -e "`eval echo $PARAM_VALS`"
fi ;; fi
;;
# Validate directories, testable states: # Validate directories, testable states:
# fatal -z -d -w, # fatal -z -d -w,
# warning -z+ -w+ # warning -z+ -w+

View file

@ -40,6 +40,8 @@ SU_LUSER = su - \$(LUSER) -c
LUSER_HOME = \$(LHOME)/\$(LUSER) LUSER_HOME = \$(LHOME)/\$(LUSER)
PRT_DU = echo -e "\nKB: \`du -skx --exclude=\$(SCRIPT_ROOT) --exclude=lost+found \$(MOUNT_PT) \`\n" 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" 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_REPORT = $REPORT
ADD_CUSTOM_TOOLS = $CUSTOM_TOOLS ADD_CUSTOM_TOOLS = $CUSTOM_TOOLS
@ -230,20 +232,26 @@ wrt_RunAsRoot() { # Some scripts must be run as root..
( (
cat << EOF 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/\$@ \$(PRT_DU) >>logs/\$@
EOF EOF
) >> $MKFILE.tmp ) >> $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 local file=$1
( (
cat << EOF cat << EOF
@( time { source ~/.bashrc && \$(CMDSDIR)/`dirname $file`/\$@ >> logs/\$@ 2>&1; } ) 2>> logs/\$@ && \\ @start=\$(TIME_MARK) && \\
source ~/.bashrc && \\
\$(CMDSDIR)/`dirname $file`/\$@ >> logs/\$@ 2>&1 && \\
end=\$(TIME_MARK) && \$(BUILD_TIME) >>logs/\$@ && \\
\$(PRT_DU) >>logs/\$@ \$(PRT_DU) >>logs/\$@
EOF EOF
) >> $MKFILE.tmp ) >> $MKFILE.tmp
@ -255,7 +263,10 @@ CHROOT_wrt_RunAsRoot() { #
local file=$1 local file=$1
( (
cat << EOF 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/\$@ \$(PRT_DU_CR) >>logs/\$@
EOF EOF
) >> $MKFILE.tmp ) >> $MKFILE.tmp
@ -272,7 +283,10 @@ LUSER_wrt_CopyFstab() { #
#----------------------------------# #----------------------------------#
( (
cat << EOF 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 EOF
) >> $MKFILE.tmp ) >> $MKFILE.tmp
} }
@ -282,7 +296,10 @@ CHROOT_wrt_CopyFstab() { #
#----------------------------------# #----------------------------------#
( (
cat << EOF 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 EOF
) >> $MKFILE.tmp ) >> $MKFILE.tmp
} }
@ -295,7 +312,6 @@ EOF
#----------------------------------# #----------------------------------#
CHROOT_wrt_TouchTimestamp() { # CHROOT_wrt_TouchTimestamp() { #
#----------------------------------# #----------------------------------#
local name=$1
( (
cat << EOF cat << EOF
@\$(call touch_timestamp) @\$(call touch_timestamp)