brintos

brintos / linux-shallow public Read only

0
0
Text · 2.1 KiB · 67c925f Raw
104 lines · bash
1#!/bin/sh2# perf record offcpu profiling tests3# SPDX-License-Identifier: GPL-2.04 5set -e6 7err=08perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)9 10cleanup() {11  rm -f ${perfdata}12  rm -f ${perfdata}.old13  trap - EXIT TERM INT14}15 16trap_cleanup() {17  cleanup18  exit 119}20trap trap_cleanup EXIT TERM INT21 22test_offcpu_priv() {23  echo "Checking off-cpu privilege"24 25  if [ "$(id -u)" != 0 ]26  then27    echo "off-cpu test [Skipped permission]"28    err=229    return30  fi31  if perf version --build-options 2>&1 | grep HAVE_BPF_SKEL | grep -q OFF32  then33    echo "off-cpu test [Skipped missing BPF support]"34    err=235    return36  fi37}38 39test_offcpu_basic() {40  echo "Basic off-cpu test"41 42  if ! perf record --off-cpu -e dummy -o ${perfdata} sleep 1 2> /dev/null43  then44    echo "Basic off-cpu test [Failed record]"45    err=146    return47  fi48  if ! perf evlist -i ${perfdata} | grep -q "offcpu-time"49  then50    echo "Basic off-cpu test [Failed no event]"51    err=152    return53  fi54  if ! perf report -i ${perfdata} -q --percent-limit=90 | grep -E -q sleep55  then56    echo "Basic off-cpu test [Failed missing output]"57    err=158    return59  fi60  echo "Basic off-cpu test [Success]"61}62 63test_offcpu_child() {64  echo "Child task off-cpu test"65 66  # perf bench sched messaging creates 400 processes67  if ! perf record --off-cpu -e dummy -o ${perfdata} -- \68    perf bench sched messaging -g 10 > /dev/null 2>&169  then70    echo "Child task off-cpu test [Failed record]"71    err=172    return73  fi74  if ! perf evlist -i ${perfdata} | grep -q "offcpu-time"75  then76    echo "Child task off-cpu test [Failed no event]"77    err=178    return79  fi80  # each process waits at least for poll, so it should be more than 400 events81  if ! perf report -i ${perfdata} -s comm -q -n -t ';' --percent-limit=90 | \82    awk -F ";" '{ if (NF > 3 && int($3) < 400) exit 1; }'83  then84    echo "Child task off-cpu test [Failed invalid output]"85    err=186    return87  fi88  echo "Child task off-cpu test [Success]"89}90 91 92test_offcpu_priv93 94if [ $err = 0 ]; then95  test_offcpu_basic96fi97 98if [ $err = 0 ]; then99  test_offcpu_child100fi101 102cleanup103exit $err104