OSDN Git Service

Merge "Simpleperf: remove unnecessary exit()." am: dd7f62ed57 am: 5345ea0e4f
[android-x86/system-extras.git] / tests / workloads / pwrtest.sh
1 # Script to gather perf and perf/watt data for several workloads
2 #
3 # Setup:
4 #
5 # - device connected to monsoon with USB passthrough enabled
6 # - network enabled (baseline will be measured and subtracted
7 #   from results) (network needed for chrome, youtube tests)
8 # - the device is rebooted after each test (can be inhibited
9 #   with "-r 0")
10 #
11 # Default behavior is to run each of the known workloads for
12 # 30 minutes gathering both performance and power data.
13 #
14 # The default time can be overridden with the -t option. To
15 # change individual test times, a config file can be specifed
16 # via -f with times for individual tests. Example file contents:
17 #
18 #       idleTime=60
19 #       recentflingTime=60
20 #       chromeTime=60
21 #       youtubeTime=0
22 #       sysappsTime=60
23 #       suntempleTime=5
24 #
25 # Output goes to the current directory.
26 #
27 # Examples:
28 #
29 # - Run all tests for 15 minutes (default is 30): ./pwrtest.sh -t 15 -R MDA20
30 #
31 # - Use a config file for test times: ./pwrtest.sh -f ./myconfig -R MDA20
32 #
33 # - Use a init file to setup device tuneables after each restart (this is
34 #   a bash script which should include adb commands to set up device):
35 #     ./pwrtest.sh -F devtunables
36 #
37 defaultTime=30
38 garbageminutes=8
39
40 function Usage {
41         echo "Usage: $0 [OPTIONS]"
42         echo "-d device : device type (shamu, bullhead, ...)"
43         echo "-f configFile : config file to override individual test times"
44         echo "-g garbageMinutes : time to skip power measurement at beginning of test"
45         echo "                    default=$garbagetime minutes"
46         echo "-r restart : 0=no reboot between tests, 1=reboot (default)"
47         echo "-t defaultTimeMin : default time to run each test"
48         echo "                    default=$defaultTime minutes"
49         echo "-D cmddir : directory to find defs.sh"
50         echo "-F restartHookFile : file of commands to set device tunables after restart (optional)"
51         echo "-R release : release running on device (MDA20, 2054728, etc)"
52 }
53
54 restart=1
55 hz=5
56 shadowgrid2TimeMax=25
57
58 CMDDIR=$(dirname $0 2>/dev/null)
59 CMDDIR=${CMDDIR:=.}
60
61 MONSOON=monsoon.par
62
63 while [ $# -gt 0 ]
64 do
65         case "$1" in
66         (-D) CMDDIR=$2; shift;;
67         (-r) restart=$2; shift;;
68         (-t) defaultTime=$2; shift;;
69         (-F) restartfile=$2; shift;;
70         (-g) garbageminutes=$2; shift;;
71         (-f)
72                 configFile=$2;
73                 echo "Reading configs from $configFile..."
74                 . ./$configFile
75                 shift;;
76         (-R) echo $2 > ./build; shift;;
77         (--) ;;
78         (--help)
79                 Usage
80                 exit 0;;
81         (*)
82                 echo "Unknown option: $1"
83                 Usage
84                 exit 1;;
85         esac
86         shift
87 done
88
89 . $CMDDIR/defs.sh --
90
91 devdir="/data/local/tmp"
92 suntempledir=${CMDDIR}/suntemple
93
94 case $DEVICE in
95 (shamu|hammerhead)
96         HWUITEST=hwuitest
97         onSwipe="700 1847 700 400 50"
98         ;;
99 (*)
100         HWUITEST=hwuitest64
101         onSwipe="500 1200 500 550 150"
102         ;;
103 esac
104
105 scripts="defs.sh systemapps.sh recentfling.sh youtube.sh chromefling.sh $HWUITEST"
106
107 if ! $MONSOON >/dev/null 2>&1; then
108         echo $MONSOON must be in your PATH >&2
109         exit 1
110 fi
111
112 function usbpassthru {
113         if [ "$1" = off ]; then
114                 state=off
115         else
116                 state=on
117         fi
118         echo Setting usb pass-thru to $state
119         monsoon.par --usbpassthrough=$state
120 }
121
122 function pwrcollect {
123         collectmin=$1
124         collectmin=${collectmin:=60}
125         # samples = hz * 60 * minutes
126         ((samples=5*60*collectmin))
127         monsoon.par --timestamp --samples $samples --hz 5
128 }
129
130 function copy_files {
131         adb shell mkdir -p $devdir
132         for file in $scripts
133         do
134                 adb push $CMDDIR/$file $devdir
135         done
136 }
137
138 function install_suntemple {
139         echo Checking for suntemple installation...
140         #stdest=/storage/sdcard0/obb/com.BrueComputing.SunTemple
141         stdest=/storage/emulated/0/obb/com.BrueComputing.SunTemple
142         dircontents=$(adb ls $stdest 2>/dev/null)
143         if [ "$dircontents" = "" ]; then
144                 echo Installing suntemple...
145                 adb install $suntempledir/*.apk
146                 adb shell mkdir -p $stdest
147                 adb push $suntempledir/main*obb $stdest
148         else
149                 echo dircontents=$dircontents
150                 echo Suntemple already installed.
151         fi
152 }
153
154 function run_test {
155         testName=$1
156         collectMinutes=$2
157         collectOutput=${testName}-power-raw.out
158         powerOutput=${testName}-power.out
159         echo -----------------------------------------------------
160         echo TEST: $testName
161         echo enabled Cores $(adb shell "cat /sys/devices/system/cpu/online")
162         date
163         echo -----------------------------------------------------
164         usbpassthru off
165         pwrcollect $collectMinutes > $collectOutput 2>/dev/null
166         # take off the first 2min of samples
167         totalSamples=$(cat $collectOutput | wc -l)
168         # we throw away the first "garbageminutes" of the data
169         # since it is volatile
170         ((garbage=hz*60*garbageminutes))
171         ((remaining=totalSamples-garbage))
172         if [ $remaining -gt 0 ]; then
173                 tail -$remaining $collectOutput > $powerOutput
174         else
175                 cp $collectOutput $powerOutput
176         fi
177         echo power data for $testName copied to $collectOutput
178         usbpassthru on
179         sleep 10
180         adb devices
181         sleep 10
182 }
183
184 function start_job {
185         cmdline="$1"
186         echo Running $cmdline
187         (adb shell "cd $devdir && nohup $cmdline > test.out") &
188         sleep 5
189         kill %1 2>/dev/null
190 }
191
192 function cleanup_job {
193         testName=$1
194         processName=$2
195         processName=${processName:=" sh "}
196         set -- $(adb shell ps | tr "\r" " " | grep "$processName")
197         echo killing PID=$2...
198         adb shell kill $2
199         sleep 1
200         echo copying test output to $testName...
201         adb pull $devdir/test.out
202         mv test.out ${testName}.out
203         if [ $restart -gt 0 ]; then
204                 restart_device
205         else
206                 doKeyevent HOME
207         fi
208 }
209
210 function airplane_mode {
211         if [ "$1" = "on" ]; then
212                 mode=true
213                 setting=1
214         else
215                 mode=false
216                 setting=0
217         fi
218         adb shell settings put global airplane_mode_on $setting
219         adb shell am broadcast -a android.intent.action.AIRPLANE_MODE --ez state $mode
220         echo Set airplane mode to $mode
221 }
222
223 function restart_device {
224         adb reboot
225         echo Wait 60s for device to restart...
226         sleep 60
227         while ! adb root
228         do
229                 echo Waiting for device to come up...
230                 sleep 10
231         done
232         echo Wait 30s to complete boot activities...
233         sleep 30
234         echo Restart complete.
235         doSwipe $onSwipe
236         restartfile=${restartfile:="./restarthook"}
237         if [ -f $restartfile ]; then
238                 # hook to change tunables after a restart
239                 . $restartfile
240         fi
241 }
242
243 usbpassthru on
244 adb devices 2>/dev/null
245
246 airplane_mode off
247 if [ $restart -gt 0 ]; then
248         restart_device
249 fi
250
251 echo Copying $scripts to device $devdir...
252 copy_files
253 tests=""
254
255 # measure background power
256 idleTime=${idleTime:=$defaultTime}
257 if [ $idleTime -gt 0 ]; then
258         echo Test 1 : measure idle power for $idleTime minutes
259         run_test idle $idleTime
260         airplane_mode on
261         echo Restarting for power baseline in airplane mode...
262         restart_device
263         run_test idle-airplane $idleTime
264         airplane_mode off
265         # the screen blanks after 30 minutes. The first 2 minutes of the test
266         # have already been filtered off. For our power baseline, keep the first
267         # 20 minutes of the results
268         ((twentyminutes=hz*20*60))
269         powerOutput="idle-power.out"
270         displayPowerOutput="idle-display-power.out"
271         airplanePowerOutput="idle-airplane-power.out"
272         airplaneDisplayPowerOutput="idle-airplane-display-power.out"
273         totalSamples=$(cat $powerOutput | wc -l)
274         if [ $twentyminutes -lt $totalSamples ]; then
275                 head -$twentyminutes $powerOutput > $displayPowerOutput
276                 head -$twentyminutes $airplanePowerOutput > $airplaneDisplayPowerOutput
277         else
278                 cp $powerOutput $displayPowerOutput
279                 cp $airplanePowerOutput $airplaneDisplayPowerOutput
280         fi
281         tests="$tests idle"
282 fi
283
284 recentflingTime=${recentflingTime:=$defaultTime}
285 if [ $recentflingTime -gt 0 ]; then
286         echo $(date) Test 2 : recents fling for $recentflingTime minutes
287         airplane_mode on
288         adb shell "cd $devdir && ./systemapps.sh -A -T -i 1"
289         start_job "./recentfling.sh -N -i 1000 -d $DEVICE"
290         run_test recentfling $recentflingTime
291         cleanup_job recentfling
292         airplane_mode off
293         date
294         tests="$tests recentfling"
295 fi
296
297 suntempleTime=${suntempleTime:=$defaultTime}
298 if [ $suntempleTime -gt 0 ]; then
299         echo $(date) Test 2 : run Sun Temple $suntempleTime minutes
300         airplane_mode on
301         install_suntemple
302         adb shell "am start $suntempleActivity"
303         run_test suntemple $suntempleTime
304         adb pull /sdcard/SunTemple/SunTemple/Saved/Logs/SunTemple.log
305         cleanup_job suntemple BrueComp
306         airplane_mode off
307         mv SunTemple.log suntemple.out
308         # grab the suntemple log
309         date
310         tests="$tests suntemple"
311 fi
312
313 chromeTime=${chromeTime:=$defaultTime}
314 if [ $chromeTime -gt 0 ]; then
315         echo $(date) Test 3 : chrome fling for $chromeTime minutes
316         start_job "./chromefling.sh -i 1000 -d $DEVICE"
317         run_test chrome $chromeTime
318         cleanup_job chrome
319         date
320         tests="$tests chrome"
321 fi
322
323 shadowgrid2Time=${shadowgrid2Time:=$defaultTime}
324 if [ $shadowgrid2Time -gt $shadowgrid2TimeMax ]; then
325         # we cap shadowgrid2 time since the display goes
326         # off after 30 minutes
327         $shadowgrid2Time=$shadowgrid2TimeMax
328 fi
329 if [ $shadowgrid2Time -gt 0 ]; then
330         airplane_mode on
331         echo $(date) Test 4 : shadowgrid2 for $shadowgrid2Time minutes
332         start_job "./$HWUITEST shadowgrid2 100000"
333         run_test shadowgrid2 $shadowgrid2Time
334         cleanup_job shadowgrid2 $HWUITEST
335         airplane_mode off
336         date
337         tests="$tests shadowgrid2"
338 fi
339
340 youtubeTime=${youtubeTime:=$defaultTime}
341 if [ $youtubeTime -gt 0 ]; then
342         echo $(date) Test 5 : youtube for $youtubeTime minutes
343         start_job "./youtube.sh -i 1000 -d $DEVICE"
344         run_test youtube $youtubeTime
345         cleanup_job youtube
346         date
347         tests="$tests youtube"
348 fi
349
350 sysappsTime=${sysappsTime:=$defaultTime}
351 if [ $sysappsTime -gt 0 ]; then
352         echo $(date) Test 6 : app switching for $sysappsTime minutes
353         start_job "./systemapps.sh -T -i 1000 -d $DEVICE"
354         run_test sysapps $sysappsTime
355         cleanup_job sysapps
356         date
357         tests="$tests sysapps"
358 fi
359
360 echo Ran tests: $tests
361 echo $tests > tests
362