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