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