oe-time-dd-test.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. uptime
  27. echo "start: top output"
  28. top -c -b -n1 -w 512
  29. echo "end: top output"
  30. echo "start: iostat"
  31. iostat -y -z -x 5 1
  32. echo "end: iostat"
  33. echo "start: cooker log"
  34. tail -30 tmp*/log/cooker/*/console-latest.log
  35. echo "end: cooker log"
  36. }
  37. if [ $# -lt 1 ]; then
  38. usage
  39. exit 1
  40. fi
  41. re_c='^[0-9]+$'
  42. #re_t='^[0-9]+([.][0-9]+)?$'
  43. while [[ $# -gt 0 ]]; do
  44. key="$1"
  45. case $key in
  46. -c|--count)
  47. COUNT=$2
  48. shift
  49. shift
  50. if ! [[ $COUNT =~ $re_c ]] || [[ $COUNT -le 0 ]] ; then
  51. usage
  52. exit 1
  53. fi
  54. ;;
  55. -t|--timeout)
  56. TIMEOUT=$2
  57. shift
  58. shift
  59. if ! [[ $TIMEOUT =~ $re_c ]] || [[ $TIMEOUT -le 0 ]] ; then
  60. usage
  61. exit 1
  62. fi
  63. ;;
  64. -l|--log-only)
  65. LOG_ONLY="true"
  66. shift
  67. shift
  68. ;;
  69. -h|--help)
  70. usage
  71. exit 0
  72. ;;
  73. *)
  74. usage
  75. exit 1
  76. ;;
  77. esac
  78. done
  79. if [ "$LOG_ONLY" = "true" ] ; then
  80. run_cmds
  81. exit
  82. fi
  83. if [ -z ${TIMEOUT+x} ] || [ -z ${COUNT+x} ] ; then
  84. usage
  85. exit 1
  86. fi
  87. echo "Timeout used: ${TIMEOUT}"
  88. timeout ${TIMEOUT} dd if=/dev/zero of=oe-time-dd-test.dat bs=1024 count=${COUNT} conv=fsync
  89. if [ $? -ne 0 ]; then
  90. run_cmds
  91. fi