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
42 echo "Usage: $0 [OPTIONS]"
43 echo "-d device : device type (shamu, bullhead, ...)"
44 echo "-f configFile : config file to override individual test times"
45 echo "-g garbageMinutes : time to skip power measurement at beginning of test"
46 echo " default=$garbagetime minutes"
47 echo "-r restart : 0=no reboot between tests, 1=reboot (default)"
48 echo "-t defaultTimeMin : default time to run each test"
49 echo " default=$defaultTime minutes"
50 echo "-D cmddir : directory to find defs.sh"
51 echo "-F restartHookFile : file of commands to set device tunables after restart (optional)"
52 echo "-R release : release running on device (MDA20, 2054728, etc)"
59 CMDDIR=$(dirname $0 2>/dev/null)
67 (-D) CMDDIR=$2; shift;;
68 (-r) restart=$2; shift;;
69 (-t) defaultTime=$2; shift;;
70 (-F) restartfile=$2; shift;;
71 (-g) garbageminutes=$2; shift;;
74 echo "Reading configs from $configFile..."
77 (-R) echo $2 > ./build; shift;;
83 echo "Unknown option: $1"
92 devdir="/data/local/tmp"
93 suntempledir=${CMDDIR}/suntemple
98 onSwipe="700 1847 700 400 50"
101 HWUIMACRO=hwuimacro64
102 onSwipe="500 1200 500 550 150"
106 scripts="defs.sh systemapps.sh recentfling.sh youtube.sh chromefling.sh"
108 if ! $MONSOON >/dev/null 2>&1; then
109 echo $MONSOON must be in your PATH >&2
113 function usbpassthru {
114 if [ "$1" = off ]; then
119 echo Setting usb pass-thru to $state
120 monsoon.par --usbpassthrough=$state
123 function pwrcollect {
125 collectmin=${collectmin:=60}
126 # samples = hz * 60 * minutes
127 ((samples=5*60*collectmin))
128 monsoon.par --timestamp --samples $samples --hz 5
131 function copy_files {
132 adb shell mkdir -p $devdir
135 adb push $CMDDIR/$file $devdir
139 function install_suntemple {
140 echo Checking for suntemple installation...
141 #stdest=/storage/sdcard0/obb/com.BrueComputing.SunTemple
142 stdest=/storage/emulated/0/obb/com.BrueComputing.SunTemple
143 dircontents=$(adb ls $stdest 2>/dev/null)
144 if [ "$dircontents" = "" ]; then
145 echo Installing suntemple...
146 adb install $suntempledir/*.apk
147 adb shell mkdir -p $stdest
148 adb push $suntempledir/main*obb $stdest
150 echo dircontents=$dircontents
151 echo Suntemple already installed.
158 collectOutput=${testName}-power-raw.out
159 powerOutput=${testName}-power.out
160 echo -----------------------------------------------------
162 echo enabled Cores $(adb shell "cat /sys/devices/system/cpu/online")
164 echo -----------------------------------------------------
166 pwrcollect $collectMinutes > $collectOutput 2>/dev/null
167 # take off the first 2min of samples
168 totalSamples=$(cat $collectOutput | wc -l)
169 # we throw away the first "garbageminutes" of the data
170 # since it is volatile
171 ((garbage=hz*60*garbageminutes))
172 ((remaining=totalSamples-garbage))
173 if [ $remaining -gt 0 ]; then
174 tail -$remaining $collectOutput > $powerOutput
176 cp $collectOutput $powerOutput
178 echo power data for $testName copied to $collectOutput
187 echo Running $cmdline
188 (adb shell "cd $devdir && nohup $cmdline > test.out") &
193 function cleanup_job {
196 processName=${processName:=" sh "}
197 set -- $(adb shell ps | tr "\r" " " | grep "$processName")
198 echo killing PID=$2...
201 echo copying test output to $testName...
202 adb pull $devdir/test.out
203 mv test.out ${testName}.out
204 if [ $restart -gt 0 ]; then
211 function airplane_mode {
212 if [ "$1" = "on" ]; then
219 adb shell settings put global airplane_mode_on $setting
220 adb shell am broadcast -a android.intent.action.AIRPLANE_MODE --ez state $mode
221 echo Set airplane mode to $mode
224 function restart_device {
226 echo Wait 60s for device to restart...
230 echo Waiting for device to come up...
233 echo Wait 30s to complete boot activities...
235 echo Restart complete.
239 restartfile=${restartfile:="./restarthook"}
240 if [ -f $restartfile ]; then
241 # hook to change tunables after a restart
247 adb devices 2>/dev/null
250 if [ $restart -gt 0 ]; then
254 echo Copying $scripts to device $devdir...
256 adb shell ln -s /data/benchmarktest/hwuimacro/$HWUIMACRO $devdir/$HWUIMACRO
259 # measure background power
260 idleTime=${idleTime:=$defaultTime}
261 if [ $idleTime -gt 0 ]; then
262 echo Test 1 : measure idle power for $idleTime minutes
263 run_test idle $idleTime
265 echo Restarting for power baseline in airplane mode...
267 run_test idle-airplane $idleTime
269 # the screen blanks after 30 minutes. The first 2 minutes of the test
270 # have already been filtered off. For our power baseline, keep the first
271 # 20 minutes of the results
272 ((twentyminutes=hz*20*60))
273 powerOutput="idle-power.out"
274 displayPowerOutput="idle-display-power.out"
275 airplanePowerOutput="idle-airplane-power.out"
276 airplaneDisplayPowerOutput="idle-airplane-display-power.out"
277 totalSamples=$(cat $powerOutput | wc -l)
278 if [ $twentyminutes -lt $totalSamples ]; then
279 head -$twentyminutes $powerOutput > $displayPowerOutput
280 head -$twentyminutes $airplanePowerOutput > $airplaneDisplayPowerOutput
282 cp $powerOutput $displayPowerOutput
283 cp $airplanePowerOutput $airplaneDisplayPowerOutput
288 recentflingTime=${recentflingTime:=$defaultTime}
289 if [ $recentflingTime -gt 0 ]; then
290 echo $(date) Test 2 : recents fling for $recentflingTime minutes
292 adb shell "cd $devdir && ./systemapps.sh -A -T -i 1"
293 start_job "./recentfling.sh -N -i 1000 -d $DEVICE"
294 run_test recentfling $recentflingTime
295 cleanup_job recentfling
298 tests="$tests recentfling"
301 suntempleTime=${suntempleTime:=$defaultTime}
302 if [ $suntempleTime -gt 0 ]; then
303 echo $(date) Test 2 : run Sun Temple $suntempleTime minutes
306 adb shell "am start $suntempleActivity"
307 run_test suntemple $suntempleTime
308 adb pull /sdcard/SunTemple/SunTemple/Saved/Logs/SunTemple.log
309 cleanup_job suntemple BrueComp
311 mv SunTemple.log suntemple.out
312 # grab the suntemple log
314 tests="$tests suntemple"
317 chromeTime=${chromeTime:=$defaultTime}
318 if [ $chromeTime -gt 0 ]; then
319 echo $(date) Test 3 : chrome fling for $chromeTime minutes
320 start_job "./chromefling.sh -i 1000 -d $DEVICE"
321 run_test chrome $chromeTime
324 tests="$tests chrome"
327 shadowgrid2Time=${shadowgrid2Time:=$defaultTime}
328 if [ $shadowgrid2Time -gt $shadowgrid2TimeMax ]; then
329 # we cap shadowgrid2 time since the display goes
330 # off after 30 minutes
331 $shadowgrid2Time=$shadowgrid2TimeMax
333 if [ $shadowgrid2Time -gt 0 ]; then
335 echo $(date) Test 4 : shadowgrid2 for $shadowgrid2Time minutes
336 start_job "./$HWUIMACRO --onscreen shadowgrid2 100000"
337 run_test shadowgrid2 $shadowgrid2Time
338 cleanup_job shadowgrid2 $HWUIMACRO
341 tests="$tests shadowgrid2"
344 youtubeTime=${youtubeTime:=$defaultTime}
345 if [ $youtubeTime -gt 0 ]; then
346 echo $(date) Test 5 : youtube for $youtubeTime minutes
347 start_job "./youtube.sh -i 1000 -d $DEVICE"
348 run_test youtube $youtubeTime
351 tests="$tests youtube"
354 sysappsTime=${sysappsTime:=$defaultTime}
355 if [ $sysappsTime -gt 0 ]; then
356 echo $(date) Test 6 : app switching for $sysappsTime minutes
357 start_job "./systemapps.sh -T -i 1000 -d $DEVICE"
358 run_test sysapps $sysappsTime
361 tests="$tests sysapps"
364 echo Ran tests: $tests