1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3# description: event trigger - test histogram trigger
4# flags: instance
5
6fail() { #msg
7    echo $1
8    exit_fail
9}
10
11if [ ! -f set_event -o ! -d events/sched ]; then
12    echo "event tracing is not supported"
13    exit_unsupported
14fi
15
16if [ ! -f events/sched/sched_process_fork/trigger ]; then
17    echo "event trigger is not supported"
18    exit_unsupported
19fi
20
21if [ ! -f events/sched/sched_process_fork/hist ]; then
22    echo "hist trigger is not supported"
23    exit_unsupported
24fi
25
26echo "Test histogram basic tigger"
27
28echo 'hist:keys=parent_pid:vals=child_pid' > events/sched/sched_process_fork/trigger
29for i in `seq 1 10` ; do ( echo "forked" > /dev/null); done
30grep parent_pid events/sched/sched_process_fork/hist > /dev/null || \
31    fail "hist trigger on sched_process_fork did not work"
32grep child events/sched/sched_process_fork/hist > /dev/null || \
33    fail "hist trigger on sched_process_fork did not work"
34
35reset_trigger
36
37echo "Test histogram with compound keys"
38
39echo 'hist:keys=parent_pid,child_pid' > events/sched/sched_process_fork/trigger
40for i in `seq 1 10` ; do ( echo "forked" > /dev/null); done
41grep '^{ parent_pid:.*, child_pid:.*}' events/sched/sched_process_fork/hist > /dev/null || \
42    fail "compound keys on sched_process_fork did not work"
43
44reset_trigger
45
46echo "Test histogram with string key"
47
48echo 'hist:keys=parent_comm' > events/sched/sched_process_fork/trigger
49for i in `seq 1 10` ; do ( echo "forked" > /dev/null); done
50COMM=`cat /proc/$$/comm`
51grep "parent_comm: $COMM" events/sched/sched_process_fork/hist > /dev/null || \
52    fail "string key on sched_process_fork did not work"
53
54reset_trigger
55
56echo "Test histogram with sort key"
57
58echo 'hist:keys=parent_pid,child_pid:sort=child_pid.ascending' > events/sched/sched_process_fork/trigger
59for i in `seq 1 10` ; do ( echo "forked" > /dev/null); done
60
61check_inc() {
62    while [ $# -gt 1 ]; do
63        [ $1 -gt $2 ] && return 1
64        shift 1
65    done
66    return 0
67}
68check_inc `grep -o "child_pid:[[:space:]]*[[:digit:]]*" \
69    events/sched/sched_process_fork/hist | cut -d: -f2 ` ||
70    fail "sort param on sched_process_fork did not work"
71
72exit 0
73