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