oe-time-dd-test.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/bash
  2. #
  3. # Copyright OpenEmbedded Contributors
  4. #
  5. # SPDX-License-Identifier: MIT
  6. #
  7. # oe-time-dd-test records how much time it takes to
  8. # write <count> number of kilobytes to the filesystem.
  9. # It also records the number of processes that are in
  10. # running (R), uninterruptible sleep (D) and interruptible
  11. # sleep (S) state from the output of "top" command.
  12. # The purporse of this script is to find which part of
  13. # the build system puts stress on the filesystem io and
  14. # log all the processes.
  15. usage() {
  16. echo "$0 is used to detect i/o latency and runs commands to display host information."
  17. echo "The following commands are run in order:"
  18. echo "1) top -c -b -n1 -w 512"
  19. echo "2) iostat -y -z -x 5 1"
  20. echo "3) tail -30 tmp*/log/cooker/*/console-latest.log to gather cooker log."
  21. echo " "
  22. echo "Options:"
  23. echo "-c | --count <amount> dd (transfer) <amount> KiB of data within specified timeout to detect latency."
  24. echo " Must enable -t option."
  25. echo "-t | --timeout <time> timeout in seconds for the <count> amount of data to be transferred."
  26. echo "-l | --log-only run the commands without performing the data transfer."
  27. echo "-h | --help show help"
  28. }
  29. run_cmds() {
  30. echo "start: top output"
  31. top -c -b -n1 -w 512
  32. echo "end: top output"
  33. echo "start: iostat"
  34. iostat -y -z -x 5 1
  35. echo "end: iostat"
  36. echo "start: cooker log"
  37. tail -30 tmp*/log/cooker/*/console-latest.log
  38. echo "end: cooker log"
  39. }
  40. if [ $# -lt 1 ]; then
  41. usage
  42. exit 1
  43. fi
  44. re_c='^[0-9]+$'
  45. #re_t='^[0-9]+([.][0-9]+)?$'
  46. while [[ $# -gt 0 ]]; do
  47. key="$1"
  48. case $key in
  49. -c|--count)
  50. COUNT=$2
  51. shift
  52. shift
  53. if ! [[ $COUNT =~ $re_c ]] || [[ $COUNT -le 0 ]] ; then
  54. usage
  55. exit 1
  56. fi
  57. ;;
  58. -t|--timeout)
  59. TIMEOUT=$2
  60. shift
  61. shift
  62. if ! [[ $TIMEOUT =~ $re_c ]] || [[ $TIMEOUT -le 0 ]] ; then
  63. usage
  64. exit 1
  65. fi
  66. ;;
  67. -l|--log-only)
  68. LOG_ONLY="true"
  69. shift
  70. shift
  71. ;;
  72. -h|--help)
  73. usage
  74. exit 0
  75. ;;
  76. *)
  77. usage
  78. exit 1
  79. ;;
  80. esac
  81. done
  82. if [ "$LOG_ONLY" = "true" ] ; then
  83. uptime
  84. run_cmds
  85. exit
  86. fi
  87. if [ -z ${TIMEOUT+x} ] || [ -z ${COUNT+x} ] ; then
  88. usage
  89. exit 1
  90. fi
  91. uptime
  92. echo "Timeout used: ${TIMEOUT}"
  93. timeout ${TIMEOUT} dd if=/dev/zero of=oe-time-dd-test.dat bs=1024 count=${COUNT} conv=fsync
  94. if [ $? -ne 0 ]; then
  95. run_cmds
  96. fi