1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3# description: trace_marker trigger - test histogram with synthetic event
4# flags:
5
6do_reset() {
7    reset_trigger
8    echo > set_event
9    echo > synthetic_events
10    clear_trace
11}
12
13fail() { #msg
14    do_reset
15    echo $1
16    exit_fail
17}
18
19if [ ! -f set_event ]; then
20    echo "event tracing is not supported"
21    exit_unsupported
22fi
23
24if [ ! -f synthetic_events ]; then
25    echo "synthetic events not supported"
26    exit_unsupported
27fi
28
29if [ ! -d events/ftrace/print ]; then
30    echo "event trace_marker is not supported"
31    exit_unsupported
32fi
33
34if [ ! -f events/ftrace/print/trigger ]; then
35    echo "event trigger is not supported"
36    exit_unsupported
37fi
38
39if [ ! -f events/ftrace/print/hist ]; then
40    echo "hist trigger is not supported"
41    exit_unsupported
42fi
43
44do_reset
45
46echo "Test histogram trace_marker to trace_marker latency histogram trigger"
47
48echo 'latency u64 lat' > synthetic_events
49echo 'hist:keys=common_pid:ts0=common_timestamp.usecs if buf == "start"' > events/ftrace/print/trigger
50echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(ftrace.print).latency($lat) if buf == "end"' >> events/ftrace/print/trigger
51echo 'hist:keys=common_pid,lat:sort=lat' > events/synthetic/latency/trigger
52echo -n "start" > trace_marker
53echo -n "end" > trace_marker
54
55cnt=`grep 'hitcount: *1$' events/ftrace/print/hist | wc -l`
56
57if [ $cnt -ne 2 ]; then
58    fail "hist trace_marker trigger did not trigger correctly"
59fi
60
61grep 'hitcount: *1$' events/synthetic/latency/hist > /dev/null || \
62    fail "hist trigger did not trigger "
63
64do_reset
65
66exit 0
67