extract-stall.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0+
  3. usage() {
  4. echo Extract any RCU CPU stall warnings present in specified file.
  5. echo Filter out clocksource lines. Note that preceding-lines excludes the
  6. echo initial line of the stall warning but trailing-lines includes it.
  7. echo
  8. echo Usage: $(basename $0) dmesg-file [ preceding-lines [ trailing-lines ] ]
  9. echo
  10. echo Error: $1
  11. }
  12. # Terminate the script, if the argument is missing
  13. if test -f "$1" && test -r "$1"
  14. then
  15. :
  16. else
  17. usage "Console log file \"$1\" missing or unreadable."
  18. exit 1
  19. fi
  20. echo $1
  21. preceding_lines="${2-3}"
  22. trailing_lines="${3-10}"
  23. awk -v preceding_lines="$preceding_lines" -v trailing_lines="$trailing_lines" '
  24. suffix <= 0 {
  25. for (i = preceding_lines; i > 0; i--)
  26. last[i] = last[i - 1];
  27. last[0] = $0;
  28. }
  29. suffix > 0 {
  30. print $0;
  31. suffix--;
  32. if (suffix <= 0)
  33. print "";
  34. }
  35. suffix <= 0 && /detected stall/ {
  36. for (i = preceding_lines; i >= 0; i--)
  37. if (last[i] != "")
  38. print last[i];
  39. suffix = trailing_lines;
  40. }' < "$1" | tr -d '\015' | grep -v clocksource