3 # Copyright (C) 2016 Julien Desfossez <jdesfossez@efficios.com>
5 # SPDX-License-Identifier: GPL-2.0-only
8 TEST_DESC
="Perf counters"
13 SESSION_NAME
="perf_counters"
17 TESTAPP_PATH
="$TESTDIR/utils/testapp"
18 TESTAPP_NAME
="gen-ust-events"
19 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
20 # Empty if libpfm is installed, "#" otherwise
21 HAVE_LIBPFM
="@LTTNG_TOOLS_BUILD_WITH_LIBPFM_TRUE@"
23 source $TESTDIR/utils
/utils.sh
25 function enable_ust_lttng_event_per_chan
()
31 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -c $chan_name -u >/dev
/null
2>&1
32 ok $?
"Enable event $event_name for session $sess_name in channel $chan_name"
35 function have_libpfm
()
38 ok $?
"Have libpfm installed"
41 function test_ust_raw
()
43 local SESSION_NAME
="ust_perf"
44 local CHAN_NAME
="mychan"
45 local EVENT_NAME
="tp:tptest"
46 local PMU
="UNHALTED_REFERENCE_CYCLES"
51 # Find the raw perf id of the event.
52 PERFID
=$
("$CURDIR/find_event" "$PMU")
54 if [ "$ret" -eq "0" ]; then
56 elif [ "$ret" -eq "1" ]; then
57 skip
0 "PMU event not found." $tests_to_skip
59 elif [ "$ret" -eq "2" ]; then
60 skip
0 "PMU event not actionable." $tests_to_skip
63 fail
"find_event returned $ret."
67 TRACE_PATH
=$
(mktemp
--tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
69 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
71 enable_ust_lttng_channel_ok
$SESSION_NAME $CHAN_NAME
73 enable_ust_lttng_event_per_chan
$SESSION_NAME $EVENT_NAME $CHAN_NAME
75 add_context_ust_ok
$SESSION_NAME $CHAN_NAME "perf:thread:raw:${PERFID}:test"
77 start_lttng_tracing_ok
79 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT >/dev
/null
2>&1
83 destroy_lttng_session_ok
$SESSION_NAME
85 validate_trace
"perf_thread_raw_${PERFID}_test" $TRACE_PATH
90 function test_kernel_raw
()
92 local SESSION_NAME
="kernel_perf"
93 local CHAN_NAME
="mychan"
94 local EVENT_NAME
="lttng_test_filter_event"
95 local PMU
="UNHALTED_REFERENCE_CYCLES"
101 # Find the raw perf id of the event.
102 PERFID
=$
("$CURDIR/find_event" "$PMU")
104 if [ "$ret" -eq "0" ]; then
106 elif [ "$ret" -eq "1" ]; then
107 skip
0 "PMU event not found." $tests_to_skip
109 elif [ "$ret" -eq "2" ]; then
110 skip
0 "PMU event not actionable." $tests_to_skip
113 fail
"find_event returned $ret."
117 TRACE_PATH
=$
(mktemp
--tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
119 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
121 lttng_enable_kernel_channel_ok
$SESSION_NAME $CHAN_NAME
123 enable_kernel_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHAN_NAME
125 add_context_kernel_ok
$SESSION_NAME $CHAN_NAME "perf:cpu:raw:${PERFID}:test"
127 start_lttng_tracing_ok
129 echo -n 10 > /proc
/lttng-test-filter-event
131 stop_lttng_tracing_ok
133 destroy_lttng_session_ok
$SESSION_NAME
135 validate_trace
"perf_cpu_raw_${PERFID}_test" $TRACE_PATH
140 if [ "$(id -u)" == "0" ]; then
146 # MUST set TESTDIR before calling those functions
147 plan_tests
$NUM_TESTS
149 print_test_banner
"$TEST_DESC"
157 skip
$isroot "Root access is needed for kernel testing, skipping." 9 ||
161 modprobe
--remove lttng-test