xref: /linux/tools/perf/tests/shell/stat+event_uniquifying.sh (revision e0c0ab04f6785abaa71b9b8dc252cb1a2072c225)
1#!/bin/bash
2# perf stat events uniquifying
3# SPDX-License-Identifier: GPL-2.0
4
5set -e
6
7stat_output=$(mktemp /tmp/__perf_test.stat_output.XXXXX)
8perf_tool=perf
9err=0
10
11test_event_uniquifying() {
12  # We use `clockticks` to verify the uniquify behavior.
13  event="clockticks"
14
15  # If the `-A` option is added, the event should be uniquified.
16  #
17  # $perf list -v clockticks
18  #
19  # List of pre-defined events (to be used in -e or -M):
20  #
21  #   uncore_imc_0/clockticks/                           [Kernel PMU event]
22  #   uncore_imc_1/clockticks/                           [Kernel PMU event]
23  #   uncore_imc_2/clockticks/                           [Kernel PMU event]
24  #   uncore_imc_3/clockticks/                           [Kernel PMU event]
25  #   uncore_imc_4/clockticks/                           [Kernel PMU event]
26  #   uncore_imc_5/clockticks/                           [Kernel PMU event]
27  #
28  #   ...
29  #
30  # $perf stat -e clockticks -A -- true
31  #
32  #  Performance counter stats for 'system wide':
33  #
34  # CPU0            3,773,018      uncore_imc_0/clockticks/
35  # CPU0            3,609,025      uncore_imc_1/clockticks/
36  # CPU0                    0      uncore_imc_2/clockticks/
37  # CPU0            3,230,009      uncore_imc_3/clockticks/
38  # CPU0            3,049,897      uncore_imc_4/clockticks/
39  # CPU0                    0      uncore_imc_5/clockticks/
40  #
41  #        0.002029828 seconds time elapsed
42
43  echo "stat event uniquifying test"
44  uniquified_event_array=()
45
46  # Check how many uniquified events.
47  while IFS= read -r line; do
48    uniquified_event=$(echo "$line" | awk '{print $1}')
49    uniquified_event_array+=("${uniquified_event}")
50  done < <(${perf_tool} list -v ${event} | grep "\[Kernel PMU event\]")
51
52  perf_command="${perf_tool} stat -e $event -A -o ${stat_output} -- true"
53  $perf_command
54
55  # Check the output contains all uniquified events.
56  for uniquified_event in "${uniquified_event_array[@]}"; do
57    if ! cat "${stat_output}" | grep -q "${uniquified_event}"; then
58      echo "Event is not uniquified [Failed]"
59      echo "${perf_command}"
60      cat "${stat_output}"
61      err=1
62      break
63    fi
64  done
65}
66
67test_event_uniquifying
68rm -f "${stat_output}"
69exit $err
70