1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3# description: event trigger - test histogram modifiers
4# flags: instance
5
6do_reset() {
7    reset_trigger
8    echo > set_event
9    clear_trace
10}
11
12fail() { #msg
13    do_reset
14    echo $1
15    exit_fail
16}
17
18if [ ! -f set_event -o ! -d events/sched ]; then
19    echo "event tracing is not supported"
20    exit_unsupported
21fi
22
23if [ ! -f events/sched/sched_process_fork/trigger ]; then
24    echo "event trigger is not supported"
25    exit_unsupported
26fi
27
28if [ ! -f events/sched/sched_process_fork/hist ]; then
29    echo "hist trigger is not supported"
30    exit_unsupported
31fi
32
33reset_tracer
34do_reset
35
36echo "Test histogram with execname modifier"
37
38echo 'hist:keys=common_pid.execname' > events/sched/sched_process_fork/trigger
39for i in `seq 1 10` ; do ( echo "forked" > /dev/null); done
40COMM=`cat /proc/$$/comm`
41grep "common_pid: $COMM" events/sched/sched_process_fork/hist > /dev/null || \
42    fail "execname modifier on sched_process_fork did not work"
43
44reset_trigger
45
46echo "Test histogram with hex modifier"
47
48echo 'hist:keys=parent_pid.hex' > events/sched/sched_process_fork/trigger
49for i in `seq 1 10` ; do ( echo "forked" > /dev/null); done
50# Note that $$ is the parent pid. $PID is current PID.
51HEX=`printf %x $PID`
52grep "parent_pid: $HEX" events/sched/sched_process_fork/hist > /dev/null || \
53    fail "hex modifier on sched_process_fork did not work"
54
55reset_trigger
56
57echo "Test histogram with syscall modifier"
58
59echo 'hist:keys=id.syscall' > events/raw_syscalls/sys_exit/trigger
60for i in `seq 1 10` ; do ( echo "forked" > /dev/null); done
61grep "id: \(unknown_\|sys_\)" events/raw_syscalls/sys_exit/hist > /dev/null || \
62    fail "syscall modifier on raw_syscalls/sys_exit did not work"
63
64
65reset_trigger
66
67echo "Test histgram with log2 modifier"
68
69echo 'hist:keys=bytes_req.log2' > events/kmem/kmalloc/trigger
70for i in `seq 1 10` ; do ( echo "forked" > /dev/null); done
71grep 'bytes_req: ~ 2^[0-9]*' events/kmem/kmalloc/hist > /dev/null || \
72    fail "log2 modifier on kmem/kmalloc did not work"
73
74do_reset
75
76exit 0
77