function verify_deps() {
[[ -z "$1" ]] && return
if ! which "$1" >& /dev/null; then
echo "error: install \"$1\" and include it in your \$PATH"
exit 1
fi
}
verify_deps strace
verify_deps sed
verify_deps sort
verify_deps uniq
opt_freq=0
opt_args=0
opt_out="/proc/self/fd/1"
while getopts "afo:h" opt; do
case $opt in
a)
opt_args=1
;;
f)
opt_freq=1
;;
o)
opt_out="$OPTARG"
;;
h|*)
echo "usage $0 [-f] [-a] [-o <file>] <command> [<args>]"
exit 1
esac
done
shift $(expr $OPTIND - 1)
raw=$(mktemp -t strace-raw_XXXXXX)
out="$raw-out"
strace -o $raw -- $*
if [[ $opt_args -eq 0 ]]; then
if [[ $opt_freq -eq 0 ]]; then
cat $raw | sed -e 's/(.*//' | sort -u > $out
else
cat $raw | sed -e 's/(.*//' | sort | uniq -c | sort -nr > $out
fi
else
if [[ $opt_freq -eq 0 ]]; then
cat $raw | sed -e 's/)[ \t]*=.*$/)/' \
| sed -e 's/".*,/"...",/g;s/\/\*.*\*\//.../g' \
| sed -e 's/0x[a-f0-9]\+/.../g' \
| sort -u > $out
else
cat $raw | sed -e 's/)[ \t]*=.*$/)/' \
| sed -e 's/".*,/"...",/g;s/\/\*.*\*\//.../g' \
| sed -e 's/0x[a-f0-9]\+/.../g' \
| sort | uniq -c | sort -nr > $out
fi
fi
echo "============================================================" > $opt_out
echo "Syscall Report (\"$*\")" >> $opt_out
[[ $opt_freq -eq 1 ]] && echo " freq syscall" >> $opt_out
echo "============================================================" >> $opt_out
cat $out >> $opt_out
rm -f $raw $out
exit 0