source: common/create-sbu_du-report.sh@ d5413a9

ablfs-more legacy trunk
Last change on this file since d5413a9 was e68c306, checked in by Pierre Labastie <pierre.labastie@…>, 3 years ago

Add the -j value to the sbu report

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