stat+csv_output.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. # perf stat CSV output linter
  3. # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
  4. # Tests various perf stat CSV output commands for the
  5. # correct number of fields and the CSV separator set to ','.
  6. set -e
  7. # shellcheck source=lib/stat_output.sh
  8. . "$(dirname $0)"/lib/stat_output.sh
  9. csv_sep=@
  10. stat_output=$(mktemp /tmp/__perf_test.stat_output.csv.XXXXX)
  11. cleanup() {
  12. rm -f "${stat_output}"
  13. trap - EXIT TERM INT
  14. }
  15. trap_cleanup() {
  16. cleanup
  17. exit 1
  18. }
  19. trap trap_cleanup EXIT TERM INT
  20. function commachecker()
  21. {
  22. local -i cnt=0
  23. local exp=0
  24. case "$1"
  25. in "--no-args") exp=6
  26. ;; "--system-wide") exp=6
  27. ;; "--event") exp=6
  28. ;; "--interval") exp=7
  29. ;; "--per-thread") exp=7
  30. ;; "--system-wide-no-aggr") exp=7
  31. [ "$(uname -m)" = "s390x" ] && exp='^[6-7]$'
  32. ;; "--per-core") exp=8
  33. ;; "--per-socket") exp=8
  34. ;; "--per-node") exp=8
  35. ;; "--per-die") exp=8
  36. ;; "--per-cluster") exp=8
  37. ;; "--per-cache") exp=8
  38. ;; "--metric-only") exp=1
  39. esac
  40. while read line
  41. do
  42. # Ignore initial "started on" comment.
  43. x=${line:0:1}
  44. [ "$x" = "#" ] && continue
  45. # Ignore initial blank line.
  46. [ "$line" = "" ] && continue
  47. # Count the number of commas
  48. x=$(echo $line | tr -d -c $csv_sep)
  49. cnt="${#x}"
  50. # echo $line $cnt
  51. [[ ! "$cnt" =~ $exp ]] && {
  52. echo "wrong number of fields. expected $exp in $line" 1>&2
  53. exit 1;
  54. }
  55. done < "${stat_output}"
  56. return 0
  57. }
  58. perf_cmd="-x$csv_sep -o ${stat_output}"
  59. skip_test=$(check_for_topology)
  60. check_no_args "CSV" "$perf_cmd"
  61. check_system_wide "CSV" "$perf_cmd"
  62. check_interval "CSV" "$perf_cmd"
  63. check_event "CSV" "$perf_cmd"
  64. check_per_thread "CSV" "$perf_cmd"
  65. check_per_node "CSV" "$perf_cmd"
  66. check_metric_only "CSV" "$perf_cmd"
  67. if [ $skip_test -ne 1 ]
  68. then
  69. check_system_wide_no_aggr "CSV" "$perf_cmd"
  70. check_per_core "CSV" "$perf_cmd"
  71. check_per_cache_instance "CSV" "$perf_cmd"
  72. check_per_cluster "CSV" "$perf_cmd"
  73. check_per_die "CSV" "$perf_cmd"
  74. check_per_socket "CSV" "$perf_cmd"
  75. else
  76. echo "[Skip] Skipping tests for system_wide_no_aggr, per_core, per_die and per_socket since socket id exposed via topology is invalid"
  77. fi
  78. cleanup
  79. exit 0