#!/bin/bash

if [ -z "$1" ]; then
  echo "Usage: $0 command"
  echo "See also: http://google-perftools.googlecode.com/svn/trunk/doc/cpuprofile.html"
  echo "Ubuntu package: google-perftools"
  exit 1
fi

tmp=prof.$$

CPUPROFILE_FREQUENCY=1000 \
CPUPROFILE=$tmp \
LD_PRELOAD=/usr/lib/libprofiler.so.0 \
	"$@"

google-pprof --callgrind `which $1` $tmp > prof.out.$$
kcachegrind prof.out.$$
