oe-time-dd-test.sh 2.2 KB

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