xref: /OK3568_Linux_fs/yocto/scripts/oe-time-dd-test.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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.
11usage() {
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}
26
27run_cmds() {
28    echo "start: top output"
29	top -c -b -n1 -w 512
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"
35	tail -30 tmp*/log/cooker/*/console-latest.log
36	echo "end: cooker log"
37}
38
39if [ $# -lt 1 ]; then
40	usage
41	exit 1
42fi
43
44re_c='^[0-9]+$'
45#re_t='^[0-9]+([.][0-9]+)?$'
46
47while [[ $# -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
83done
84
85
86if [ "$LOG_ONLY" = "true" ] ; then
87    uptime
88    run_cmds
89    exit
90fi
91
92if [ -z ${TIMEOUT+x} ] || [ -z ${COUNT+x} ] ; then
93    usage
94    exit 1
95fi
96
97uptime
98echo "Timeout used: ${TIMEOUT}"
99timeout ${TIMEOUT} dd if=/dev/zero of=oe-time-dd-test.dat bs=1024 count=${COUNT} conv=fsync
100if [ $? -ne 0 ]; then
101    run_cmds
102fi
103