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