Skip to content

Commit f06eec4

Browse files
rjingarrostedt
authored andcommitted
selftests: ftrace: Add inter-event hist triggers testcases
This adds inter-event hist triggers testcases which covers following: - create/remove synthetic event - disable histogram for synthetic event - extended error support - field variable support - histogram variables - histogram trigger onmatch action - histogram trigger onmax action - histogram trigger onmatch-onmax action - simple expression support - combined histogram Here is the test result. === Ftrace unit tests === [1] event trigger - test extended error support [PASS] [2] event trigger - test field variable support [PASS] [3] event trigger - test inter-event combined histogram trigger [PASS] [4] event trigger - test inter-event histogram trigger onmatch action [PASS] [5] event trigger - test inter-event histogram trigger onmatch-onmax action [PASS] [6] event trigger - test inter-event histogram trigger onmax action [PASS] [7] event trigger - test synthetic event create remove [PASS] Link: http://lkml.kernel.org/r/e07ef1e72f7bf0f84dc87c9b736d6dc91b4b0b49.1516069914.git.tom.zanussi@linux.intel.com Signed-off-by: Rajvi Jingar <[email protected]> Signed-off-by: Tom Zanussi <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 89e270c commit f06eec4

8 files changed

+360
-0
lines changed

tools/testing/selftests/ftrace/test.d/functions

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ disable_events() {
5959
echo 0 > events/enable
6060
}
6161

62+
clear_synthetic_events() { # reset all current synthetic events
63+
grep -v ^# synthetic_events |
64+
while read line; do
65+
echo "!$line" >> synthetic_events
66+
done
67+
}
68+
6269
initialize_ftrace() { # Reset ftrace to initial-state
6370
# As the initial state, ftrace will be set to nop tracer,
6471
# no events, no triggers, no filters, no function filters,
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/sh
2+
# description: event trigger - test extended error support
3+
4+
5+
do_reset() {
6+
reset_trigger
7+
echo > set_event
8+
clear_trace
9+
}
10+
11+
fail() { #msg
12+
do_reset
13+
echo $1
14+
exit_fail
15+
}
16+
17+
if [ ! -f set_event ]; then
18+
echo "event tracing is not supported"
19+
exit_unsupported
20+
fi
21+
22+
if [ ! -f synthetic_events ]; then
23+
echo "synthetic event is not supported"
24+
exit_unsupported
25+
fi
26+
27+
reset_tracer
28+
do_reset
29+
30+
echo "Test extended error support"
31+
echo 'hist:keys=pid:ts0=common_timestamp.usecs if comm=="ping"' > events/sched/sched_wakeup/trigger
32+
echo 'hist:keys=pid:ts0=common_timestamp.usecs if comm=="ping"' >> events/sched/sched_wakeup/trigger &>/dev/null
33+
if ! grep -q "ERROR:" events/sched/sched_wakeup/hist; then
34+
fail "Failed to generate extended error in histogram"
35+
fi
36+
37+
do_reset
38+
39+
exit 0
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/sh
2+
# description: event trigger - test field variable support
3+
4+
do_reset() {
5+
reset_trigger
6+
echo > set_event
7+
clear_trace
8+
}
9+
10+
fail() { #msg
11+
do_reset
12+
echo $1
13+
exit_fail
14+
}
15+
16+
if [ ! -f set_event ]; then
17+
echo "event tracing is not supported"
18+
exit_unsupported
19+
fi
20+
21+
if [ ! -f synthetic_events ]; then
22+
echo "synthetic event is not supported"
23+
exit_unsupported
24+
fi
25+
26+
clear_synthetic_events
27+
reset_tracer
28+
do_reset
29+
30+
echo "Test field variable support"
31+
32+
echo 'wakeup_latency u64 lat; pid_t pid; int prio; char comm[16]' > synthetic_events
33+
echo 'hist:keys=comm:ts0=common_timestamp.usecs if comm=="ping"' > events/sched/sched_waking/trigger
34+
echo 'hist:keys=next_comm:wakeup_lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).wakeup_latency($wakeup_lat,next_pid,sched.sched_waking.prio,next_comm) if next_comm=="ping"' > events/sched/sched_switch/trigger
35+
echo 'hist:keys=pid,prio,comm:vals=lat:sort=pid,prio' > events/synthetic/wakeup_latency/trigger
36+
37+
ping localhost -c 3
38+
if ! grep -q "ping" events/synthetic/wakeup_latency/hist; then
39+
fail "Failed to create inter-event histogram"
40+
fi
41+
42+
if ! grep -q "synthetic_prio=prio" events/sched/sched_waking/hist; then
43+
fail "Failed to create histogram with field variable"
44+
fi
45+
46+
echo '!hist:keys=next_comm:wakeup_lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).wakeup_latency($wakeup_lat,next_pid,sched.sched_waking.prio,next_comm) if next_comm=="ping"' >> events/sched/sched_switch/trigger
47+
48+
if grep -q "synthetic_prio=prio" events/sched/sched_waking/hist; then
49+
fail "Failed to remove histogram with field variable"
50+
fi
51+
52+
do_reset
53+
54+
exit 0
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/sh
2+
# description: event trigger - test inter-event combined histogram trigger
3+
4+
do_reset() {
5+
reset_trigger
6+
echo > set_event
7+
clear_trace
8+
}
9+
10+
fail() { #msg
11+
do_reset
12+
echo $1
13+
exit_fail
14+
}
15+
16+
if [ ! -f set_event ]; then
17+
echo "event tracing is not supported"
18+
exit_unsupported
19+
fi
20+
21+
if [ ! -f synthetic_events ]; then
22+
echo "synthetic event is not supported"
23+
exit_unsupported
24+
fi
25+
26+
reset_tracer
27+
do_reset
28+
clear_synthetic_events
29+
30+
echo "Test create synthetic event"
31+
32+
echo 'waking_latency u64 lat pid_t pid' > synthetic_events
33+
if [ ! -d events/synthetic/waking_latency ]; then
34+
fail "Failed to create waking_latency synthetic event"
35+
fi
36+
37+
echo "Test combined histogram"
38+
39+
echo 'hist:keys=pid:ts0=common_timestamp.usecs if comm=="ping"' > events/sched/sched_waking/trigger
40+
echo 'hist:keys=pid:waking_lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).waking_latency($waking_lat,pid) if comm=="ping"' > events/sched/sched_wakeup/trigger
41+
echo 'hist:keys=pid,lat:sort=pid,lat' > events/synthetic/waking_latency/trigger
42+
43+
echo 'wakeup_latency u64 lat pid_t pid' >> synthetic_events
44+
echo 'hist:keys=pid:ts1=common_timestamp.usecs if comm=="ping"' >> events/sched/sched_wakeup/trigger
45+
echo 'hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts1:onmatch(sched.sched_wakeup).wakeup_latency($wakeup_lat,next_pid) if next_comm=="ping"' > events/sched/sched_switch/trigger
46+
47+
echo 'waking+wakeup_latency u64 lat; pid_t pid' >> synthetic_events
48+
echo 'hist:keys=pid,lat:sort=pid,lat:ww_lat=$waking_lat+$wakeup_lat:onmatch(synthetic.wakeup_latency).waking+wakeup_latency($ww_lat,pid)' >> events/synthetic/wakeup_latency/trigger
49+
echo 'hist:keys=pid,lat:sort=pid,lat' >> events/synthetic/waking+wakeup_latency/trigger
50+
51+
ping localhost -c 3
52+
if ! grep -q "pid:" events/synthetic/waking+wakeup_latency/hist; then
53+
fail "Failed to create combined histogram"
54+
fi
55+
56+
do_reset
57+
58+
exit 0
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/sh
2+
# description: event trigger - test inter-event histogram trigger onmatch action
3+
4+
do_reset() {
5+
reset_trigger
6+
echo > set_event
7+
clear_trace
8+
}
9+
10+
fail() { #msg
11+
do_reset
12+
echo $1
13+
exit_fail
14+
}
15+
16+
if [ ! -f set_event ]; then
17+
echo "event tracing is not supported"
18+
exit_unsupported
19+
fi
20+
21+
if [ ! -f synthetic_events ]; then
22+
echo "synthetic event is not supported"
23+
exit_unsupported
24+
fi
25+
26+
clear_synthetic_events
27+
reset_tracer
28+
do_reset
29+
30+
echo "Test create synthetic event"
31+
32+
echo 'wakeup_latency u64 lat pid_t pid char comm[16]' > synthetic_events
33+
if [ ! -d events/synthetic/wakeup_latency ]; then
34+
fail "Failed to create wakeup_latency synthetic event"
35+
fi
36+
37+
echo "Test create histogram for synthetic event"
38+
echo "Test histogram variables,simple expression support and onmatch action"
39+
40+
echo 'hist:keys=pid:ts0=common_timestamp.usecs if comm=="ping"' > events/sched/sched_wakeup/trigger
41+
echo 'hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_wakeup).wakeup_latency($wakeup_lat,next_pid,next_comm) if next_comm=="ping"' > events/sched/sched_switch/trigger
42+
echo 'hist:keys=comm,pid,lat:wakeup_lat=lat:sort=lat' > events/synthetic/wakeup_latency/trigger
43+
ping localhost -c 5
44+
if ! grep -q "ping" events/synthetic/wakeup_latency/hist; then
45+
fail "Failed to create onmatch action inter-event histogram"
46+
fi
47+
48+
do_reset
49+
50+
exit 0
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/sh
2+
# description: event trigger - test inter-event histogram trigger onmatch-onmax action
3+
4+
do_reset() {
5+
reset_trigger
6+
echo > set_event
7+
clear_trace
8+
}
9+
10+
fail() { #msg
11+
do_reset
12+
echo $1
13+
exit_fail
14+
}
15+
16+
if [ ! -f set_event ]; then
17+
echo "event tracing is not supported"
18+
exit_unsupported
19+
fi
20+
21+
if [ ! -f synthetic_events ]; then
22+
echo "synthetic event is not supported"
23+
exit_unsupported
24+
fi
25+
26+
clear_synthetic_events
27+
reset_tracer
28+
do_reset
29+
30+
echo "Test create synthetic event"
31+
32+
echo 'wakeup_latency u64 lat pid_t pid char comm[16]' > synthetic_events
33+
if [ ! -d events/synthetic/wakeup_latency ]; then
34+
fail "Failed to create wakeup_latency synthetic event"
35+
fi
36+
37+
echo "Test create histogram for synthetic event"
38+
echo "Test histogram variables,simple expression support and onmatch-onmax action"
39+
40+
echo 'hist:keys=pid:ts0=common_timestamp.usecs if comm=="ping"' > events/sched/sched_wakeup/trigger
41+
echo 'hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_wakeup).wakeup_latency($wakeup_lat,next_pid,next_comm):onmax($wakeup_lat).save(next_comm,prev_pid,prev_prio,prev_comm) if next_comm=="ping"' >> events/sched/sched_switch/trigger
42+
echo 'hist:keys=comm,pid,lat:wakeup_lat=lat:sort=lat' > events/synthetic/wakeup_latency/trigger
43+
ping localhost -c 5
44+
if [ ! grep -q "ping" events/synthetic/wakeup_latency/hist -o ! grep -q "max:" events/sched/sched_switch/hist]; then
45+
fail "Failed to create onmatch-onmax action inter-event histogram"
46+
fi
47+
48+
do_reset
49+
50+
exit 0
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/sh
2+
# description: event trigger - test inter-event histogram trigger onmax action
3+
4+
do_reset() {
5+
reset_trigger
6+
echo > set_event
7+
clear_trace
8+
}
9+
10+
fail() { #msg
11+
do_reset
12+
echo $1
13+
exit_fail
14+
}
15+
16+
if [ ! -f set_event ]; then
17+
echo "event tracing is not supported"
18+
exit_unsupported
19+
fi
20+
21+
if [ ! -f synthetic_events ]; then
22+
echo "synthetic event is not supported"
23+
exit_unsupported
24+
fi
25+
26+
clear_synthetic_events
27+
reset_tracer
28+
do_reset
29+
30+
echo "Test create synthetic event"
31+
32+
echo 'wakeup_latency u64 lat pid_t pid char comm[16]' > synthetic_events
33+
if [ ! -d events/synthetic/wakeup_latency ]; then
34+
fail "Failed to create wakeup_latency synthetic event"
35+
fi
36+
37+
echo "Test onmax action"
38+
39+
echo 'hist:keys=pid:ts0=common_timestamp.usecs if comm=="ping"' >> events/sched/sched_waking/trigger
40+
echo 'hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0:onmax($wakeup_lat).save(next_comm,prev_pid,prev_prio,prev_comm) if next_comm=="ping"' >> events/sched/sched_switch/trigger
41+
ping localhost -c 3
42+
if ! grep -q "max:" events/sched/sched_switch/hist; then
43+
fail "Failed to create onmax action inter-event histogram"
44+
fi
45+
46+
do_reset
47+
48+
exit 0
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/sh
2+
# description: event trigger - test synthetic event create remove
3+
do_reset() {
4+
reset_trigger
5+
echo > set_event
6+
clear_trace
7+
}
8+
9+
fail() { #msg
10+
do_reset
11+
echo $1
12+
exit_fail
13+
}
14+
15+
if [ ! -f set_event ]; then
16+
echo "event tracing is not supported"
17+
exit_unsupported
18+
fi
19+
20+
if [ ! -f synthetic_events ]; then
21+
echo "synthetic event is not supported"
22+
exit_unsupported
23+
fi
24+
25+
clear_synthetic_events
26+
reset_tracer
27+
do_reset
28+
29+
echo "Test create synthetic event"
30+
31+
echo 'wakeup_latency u64 lat pid_t pid char comm[16]' > synthetic_events
32+
if [ ! -d events/synthetic/wakeup_latency ]; then
33+
fail "Failed to create wakeup_latency synthetic event"
34+
fi
35+
36+
reset_trigger
37+
38+
echo "Test create synthetic event with an error"
39+
echo 'wakeup_latency u64 lat pid_t pid char' > synthetic_events > /dev/null
40+
if [ -d events/synthetic/wakeup_latency ]; then
41+
fail "Created wakeup_latency synthetic event with an invalid format"
42+
fi
43+
44+
reset_trigger
45+
46+
echo "Test remove synthetic event"
47+
echo '!wakeup_latency u64 lat pid_t pid char comm[16]' > synthetic_events
48+
if [ -d events/synthetic/wakeup_latency ]; then
49+
fail "Failed to delete wakeup_latency synthetic event"
50+
fi
51+
52+
do_reset
53+
54+
exit 0

0 commit comments

Comments
 (0)