38 if [ $iterations -lt 100 ]; then
46 echo "Data for $app :"
48 # Activity Manager reports ThisTime and TotalTime. TotalTime seems to be
49 # a more measure of the launch from the users perspective. So using TotalTime
50 # as our metric for launch latency
52 # From Activity Manager
53 echo "Launch Time (TotalTime) :"
54 fgrep TotalTime $infile | awk '{print $2}' | computestats
56 # Data from simpleperf
58 fgrep cpu-cycles $infile | awk '{print $1}' | sed s/,//g | computestats
60 # CPU util% Data from /proc/stat
62 fgrep 'Total CPU util' $infile | awk '{print $5}' | computestatsf
63 echo "user-cpu-util% :"
64 fgrep 'User CPU util' $infile | awk '{print $5}' | computestatsf
65 echo "sys-cpu-util% (incl hardirq/softirq) :"
66 fgrep 'Sys CPU util' $infile | awk '{print $5}' | computestatsf
68 if [ $verbose == true ]; then
69 echo "instructions : "
70 fgrep instructions $infile | awk '{print $1}' | sed s/,//g | computestats
72 echo "cycles per instruction : "
73 fgrep instructions $infile | awk '{print $4}' | sed s/,//g | computestatsf
75 echo "branch-misses : "
76 fgrep branch-misses $infile | awk '{print $1}' | sed s/,//g | computestats
78 echo "context-switches : "
79 fgrep context-switches $infile | awk '{print $1}' | sed s/,//g | computestats
82 fgrep page-faults $infile | awk '{print $1}' | sed s/,//g | computestats
85 if [ $system_bdev_set == true ]; then
86 # (Storage) Data from /proc we've collected
87 echo "KB read for $system_block_device blkdev :"
88 fgrep KB $infile | grep system | awk '{print $5}' | computestats
91 fgrep IOwait $infile | awk '{print $3}' | computestatsf
93 echo "Device util% for $system_block_device blkdev :"
94 fgrep 'Device util' $infile | awk '{print $4}' | computestatsf
99 echo "Setting Governor to performance"
100 if [ $little_cores_off == true ]; then
101 echo "Cannot turn off Little cores on $model"
106 while [ $i -lt $num_cores ]
108 adb shell "echo performance > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_g\
110 adb shell "echo 2499000 > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_fr\
114 # Lock the GPU frequencies
115 echo -n 852000000 > /d/clock/override.gbus/rate
116 echo -n 1 > /d/clock/override.gbus/state
120 echo "Setting Governor to performance"
121 if [ $little_cores_off == true ]; then
122 echo "Cannot turn off Little cores on $model"
127 while [ $i -lt $num_cores ]
129 adb shell "echo performance > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor"
130 adb shell "echo 1833000 > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_freq"
135 cpufreq_marlin_sailfish () {
136 echo "Setting Governor to performance"
137 # GPU Governor and Frequency
138 adb shell 'echo performance > /sys/class/kgsl/kgsl-3d0/devfreq/governor'
139 adb shell 'echo 624000000 > /sys/class/kgsl/kgsl-3d0/devfreq/max_freq'
140 if [ $little_cores_off == true ]; then
141 # Disable Little Cores, force app to run on big cores
142 echo "Disabling Little Cores"
143 adb shell 'echo 0 > /sys/devices/system/cpu/cpu0/online'
144 adb shell 'echo 0 > /sys/devices/system/cpu/cpu1/online'
146 echo "Enabling All Cores"
147 adb shell 'echo 1 > /sys/devices/system/cpu/cpu0/online'
148 adb shell 'echo 1 > /sys/devices/system/cpu/cpu1/online'
149 adb shell 'echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor'
150 adb shell 'echo 1996800 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq'
152 adb shell 'echo performance > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor'
153 adb shell 'echo 1996800 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq'
155 # Set Governor to performance, up scaling_max_frequency to highest
156 adb shell 'echo performance > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor'
157 # Only necessary to set max_freq on cpu2, cpu3 is in same cluster and will
158 # automatically get the same settings
159 adb shell 'echo 2150400 > /sys/devices/system/cpu/cpu2/cpufreq/scaling_max_freq'
163 echo "Setting Governor and Frequency"
164 # GPU Governor and Frequency
165 adb shell "echo performance > /sys/class/kgsl/kgsl-3d0/devfreq/governor"
166 adb shell "echo 0 > /sys/class/kgsl/kgsl-3d0/bus_split"
167 adb shell "echo 1 > /sys/class/kgsl/kgsl-3d0/force_clk_on"
168 adb shell "echo 10000 > /sys/class/kgsl/kgsl-3d0/idle_timer"
169 if [ $little_cores_off == true ]; then
170 # Disable Little Cores, force app to run on big cores
171 echo "Disabling Little Cores"
174 while [ $i -lt $num_cores ]
176 adb shell "echo 0 > /sys/devices/system/cpu/cpu$i/online"
180 echo "Enabling All Cores"
181 # Enable Little cores here, set governor to performance
182 # Lock frequency of little cores
185 while [ $i -lt $num_cores ]
187 adb shell "echo 1 > /sys/devices/system/cpu/cpu$i/online"
188 adb shell "echo performance > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor"
189 # Lock frequency of little cores
190 adb shell "echo 1555200 > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_freq"
196 while [ $i -lt $num_cores ]
198 adb shell "echo performance > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor"
199 # Lock frequency of big cores
200 adb shell "echo 1958400 > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_freq"
206 # This strange bit of logic is needed to get the underlying block devices for /system
207 # for Marlin/Sailfish
209 get_marlin_sailfish_devnames () {
210 # This bit of code required to get the block dev for /system and /vendor
211 # Suffix can be _a or _b, depending on what the active /system partition is
212 # suffix=`adb shell getprop ro.boot.slot_suffix`
213 # Get the blockdevice using the suffix we got above
214 # system_block_device=`adb shell ls -l /dev/block/platform/soc/*ufs*/by-name/system$suffix | awk '{ print $10 }' `
215 # Vendor is more straightforward, but we don't use it right now
216 # vendor_block_device=`adb shell df /vendor | grep -v Filesystem | awk '{print $1}' `
217 # finally extract the last component of the absolute device pathname we got above
218 # system_block_device=`echo $system_block_device | awk 'BEGIN { FS ="/" } ; { print $4 }' `
219 # vendor_block_device=`echo $vendor_block_device | awk 'BEGIN { FS ="/" } ; { print $4 }' `
221 # For now, hardcode sda for Marlin/Sailfish block device
222 # XXX - We'll get stats for entire device
223 system_block_device=sda
224 echo Block Device $system_block_device
227 get_angler_devnames () {
228 # Get the underlying bdev from the "by-name" mapping
229 system_block_device=`adb shell 'find /dev/block/platform -name by-name | xargs ls -l' | grep system | awk '{ print $10 }' `
230 # extract the last component of the absolute device pathname we got above
231 system_block_device=`echo $system_block_device | awk 'BEGIN { FS ="/" } ; { print $4 }' `
232 # vendor is unused right now, but get the bdev anyway in case we decide to use it
233 # Get the underlying bdev from the "by-name" mapping
234 vendor_block_device=`adb shell 'find /dev/block/platform -name by-name | xargs ls -l' | grep vendor | awk '{ print $10 }' `
235 # extract the last component of the absolute device pathname we got above
236 vendor_block_device=`echo $vendor_block_device | awk 'BEGIN { FS ="/" } ; { print $4 }' `
240 get_fugu_devnames () {
241 system_block_device=`adb shell ls -l /dev/block/by-name/system | awk '{ print $10 }' `
242 system_block_device=`echo $system_block_device | awk 'BEGIN { FS ="/" } ; { print $4 }' `
246 get_volantis_devnames () {
247 # Hardcoding all of the mmcblk0 device for now
248 system_block_device=mmcblk0
252 system_stats_before() {
253 if [ $system_bdev_set == true ]; then
254 # Get BEFORE read stats for /system
255 adb shell 'cat /proc/diskstats' | grep -w $system_block_device > /tmp/$model-system
256 BEFORE_RD_IOS_SYSTEM=`awk '{ print $4 }' /tmp/$model-system`
257 BEFORE_RD_SECTORS_SYSTEM=`awk '{ print $6 }' /tmp/$model-system`
258 # iowait% computation
259 adb shell 'cat /proc/stat' | grep -w cpu > /tmp/procstat
260 user_ticks_before=`awk '{ print ($2 + $3) }' /tmp/procstat`
261 sys_ticks_before=`awk '{ print ($4 + $7 + $8) }' /tmp/procstat`
262 cpubusy_ticks_before=`awk '{ print ($2 + $3 + $4 + $7 + $8) }' /tmp/procstat`
263 iowait_ticks_before=`awk '{ print $6 }' /tmp/procstat`
264 total_ticks_before=`awk '{ print ($2 + $3 + $4 + $5 + $7 + $8) }' /tmp/procstat`
265 # Device util% computation
266 # Note hz=100, so multiplying uptime (in seconds) by 100, gives us
268 adb shell 'cat /proc/uptime' > /tmp/uptime
269 uptime_before_hz=`awk '{ print ($1 * 100) }' /tmp/uptime`
270 # Note that the device (busy) ticks is in ms. Since hz=100, dividing
271 # device (busy) ticks by 10, gives us this in the correct ticks units
272 device_util_before_hz=`awk '{ print ($13 / 10) }' /tmp/$model-system`
276 system_stats_after() {
277 if [ $system_bdev_set == true ]; then
278 # Get AFTER read stats for /system
279 adb shell 'cat /proc/diskstats' | grep -w $system_block_device > /tmp/$model-system
280 AFTER_RD_IOS_SYSTEM=`awk '{ print $4 }' /tmp/$model-system`
281 AFTER_RD_SECTORS_SYSTEM=`awk '{ print $6 }' /tmp/$model-system`
282 # iowait% computation
283 adb shell 'cat /proc/stat' | grep -w cpu > /tmp/procstat
284 user_ticks_after=`awk '{ print ($2 + $3) }' /tmp/procstat`
285 sys_ticks_after=`awk '{ print ($4 + $7 + $8) }' /tmp/procstat`
286 cpubusy_ticks_after=`awk '{ print ($2 + $3 + $4 + $7 + $8) }' /tmp/procstat`
287 iowait_ticks_after=`awk '{ print $6 }' /tmp/procstat`
288 total_ticks_after=`awk '{ print ($2 + $3 + $4 + $5 + $7 + $8) }' /tmp/procstat`
289 # Device util% computation
290 # Note hz=100, so multiplying uptime (in seconds) by 100, gives us
292 adb shell 'cat /proc/uptime' > /tmp/uptime
293 uptime_after_hz=`awk '{ print ($1 * 100) }' /tmp/uptime`
294 # Note that the device (busy) ticks is in ms. Since hz=100, dividing
295 # device (busy) ticks by 10, gives us this in the correct ticks units
296 device_util_after_hz=`awk '{ print ($13 / 10) }' /tmp/$model-system`
300 system_stats_delta() {
301 if [ $system_bdev_set == true ]; then
303 READ_KB_SYSTEM=`expr $AFTER_RD_SECTORS_SYSTEM - $BEFORE_RD_SECTORS_SYSTEM`
304 READ_KB_SYSTEM=`expr $READ_KB_SYSTEM / 2`
305 echo Read IOs /system = `expr $AFTER_RD_IOS_SYSTEM - $BEFORE_RD_IOS_SYSTEM`
306 echo Read KB /system = $READ_KB_SYSTEM
307 echo $iowait_ticks_before $iowait_ticks_after $total_ticks_before $total_ticks_after | awk '{ printf "IOwait = %.2f\n", (($2 - $1) * 100.0) / ($4 - $3) }'
308 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) }'
309 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) }'
310 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) }'
311 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) }'
318 adb shell "am force-stop $package"
322 while [ $i -lt $iterations ]
324 if [ $pagecached == false ]; then
325 adb shell 'echo 3 > /proc/sys/vm/drop_caches'
327 # The -W argument to am start forces am start to wait till the launch completes.
328 # The -S argument forces it to kill any existing app that is running first
329 # eg. adb shell 'am start -W -S -n com.android.chrome/com.google.android.apps.chrome.Main'
331 adb shell "simpleperf stat -a am start -W -n $package/$activity"
335 adb shell "am force-stop $package"
342 launch_app com.google.android.youtube.tv com.google.android.apps.youtube.tv.activity.TvGuideActivity > youtube-$model
343 getstats youtube-$model YouTube
344 launch_app com.google.android.play.games com.google.android.gms.games.pano.activity.PanoGamesOnboardHostActivity > games-$model
345 getstats games-$model Games
346 launch_app com.google.android.music com.android.music.activitymanagement.TopLevelActivity > music-$model
347 getstats music-$model Music
350 launch_phone_apps() {
351 launch_app com.android.chrome com.google.android.apps.chrome.Main > chrome-$model
352 getstats chrome-$model Chrome
353 launch_app com.google.android.GoogleCamera com.android.camera.CameraActivity > camera-$model
354 getstats camera-$model Camera
355 launch_app com.google.android.apps.maps com.google.android.maps.MapsActivity > maps-$model
356 getstats maps-$model Maps
357 launch_app com.google.android.youtube com.google.android.apps.youtube.app.WatchWhileActivity > youtube-$model
358 getstats youtube-$model YouTube
362 echo 'Usage: app-launcher [-c|-v] -a|-b|-u num-iterations'
363 echo 'where num-iterations >= 100'
364 echo '-v (optional) for verbose stats dump'
365 echo '-a|-b|-u required:'
367 echo ' -b:only big cores'
368 echo ' -c:pagecached. Do not drop pagecache before each launch (not default)'
369 echo ' -h:Dump this help menu'
370 echo ' -u:user experience, no change to cpu/gpu frequencies or governors'
371 echo ' -a/-b locks CPU/GPU freqs to max, performance governor, thermal/perfd off'
372 echo ' -u runs with default device configs, as users would see it'
377 # The main() part of the script follows :
380 if [ $# -lt 2 ]; then
384 which computestats > /dev/null
386 echo "ERROR: Please add computestats utiliy to your PATH"
390 which computestatsf > /dev/null
392 echo "Error: Please add computestatsf utility to your PATH"
400 if [ $user_experience == false ]; then
401 # Important to stop the thermal-engine to prevent throttling while test is running
403 adb shell 'stop thermal-engine'
404 adb shell 'stop perfd'
406 echo "User Experience: Default Configs. No changes to cpufreq settings"
409 model=`adb shell getprop ro.product.name`
410 # Releases are inconsistent with various trailing characters, remove them all
411 model=`echo $model | sed 's/[ \t\r\n]*$//' `
413 echo Found $model Device
415 system_bdev_set=false
418 if [ $user_experience == false ]; then
419 cpufreq_marlin_sailfish
421 get_marlin_sailfish_devnames
424 if [ $user_experience == false ]; then
430 if [ $user_experience == false ]; then
435 volantis | volantisg)
436 if [ $user_experience == false ]; then
439 get_volantis_devnames
442 echo Unknown Device $model
449 # launch each app in turn
451 if [ $model == "fugu" ]; then