46 if [ $iterations -lt 100 ]; then
54 echo "Data for $app :"
56 # Activity Manager reports ThisTime and TotalTime. TotalTime seems to be
57 # a more measure of the launch from the users perspective. So using TotalTime
58 # as our metric for launch latency
60 # From Activity Manager
61 echo "Launch Time (TotalTime) :"
62 fgrep TotalTime $infile | awk '{print $2}' | computestats
64 # Data from simpleperf
66 fgrep cpu-cycles $infile | awk '{print $1}' | sed s/,//g | computestats
68 # CPU util% Data from /proc/stat
70 fgrep 'Total CPU util' $infile | awk '{print $5}' | computestatsf
71 echo "user-cpu-util% :"
72 fgrep 'User CPU util' $infile | awk '{print $5}' | computestatsf
73 echo "sys-cpu-util% (incl hardirq/softirq) :"
74 fgrep 'Sys CPU util' $infile | awk '{print $5}' | computestatsf
76 if [ $verbose == true ]; then
77 echo "instructions : "
78 fgrep instructions $infile | awk '{print $1}' | sed s/,//g | computestats
80 echo "cycles per instruction : "
81 fgrep instructions $infile | awk '{print $4}' | sed s/,//g | computestatsf
83 echo "branch-misses : "
84 fgrep branch-misses $infile | awk '{print $1}' | sed s/,//g | computestats
86 echo "context-switches : "
87 fgrep context-switches $infile | awk '{print $1}' | sed s/,//g | computestats
90 fgrep page-faults $infile | awk '{print $1}' | sed s/,//g | computestats
93 if [ $system_bdev_set == true ]; then
94 # (Storage) Data from /proc we've collected
95 echo "KB read for $system_block_device blkdev :"
96 fgrep KB $infile | grep system | awk '{print $5}' | computestats
99 fgrep IOwait $infile | awk '{print $3}' | computestatsf
101 echo "Device util% for $system_block_device blkdev :"
102 fgrep 'Device util' $infile | awk '{print $4}' | computestatsf
107 echo "Setting Governor to performance"
108 if [ $little_cores_off == true ]; then
109 echo "Cannot turn off Little cores on $model"
114 while [ $i -lt $num_cores ]
116 $adb shell "echo performance > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_g\
118 $adb shell "echo 2499000 > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_fr\
122 # Lock the GPU frequencies
123 echo -n 852000000 > /d/clock/override.gbus/rate
124 echo -n 1 > /d/clock/override.gbus/state
128 echo "Setting Governor to performance"
129 if [ $little_cores_off == true ]; then
130 echo "Cannot turn off Little cores on $model"
135 while [ $i -lt $num_cores ]
137 $adb shell "echo performance > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor"
138 $adb shell "echo 1833000 > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_freq"
143 cpufreq_taimen_walleye () {
144 echo "Setting Governor to performance"
145 # GPU Governor and Frequency
146 $adb shell 'echo performance > /sys/class/kgsl/kgsl-3d0/devfreq/governor'
147 $adb shell 'echo 624000000 > /sys/class/kgsl/kgsl-3d0/devfreq/max_freq'
148 if [ $little_cores_off == true ]; then
149 # Disable Little Cores, force app to run on big cores
150 echo "Disabling Little Cores"
151 $adb shell 'echo 0 > /sys/devices/system/cpu/cpu0/online'
152 $adb shell 'echo 0 > /sys/devices/system/cpu/cpu1/online'
153 $adb shell 'echo 0 > /sys/devices/system/cpu/cpu2/online'
154 $adb shell 'echo 0 > /sys/devices/system/cpu/cpu3/online'
156 echo "Enabling All Cores"
157 $adb shell 'echo 1 > /sys/devices/system/cpu/cpu0/online'
158 $adb shell 'echo 1 > /sys/devices/system/cpu/cpu1/online'
159 $adb shell 'echo 1 > /sys/devices/system/cpu/cpu2/online'
160 $adb shell 'echo 1 > /sys/devices/system/cpu/cpu3/online'
161 $adb shell 'echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor'
162 $adb shell 'echo 1900800 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq'
164 # Set Governor to performance, up scaling_max_frequency to highest
165 $adb shell 'echo performance > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor'
166 # Only necessary to set max_freq on cpu4, cpu5-7 are in same cluster and will
167 # automatically get the same settings
168 $adb shell 'echo 2457600 > /sys/devices/system/cpu/cpu2/cpufreq/scaling_max_freq'
171 cpufreq_marlin_sailfish () {
172 echo "Setting Governor to performance"
173 # GPU Governor and Frequency
174 $adb shell 'echo performance > /sys/class/kgsl/kgsl-3d0/devfreq/governor'
175 $adb shell 'echo 624000000 > /sys/class/kgsl/kgsl-3d0/devfreq/max_freq'
176 if [ $little_cores_off == true ]; then
177 # Disable Little Cores, force app to run on big cores
178 echo "Disabling Little Cores"
179 $adb shell 'echo 0 > /sys/devices/system/cpu/cpu0/online'
180 $adb shell 'echo 0 > /sys/devices/system/cpu/cpu1/online'
182 echo "Enabling All Cores"
183 $adb shell 'echo 1 > /sys/devices/system/cpu/cpu0/online'
184 $adb shell 'echo 1 > /sys/devices/system/cpu/cpu1/online'
185 $adb shell 'echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor'
186 $adb shell 'echo 1996800 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq'
188 $adb shell 'echo performance > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor'
189 $adb shell 'echo 1996800 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq'
191 # Set Governor to performance, up scaling_max_frequency to highest
192 $adb shell 'echo performance > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor'
193 # Only necessary to set max_freq on cpu2, cpu3 is in same cluster and will
194 # automatically get the same settings
195 $adb shell 'echo 2150400 > /sys/devices/system/cpu/cpu2/cpufreq/scaling_max_freq'
199 echo "Setting Governor and Frequency"
200 # GPU Governor and Frequency
201 $adb shell "echo performance > /sys/class/kgsl/kgsl-3d0/devfreq/governor"
202 $adb shell "echo 0 > /sys/class/kgsl/kgsl-3d0/bus_split"
203 $adb shell "echo 1 > /sys/class/kgsl/kgsl-3d0/force_clk_on"
204 $adb shell "echo 10000 > /sys/class/kgsl/kgsl-3d0/idle_timer"
205 if [ $little_cores_off == true ]; then
206 # Disable Little Cores, force app to run on big cores
207 echo "Disabling Little Cores"
210 while [ $i -lt $num_cores ]
212 $adb shell "echo 0 > /sys/devices/system/cpu/cpu$i/online"
216 echo "Enabling All Cores"
217 # Enable Little cores here, set governor to performance
218 # Lock frequency of little cores
221 while [ $i -lt $num_cores ]
223 $adb shell "echo 1 > /sys/devices/system/cpu/cpu$i/online"
224 $adb shell "echo performance > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor"
225 # Lock frequency of little cores
226 $adb shell "echo 1555200 > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_freq"
232 while [ $i -lt $num_cores ]
234 $adb shell "echo performance > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor"
235 # Lock frequency of big cores
236 $adb shell "echo 1958400 > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_freq"
241 get_taimen_walleye_devnames () {
242 # This bit of code required to get the block dev for /system and /vendor
243 # Suffix can be _a or _b, depending on what the active /system partition is
244 # suffix=`$adb shell getprop ro.boot.slot_suffix`
245 # Get the blockdevice using the suffix we got above
246 # system_block_device=`$adb shell ls -l /dev/block/platform/soc/*ufs*/by-name/system$suffix | awk '{ print $10 }' `
247 # Vendor is more straightforward, but we don't use it right now
248 # vendor_block_device=`$adb shell df /vendor | grep -v Filesystem | awk '{print $1}' `
249 # finally extract the last component of the absolute device pathname we got above
250 # system_block_device=`echo $system_block_device | awk 'BEGIN { FS ="/" } ; { print $4 }' `
251 # vendor_block_device=`echo $vendor_block_device | awk 'BEGIN { FS ="/" } ; { print $4 }' `
253 # For now, hardcode sda for Marlin/Sailfish block device
254 # XXX - We'll get stats for entire device
255 system_block_device=sda
256 echo Block Device $system_block_device
260 # This strange bit of logic is needed to get the underlying block devices for /system
261 # for Marlin/Sailfish
263 get_marlin_sailfish_devnames () {
264 # This bit of code required to get the block dev for /system and /vendor
265 # Suffix can be _a or _b, depending on what the active /system partition is
266 # suffix=`$adb shell getprop ro.boot.slot_suffix`
267 # Get the blockdevice using the suffix we got above
268 # system_block_device=`$adb shell ls -l /dev/block/platform/soc/*ufs*/by-name/system$suffix | awk '{ print $10 }' `
269 # Vendor is more straightforward, but we don't use it right now
270 # vendor_block_device=`$adb shell df /vendor | grep -v Filesystem | awk '{print $1}' `
271 # finally extract the last component of the absolute device pathname we got above
272 # system_block_device=`echo $system_block_device | awk 'BEGIN { FS ="/" } ; { print $4 }' `
273 # vendor_block_device=`echo $vendor_block_device | awk 'BEGIN { FS ="/" } ; { print $4 }' `
275 # For now, hardcode sda for Marlin/Sailfish block device
276 # XXX - We'll get stats for entire device
277 system_block_device=sda
278 echo Block Device $system_block_device
281 get_angler_devnames () {
282 # Get the underlying bdev from the "by-name" mapping
283 system_block_device=`$adb shell 'find /dev/block/platform -name by-name | xargs ls -l' | grep system | awk '{ print $10 }' `
284 # extract the last component of the absolute device pathname we got above
285 system_block_device=`echo $system_block_device | awk 'BEGIN { FS ="/" } ; { print $4 }' `
286 # vendor is unused right now, but get the bdev anyway in case we decide to use it
287 # Get the underlying bdev from the "by-name" mapping
288 vendor_block_device=`$adb shell 'find /dev/block/platform -name by-name | xargs ls -l' | grep vendor | awk '{ print $10 }' `
289 # extract the last component of the absolute device pathname we got above
290 vendor_block_device=`echo $vendor_block_device | awk 'BEGIN { FS ="/" } ; { print $4 }' `
294 get_fugu_devnames () {
295 system_block_device=`$adb shell ls -l /dev/block/by-name/system | awk '{ print $10 }' `
296 system_block_device=`echo $system_block_device | awk 'BEGIN { FS ="/" } ; { print $4 }' `
300 get_volantis_devnames () {
301 # Hardcoding all of the mmcblk0 device for now
302 system_block_device=mmcblk0
306 system_stats_before() {
307 if [ $system_bdev_set == true ]; then
308 # Get BEFORE read stats for /system
309 $adb shell 'cat /proc/diskstats' | grep -w $system_block_device > /tmp/$model-system
310 BEFORE_RD_IOS_SYSTEM=`awk '{ print $4 }' /tmp/$model-system`
311 BEFORE_RD_SECTORS_SYSTEM=`awk '{ print $6 }' /tmp/$model-system`
312 # iowait% computation
313 $adb shell 'cat /proc/stat' | grep -w cpu > /tmp/procstat
314 user_ticks_before=`awk '{ print ($2 + $3) }' /tmp/procstat`
315 sys_ticks_before=`awk '{ print ($4 + $7 + $8) }' /tmp/procstat`
316 cpubusy_ticks_before=`awk '{ print ($2 + $3 + $4 + $7 + $8) }' /tmp/procstat`
317 iowait_ticks_before=`awk '{ print $6 }' /tmp/procstat`
318 total_ticks_before=`awk '{ print ($2 + $3 + $4 + $5 + $7 + $8) }' /tmp/procstat`
319 # Device util% computation
320 # Note hz=100, so multiplying uptime (in seconds) by 100, gives us
322 $adb shell 'cat /proc/uptime' > /tmp/uptime
323 uptime_before_hz=`awk '{ print ($1 * 100) }' /tmp/uptime`
324 # Note that the device (busy) ticks is in ms. Since hz=100, dividing
325 # device (busy) ticks by 10, gives us this in the correct ticks units
326 device_util_before_hz=`awk '{ print ($13 / 10) }' /tmp/$model-system`
330 system_stats_after() {
331 if [ $system_bdev_set == true ]; then
332 # Get AFTER read stats for /system
333 $adb shell 'cat /proc/diskstats' | grep -w $system_block_device > /tmp/$model-system
334 AFTER_RD_IOS_SYSTEM=`awk '{ print $4 }' /tmp/$model-system`
335 AFTER_RD_SECTORS_SYSTEM=`awk '{ print $6 }' /tmp/$model-system`
336 # iowait% computation
337 $adb shell 'cat /proc/stat' | grep -w cpu > /tmp/procstat
338 user_ticks_after=`awk '{ print ($2 + $3) }' /tmp/procstat`
339 sys_ticks_after=`awk '{ print ($4 + $7 + $8) }' /tmp/procstat`
340 cpubusy_ticks_after=`awk '{ print ($2 + $3 + $4 + $7 + $8) }' /tmp/procstat`
341 iowait_ticks_after=`awk '{ print $6 }' /tmp/procstat`
342 total_ticks_after=`awk '{ print ($2 + $3 + $4 + $5 + $7 + $8) }' /tmp/procstat`
343 # Device util% computation
344 # Note hz=100, so multiplying uptime (in seconds) by 100, gives us
346 $adb shell 'cat /proc/uptime' > /tmp/uptime
347 uptime_after_hz=`awk '{ print ($1 * 100) }' /tmp/uptime`
348 # Note that the device (busy) ticks is in ms. Since hz=100, dividing
349 # device (busy) ticks by 10, gives us this in the correct ticks units
350 device_util_after_hz=`awk '{ print ($13 / 10) }' /tmp/$model-system`
354 system_stats_delta() {
355 if [ $system_bdev_set == true ]; then
357 READ_KB_SYSTEM=`expr $AFTER_RD_SECTORS_SYSTEM - $BEFORE_RD_SECTORS_SYSTEM`
358 READ_KB_SYSTEM=`expr $READ_KB_SYSTEM / 2`
359 echo Read IOs /system = `expr $AFTER_RD_IOS_SYSTEM - $BEFORE_RD_IOS_SYSTEM`
360 echo Read KB /system = $READ_KB_SYSTEM
361 echo $iowait_ticks_before $iowait_ticks_after $total_ticks_before $total_ticks_after | awk '{ printf "IOwait = %.2f\n", (($2 - $1) * 100.0) / ($4 - $3) }'
362 echo $device_util_before_hz $device_util_after_hz $uptime_before_hz $uptime_after_hz | awk '{ printf "Device util% = %.2f\n", (($2 - $1) * 100.0) / ($4 - $3) }'
363 echo $user_ticks_after $user_ticks_before $total_ticks_after $total_ticks_before | awk '{ printf "User CPU util% = %.2f\n", (($1 - $2) * 100.0) / ($3 - $4) }'
364 echo $sys_ticks_after $sys_ticks_before $total_ticks_after $total_ticks_before | awk '{ printf "Sys CPU util% = %.2f\n", (($1 - $2) * 100.0) / ($3 - $4) }'
365 echo $cpubusy_ticks_after $cpubusy_ticks_before $total_ticks_after $total_ticks_before | awk '{ printf "Total CPU util% = %.2f\n", (($1 - $2) * 100.0) / ($3 - $4) }'
372 $adb shell "am force-stop $package"
375 printf "Testing %s: \n" "$package" 1>&2
377 while [ $i -lt $iterations ]
379 if [ $pagecached == false ]; then
380 $adb shell 'echo 3 > /proc/sys/vm/drop_caches'
382 printf '[ %d%% ]\r' "$(($i * 100 / $iterations))" 1>&2
383 # The -W argument to am start forces am start to wait till the launch completes.
384 # The -S argument forces it to kill any existing app that is running first
385 # eg. adb shell 'am start -W -S -n com.android.chrome/com.google.android.apps.chrome.Main'
387 $adb shell "simpleperf stat -a am start -W -n $package/$activity"
391 $adb shell "am force-stop $package"
399 launch_app com.google.android.youtube.tv com.google.android.apps.youtube.tv.activity.TvGuideActivity > youtube-$model
400 getstats youtube-$model YouTube
401 launch_app com.google.android.play.games com.google.android.gms.games.pano.activity.PanoGamesOnboardHostActivity > games-$model
402 getstats games-$model Games
403 launch_app com.google.android.music com.android.music.activitymanagement.TopLevelActivity > music-$model
404 getstats music-$model Music
407 launch_phone_apps() {
408 launch_app com.android.chrome com.google.android.apps.chrome.Main > chrome-$model
409 getstats chrome-$model Chrome
410 launch_app com.google.android.GoogleCamera com.android.camera.CameraActivity > camera-$model
411 getstats camera-$model Camera
412 launch_app com.google.android.apps.maps com.google.android.maps.MapsActivity > maps-$model
413 getstats maps-$model Maps
414 launch_app com.google.android.youtube com.google.android.apps.youtube.app.WatchWhileActivity > youtube-$model
415 getstats youtube-$model YouTube
419 echo 'Usage: app-launcher [-c|-v|-s <serial num>] -a|-b|-u num-iterations'
420 echo 'where num-iterations >= 100'
421 echo '-v (optional) for verbose stats dump'
422 echo '-s <serial num> (optional) run test on specific device'
423 echo '-a|-b|-u required:'
425 echo ' -b:only big cores'
426 echo ' -c:pagecached. Do not drop pagecache before each launch (not default)'
427 echo ' -h:Dump this help menu'
428 echo ' -u:user experience, no change to cpu/gpu frequencies or governors'
429 echo ' -a/-b locks CPU/GPU freqs to max, performance governor, thermal/perfd off'
430 echo ' -u runs with default device configs, as users would see it'
435 # Disable automatic rotation, NFC and wifi
436 # This works on OC, but haven't tested on NYC or earlier
437 $adb shell 'content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0'
438 $adb shell 'svc nfc disable'
439 $adb shell 'svc wifi disable'
441 # Set developer options, will automatically 'Stay Awake'
442 $adb shell 'am start -n com.android.settings/.DevelopmentSettings'
443 # Set screen timeout to 30 minutes
444 $adb shell 'settings put system screen_off_timeout 1800000'
445 # Clear all notifications
446 $adb shell 'service call notification 1'
448 $adb shell 'input keyevent KEYCODE_WAKEUP' && sleep 0.5
449 $adb shell 'input keyevent KEYCODE_ENTER' && sleep 0.5
450 $adb shell 'input keyevent KEYCODE_HOME' && sleep 0.5
452 # TODO: kill all background apps
457 # The main() part of the script follows :
460 if [ $# -lt 2 ]; then
464 which computestats > /dev/null
466 echo "ERROR: Please add computestats utiliy to your PATH"
470 which computestatsf > /dev/null
472 echo "Error: Please add computestatsf utility to your PATH"
478 $adb root && $adb wait-for-device
480 if [ $user_experience == false ]; then
481 # Important to stop the thermal-engine to prevent throttling while test is running
483 $adb shell 'stop thermal-engine'
484 $adb shell 'stop perfd'
486 echo "User Experience: Default Configs. No changes to cpufreq settings"
489 model=`$adb shell getprop ro.product.name`
490 # Releases are inconsistent with various trailing characters, remove them all
491 model=`echo $model | sed 's/[ \t\r\n]*$//' `
493 echo Found $model Device
495 system_bdev_set=false
497 taimen | muskie | walleye)
498 if [ $user_experience == false ]; then
499 cpufreq_taimen_walleye
501 get_taimen_walleye_devnames
504 if [ $user_experience == false ]; then
505 cpufreq_marlin_sailfish
507 get_marlin_sailfish_devnames
510 if [ $user_experience == false ]; then
516 if [ $user_experience == false ]; then
521 volantis | volantisg)
522 if [ $user_experience == false ]; then
525 get_volantis_devnames
528 echo Unknown Device $model
536 # launch each app in turn
538 if [ $model == "fugu" ]; then