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

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

Remove $Id$ comments, they are useless with git

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