trace_summary.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. # perf trace summary (exclusive)
  3. # SPDX-License-Identifier: GPL-2.0
  4. # Check that perf trace works with various summary mode
  5. # shellcheck source=lib/probe.sh
  6. . "$(dirname $0)"/lib/probe.sh
  7. skip_if_no_perf_trace || exit 2
  8. [ "$(id -u)" = 0 ] || exit 2
  9. OUTPUT=$(mktemp /tmp/perf_trace_test.XXXXX)
  10. test_perf_trace() {
  11. args=$1
  12. workload="true"
  13. search="^\s*(open|read|close).*[0-9]+%$"
  14. echo "testing: perf trace ${args} -- ${workload}"
  15. perf trace ${args} -- ${workload} >${OUTPUT} 2>&1
  16. if [ $? -ne 0 ]; then
  17. echo "Error: perf trace ${args} failed unexpectedly"
  18. cat ${OUTPUT}
  19. rm -f ${OUTPUT}
  20. exit 1
  21. fi
  22. count=$(grep -E -c -m 3 "${search}" ${OUTPUT})
  23. if [ "${count}" != "3" ]; then
  24. echo "Error: cannot find enough pattern ${search} in the output"
  25. cat ${OUTPUT}
  26. rm -f ${OUTPUT}
  27. exit 1
  28. fi
  29. }
  30. # summary only for a process
  31. test_perf_trace "-s"
  32. # normal output with summary at the end
  33. test_perf_trace "-S"
  34. # summary only with an explicit summary mode
  35. test_perf_trace "-s --summary-mode=thread"
  36. # summary with normal output - total summary mode
  37. test_perf_trace "-S --summary-mode=total"
  38. # summary only for system wide - per-thread summary
  39. test_perf_trace "-as --summary-mode=thread --no-bpf-summary"
  40. # summary only for system wide - total summary mode
  41. test_perf_trace "-as --summary-mode=total --no-bpf-summary"
  42. if ! perf check feature -q bpf; then
  43. echo "Skip --bpf-summary tests as perf built without libbpf"
  44. rm -f ${OUTPUT}
  45. exit 2
  46. fi
  47. # summary only for system wide - per-thread summary with BPF
  48. test_perf_trace "-as --summary-mode=thread --bpf-summary"
  49. # summary only for system wide - total summary mode with BPF
  50. test_perf_trace "-as --summary-mode=total --bpf-summary"
  51. # summary with normal output for system wide - total summary mode with BPF
  52. test_perf_trace "-aS --summary-mode=total --bpf-summary"
  53. # summary only for system wide - cgroup summary mode with BPF
  54. test_perf_trace "-as --summary-mode=cgroup --bpf-summary"
  55. # summary with normal output for system wide - cgroup summary mode with BPF
  56. test_perf_trace "-aS --summary-mode=cgroup --bpf-summary"
  57. rm -f ${OUTPUT}