#!/bin/bash

# Hint:
# DARCS_P=/usr/local/bin/darcs ./profile-big-zoo.sh
# DARCS_P=/path/to/my/darcs ./profile-big-zoo.sh
if [ "${DARCS_P}" = "" ]; then
  DARCS_P=darcs
  TESTNAME=frompath
else
  DARCS_P_DIR=`dirname ${DARCS_P}`
  DARCS_P_DIR_DIR=`dirname ${DARCS_P_DIR}`
  DARCS_P_DIR_DIR=`basename ${DARCS_P_DIR_DIR}`
  DARCS_P_DIR_BASE=`basename ${DARCS_P_DIR}`
  TESTNAME=${DARCS_P_DIR_DIR}-${DARCS_P_DIR_BASE}
fi
if [ "${TIMESTAMP}" = "" ]; then
  TIMESTAMP=`date +%Y-%m-%d.%H%M.%S`
fi
PROF_DIR=`pwd`
#PROF_FLAGS="+RTS -prof -RTS"
LATEST_RESULTS=big_${TIMESTAMP}_${PREFIX}_${TESTNAME}

profile () {
  name=$1
  shift
  echo "=== $name ==="
  {
    time -p ${DARCS_P} $* -q ${PROF_FLAGS} > /dev/null
  } 2> ${PROF_DIR}/${name}.time
  if [ -e darcs_p.prof ]; then
    mv darcs_p.prof ${PROF_DIR}/${name}.prof
  fi
  echo "=== $name ===" >> ${PROF_DIR}/${LATEST_RESULTS}
  cat ${PROF_DIR}/${name}.time >> ${PROF_DIR}/${LATEST_RESULTS}
}

cd big-zoo

rm -rf ghc-hashed-2
profile get-complete get --no-cache --complete ghc-hashed ghc-hashed-2

cd ghc-hashed-2
profile check check
cd ..

rm -rf ghc-hashed-lazy
${DARCS_P} get --no-cache --lazy ghc-hashed ghc-hashed-lazy
rm -rf ghc-hashed-lazy/_darcs
cd ghc-hashed-lazy
profile init init
profile add-r-ghc add -r .
cd ..

rm -rf ghc-hashed-lazy
profile get-lazy get --no-cache --lazy ghc-hashed ghc-hashed-lazy

cd ghc-hashed-lazy

profile unpull-10 unpull -a --last=10
profile pull-10   pull --no-cache -a

rm -f _darcs/patches/unrevert
profile unpull-100 unpull -a --last=100
profile pull-100   pull --no-cache -a

rm -f _darcs/patches/unrevert
profile unpull-1000 unpull -a --last=1000
profile pull-1000   pull --no-cache -a

rm -f _darcs/patches/unrevert
profile unpull-1000-cache unpull -a --last=1000
profile pull-1000-cache   pull --no-cache -a

profile whatsnew-empty whatsnew
for i in `find compiler -name '*hs'`;\
do sed -e 's/id/ego/' $i > $i.2 ;\
   mv -f $i.2 $i;\
done
profile whatsnew-id-ego whatsnew
profile revert          revert -a
for i in `find compiler -name '*hs'`;\
do sed -e 's/id/ego/' $i > $i.2 ;\
   mv -f $i.2 $i;\
done
profile record          record -a -m foo -A me
profile unrecord        unrecord -a --last=1
profile record-l        record -l -a -m foo -A me
${DARCS_P} unpull --last=1 -a

profile annotate        annotate compiler/prelude/PrimOp.lhs +RTS -K100M -RTS
