Skip to contentSkip to conversation

perf test: Add flake tolerance to record test

PATCH New Ian Rogers 1 participant 1 message Jun 9, 2022 perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 perf test: Add flake tolerance to record test

Testing at scale exposes record tests failing with no samples. Retry the test a bounded number of times to eliminate this.

---
 tools/perf/tests/shell/record.sh | 70 +++++++++++++++++++++-----------
 1 file changed, 47 insertions(+), 23 deletions(-)
tools/perf/tests/shell/record.sh +47 -23
index 00c7285ce1ac..aeed364e834a 100755
@@ -30,19 +30,29 @@ test_per_thread() {
     fi
     return
   fi
-  if ! perf record -e instructions:u --per-thread -o ${perfdata} true 2> /dev/null
-  then
-    echo "Per-thread record of instructions:u [Failed]"
-    err=1
-    return
-  fi
-  if ! perf report -i ${perfdata} -q | egrep -q true
-  then
-    echo "Per-thread record [Failed missing output]"
-    err=1
-    return
-  fi
-  echo "Basic --per-thread mode test [Success]"
+  flake_count=0
+  while true
+  do
+    if ! perf record -e instructions:u --per-thread -o ${perfdata} true 2> /dev/null
+    then
+      echo "Per-thread record of instructions:u [Failed]"
+      err=1
+      return
+    fi
+    if perf report -i ${perfdata} -q | egrep -q true
+    then
+      echo "Basic --per-thread mode test [Success]"
+      return
+    else
+      flake_count=$(($flake_count + 1))
+      if [ $flake_count -ge 30 ]
+      then
+        echo "Per-thread record attempted 30 times [Failed missing output]"
+        err=1
+        return
+      fi
+    fi
+  done
 }
 
 test_register_capture() {
@@ -61,16 +71,30 @@ test_register_capture() {
     echo "Register capture test [Skipped missing registers]"
     return
   fi
-  if ! perf record -o - --intr-regs=di,r8,dx,cx -e cpu/br_inst_retired.near_call/p \
-    -c 1000 --per-thread true 2> /dev/null \
-    | perf script -F ip,sym,iregs -i - 2> /dev/null \
-    | egrep -q "DI:"
-  then
-    echo "Register capture test [Failed missing output]"
-    err=1
-    return
-  fi
-  echo "Register capture test [Success]"
+  flake_count=0
+  while true
+  do
+    if ! perf record -o ${perfdata} --intr-regs=di,r8,dx,cx -e cpu/br_inst_retired.near_call/p \
+      -c 1000 --per-thread true 2> /dev/null
+    then
+      echo "Register capture test of cpu/br_inst_retired.near_call/p with --intr-regs [Failed]"
+      err=1
+      return
+    fi
+    if perf script -F ip,sym,iregs -i ${perfdata} 2> /dev/null | egrep -q "DI:"
+    then
+      echo "Register capture test [Success]"
+      return
+    else
+      flake_count=$(($flake_count + 1))
+      if [ $flake_count -ge 30 ]
+      then
+        echo "Register capture test attempted 30 times [Failed missing output]"
+        err=1
+        return
+      fi
+    fi
+  done
 }
 
 test_per_thread
Signature · 1 line
2.36.1.255.ge46751e96f-goog