-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgftrace.sh
executable file
·69 lines (55 loc) · 2.13 KB
/
gftrace.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
69
#!/bin/bash
if [ "$#" -lt 1 ]; then
echo "usage: $0 <kernel_function> [<kernel_function> ...]"
echo "kernel_function - functions to trace (separated by spaces), all should be in #available_filter_functions list"
exit 1
fi
KFUNCS="${@:1}"
for KFUNC in $KFUNCS
do
# Check that kernel function is traceable
if ! cat /sys/kernel/debug/tracing/available_filter_functions \
| grep "\<$KFUNC\>" >/dev/null; then
echo "There is no traceable kfunc \"$KFUNC\" may be you mean:"
cat /sys/kernel/debug/tracing/available_filter_functions | grep $KFUNC
exit 1
fi
done
# Disable previous tracing
echo 0 > /sys/kernel/debug/tracing/tracing_on
echo nop > /sys/kernel/debug/tracing/current_tracer
echo 0 > /sys/kernel/debug/tracing/max_graph_depth
echo 0 > /sys/kernel/debug/tracing/events/enable
# Setup tracing all call graphs for a KFUNCS kernel functions
echo "$KFUNCS" > /sys/kernel/debug/tracing/set_graph_function
echo "Will graph trace:"
cat /sys/kernel/debug/tracing/set_graph_function
echo function_graph > /sys/kernel/debug/tracing/current_tracer
# Setup some useful tracing options:
echo funcgraph-tail > /sys/kernel/debug/tracing/trace_options 2>/dev/null
echo funcgraph-abstime > /sys/kernel/debug/tracing/trace_options
echo nofuncgraph-irqs > /sys/kernel/debug/tracing/trace_options
# Set max recursion to 5, use it to shorten too wide output
# echo 5 > /sys/kernel/debug/tracing/max_graph_depth
finish_trace() {
echo 0 > /sys/kernel/debug/tracing/tracing_on
cat /sys/kernel/debug/tracing/trace > trace
echo "hint: cat ./trace | less"
echo nop > /sys/kernel/debug/tracing/current_tracer
echo 0 > /sys/kernel/debug/tracing/max_graph_depth
if [ -f "/sys/kernel/debug/tracing/events/probe/enable" ]; then
echo 0 > /sys/kernel/debug/tracing/events/enable
fi
exit 0
}
trap 'finish_trace' SIGINT
# Enable perf probes, may be useful to see return values along with graph trace
if [ -f "/sys/kernel/debug/tracing/events/probe/enable" ]; then
# Enable probes
echo 1 > /sys/kernel/debug/tracing/events/probe/enable
fi
# Enable ftrace
echo 1 > /sys/kernel/debug/tracing/tracing_on
echo "Enter something (or ctrl+c) to stop tracing"
read
finish_trace