cookutils rev 1051

cook: add cache/timestats and .bdeps
author Aleksej Bobylev <al.bobylev@gmail.com>
date Wed Apr 25 13:19:48 2018 +0300 (2018-04-25)
parents 6fee065d94c8
children 847d0e99c922
files cook doc/timestats.txt
line diff
     1.1 --- a/cook	Fri Apr 20 13:55:27 2018 +0300
     1.2 +++ b/cook	Wed Apr 25 13:19:48 2018 +0300
     1.3 @@ -11,6 +11,7 @@
     1.4  
     1.5  VERSION="3.2"
     1.6  export output=raw
     1.7 +prev_ts="/home/slitaz/cache/prev_ts"; touch $prev_ts
     1.8  
     1.9  
    1.10  # Internationalization.
    1.11 @@ -581,6 +582,50 @@
    1.12  }
    1.13  
    1.14  
    1.15 +# Store timestamps, log jobs length
    1.16 +
    1.17 +timestamp() {
    1.18 +	local ts_file="$WOK/$pkg/.ts"
    1.19 +	local curr_ts=$(date '+%s')
    1.20 +	case $1 in
    1.21 +		init)
    1.22 +			rm $ts_file 2>/dev/null
    1.23 +			echo $curr_ts > $prev_ts
    1.24 +			;;
    1.25 +		job*)
    1.26 +			# calculate time from the last timestamp
    1.27 +			echo "$1='$(( $curr_ts - $(cat $prev_ts) ))'" >> $ts_file
    1.28 +			echo $curr_ts > $prev_ts
    1.29 +			;;
    1.30 +		sets)
    1.31 +			echo "sets='$2'" >> $ts_file
    1.32 +			;;
    1.33 +	esac
    1.34 +}
    1.35 +
    1.36 +
    1.37 +# Store time statsistics to the cache
    1.38 +
    1.39 +store_timestats() {
    1.40 +	# see doc/timestats.txt for file format
    1.41 +	temp=$(mktemp)
    1.42 +	{
    1.43 +		for i in $(seq 1 30); do echo "job$i=0"; done
    1.44 +		cat $WOK/$pkg/.ts
    1.45 +		echo -n 'total=$(( 0'
    1.46 +		for i in $(seq 1 30); do echo -n " + job$i"; done
    1.47 +		echo ' ))'
    1.48 +	} > $temp
    1.49 +	. $temp
    1.50 +	{
    1.51 +		echo -n "$pkg	$sets	"
    1.52 +		for i in $(seq 1 30); do echo -n "$((job$i))	"; done
    1.53 +		echo "$total"
    1.54 +	} >> /home/slitaz/cache/timestats
    1.55 +	rm $temp $WOK/$pkg/.ts # clean
    1.56 +}
    1.57 +
    1.58 +
    1.59  # The main cook function.
    1.60  
    1.61  cookit() {
    1.62 @@ -591,6 +636,7 @@
    1.63  
    1.64  	title 'Cook: %s' "$PACKAGE $VERSION"
    1.65  	set_paths
    1.66 +	timestamp init # the very start
    1.67  
    1.68  	# Handle cross-tools.
    1.69  	[ "$BUILD_SYSTEM" != "$HOST_SYSTEM" ] &&
    1.70 @@ -647,6 +693,8 @@
    1.71  	export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C \
    1.72  	LDFLAGS
    1.73  
    1.74 +	timestamp job1 # pre-checks
    1.75 +
    1.76  	# BUILD_DEPENDS may vary depending on the ARCH
    1.77  	case "$ARCH" in
    1.78  		arm*)   [ -n "$BUILD_DEPENDS_arm" ]    && BUILD_DEPENDS=$BUILD_DEPENDS_arm    ;;
    1.79 @@ -735,6 +783,8 @@
    1.80  
    1.81  	update_installed_cook_diff
    1.82  
    1.83 +	timestamp job2 # installing bdeps
    1.84 +
    1.85  	# Get source tarball and make sure we have source dir named:
    1.86  	# $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
    1.87  	# tarball if it exists.
    1.88 @@ -785,6 +835,8 @@
    1.89  		arm*) cross libhack ;;
    1.90  	esac
    1.91  
    1.92 +	timestamp job3 # get/unpack src tarball
    1.93 +
    1.94  	# Compiling all the sets
    1.95  	if grep -q ^compile_rules $receipt; then
    1.96  		_ 'Executing: %s' 'compile_rules'
    1.97 @@ -793,6 +845,8 @@
    1.98  		[ -d "$src" ] && cd $src
    1.99  		patchit
   1.100  
   1.101 +		timestamp job4 # patching
   1.102 +
   1.103  		# Get set names from $SPLIT variable, format ex. 'pkg1 pkg2:set1 pkg3:set2'
   1.104  		SETS=$(echo $SPLIT \
   1.105  			| awk '
   1.106 @@ -808,6 +862,10 @@
   1.107  			cp -a $src $src-$set
   1.108  		done
   1.109  
   1.110 +		timestamp job5 # preparing sets
   1.111 +		timestamp sets "$SETS"
   1.112 +
   1.113 +		job_counter='6'
   1.114  		for SET in '' $SETS; do
   1.115  			# Switch to the specified source set
   1.116  			set_paths
   1.117 @@ -839,19 +897,26 @@
   1.118  
   1.119  			copy_generic_stuff
   1.120  
   1.121 +			timestamp job$job_counter # compiling (set '$SET')
   1.122 +
   1.123  			# Actions to do after compiling the package
   1.124  			# Skip all for split packages (already done in main package)
   1.125  			if [ -z "$WANTED" ]; then
   1.126  				footer
   1.127  				export COOKOPTS ARCH install
   1.128  				@@PREFIX@@/libexec/cookutils/compressor install
   1.129 +				timestamp job$(($job_counter + 1)) # compressing (set '$SET')
   1.130  			fi
   1.131 +
   1.132 +			job_counter=$(($job_counter + 2))
   1.133  		done
   1.134  	else
   1.135  		mkdir -p $install	# allow receipts without `compile_rules()`
   1.136  	fi
   1.137  	footer
   1.138  
   1.139 +	timestamp job # reset counter
   1.140 +
   1.141  	# Execute testsuite.
   1.142  	if grep -q ^testsuite $receipt; then
   1.143  		title 'Running testsuite'
   1.144 @@ -859,6 +924,8 @@
   1.145  		footer
   1.146  	fi
   1.147  
   1.148 +	timestamp job26 # test suite
   1.149 +
   1.150  	update_installed_cook_diff force
   1.151  }
   1.152  
   1.153 @@ -2099,7 +2166,9 @@
   1.154  
   1.155  		# Remove build dependencies both when `cookit` done or fail
   1.156  		remove_deps | tee -a $LOGS/$pkg.log
   1.157 +		timestamp job27 # removing bdeps
   1.158  		cookit_quality
   1.159 +		timestamp job28 # checking quality
   1.160  
   1.161  		# Log and stop if `cookit` fails
   1.162  		if [ $rq -eq 1 ]; then
   1.163 @@ -2111,6 +2180,7 @@
   1.164  
   1.165  		# Proceed only if `cookit` return code is zero-OK
   1.166  		packall 2>&1 | loglimit 5 >> $LOGS/$pkg.log
   1.167 +		timestamp job29 # packing
   1.168  
   1.169  		clean_log
   1.170  
   1.171 @@ -2140,6 +2210,15 @@
   1.172  		# Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
   1.173  		# If you want automation, use the Cooker Build Bot.
   1.174  		rm -f $command
   1.175 +		timestamp job30 # misc. final operations
   1.176 +		store_timestats
   1.177 +
   1.178 +		sed -n '/^Build dependencies to remove:/,/^$/p' $LOGS/$pkg.log \
   1.179 +		| sed '/^Build/d; s|Removing: ||' \
   1.180 +		| tr ' ' '\n' \
   1.181 +		| sed '/^$/d' \
   1.182 +		> $WOK/$pkg/.bdeps
   1.183 +
   1.184  		;;
   1.185  esac
   1.186  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/doc/timestats.txt	Wed Apr 25 13:19:48 2018 +0300
     2.3 @@ -0,0 +1,20 @@
     2.4 +File /home/slitaz/cache/timestats is in CSV format with the TAB delimiter.
     2.5 +
     2.6 +Fields description:
     2.7 +
     2.8 +1: receipt name
     2.9 +2: used SETS: empty or " set1", " set1 set2" and so on
    2.10 +3-33: time in seconds spent on the following operations
    2.11 +3: pre-checks
    2.12 +4: installing bdeps
    2.13 +5: get/unpack src tarball
    2.14 +6: patching
    2.15 +7: preparing sets
    2.16 +8, 10, 12, 14, 16, 18, 20, 22, 24, 26: compiling (default SET, then each other)
    2.17 +9, 11, 13, 15, 17, 19, 21, 23, 25, 27: compressing (too)
    2.18 +28: test suite
    2.19 +29: removing bdeps
    2.20 +30: checking quality
    2.21 +31: packing
    2.22 +32: misc. final operations
    2.23 +33: grand total