1
2clear_trace() { # reset trace output
3    echo > trace
4}
5
6disable_tracing() { # stop trace recording
7    echo 0 > tracing_on
8}
9
10enable_tracing() { # start trace recording
11    echo 1 > tracing_on
12}
13
14reset_tracer() { # reset the current tracer
15    echo nop > current_tracer
16}
17
18reset_trigger_file() {
19    # remove action triggers first
20    grep -H ':on[^:]*(' $@ |
21    while read line; do
22        cmd=`echo $line | cut -f2- -d: | cut -f1 -d"["`
23	file=`echo $line | cut -f1 -d:`
24	echo "!$cmd" >> $file
25    done
26    grep -Hv ^# $@ |
27    while read line; do
28        cmd=`echo $line | cut -f2- -d: | cut -f1 -d"["`
29	file=`echo $line | cut -f1 -d:`
30	echo "!$cmd" > $file
31    done
32}
33
34reset_trigger() { # reset all current setting triggers
35    if [ -d events/synthetic ]; then
36        reset_trigger_file events/synthetic/*/trigger
37    fi
38    reset_trigger_file events/*/*/trigger
39}
40
41reset_events_filter() { # reset all current setting filters
42    grep -v ^none events/*/*/filter |
43    while read line; do
44	echo 0 > `echo $line | cut -f1 -d:`
45    done
46}
47
48reset_ftrace_filter() { # reset all triggers in set_ftrace_filter
49    echo > set_ftrace_filter
50    grep -v '^#' set_ftrace_filter | while read t; do
51	tr=`echo $t | cut -d: -f2`
52	if [ "$tr" = "" ]; then
53	    continue
54	fi
55	if ! grep -q "$t" set_ftrace_filter; then
56		continue;
57	fi
58	name=`echo $t | cut -d: -f1 | cut -d' ' -f1`
59	if [ $tr = "enable_event" -o $tr = "disable_event" ]; then
60	    tr=`echo $t | cut -d: -f2-4`
61	    limit=`echo $t | cut -d: -f5`
62	else
63	    tr=`echo $t | cut -d: -f2`
64	    limit=`echo $t | cut -d: -f3`
65	fi
66	if [ "$limit" != "unlimited" ]; then
67	    tr="$tr:$limit"
68	fi
69	echo "!$name:$tr" > set_ftrace_filter
70    done
71}
72
73disable_events() {
74    echo 0 > events/enable
75}
76
77clear_synthetic_events() { # reset all current synthetic events
78    grep -v ^# synthetic_events |
79    while read line; do
80        echo "!$line" >> synthetic_events
81    done
82}
83
84initialize_ftrace() { # Reset ftrace to initial-state
85# As the initial state, ftrace will be set to nop tracer,
86# no events, no triggers, no filters, no function filters,
87# no probes, and tracing on.
88    disable_tracing
89    reset_tracer
90    reset_trigger
91    reset_events_filter
92    reset_ftrace_filter
93    disable_events
94    echo > set_event_pid	# event tracer is always on
95    echo > set_ftrace_pid
96    [ -f set_ftrace_filter ] && echo | tee set_ftrace_*
97    [ -f set_graph_function ] && echo | tee set_graph_*
98    [ -f stack_trace_filter ] && echo > stack_trace_filter
99    [ -f kprobe_events ] && echo > kprobe_events
100    [ -f uprobe_events ] && echo > uprobe_events
101    [ -f synthetic_events ] && echo > synthetic_events
102    [ -f snapshot ] && echo 0 > snapshot
103    clear_trace
104    enable_tracing
105}
106
107LOCALHOST=127.0.0.1
108
109yield() {
110    ping $LOCALHOST -c 1 || sleep .001 || usleep 1 || sleep 1
111}
112