1 # Script to gather perf and perf/watt data for several workloads
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
11 # Default behavior is to run each of the known workloads for
12 # 30 minutes gathering both performance and power data.
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:
25 # Output goes to the current directory.
29 # - Run all tests for 15 minutes (default is 30): ./pwrtest.sh -t 15 -R MDA20
31 # - Use a config file for test times: ./pwrtest.sh -f ./myconfig -R MDA20
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
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)"
58 CMDDIR=$(dirname $0 2>/dev/null)
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;;
73 echo "Reading configs from $configFile..."
76 (-R) echo $2 > ./build; shift;;
82 echo "Unknown option: $1"
91 devdir="/data/local/tmp"
92 suntempledir=${CMDDIR}/suntemple
97 onSwipe="700 1847 700 400 50"
101 onSwipe="500 1200 500 550 150"
105 scripts="defs.sh systemapps.sh recentfling.sh youtube.sh chromefling.sh $HWUITEST"
107 if ! $MONSOON >/dev/null 2>&1; then
108 echo $MONSOON must be in your PATH >&2
112 function usbpassthru {
113 if [ "$1" = off ]; then
118 echo Setting usb pass-thru to $state
119 monsoon.par --usbpassthrough=$state
122 function pwrcollect {
124 collectmin=${collectmin:=60}
125 # samples = hz * 60 * minutes
126 ((samples=5*60*collectmin))
127 monsoon.par --timestamp --samples $samples --hz 5
130 function copy_files {
131 adb shell mkdir -p $devdir
134 adb push $CMDDIR/$file $devdir
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
149 echo dircontents=$dircontents
150 echo Suntemple already installed.
157 collectOutput=${testName}-power-raw.out
158 powerOutput=${testName}-power.out
159 echo -----------------------------------------------------
161 echo enabled Cores $(adb shell "cat /sys/devices/system/cpu/online")
163 echo -----------------------------------------------------
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
175 cp $collectOutput $powerOutput
177 echo power data for $testName copied to $collectOutput
186 echo Running $cmdline
187 (adb shell "cd $devdir && nohup $cmdline > test.out") &
192 function cleanup_job {
195 processName=${processName:=" sh "}
196 set -- $(adb shell ps | tr "\r" " " | grep "$processName")
197 echo killing PID=$2...
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
210 function airplane_mode {
211 if [ "$1" = "on" ]; then
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
223 function restart_device {
225 echo Wait 60s for device to restart...
229 echo Waiting for device to come up...
232 echo Wait 30s to complete boot activities...
234 echo Restart complete.
236 restartfile=${restartfile:="./restarthook"}
237 if [ -f $restartfile ]; then
238 # hook to change tunables after a restart
244 adb devices 2>/dev/null
247 if [ $restart -gt 0 ]; then
251 echo Copying $scripts to device $devdir...
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
261 echo Restarting for power baseline in airplane mode...
263 run_test idle-airplane $idleTime
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
278 cp $powerOutput $displayPowerOutput
279 cp $airplanePowerOutput $airplaneDisplayPowerOutput
284 recentflingTime=${recentflingTime:=$defaultTime}
285 if [ $recentflingTime -gt 0 ]; then
286 echo $(date) Test 2 : recents fling for $recentflingTime minutes
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
294 tests="$tests recentfling"
297 suntempleTime=${suntempleTime:=$defaultTime}
298 if [ $suntempleTime -gt 0 ]; then
299 echo $(date) Test 2 : run Sun Temple $suntempleTime minutes
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
307 mv SunTemple.log suntemple.out
308 # grab the suntemple log
310 tests="$tests suntemple"
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
320 tests="$tests chrome"
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
329 if [ $shadowgrid2Time -gt 0 ]; then
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
337 tests="$tests shadowgrid2"
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
347 tests="$tests youtube"
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
357 tests="$tests sysapps"
360 echo Ran tests: $tests