1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#!/bin/bash
UFTRACE="../uftrace --libmcount-path=../libmcount"
UOPTS=
PROG="./bench"
DATA=bench.data
# setup cpufreq (on a cpu)
CPU=3
function msg() {
if [ "${VERBOSE}" != "1" ]; then
return
fi
echo $*
}
function help() {
echo "Usage: bench.sh [OPTION]"
echo " OPTION -c N Use CPU N during the benchmark. (default: 3)"
echo " -p PROG Use program PROG. (default: ./bench)"
echo " -u UOPT Use uftrace option UOPT. Please quote it."
echo " -v Show verbose messages."
echo " -h Show this help and exit."
exit 0
}
function set_cpufreq() {
NEWGOV=$1
CPUFREQ="/sys/devices/system/cpu/cpufreq/policy${CPU}/scaling_governor"
if [ ! -e ${CPUFREQ} ]; then
msg "Skip setting cpufreq since the file is not found: ${CPUFREQ}"
return
fi
if [ "${ORIG_GOV}" == "" ]; then
ORIG_GOV=$(cat ${CPUFREQ})
fi
CURGOV=$(cat ${CPUFREQ})
msg "Changing cpufreq governor: ${CURGOV} ==> ${NEWGOV} : ${CPUFREQ}"
sudo sh -c "echo ${NEWGOV} > ${CPUFREQ}"
}
# parse command line options
while getopts "c:p:u:vh" arg; do
case $arg in
c)
CPU=$OPTARG
;;
p)
PROG=$OPTARG
;;
u)
UOPTS=$OPTARG
;;
v)
VERBOSE=1
;;
h)
help
;;
esac
done
shift $((OPTIND - 1))
ARGS=$*
TARGET="${PROG} ${ARGS}"
TASKSET="taskset -c ${CPU}"
echo "# uftrace bench"
# this will set $ORIG_GOV
set_cpufreq "performance"
sleep 1
# do not use taskset (CPU affinity) when cpufreq is not available
if [ "${ORIG_GOV}" == "" ]; then
TASKSET=
fi
msg "running uftrace record ${UOPTS} with ${TARGET}"
${TASKSET} ${UFTRACE} record -d ${DATA} ${UOPTS} ${TARGET}
${UFTRACE} report -d ${DATA} -F 'foo' -F '^ba' -f self-avg,self-min
set_cpufreq "${ORIG_GOV}"
rm -rf ${DATA}{,.old}
|