-
Notifications
You must be signed in to change notification settings - Fork 0
/
qemu-prof.sh
executable file
·56 lines (44 loc) · 1010 Bytes
/
qemu-prof.sh
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
#!/bin/bash
set -e
ARCH="$1"
INTERVAL="$2"
CMDLINE="$3"
KERNEL="$4"
if [ -z "$ARCH" ]; then
printf "Usage: $0 [QEMU architecture] [sample interval in seconds] [QEMU cmdline] [kernel ELF file]\n"
exit 1
fi
if [ -z "$INTERVAL" ]; then
INTERVAL=1
fi
SOCKET="$(mktemp)"
OUTFILE="$(mktemp)"
SUBSHELL="$(mktemp)"
trap "rm -f '$SOCKET' '$OUTFILE' '$SUBSHELL'" EXIT INT TERM HUP
(
echo $BASHPID >"$SUBSHELL"
while true; do
echo "info registers" >>"$SOCKET"
sleep $INTERVAL
done
) &
tail -f "$SOCKET" | qemu-system-"$ARCH" $CMDLINE -monitor stdio \
| grep -o '[RE]IP=[0-9a-f]*' \
| sed 's/[RE]IP=//g' \
| sort | uniq -c | sort -nr >"$OUTFILE"
kill $(cat "$SUBSHELL")
ISLINENUM=1
for p in $(cat "$OUTFILE"); do
if [ $ISLINENUM = 1 ]; then
ISLINENUM=0
echo -ne "$p\t"
continue
fi
if ! [ -z "$KERNEL" ]; then
addr2line -e "$KERNEL" "0x$p" | tr -d '\n'
echo " (0x$p)"
else
echo "(0x$p)"
fi
ISLINENUM=1
done