-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsetup_etrace.sh
executable file
·69 lines (58 loc) · 1.69 KB
/
setup_etrace.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
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
print_usage () {
echo "Usage: $0 (-i ROOT_PID [...]|-r|-f)"
}
if [ "$#" -lt 1 ]; then
print_usage
exit 1
fi
if [ "$1" = "-f" ]; then
# set up ftrace
# After system restart the second chmod may actually not work,
# even if run as root. Experiments show that it is probably
# caused by lazy creation of tracefs, because poking this
# filesystem in some other way (i.e. ls) magically causes
# chmod to work again. So, do a dummy ls before second chmod.
chmod 755 /sys/kernel/debug
if [ "$?" -ne 0 ]; then exit "$?"; fi
ls /sys/kernel/debug/tracing 1>/dev/null 2>/dev/null
chmod 755 /sys/kernel/debug/tracing
chmod 755 /sys/kernel/debug/tracing/trace_pipe
chmod 755 -R /sys/kernel/debug/tracing/per_cpu/
if [ "$?" -ne 0 ]; then exit "$?"; fi
# set buffers size
if [ ! -z "${TRACING_BUFF_SIZE_KB}" ]; then
echo "${TRACING_BUFF_SIZE_KB}" > /sys/kernel/debug/tracing/buffer_size_kb
else
echo "262144" > /sys/kernel/debug/tracing/buffer_size_kb
fi
if [ "$?" -ne 0 ]; then
exit "$?"
fi
# Remove log headers
echo "nocontext-info" > /sys/kernel/debug/tracing/trace_options
# clear buffers
echo "dummy" > "/sys/kernel/debug/tracing/trace"
if [ "$?" -ne 0 ]; then
exit "$?"
fi
elif [ "$1" = "-i" ]; then
if [ "$#" -lt 2 ]; then
print_usage
exit 1
fi
# install module
SUPPORT_NS_PID=""
uname -r | grep WSL > /dev/null && SUPPORT_NS_PID="support_ns_pid=1"
if [ ! -z "${SUPPORT_NS_PID}" ]; then
echo SUPPORT_NS_PID=$SUPPORT_NS_PID
fi
/sbin/modprobe bas_tracer root_pid="$2" "$SUPPORT_NS_PID" "${@:3}"
exit "$?"
elif [ "$1" = "-r" ]; then
/sbin/rmmod bas_tracer
echo "1410" > /sys/kernel/debug/tracing/buffer_size_kb
exit "$?"
else
print_usage
fi