On Sun, May 20, at 08:14 Dan Nicholson wrote:
> A couple things to thing about.
>
> 1. The script would obviously be improved if it was done all in perl
> instead of forking a ton of processes. But that would require one of
> use to know perl :) It looks pretty nice, though.
>
> 2. We can be smarter about how we log the time to start out with.
> Instead of just taking the output that `time' gives, it would be
> better if there was a value just in seconds. You can do this by using
> the TIMEFORMAT variable in bash or by doing some external timing like
> I did before with perl.
>
Yes, the perl trick we should consider to integrate it. I prefer perl, than bash
or even better zsh ( it can handle floating point numbers nicely)...
Oh I forgot we have bash in linux. :(
Ok, the patch attached, I tried it in the last build and it seems to work.
Please review it for a second before apply it, and feel free to change
it.
I also commented out the REPORT option in the case statement, in
common/libs/func_validate_configs.sh.
I don't know if there is another trail for bc, I don't know the code that well,
but with a quick grep'ing' I didn't see anything else,
PS to Dan.
Loyalty to Hinrich?
Give me a break, the really question is:
Who was worse than Kirk, in the playoffs?
Oh yes. Wade.
Please sign Diamantidis. He is a champ. A really one.
Index: common/create-sbu_du-report.sh
===================================================================
--- common/create-sbu_du-report.sh (revision 3355)
+++ common/create-sbu_du-report.sh (working copy)
@@ -6,6 +6,8 @@
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 @@
# 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,77 @@
free >> "$REPORT"
# Parse only that logs that have time data
-BUILDLOGS=`grep -l "^real\>" $LOGSDIR/*`
+BUILDLOGS="`grep -l "^real\>" ${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"
+echo -e "\nUsing ${BASELOG#*[[:digit:]]-} to obtain the SBU unit value."
+BASEMINUTES=`sed -n 's/^real[ \t]*\([[:digit:]]*\)m.*$/\1/p' $BASELOG`
+BASESECONDS=`sed -n 's/^real[ \t].*m\([[:digit:]]*\)\..*$/\1/p' $BASELOG`
+SBU_UNIT=`perl -e 'print ('$BASEMINUTES' * '60' + '$BASESECONDS',"\n")';`
+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
+ BUILDTIME=`sed -n 's/^real[ \t]*\([[:digit:]]*\)m\([[:digit:]]*\)\..*$/\1
minutes and \2 seconds/p' $log`
+ MINUTES=`sed -n 's/^real[ \t]*\([[:digit:]]*\)m.*$/\1/p' $log`
+ SECS=`sed -n 's/^real[ \t].*m\([[:digit:]]*\)\..*$/\1/p' $log`
+ TIME=`perl -e 'print ('$MINUTES' * '60' + '$SECS')';`
+# Calculate build time in SBU
+ SBU=`perl -e 'printf "%.3f\n" , ('$TIME' / '$SBU_UNIT')';`
+# Append SBU value to SBU2 for grand total
+ SBU2=`perl -e 'printf "%.3f\n" , ('$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\n" , ('$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\n" , ('$DU2' / '1024')';`
+# Calculate disk space required to do the build
+ REQUIRED1=`perl -e 'print ('$DU2' - '$DU1', "\n")';`
+ REQUIRED2=`perl -e 'printf "%.3f\n" , ('$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', "\n")';`
+ INSTALLMB=`perl -e 'printf "%.3f\n" , ('$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\n" , ('$INSTALL2' + '$INSTALL')';`
+ INSTALLMB2=`perl -e 'printf "%.3f\n" , ('$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 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$BUILDTIME" >> $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
- # 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"
-
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
Index: common/libs/func_validate_configs.sh
===================================================================
--- common/libs/func_validate_configs.sh (revision 3355)
+++ common/libs/func_validate_configs.sh (working copy)
@@ -138,18 +138,18 @@
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 ;;
-
+# 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
--
http://linuxfromscratch.org/mailman/listinfo/alfs-discuss
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page