#!/bin/sh
# @(#) $Revision: 1.8 $
# @(#) RCS control in //prime.corp/usr/local/src/cmd/prime/src/progress.sh
#
# progress - report the progress of twin candidate elimination
#
# usage:
#	progress [topdir]
#
#	optional top level directory to work from
#
# Copyright (C) 1997 Landon Curt Noll, all rights reserved.
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose is hereby granted, provided that
# the above copyright, this permission notice, and the disclaimer
# below appear in all of the following:
#
#         * supporting documentation
#         * source copies
#         * source works derived from this source
#
# THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
# EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
# USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
#
# Landon Curt Noll <chongo was here> /\oo/\
#
# chongo@{toad,sgi}.com		Share and Enjoy!

# parse args
#
TOPDIR=/usr/local/lib/map
if [ $# -eq 1 ]; then
    TOPDIR="$1"
fi
if [ ! -d "$TOPDIR" ]; then
    echo "$0: $TOPDIR is not a top level directory" 1>&2
    exit 1
fi
cd "$TOPDIR"
if [ ! -d stat ]; then
    echo "$0: stat directory not found under $TOPDIR" 1>&2
    exit 2
fi

# temp file setup
#
tmp=/var/tmp/.prog.$$
rm -f $tmp
if [ -f $tmp ]; then
    echo "$0: tmp file $tmp exists" 1>&2
    exit 1
fi
trap "rm -f $tmp; exit" 1 2 3 15

# obtain info
#
# The output will be of the form:
#
# 080995.070000 meg2e9 59
# 080995.130000 meg2e9 40
# ...
# 100995.070000 meg2e9 39
# 100995.130000 meg2e9 30
#
find stat -name '*.mapstat' -print | sort | xargs grep '\.or:' | 
    sed -e 's/8388608 bits.*,//' -e 's:stat/::' \
	-e 's/\/info.mapstat:/ /' -e 's/\.or://' | sort -k2 | 
    awk 'NR==1 {x=$2;} NR>1 {print $1,x-$2; x=$2;}'

# report the first 8 stats
#
head -8 $tmp
echo

# report last 8 stats
#
tail -8 $tmp
rm -f $tmp
exit 0
