source: common/create-sbu_du-report.sh@ 7db3be7

experimental
Last change on this file since 7db3be7 was 9c9775f, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

Updated experimental branch to current trunk code.

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