0#!/bin/bash
2# Creates profiling graphs as png in your current directory.
3#
4# You'll need:
5# - gprof2dot
6# - dot
9bin="$1"
10shift
11out="${bin}.callgrind"
13if [[ -z "$bin" || ! -x "$bin" ]]; then
14 echo "Usage: cprof <executable> [program args]"
15 exit 1
16fi
18valgrind --tool=callgrind \
19 --callgrind-out-file="$out" \
20 "$bin" "$@" \
21 || echo "valgrind non-zero. Continuing..."
23gprof2dot "$out" --format=callgrind -o out.dot || exit 1
24dot -Tpng out.dot -o graph.png || exit 1
26echo "done"