Skip to contentSkip to conversation

perf test: Avoid system wide when not privileged

PATCH In review Ian Rogers 2 participants 4 messages Sep 30, 2023 – Oct 9, 2023 perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 perf test: Avoid system wide when not privileged

Switch the test program to sleep that makes more sense for system wide events. Only enable system wide when root or not paranoid. This avoids failures under some testing conditions like ARM cloud.

---
 tools/perf/tests/shell/stat_all_metricgroups.sh | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
tools/perf/tests/shell/stat_all_metricgroups.sh +14 -2
index cb35e488809a..f3e305649e2c 100755
@@ -4,9 +4,21 @@
 
 set -e
 
-for m in $(perf list --raw-dump metricgroups); do
+function ParanoidAndNotRoot()
+{
+  [ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ]
+}
+
+system_wide_flag="-a"
+if ParanoidAndNotRoot 0
+then
+  system_wide_flag=""
+fi
+
+for m in $(perf list --raw-dump metricgroups)
+do
   echo "Testing $m"
-  perf stat -M "$m" -a true
+  perf stat -M "$m" $system_wide_flag sleep 0.01
 done
 
 exit 0
Signature · 1 line
2.42.0.582.g8ccd20d70d-goog
maintainer Acked-by on v1 1/1
#1 lore raw

Hi Ian,

Quoted 6 lines · Ian Rogers

Switch the test program to sleep that makes more sense for system wide events. Only enable system wide when root or not paranoid. This avoids failures under some testing conditions like ARM cloud.

While I'm ok with the change, I wonder why it doesn't have the same code structure as in the stat_all_metrics.sh which checks the actual result.

Thanks,
Namhyung

Quoted 35 lines
---
 tools/perf/tests/shell/stat_all_metricgroups.sh | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
tools/perf/tests/shell/stat_all_metricgroups.sh +14 -3
index cb35e488809a..f3e305649e2c 100755
@@ -4,9 +4,21 @@
 
 set -e
 
-for m in $(perf list --raw-dump metricgroups); do
+function ParanoidAndNotRoot()
+{
+  [ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ]
+}
+
+system_wide_flag="-a"
+if ParanoidAndNotRoot 0
+then
+  system_wide_flag=""
+fi
+
+for m in $(perf list --raw-dump metricgroups)
+do
   echo "Testing $m"
-  perf stat -M "$m" -a true
+  perf stat -M "$m" $system_wide_flag sleep 0.01
 done
 
 exit 0
--

2.42.0.582.g8ccd20d70d-goog

author reviewer
#2 lore raw
Quoted 9 lines · Namhyung Kim

Hi Ian,

Quoted 5 lines · Ian Rogers

Switch the test program to sleep that makes more sense for system wide events. Only enable system wide when root or not paranoid. This avoids failures under some testing conditions like ARM cloud.

Quoted 6 lines
Quoted 1 line

While I'm ok with the change, I wonder why it doesn't have the same code structure as in the stat_all_metrics.sh which checks the actual result.

The metric group isn't printed when we print the metrics within it. This could be changed.

Thanks,
Ian

Quoted 38 lines

Thanks,
Namhyung

Quoted 35 lines
---
 tools/perf/tests/shell/stat_all_metricgroups.sh | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
tools/perf/tests/shell/stat_all_metricgroups.sh +14 -3
index cb35e488809a..f3e305649e2c 100755
@@ -4,9 +4,21 @@
 
 set -e
 
-for m in $(perf list --raw-dump metricgroups); do
+function ParanoidAndNotRoot()
+{
+  [ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ]
+}
+
+system_wide_flag="-a"
+if ParanoidAndNotRoot 0
+then
+  system_wide_flag=""
+fi
+
+for m in $(perf list --raw-dump metricgroups)
+do
   echo "Testing $m"
-  perf stat -M "$m" -a true
+  perf stat -M "$m" $system_wide_flag sleep 0.01
 done
 
 exit 0
--

2.42.0.582.g8ccd20d70d-goog

maintainer
#3 lore raw
Quoted 13 lines · Ian Rogers
Quoted 11 lines · Namhyung Kim

Hi Ian,

Quoted 6 lines · Ian Rogers

Switch the test program to sleep that makes more sense for system wide events. Only enable system wide when root or not paranoid. This avoids failures under some testing conditions like ARM cloud.

Quoted 7 lines
Quoted 4 lines

While I'm ok with the change, I wonder why it doesn't have the same code structure as in the stat_all_metrics.sh which checks the actual result.

The metric group isn't printed when we print the metrics within it. This could be changed.

Ok, we can change it later. Applied to perf-tools-next, thanks!