#!/bin/bash
# provide non-paralleled build statistics

logs=$TMP/bt
pushd .
rm -rf $logs
mkdir $logs

cd /tasks &&
for t in [0-9]* archive/done/_*/[0-9]*; do
	read repo < /tasks/$t/task/repo &&
	[ "$repo" = "sisyphus_e2k" ] || continue
	cd /tasks/$t/build 2>/dev/null &&
	for i in [0-9]*; do
		[ -f $i/pkgname ] || continue
		read name < $i/pkgname 2>/dev/null &&
		case "$name" in
		dummy-*)
			continue;;
		esac &&
		read usr sys cpu < <(tail -qn2 $i/e2k*/log | sed -rn 's,^([0-9]+)\...user ([0-9]+)\...system .* ([0-9]+)%CPU.*$,\1 \2 \3,p') &&
		case "$cpu" in
		[0-9][0-9])
			echo "$(($usr+$sys)) $cpu%" >> $logs/$name
		esac
	done
done

popd
