This repository has been archived on 2024-10-17. You can view files and clone it, but cannot push or open issues or pull requests.
MahiroOS-jhalfs/common/create-sbu_du-report.sh

150 lines
5.8 KiB
Bash
Raw Normal View History

#!/bin/bash
set -e
LOGSDIR=$1
VERSION=$2
DATE=$3
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] [date]\n" && exit
# 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
# Make sure something has been built otherwise no need for report :)
[ ! -f "$LOGSDIR"/???-binutils-pass1* ] && \
echo -e "\nLooks like nothing has been built yet. Aborting report.\n" && exit
2006-05-03 06:17:38 +02:00
# If this script is run manually, the book version may be unknown
[ -z "$VERSION" ] && VERSION=unknown
[ -z "$DATE" ] && DATE=$(date --iso-8601)
# If there is iteration logs directories, copy the logs inside iteration-1
# to the top level dir
[ -d "$LOGSDIR"/build_1 ] && \
cp $LOGSDIR/build_1/* $LOGSDIR
# Set the report file
REPORT="$VERSION"-SBU_DU-"$DATE".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"
# 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
# Dump CPU and memory info
echo -e "\n\n\t\tCPU type:\n" >> "$REPORT"
lscpu >> "$REPORT"
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
pushd ${LOGSDIR}
BUILDLOGS="`grep -l "^Totalseconds:" * | sort -n`"
# Match the first timed log to extract the SBU unit value from it
FIRSTLOG=`grep -l "^Totalseconds:" * | sort -n | head -n1`
BASELOG=`grep -l "^Totalseconds:" ???-binutils* | head -n1`
echo -e "\nUsing ${BASELOG#*[[:digit:]]-} to obtain the SBU unit value."
SBU_UNIT=`sed -n 's/^Totalseconds:\s\([[:digit:]]*\)$/\1/p' $BASELOG`
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
2021-08-28 22:50:40 +02:00
J_VALUE="1"
else
J_VALUE=$(sed -n '/N_PARALLEL/s/.*<\([^>]*\).*/\1/p' "$REPORT")
fi
# if jhalfs.config does not exist, or OPTIMIZE is 0, then J_VALUE is
# still empty. Assume 1 in that case
echo -e "\nThe SBU unit value is equal to $SBU_UNIT seconds at -j${J_VALUE:=1}.\n"
2021-08-28 22:50:40 +02:00
echo -e "\n\n$LINE\n\nThe SBU unit value is equal to $SBU_UNIT seconds at -j$J_VALUE.\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
# Strip the filename
PACKAGE="${log#*[[:digit:]]*-}"
# Start SBU calculation
# Build time
TIME=`sed -n 's/^Totalseconds:\s\([[:digit:]]*\)$/\1/p' ${LOGSDIR}/$log`
SECS=`perl -e 'print ('$TIME' % '60')';`
MINUTES=`perl -e 'printf "%.0f" , (('$TIME' - '$SECS') / '60')';`
SBU=`perl -e 'printf "%.1f" , ('$TIME' / '$SBU_UNIT')';`
# Append SBU value to SBU2 for grand total
SBU2=`perl -e 'printf "%.1f" , ('$SBU2' + '$SBU')';`
# Start disk usage calculation
# Disk usage before unpacking the package
DU1=`grep "^KB: " ${LOGSDIR}/$log | head -n1 | cut -f1 | sed -e 's/KB: //'`
DU1MB=`perl -e 'printf "%.3f" , ('$DU1' / '1024')';`
# Disk usage before deleting the source and build dirs
DU2=`grep "^KB: " ${LOGSDIR}/$log | tail -n1 | cut -f1 | sed -e 's/KB: //'`
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
if [ "$log" != "$FIRSTLOG" ] ; then
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')';`
fi
# Set variables to calculate installed files disk usage
DU1PREV=$DU1
DU1MBPREV=$DU1MB
# 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
# 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/../..
DU1=`du -skx --exclude=jhalfs --exclude=lost+found --exclude var/lib $LOGSDIR/../.. | cut -f1`
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')';`
# 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
# Total disk usage: including /tools but not /sources.
echo -e "Total Installed files disk usage:\t\t\t$INSTALL2 KB or $INSTALLMB2 MB" >> $REPORT