Skip to content

Commit 1c5721c

Browse files
Chun-Tse Shaoacmel
authored andcommitted
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/20250328182752.769662-1-ctshao@google.com Suggested-by: Ian Rogers <irogers@google.com> Suggested-by: Thomas Richter <tmricht@linux.ibm.com> Reviewed-by: Ian Rogers <irogers@google.com> Signed-off-by: Chun-Tse Shao <ctshao@google.com> Co-developed-by: Thomas Richter <tmricht@linux.ibm.com> Signed-off-by: Thomas Richter <tmricht@linux.ibm.com> Tested-by: Thomas Richter <tmricht@linux.ibm.com> Cc: Alexander Gordeev <agordeev@linux.ibm.com> Cc: Heiko Carstens <hca@linux.ibm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Sumanth Korikkar <sumanthk@linux.ibm.com> Cc: Vasily Gorbik <gor@linux.ibm.com> Link: https://lore.kernel.org/r/20250430140611.599078-1-tmricht@linux.ibm.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent cb42259 commit 1c5721c

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

tools/perf/tests/shell/record.sh

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,22 +240,43 @@ test_leader_sampling() {
240240
err=1
241241
return
242242
fi
243+
perf script -i "${perfdata}" | grep brstack > $script_output
244+
# Check if the two instruction counts are equal in each record.
245+
# However, the throttling code doesn't consider event grouping. During throttling, only the
246+
# leader is stopped, causing the slave's counts significantly higher. To temporarily solve this,
247+
# let's set the tolerance rate to 80%.
248+
# TODO: Revert the code for tolerance once the throttling mechanism is fixed.
243249
index=0
244-
perf script -i "${perfdata}" > "${script_output}"
250+
valid_counts=0
251+
invalid_counts=0
252+
tolerance_rate=0.8
245253
while IFS= read -r line
246254
do
247-
# Check if the two instruction counts are equal in each record
248255
cycles=$(echo $line | awk '{for(i=1;i<=NF;i++) if($i=="cycles:") print $(i-1)}')
249256
if [ $(($index%2)) -ne 0 ] && [ ${cycles}x != ${prev_cycles}x ]
250257
then
251-
echo "Leader sampling [Failed inconsistent cycles count]"
252-
err=1
253-
return
258+
invalid_counts=$(($invalid_counts+1))
259+
else
260+
valid_counts=$(($valid_counts+1))
254261
fi
255262
index=$(($index+1))
256263
prev_cycles=$cycles
257264
done < "${script_output}"
258-
echo "Basic leader sampling test [Success]"
265+
total_counts=$(bc <<< "$invalid_counts+$valid_counts")
266+
if (( $(bc <<< "$total_counts <= 0") ))
267+
then
268+
echo "Leader sampling [No sample generated]"
269+
err=1
270+
return
271+
fi
272+
isok=$(bc <<< "scale=2; if (($invalid_counts/$total_counts) < (1-$tolerance_rate)) { 0 } else { 1 };")
273+
if [ $isok -eq 1 ]
274+
then
275+
echo "Leader sampling [Failed inconsistent cycles count]"
276+
err=1
277+
else
278+
echo "Basic leader sampling test [Success]"
279+
fi
259280
}
260281

261282
test_topdown_leader_sampling() {

0 commit comments

Comments
 (0)