2006-04-25 22:29:58 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#$Id$
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
LOGSDIR=$1
|
|
|
|
VERSION=$2
|
2017-06-29 18:45:31 +02:00
|
|
|
DATE=$3
|
2006-04-25 22:29:58 +02:00
|
|
|
|
2007-05-26 23:16:18 +02:00
|
|
|
LINE="================================================================================"
|
|
|
|
|
2006-04-25 22:29:58 +02:00
|
|
|
# Make sure that we have a directory as first argument
|
|
|
|
[[ ! -d "$LOGSDIR" ]] && \
|
2017-06-29 18:45:31 +02:00
|
|
|
echo -e "\nUSAGE: create-sbu_du-report.sh logs_directory [book_version] [date]\n" && exit
|
2006-04-25 22:29:58 +02:00
|
|
|
|
|
|
|
# Make sure that the first argument is a jhalfs logs directory
|
|
|
|
[[ ! -f "$LOGSDIR"/000-masterscript.log ]] && \
|
|
|
|
echo -e "\nLooks like $LOGSDIR isn't a jhalfs logs directory.\n" && exit
|
|
|
|
|
2006-05-03 06:17:38 +02:00
|
|
|
# If this script is run manually, the book version may be unknown
|
2006-04-25 22:29:58 +02:00
|
|
|
[[ -z "$VERSION" ]] && VERSION=unknown
|
2017-06-29 18:45:31 +02:00
|
|
|
[[ -z "$DATE" ]] && DATE=$(date --iso-8601)
|
2006-04-25 22:29:58 +02:00
|
|
|
|
|
|
|
# If there is iteration logs directories, copy the logs inside iteration-1
|
|
|
|
# to the top level dir
|
2006-12-05 16:25:00 +01:00
|
|
|
[[ -d "$LOGSDIR"/build_1 ]] && \
|
|
|
|
cp $LOGSDIR/build_1/* $LOGSDIR
|
2006-04-25 22:29:58 +02:00
|
|
|
|
|
|
|
# Set the report file
|
2017-06-29 18:45:31 +02:00
|
|
|
REPORT="$VERSION"-SBU_DU-"$DATE".report
|
2006-04-25 22:29:58 +02:00
|
|
|
|
2007-05-26 23:16:18 +02:00
|
|
|
[ -f $REPORT ] && : >$REPORT
|
|
|
|
|
2006-04-27 22:15:07 +02:00
|
|
|
# Dump generation time stamp and book version
|
2006-04-25 22:29:58 +02:00
|
|
|
echo -e "\n`date`\n" > "$REPORT"
|
|
|
|
echo -e "Book version is:\t$VERSION\n" >> "$REPORT"
|
2006-04-27 22:15:07 +02:00
|
|
|
|
|
|
|
# If found, dump jhalfs.config file in a readable format
|
|
|
|
if [[ -f jhalfs.config ]] ; then
|
|
|
|
echo -e "\n\tjhalfs configuration settings:\n" >> "$REPORT"
|
|
|
|
cat jhalfs.config | sed -e '/parameters/d;s/.\[[013;]*m//g;s/</\t</;s/^\w\{1,6\}:/&\t/' >> "$REPORT"
|
|
|
|
else
|
|
|
|
echo -e "\nNOTE: the jhalfs configuration settings are unknown" >> "$REPORT"
|
|
|
|
fi
|
2006-04-25 22:29:58 +02:00
|
|
|
|
|
|
|
# Dump CPU and memory info
|
2006-04-27 22:15:07 +02:00
|
|
|
echo -e "\n\n\t\tCPU type:\n" >> "$REPORT"
|
2020-06-19 08:51:10 +02:00
|
|
|
lscpu >> "$REPORT"
|
2006-04-25 22:29:58 +02:00
|
|
|
echo -e "\n\t\tMemory info:\n" >> "$REPORT"
|
|
|
|
free >> "$REPORT"
|
|
|
|
|
2006-04-27 22:27:21 +02:00
|
|
|
# Parse only that logs that have time data
|
2020-06-11 15:59:59 +02:00
|
|
|
pushd ${LOGSDIR}
|
|
|
|
BUILDLOGS="`grep -l "^Totalseconds:" * | sort -n`"
|
2006-04-25 22:29:58 +02:00
|
|
|
|
|
|
|
# Match the first timed log to extract the SBU unit value from it
|
2020-06-11 15:59:59 +02:00
|
|
|
FIRSTLOG=`grep -l "^Totalseconds:" * | sort -n | head -n1`
|
|
|
|
BASELOG=`grep -l "^Totalseconds:" ???-binutils* | head -n1`
|
2007-05-26 23:16:18 +02:00
|
|
|
echo -e "\nUsing ${BASELOG#*[[:digit:]]-} to obtain the SBU unit value."
|
2007-08-17 18:24:47 +02:00
|
|
|
SBU_UNIT=`sed -n 's/^Totalseconds:\s\([[:digit:]]*\)$/\1/p' $BASELOG`
|
2020-06-11 15:59:59 +02:00
|
|
|
popd
|
2021-08-28 22:50:40 +02:00
|
|
|
# Get the -j value of the SBU
|
|
|
|
if [ $(sed -n '/REALSBU/s/.*\([yn]\).*/\1/p' "$REPORT") = y ]; then
|
|
|
|
J_VALUE="1"
|
|
|
|
else
|
|
|
|
J_VALUE=$(sed -n '/N_PARALLEL/s/.*<\([^>]*\).*/\1/p' "$REPORT")
|
|
|
|
fi
|
|
|
|
echo -e "\nThe SBU unit value is equal to $SBU_UNIT seconds at -j$J_VALUE.\n"
|
|
|
|
echo -e "\n\n$LINE\n\nThe SBU unit value is equal to $SBU_UNIT seconds at -j$J_VALUE.\n" >> "$REPORT"
|
2006-04-25 22:29:58 +02:00
|
|
|
|
|
|
|
# Set the first value to 0 for grand totals calculation
|
|
|
|
SBU2=0
|
|
|
|
INSTALL2=0
|
|
|
|
INSTALLMB2=0
|
|
|
|
|
2007-05-26 23:16:18 +02:00
|
|
|
# Start the loop
|
2006-04-25 22:29:58 +02:00
|
|
|
for log in $BUILDLOGS ; do
|
|
|
|
|
2007-05-26 23:16:18 +02:00
|
|
|
# Strip the filename
|
|
|
|
PACKAGE="${log#*[[:digit:]]*-}"
|
|
|
|
|
|
|
|
# Start SBU calculation
|
|
|
|
# Build time
|
2020-06-11 15:59:59 +02:00
|
|
|
TIME=`sed -n 's/^Totalseconds:\s\([[:digit:]]*\)$/\1/p' ${LOGSDIR}/$log`
|
2007-05-26 23:16:18 +02:00
|
|
|
SECS=`perl -e 'print ('$TIME' % '60')';`
|
|
|
|
MINUTES=`perl -e 'printf "%.0f" , (('$TIME' - '$SECS') / '60')';`
|
2007-08-17 18:24:47 +02:00
|
|
|
SBU=`perl -e 'printf "%.1f" , ('$TIME' / '$SBU_UNIT')';`
|
2007-05-26 23:16:18 +02:00
|
|
|
|
|
|
|
# Append SBU value to SBU2 for grand total
|
2007-08-17 18:24:47 +02:00
|
|
|
SBU2=`perl -e 'printf "%.1f" , ('$SBU2' + '$SBU')';`
|
2007-05-26 23:16:18 +02:00
|
|
|
|
|
|
|
# Start disk usage calculation
|
|
|
|
# Disk usage before unpacking the package
|
2020-06-11 15:59:59 +02:00
|
|
|
DU1=`grep "^KB: " ${LOGSDIR}/$log | head -n1 | cut -f1 | sed -e 's/KB: //'`
|
2007-05-26 23:16:18 +02:00
|
|
|
DU1MB=`perl -e 'printf "%.3f" , ('$DU1' / '1024')';`
|
|
|
|
# Disk usage before deleting the source and build dirs
|
2020-06-11 15:59:59 +02:00
|
|
|
DU2=`grep "^KB: " ${LOGSDIR}/$log | tail -n1 | cut -f1 | sed -e 's/KB: //'`
|
2007-05-26 23:16:18 +02:00
|
|
|
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')';`
|
2006-04-25 22:29:58 +02:00
|
|
|
|
2007-05-26 23:16:18 +02:00
|
|
|
# Append installed files disk usage to the previous entry,
|
|
|
|
# except for the first parsed log
|
2012-02-28 14:20:40 +01:00
|
|
|
if [ "$log" != "$FIRSTLOG" ] ; then
|
2007-05-26 23:16:18 +02:00
|
|
|
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
|
2006-04-25 22:29:58 +02:00
|
|
|
# Append install values for grand total
|
2007-05-26 23:16:18 +02:00
|
|
|
INSTALL2=`perl -e 'printf "%.3f" , ('$INSTALL2' + '$INSTALL')';`
|
|
|
|
INSTALLMB2=`perl -e 'printf "%.3f" , ('$INSTALLMB2' + '$INSTALLMB')';`
|
2006-04-25 22:29:58 +02:00
|
|
|
fi
|
|
|
|
|
2007-05-26 23:16:18 +02:00
|
|
|
# Set variables to calculate installed files disk usage
|
2006-04-25 22:29:58 +02:00
|
|
|
DU1PREV=$DU1
|
|
|
|
DU1MBPREV=$DU1MB
|
|
|
|
|
2007-05-26 23:16:18 +02:00
|
|
|
# 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
|
2006-04-25 22:29:58 +02:00
|
|
|
|
|
|
|
done
|
|
|
|
|
2012-02-28 14:20:40 +01:00
|
|
|
# For printing the last 'Installed files disk usage', we need to 'du' the
|
|
|
|
# root dir, excluding the jhalfs directory (and lost+found). We assume
|
|
|
|
# that the rootdir is $LOGSDIR/../..
|
2019-07-15 22:00:32 +02:00
|
|
|
DU1=`du -skx --exclude=jhalfs --exclude=lost+found --exclude var/lib $LOGSDIR/../.. | cut -f1`
|
2012-02-28 14:20:40 +01:00
|
|
|
DU1MB=`perl -e 'printf "%.3f" , ('$DU1' / '1024')';`
|
|
|
|
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=`perl -e 'printf "%.3f" , ('$INSTALL2' + '$INSTALL')';`
|
|
|
|
INSTALLMB2=`perl -e 'printf "%.3f" , ('$INSTALLMB2' + '$INSTALLMB')';`
|
|
|
|
|
2006-04-25 22:29:58 +02:00
|
|
|
# Dump grand totals
|
2013-03-21 12:02:48 +01:00
|
|
|
echo -e "\n$LINE\n\nTotal time required to build the system:\t\t$SBU2 SBU" >> $REPORT
|
2007-05-26 23:16:18 +02:00
|
|
|
# Total disk usage: including /tools but not /sources.
|
|
|
|
echo -e "Total Installed files disk usage:\t\t\t$INSTALL2 KB or $INSTALLMB2 MB" >> $REPORT
|