#!/bin/sh
# @(#) $Revision: 1.13 $
# @(#) RCS control in //prime.corp/usr/local/src/cmd/prime/src/report.sh
#
# report - generate a report of map1 processes
#
# usage:
#	report [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
if [ ! -x src/mapstat ]; then
    echo "$0: src/mapstat executable not found under $TOPDIR" 1>&2
    exit 3
fi
if [ ! -d set ]; then
    echo "$0: set is not a directory under $TOPDIR" 1>&2
    exit 4
fi
cd set

# get date dir
#
DATE="../stat/`date '+%d%m%y.%H%M%S'`"
if [ -d "$DATE" ]; then
    echo "$0: directory for $DATE already exists" 1>&2
    exit 5
fi
mkdir -p "$DATE"

# form mapstat
#
ls -1F . | grep / | grep -v '[A-Z]' | sed -e 's;/$;;' | 
    xargs ../src/mapstat > "$DATE/info.mapstat"

# form ps
#
ps -ef | egrep 'map0 |map1 |map1a |map2 ' | 
    egrep -v time | egrep -v egrep > "$DATE/info.ps"

# form tail
#
ls -1F . | grep / | grep -v '[A-Z]' | sed -e 's;/$;;' | while read setname; do
    echo -n "$setname =-=-= "
    tail -1 "$setname/$setname.ckpt"
done > "$DATE/info.tail"

# form wc
#
ls -1F . | grep / | grep -v '[A-Z]' | sed -e 's;/$;;' | while read setname; do
    (cd "$setname"; wc -l "$setname.ckpt")
done > "$DATE/info.wc"

# all done
#
exit 0
