1#!/bin/sh
2# description: event trigger - test inter-event histogram trigger onmatch-onmax action
3
4do_reset() {
5    reset_trigger
6    echo > set_event
7    clear_trace
8}
9
10fail() { #msg
11    do_reset
12    echo $1
13    exit_fail
14}
15
16if [ ! -f set_event ]; then
17    echo "event tracing is not supported"
18    exit_unsupported
19fi
20
21if [ ! -f synthetic_events ]; then
22    echo "synthetic event is not supported"
23    exit_unsupported
24fi
25
26clear_synthetic_events
27reset_tracer
28do_reset
29
30echo "Test create synthetic event"
31
32echo 'wakeup_latency  u64 lat pid_t pid char comm[16]' > synthetic_events
33if [ ! -d events/synthetic/wakeup_latency ]; then
34    fail "Failed to create wakeup_latency synthetic event"
35fi
36
37echo "Test create histogram for synthetic event"
38echo "Test histogram variables,simple expression support and onmatch-onmax action"
39
40echo 'hist:keys=pid:ts0=common_timestamp.usecs if comm=="ping"' > events/sched/sched_wakeup/trigger
41echo '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
42echo 'hist:keys=comm,pid,lat:wakeup_lat=lat:sort=lat' > events/synthetic/wakeup_latency/trigger
43ping localhost -c 5
44if [ ! 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"
46fi
47
48do_reset
49
50exit 0
51