Skip to contentSkip to conversation

perf test: Allow tolerance for leader sampling test

PATCH In review Chun-Tse Shao 1 participant 2 messages Apr 9, 2025 perf events

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 perf test: Allow tolerance for leader sampling test

There is a known issue that the leader sampling is inconsistent, since throttle only affect leader, not the slave. The detail is in [1]. To maintain test coverage, this patch sets a tolerance rate of 80% to accommodate the throttled samples and prevent test failures due to throttling.

[1] lore.kernel.org/[email protected]

---
 tools/perf/tests/shell/record.sh | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)
tools/perf/tests/shell/record.sh +24 -4
index ba8d873d3ca7..06a718e80121 100755
@@ -240,19 +240,39 @@ test_leader_sampling() {
   fi
   index=0
   perf script -i "${perfdata}" > $script_output
+  # Check if the two instruction counts are equal in each record.
+  # However, the throttling code doesn't consider event grouping. During throttling, only the
+  # leader is stopped, causing the slave's counts significantly higher. To temporarily solve this,
+  # let's set the tolerance rate to 80%.
+  # TODO: Revert the code for tolerance once the throttling mechanism is fixed.
+  valid_counts=0
+  invalid_counts=0
+  tolerance_rate=0.8
   while IFS= read -r line
   do
-    # Check if the two instruction counts are equal in each record
     cycles=$(echo $line | awk '{for(i=1;i<=NF;i++) if($i=="cycles:") print $(i-1)}')
     if [ $(($index%2)) -ne 0 ] && [ ${cycles}x != ${prev_cycles}x ]
     then
-      echo "Leader sampling [Failed inconsistent cycles count]"
-      err=1
-      return
+      invalid_counts=$(($invalid_counts+1))
+    else
+      valid_counts=$(($valid_counts+1))
     fi
     index=$(($index+1))
     prev_cycles=$cycles
   done < $script_output
+  total_counts=$(bc <<< "$invalid_counts+$valid_counts")
+  if (( $(bc <<< "$total_counts <= 0") ))
+  then
+      echo "Leader sampling [No sample generated]"
+      err=1
+      return
+  fi
+  if (( $(bc <<< "scale=3; $invalid_counts/$total_counts > 1-$tolerance_rate") ))
+  then
+      echo "Leader sampling [Failed inconsistent cycles count]"
+      err=1
+      return
+  fi
   echo "Basic leader sampling test [Success]"
 }
 

--
2.49.0.504.g3bcea36a83-goog

#1 lore raw

Please ignore this since Thomas Richter already submitted the fix [1] with bc invocation.

[1] lore.kernel.org/[email protected]/

Thanks,
CT

Quoted 68 lines · Chun-Tse Shao

There is a known issue that the leader sampling is inconsistent, since throttle only affect leader, not the slave. The detail is in [1]. To maintain test coverage, this patch sets a tolerance rate of 80% to accommodate the throttled samples and prevent test failures due to throttling.

[1] lore.kernel.org/[email protected]

---
 tools/perf/tests/shell/record.sh | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)
tools/perf/tests/shell/record.sh +24 -5
index ba8d873d3ca7..06a718e80121 100755
@@ -240,19 +240,39 @@ test_leader_sampling() {
   fi
   index=0
   perf script -i "${perfdata}" > $script_output
+  # Check if the two instruction counts are equal in each record.
+  # However, the throttling code doesn't consider event grouping. During throttling, only the
+  # leader is stopped, causing the slave's counts significantly higher. To temporarily solve this,
+  # let's set the tolerance rate to 80%.
+  # TODO: Revert the code for tolerance once the throttling mechanism is fixed.
+  valid_counts=0
+  invalid_counts=0
+  tolerance_rate=0.8
   while IFS= read -r line
   do
-    # Check if the two instruction counts are equal in each record
     cycles=$(echo $line | awk '{for(i=1;i<=NF;i++) if($i=="cycles:") print $(i-1)}')
     if [ $(($index%2)) -ne 0 ] && [ ${cycles}x != ${prev_cycles}x ]
     then
-      echo "Leader sampling [Failed inconsistent cycles count]"
-      err=1
-      return
+      invalid_counts=$(($invalid_counts+1))
+    else
+      valid_counts=$(($valid_counts+1))
     fi
     index=$(($index+1))
     prev_cycles=$cycles
   done < $script_output
+  total_counts=$(bc <<< "$invalid_counts+$valid_counts")
+  if (( $(bc <<< "$total_counts <= 0") ))
+  then
+      echo "Leader sampling [No sample generated]"
+      err=1
+      return
+  fi
+  if (( $(bc <<< "scale=3; $invalid_counts/$total_counts > 1-$tolerance_rate") ))
+  then
+      echo "Leader sampling [Failed inconsistent cycles count]"
+      err=1
+      return
+  fi
   echo "Basic leader sampling test [Success]"
 }
 
--

2.49.0.504.g3bcea36a83-goog