source: common/create-sbu_du-report.sh@ 875366f

ablfs-more trunk
Last change on this file since 875366f was 03b24b2, checked in by Pierre Labastie <pierre.labastie@…>, 3 years ago

Various fixes for create-sbu_du-report.sh

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