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