#!/bin/sh
usage () {
    echo  Usage:
    echo "    $0 PROGRAM args..."
    echo  runs PROGRAM under the profil PCT statistical profiling system.
}
if [ $# -lt 1 ]; then usage; exit 1; fi

OUT=/tmp/pct/ct.$$
echo "PCT output sent to $OUT"

LD_PRELOAD=${LIB_SO:-/usr/local/lib}/libprofil.so
export LD_PRELOAD

PCT="vo$OUT"
export PCT
"$@"
unset PCT

# XXX just pass through a format style to the 'pct' script?
pct-pr -t addr2line,-e,@ `find $OUT -type f` |
    pct-sort 1 |
    pct-fold   |
    sort -n    |
    pct-%

