source: common/create-sbu_du-report.sh@ 05b955b

ablfs-more trunk
Last change on this file since 05b955b was 03b24b2, checked in by Pierre Labastie <pierre.labastie@…>, 2 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
Line 
1#!/bin/bash
2
3set -e
4
5LOGSDIR=$1
6VERSION=$2
7DATE=$3
8
9LINE="================================================================================"
10
11# Make sure that we have a directory as first argument
12[ ! -d "$LOGSDIR" ] && \
13 echo -e "\nUSAGE: create-sbu_du-report.sh logs_directory [book_version] [date]\n" && exit
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
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
23# If this script is run manually, the book version may be unknown
24[ -z "$VERSION" ] && VERSION=unknown
25[ -z "$DATE" ] && DATE=$(date --iso-8601)
26
27# If there is iteration logs directories, copy the logs inside iteration-1
28# to the top level dir
29[ -d "$LOGSDIR"/build_1 ] && \
30 cp $LOGSDIR/build_1/* $LOGSDIR
31
32# Set the report file
33REPORT="$VERSION"-SBU_DU-"$DATE".report
34
35[ -f "$REPORT" ] && : >$REPORT
36
37# Dump generation time stamp and book version
38echo -e "\n`date`\n" > "$REPORT"
39echo -e "Book version is:\t$VERSION\n" >> "$REPORT"
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
48
49# Dump CPU and memory info
50echo -e "\n\n\t\tCPU type:\n" >> "$REPORT"
51lscpu >> "$REPORT"
52echo -e "\n\t\tMemory info:\n" >> "$REPORT"
53free >> "$REPORT"
54
55# Parse only that logs that have time data
56pushd ${LOGSDIR}
57BUILDLOGS="`grep -l "^Totalseconds:" * | sort -n`"
58
59# Match the first timed log to extract the SBU unit value from it
60FIRSTLOG=`grep -l "^Totalseconds:" * | sort -n | head -n1`
61BASELOG=`grep -l "^Totalseconds:" ???-binutils* | head -n1`
62echo -e "\nUsing ${BASELOG#*[[:digit:]]-} to obtain the SBU unit value."
63SBU_UNIT=`sed -n 's/^Totalseconds:\s\([[:digit:]]*\)$/\1/p' $BASELOG`
64popd
65# Get the -j value of the SBU
66if [ "$(sed -n '/REALSBU/s/.*\([yn]\).*/\1/p' "$REPORT")" = y ]; then
67 J_VALUE="1"
68else
69 J_VALUE=$(sed -n '/N_PARALLEL/s/.*<\([^>]*\).*/\1/p' "$REPORT")
70fi
71# if jhalfs.config does not exist, or OPTIMIZE is 0, then J_VALUE is
72# still empty. Assume 1 in that case
73echo -e "\nThe SBU unit value is equal to $SBU_UNIT seconds at -j${J_VALUE:=1}.\n"
74echo -e "\n\n$LINE\n\nThe SBU unit value is equal to $SBU_UNIT seconds at -j$J_VALUE.\n" >> "$REPORT"
75
76# Set the first value to 0 for grand totals calculation
77SBU2=0
78INSTALL2=0
79INSTALLMB2=0
80
81# Start the loop
82for log in $BUILDLOGS ; do
83
84# Strip the filename
85 PACKAGE="${log#*[[:digit:]]*-}"
86
87# Start SBU calculation
88# Build time
89 TIME=`sed -n 's/^Totalseconds:\s\([[:digit:]]*\)$/\1/p' ${LOGSDIR}/$log`
90 SECS=`perl -e 'print ('$TIME' % '60')';`
91 MINUTES=`perl -e 'printf "%.0f" , (('$TIME' - '$SECS') / '60')';`
92 SBU=`perl -e 'printf "%.1f" , ('$TIME' / '$SBU_UNIT')';`
93
94# Append SBU value to SBU2 for grand total
95 SBU2=`perl -e 'printf "%.1f" , ('$SBU2' + '$SBU')';`
96
97# Start disk usage calculation
98# Disk usage before unpacking the package
99 DU1=`grep "^KB: " ${LOGSDIR}/$log | head -n1 | cut -f1 | sed -e 's/KB: //'`
100 DU1MB=`perl -e 'printf "%.3f" , ('$DU1' / '1024')';`
101# Disk usage before deleting the source and build dirs
102 DU2=`grep "^KB: " ${LOGSDIR}/$log | tail -n1 | cut -f1 | sed -e 's/KB: //'`
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')';`
107
108# Append installed files disk usage to the previous entry,
109# except for the first parsed log
110 if [ "$log" != "$FIRSTLOG" ] ; then
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
114 # Append install values for grand total
115 INSTALL2=`perl -e 'printf "%.3f" , ('$INSTALL2' + '$INSTALL')';`
116 INSTALLMB2=`perl -e 'printf "%.3f" , ('$INSTALLMB2' + '$INSTALLMB')';`
117 fi
118
119# Set variables to calculate installed files disk usage
120 DU1PREV=$DU1
121 DU1MBPREV=$DU1MB
122
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
131
132done
133
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/../..
137DU1=`du -skx --exclude=jhalfs --exclude=lost+found --exclude var/lib $LOGSDIR/../.. | cut -f1`
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
146# Dump grand totals
147echo -e "\n$LINE\n\nTotal time required to build the system:\t\t$SBU2 SBU" >> $REPORT
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.