| 1 | |
| 2 | |
| 3 | |
| 4 |
|
| 5 | set -e
|
| 6 |
|
| 7 | err=0
|
| 8 | perfdata=$(mktemp /tmp/__perf_test_header.perf.data.XXXXX)
|
| 9 | script_output=$(mktemp /tmp/__perf_test_header.perf.data.XXXXX.script)
|
| 10 |
|
| 11 | cleanup() {
|
| 12 | rm -f "${perfdata}"
|
| 13 | rm -f "${perfdata}".old
|
| 14 | rm -f "${script_output}"
|
| 15 |
|
| 16 | trap - EXIT TERM INT
|
| 17 | }
|
| 18 |
|
| 19 | trap_cleanup() {
|
| 20 | echo "Unexpected signal in ${FUNCNAME[1]}"
|
| 21 | cleanup
|
| 22 | exit 1
|
| 23 | }
|
| 24 | trap trap_cleanup EXIT TERM INT
|
| 25 |
|
| 26 | check_header_output() {
|
| 27 | declare -a fields=(
|
| 28 | "captured"
|
| 29 | "hostname"
|
| 30 | "os release"
|
| 31 | "arch"
|
| 32 | "cpuid"
|
| 33 | "nrcpus"
|
| 34 | "event"
|
| 35 | "cmdline"
|
| 36 | "perf version"
|
| 37 | "sibling (cores|dies|threads)"
|
| 38 | "sibling threads"
|
| 39 | "total memory"
|
| 40 | )
|
| 41 | for i in "${fields[@]}"
|
| 42 | do
|
| 43 | if ! grep -q -E "$i" "${script_output}"
|
| 44 | then
|
| 45 | echo "Failed to find expected $i in output"
|
| 46 | err=1
|
| 47 | fi
|
| 48 | done
|
| 49 | }
|
| 50 |
|
| 51 | test_file() {
|
| 52 | echo "Test perf header file"
|
| 53 |
|
| 54 | perf record -o "${perfdata}" -- perf test -w noploop
|
| 55 | perf report --header-only -I -i "${perfdata}" > "${script_output}"
|
| 56 | check_header_output
|
| 57 |
|
| 58 | echo "Test perf header file [Done]"
|
| 59 | }
|
| 60 |
|
| 61 | test_pipe() {
|
| 62 | echo "Test perf header pipe"
|
| 63 |
|
| 64 | perf record -o - -- perf test -w noploop | perf report --header-only -I -i - > "${script_output}"
|
| 65 | check_header_output
|
| 66 |
|
| 67 | echo "Test perf header pipe [Done]"
|
| 68 | }
|
| 69 |
|
| 70 | test_file
|
| 71 | test_pipe
|
| 72 |
|
| 73 | cleanup
|
| 74 | exit $err
|