3 # Copyright (C) - 2016 Julien Desfossez <jdesfossez@efficios.com>
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License, version 2 only, as
7 # published by the Free Software Foundation.
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 # You should have received a copy of the GNU General Public License along with
15 # this program; if not, write to the Free Software Foundation, Inc., 51
16 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 TEST_DESC
="Perf counters"
23 SESSION_NAME
="perf_counters"
27 TESTAPP_PATH
="$TESTDIR/utils/testapp"
28 TESTAPP_NAME
="gen-ust-events"
29 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
30 # Empty if libpfm is installed, "#" otherwise
31 HAVE_LIBPFM
="@LTTNG_TOOLS_BUILD_WITH_LIBPFM_TRUE@"
33 source $TESTDIR/utils
/utils.sh
35 function enable_ust_lttng_event_per_chan
()
41 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -c $chan_name -u >/dev
/null
2>&1
42 ok $?
"Enable event $event_name for session $sess_name in channel $chan_name"
45 function have_libpfm
()
48 ok $?
"Have libpfm installed"
51 function test_ust_raw
()
53 TRACE_PATH
=$
(mktemp
-d)
54 SESSION_NAME
="ust_perf"
56 EVENT_NAME
="tp:tptest"
57 PMU
="UNHALTED_REFERENCE_CYCLES"
58 PERFID
=$
($CURDIR/find_event
$PMU)
62 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
64 enable_ust_lttng_channel_ok
$SESSION_NAME $CHAN_NAME
66 enable_ust_lttng_event_per_chan
$SESSION_NAME $EVENT_NAME $CHAN_NAME
68 add_context_ust_ok
$SESSION_NAME $CHAN_NAME "perf:thread:raw:${PERFID}:test"
70 start_lttng_tracing_ok
72 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT >/dev
/null
2>&1
76 destroy_lttng_session_ok
$SESSION_NAME
78 validate_trace
"perf_thread_raw_${PERFID}_test" $TRACE_PATH
83 function test_kernel_raw
()
85 TRACE_PATH
=$
(mktemp
-d)
86 SESSION_NAME
="kernel_perf"
88 EVENT_NAME
="lttng_test_filter_event"
89 PMU
="UNHALTED_REFERENCE_CYCLES"
90 PERFID
=$
($CURDIR/find_event
$PMU)
94 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
96 lttng_enable_kernel_channel_ok
$SESSION_NAME $CHAN_NAME
98 enable_kernel_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHAN_NAME
100 add_context_kernel_ok
$SESSION_NAME $CHAN_NAME "perf:cpu:raw:${PERFID}:test"
102 start_lttng_tracing_ok
104 echo -n 10 > /proc
/lttng-test-filter-event
106 stop_lttng_tracing_ok
108 destroy_lttng_session_ok
$SESSION_NAME
110 validate_trace
"perf_cpu_raw_${PERFID}_test" $TRACE_PATH
115 if [ "$(id -u)" == "0" ]; then
121 # MUST set TESTDIR before calling those functions
122 plan_tests
$NUM_TESTS
124 print_test_banner
"$TEST_DESC"
132 skip
$isroot "Root access is needed for kernel testing, skipping." 9 ||