-
Notifications
You must be signed in to change notification settings - Fork 0
/
logkernel.sh
executable file
·34 lines (34 loc) · 1.18 KB
/
logkernel.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
#!/bin/bash
usage() {
echo 'usage:
./logkernel.sh ./prog
outputfile: ./output.log'
}
recover() {
# not started yet
while [ `ps aux|grep -v grep|grep -wv logkernel|grep $1 -w|wc -l` -eq 0 ]; do
:
done
# detect finish
while [ `ps aux|grep -v grep|grep -wv logkernel -w|grep $1 -w|wc -l` -gt 0 ]; do
:
done
cat /sys/kernel/debug/tracing/trace > output.log
# Recover
echo nop > /sys/kernel/debug/tracing/current_tracer
echo > /sys/kernel/debug/tracing/set_ftrace_pid
echo 0 > /sys/kernel/debug/tracing/max_graph_depth
echo 1 > /sys/kernel/debug/tracing/options/funcgraph-irqs
}
[ `whoami|grep root|wc -l` -eq 0 ] && echo Must be root! && exit
[ "x$1" == "x-help" ] && usage && exit
[ "x$2" == "x-r" ] && recover $3 && exit
(`pwd`/logkernel.sh $1 -r $$ &)
echo 0 > /sys/kernel/debug/tracing/tracing_on
echo $$ > /sys/kernel/debug/tracing/set_ftrace_pid
echo 0 > /sys/kernel/debug/tracing/max_graph_depth
echo function_graph > /sys/kernel/debug/tracing/current_tracer
echo 0 > /sys/kernel/debug/tracing/options/funcgraph-irqs
echo 1 > /sys/kernel/debug/tracing/tracing_on
# Run task as current pid
exec $1