aboutsummaryrefslogtreecommitdiff
path: root/fw/tools/profile.sh
blob: b209a14cdb9bb4e4d6ca61e771e58826f9c6b780 (plain)
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
#!/bin/sh
NLOOPS=1000
SLEEP=0.1

[ $# -lt 1 ] && echo "ERROR: Not enough arguments" && exit 2
elffile="$1"

trap "exit" SIGINT

logfile=$(mktemp)

arm-none-eabi-gdb -x profile.gdb "$elffile" > "$logfile" 2>/dev/null&
gdbpid=$!
trap "kill -TERM $gdbpid; rm $logfile" EXIT
echo "Gathering..."
for i in $(seq 1 $NLOOPS); do
    echo "$i/$NLOOPS"
    kill -INT $gdbpid
    sleep $SLEEP
done
kill -TERM $gdbpid
trap "rm '$logfile'" EXIT

egrep -o '\w+ \(.*\) at .*' "$logfile" |cut -d' ' -f1|sort|uniq -c|sort -n
echo 'Total:' $(egrep -c '\w+ \(.*\) at .*' "$logfile")