[9ea3d54] | 1 | #!/bin/bash
|
---|
| 2 | #$Id$
|
---|
| 3 |
|
---|
| 4 | set -e
|
---|
| 5 |
|
---|
| 6 | LOGSDIR=$1
|
---|
| 7 | VERSION=$2
|
---|
[c57747d] | 8 | DATE=$3
|
---|
[9ea3d54] | 9 |
|
---|
[0210014] | 10 | LINE="================================================================================"
|
---|
| 11 |
|
---|
[9ea3d54] | 12 | # Make sure that we have a directory as first argument
|
---|
| 13 | [[ ! -d "$LOGSDIR" ]] && \
|
---|
[c57747d] | 14 | echo -e "\nUSAGE: create-sbu_du-report.sh logs_directory [book_version] [date]\n" && exit
|
---|
[9ea3d54] | 15 |
|
---|
| 16 | # Make sure that the first argument is a jhalfs logs directory
|
---|
| 17 | [[ ! -f "$LOGSDIR"/000-masterscript.log ]] && \
|
---|
| 18 | echo -e "\nLooks like $LOGSDIR isn't a jhalfs logs directory.\n" && exit
|
---|
| 19 |
|
---|
[26d25e8] | 20 | # If this script is run manually, the book version may be unknown
|
---|
[9ea3d54] | 21 | [[ -z "$VERSION" ]] && VERSION=unknown
|
---|
[c57747d] | 22 | [[ -z "$DATE" ]] && DATE=$(date --iso-8601)
|
---|
[9ea3d54] | 23 |
|
---|
| 24 | # If there is iteration logs directories, copy the logs inside iteration-1
|
---|
| 25 | # to the top level dir
|
---|
[10c8b78] | 26 | [[ -d "$LOGSDIR"/build_1 ]] && \
|
---|
| 27 | cp $LOGSDIR/build_1/* $LOGSDIR
|
---|
[9ea3d54] | 28 |
|
---|
| 29 | # Set the report file
|
---|
[c57747d] | 30 | REPORT="$VERSION"-SBU_DU-"$DATE".report
|
---|
[9ea3d54] | 31 |
|
---|
[0210014] | 32 | [ -f $REPORT ] && : >$REPORT
|
---|
| 33 |
|
---|
[a9429d5] | 34 | # Dump generation time stamp and book version
|
---|
[9ea3d54] | 35 | echo -e "\n`date`\n" > "$REPORT"
|
---|
| 36 | echo -e "Book version is:\t$VERSION\n" >> "$REPORT"
|
---|
[a9429d5] | 37 |
|
---|
| 38 | # If found, dump jhalfs.config file in a readable format
|
---|
| 39 | if [[ -f jhalfs.config ]] ; then
|
---|
| 40 | echo -e "\n\tjhalfs configuration settings:\n" >> "$REPORT"
|
---|
| 41 | cat jhalfs.config | sed -e '/parameters/d;s/.\[[013;]*m//g;s/</\t</;s/^\w\{1,6\}:/&\t/' >> "$REPORT"
|
---|
| 42 | else
|
---|
| 43 | echo -e "\nNOTE: the jhalfs configuration settings are unknown" >> "$REPORT"
|
---|
| 44 | fi
|
---|
[9ea3d54] | 45 |
|
---|
| 46 | # Dump CPU and memory info
|
---|
[a9429d5] | 47 | echo -e "\n\n\t\tCPU type:\n" >> "$REPORT"
|
---|
[e4b7aa8] | 48 | lscpu >> "$REPORT"
|
---|
[9ea3d54] | 49 | echo -e "\n\t\tMemory info:\n" >> "$REPORT"
|
---|
| 50 | free >> "$REPORT"
|
---|
| 51 |
|
---|
[d9a53e0] | 52 | # Parse only that logs that have time data
|
---|
[b217a30] | 53 | pushd ${LOGSDIR}
|
---|
| 54 | BUILDLOGS="`grep -l "^Totalseconds:" * | sort -n`"
|
---|
[9ea3d54] | 55 |
|
---|
| 56 | # Match the first timed log to extract the SBU unit value from it
|
---|
[b217a30] | 57 | FIRSTLOG=`grep -l "^Totalseconds:" * | sort -n | head -n1`
|
---|
| 58 | BASELOG=`grep -l "^Totalseconds:" ???-binutils* | head -n1`
|
---|
[0210014] | 59 | echo -e "\nUsing ${BASELOG#*[[:digit:]]-} to obtain the SBU unit value."
|
---|
[68713c9] | 60 | SBU_UNIT=`sed -n 's/^Totalseconds:\s\([[:digit:]]*\)$/\1/p' $BASELOG`
|
---|
[b217a30] | 61 | popd
|
---|
[0210014] | 62 | echo -e "\nThe SBU unit value is equal to $SBU_UNIT seconds.\n"
|
---|
| 63 | echo -e "\n\n$LINE\n\nThe SBU unit value is equal to $SBU_UNIT seconds.\n" >> "$REPORT"
|
---|
[9ea3d54] | 64 |
|
---|
| 65 | # Set the first value to 0 for grand totals calculation
|
---|
| 66 | SBU2=0
|
---|
| 67 | INSTALL2=0
|
---|
| 68 | INSTALLMB2=0
|
---|
| 69 |
|
---|
[0210014] | 70 | # Start the loop
|
---|
[9ea3d54] | 71 | for log in $BUILDLOGS ; do
|
---|
| 72 |
|
---|
[0210014] | 73 | # Strip the filename
|
---|
| 74 | PACKAGE="${log#*[[:digit:]]*-}"
|
---|
| 75 |
|
---|
| 76 | # Start SBU calculation
|
---|
| 77 | # Build time
|
---|
[b217a30] | 78 | TIME=`sed -n 's/^Totalseconds:\s\([[:digit:]]*\)$/\1/p' ${LOGSDIR}/$log`
|
---|
[0210014] | 79 | SECS=`perl -e 'print ('$TIME' % '60')';`
|
---|
| 80 | MINUTES=`perl -e 'printf "%.0f" , (('$TIME' - '$SECS') / '60')';`
|
---|
[68713c9] | 81 | SBU=`perl -e 'printf "%.1f" , ('$TIME' / '$SBU_UNIT')';`
|
---|
[0210014] | 82 |
|
---|
| 83 | # Append SBU value to SBU2 for grand total
|
---|
[68713c9] | 84 | SBU2=`perl -e 'printf "%.1f" , ('$SBU2' + '$SBU')';`
|
---|
[0210014] | 85 |
|
---|
| 86 | # Start disk usage calculation
|
---|
| 87 | # Disk usage before unpacking the package
|
---|
[b217a30] | 88 | DU1=`grep "^KB: " ${LOGSDIR}/$log | head -n1 | cut -f1 | sed -e 's/KB: //'`
|
---|
[0210014] | 89 | DU1MB=`perl -e 'printf "%.3f" , ('$DU1' / '1024')';`
|
---|
| 90 | # Disk usage before deleting the source and build dirs
|
---|
[b217a30] | 91 | DU2=`grep "^KB: " ${LOGSDIR}/$log | tail -n1 | cut -f1 | sed -e 's/KB: //'`
|
---|
[0210014] | 92 | DU2MB=`perl -e 'printf "%.3f" , ('$DU2' / '1024')';`
|
---|
| 93 | # Calculate disk space required to do the build
|
---|
| 94 | REQUIRED1=`perl -e 'print ('$DU2' - '$DU1')';`
|
---|
| 95 | REQUIRED2=`perl -e 'printf "%.3f" , ('$DU2MB' - '$DU1MB')';`
|
---|
[9ea3d54] | 96 |
|
---|
[0210014] | 97 | # Append installed files disk usage to the previous entry,
|
---|
| 98 | # except for the first parsed log
|
---|
[125e05e] | 99 | if [ "$log" != "$FIRSTLOG" ] ; then
|
---|
[0210014] | 100 | INSTALL=`perl -e 'print ('$DU1' - '$DU1PREV')';`
|
---|
| 101 | INSTALLMB=`perl -e 'printf "%.3f" , ('$DU1MB' - '$DU1MBPREV')';`
|
---|
| 102 | echo -e "Installed files disk usage:\t\t\t\t$INSTALL KB or $INSTALLMB MB\n" >> $REPORT
|
---|
[9ea3d54] | 103 | # Append install values for grand total
|
---|
[0210014] | 104 | INSTALL2=`perl -e 'printf "%.3f" , ('$INSTALL2' + '$INSTALL')';`
|
---|
| 105 | INSTALLMB2=`perl -e 'printf "%.3f" , ('$INSTALLMB2' + '$INSTALLMB')';`
|
---|
[9ea3d54] | 106 | fi
|
---|
| 107 |
|
---|
[0210014] | 108 | # Set variables to calculate installed files disk usage
|
---|
[9ea3d54] | 109 | DU1PREV=$DU1
|
---|
| 110 | DU1MBPREV=$DU1MB
|
---|
| 111 |
|
---|
[0210014] | 112 | # Dump time and disk usage values
|
---|
| 113 | echo -e "$LINE\n\t\t\t\t[$PACKAGE]\n" >> $REPORT
|
---|
| 114 | echo -e "Build time is:\t\t\t\t\t\t$MINUTES minutes and $SECS seconds" >> $REPORT
|
---|
| 115 | echo -e "Build time in seconds is:\t\t\t\t$TIME" >> $REPORT
|
---|
| 116 | echo -e "Approximate SBU time is:\t\t\t\t$SBU" >> $REPORT
|
---|
| 117 | echo -e "Disk usage before unpacking the package:\t\t$DU1 KB or $DU1MB MB" >> $REPORT
|
---|
| 118 | echo -e "Disk usage before deleting the source and build dirs:\t$DU2 KB or $DU2MB MB" >> $REPORT
|
---|
| 119 | echo -e "Required space to build the package:\t\t\t$REQUIRED1 KB or $REQUIRED2 MB" >> $REPORT
|
---|
[9ea3d54] | 120 |
|
---|
| 121 | done
|
---|
| 122 |
|
---|
[125e05e] | 123 | # For printing the last 'Installed files disk usage', we need to 'du' the
|
---|
| 124 | # root dir, excluding the jhalfs directory (and lost+found). We assume
|
---|
| 125 | # that the rootdir is $LOGSDIR/../..
|
---|
[3b14992] | 126 | DU1=`du -skx --exclude=jhalfs --exclude=lost+found --exclude var/lib $LOGSDIR/../.. | cut -f1`
|
---|
[125e05e] | 127 | DU1MB=`perl -e 'printf "%.3f" , ('$DU1' / '1024')';`
|
---|
| 128 | INSTALL=`perl -e 'print ('$DU1' - '$DU1PREV')';`
|
---|
| 129 | INSTALLMB=`perl -e 'printf "%.3f" , ('$DU1MB' - '$DU1MBPREV')';`
|
---|
| 130 | echo -e "Installed files disk usage:\t\t\t\t$INSTALL KB or $INSTALLMB MB\n" >> $REPORT
|
---|
| 131 | # Append install values for grand total
|
---|
| 132 | INSTALL2=`perl -e 'printf "%.3f" , ('$INSTALL2' + '$INSTALL')';`
|
---|
| 133 | INSTALLMB2=`perl -e 'printf "%.3f" , ('$INSTALLMB2' + '$INSTALLMB')';`
|
---|
| 134 |
|
---|
[9ea3d54] | 135 | # Dump grand totals
|
---|
[7d109d4] | 136 | echo -e "\n$LINE\n\nTotal time required to build the system:\t\t$SBU2 SBU" >> $REPORT
|
---|
[0210014] | 137 | # Total disk usage: including /tools but not /sources.
|
---|
| 138 | echo -e "Total Installed files disk usage:\t\t\t$INSTALL2 KB or $INSTALLMB2 MB" >> $REPORT
|
---|