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

122 lines
4.5 KiB
Bash
Raw Permalink Normal View History

2006-04-26 22:24:58 +02:00
#!/bin/bash
#$Id$
set -e
LOGSDIR=$1
VERSION=$2
LINE="================================================================================"
2006-04-26 22:24:58 +02:00
# Make sure that we have a directory as first argument
[[ ! -d "$LOGSDIR" ]] && \
2006-04-27 22:33:46 +02:00
echo -e "\nUSAGE: create-sbu_du-report.sh logs_directory [book_version]\n" && exit
2006-04-26 22:24: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
# If this script is run manually, the book version may be unknown
2006-04-26 22:24:58 +02:00
[[ -z "$VERSION" ]] && VERSION=unknown
# 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
2006-04-26 22:24:58 +02:00
# Set the report file
REPORT="$VERSION"-SBU_DU-$(date --iso-8601).report
[ -f $REPORT ] && : >$REPORT
2006-04-27 22:33:46 +02:00
# Dump generation time stamp and book version
2006-04-26 22:24:58 +02:00
echo -e "\n`date`\n" > "$REPORT"
echo -e "Book version is:\t$VERSION\n" >> "$REPORT"
2006-04-27 22:33:46 +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-26 22:24:58 +02:00
# Dump CPU and memory info
2006-04-27 22:33:46 +02:00
echo -e "\n\n\t\tCPU type:\n" >> "$REPORT"
2006-04-26 22:24:58 +02:00
cat /proc/cpuinfo >> "$REPORT"
echo -e "\n\t\tMemory info:\n" >> "$REPORT"
free >> "$REPORT"
# Parse only that logs that have time data
BUILDLOGS="`grep -l "^Totalseconds:" ${LOGSDIR}/*`"
2006-04-26 22:24:58 +02:00
# Match the first timed log to extract the SBU unit value from it
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:]]*\)$/\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"
2006-04-26 22:24:58 +02:00
# Set the first value to 0 for grand totals calculation
SBU2=0
INSTALL2=0
INSTALLMB2=0
# Start the loop
2006-04-26 22:24:58 +02:00
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' $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
2006-04-26 22:24:58 +02:00
DU1=`grep "^KB: " $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
2006-04-26 22:24:58 +02:00
DU2=`grep "^KB: " $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')';`
2006-04-26 22:24:58 +02:00
# Append installed files disk usage to the previous entry,
# except for the first parsed log
2006-04-26 22:24:58 +02:00
if [ "$log" != "$BASELOG" ] ; 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
2006-04-26 22:24:58 +02:00
# Append install values for grand total
INSTALL2=`perl -e 'printf "%.3f" , ('$INSTALL2' + '$INSTALL')';`
INSTALLMB2=`perl -e 'printf "%.3f" , ('$INSTALLMB2' + '$INSTALLMB')';`
2006-04-26 22:24:58 +02:00
fi
# Set variables to calculate installed files disk usage
2006-04-26 22:24:58 +02:00
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
2006-04-26 22:24:58 +02:00
done
# Dump grand totals
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