1684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos#
2684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos# Script to start a set of apps, switch to recents and fling it back and forth.
3684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos# For each iteration, Total frames and janky frames are reported.
4684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos#
5684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos# Options are described below.
6684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos#
7684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos# Works for volantis, shamu, and hammerhead. Can be pushed and executed on
8684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos# the device.
9684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos#
10684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjositerations=10
11684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjosstartapps=1
12684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjoscapturesystrace=0
13684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos
14684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjosfunction processLocalOption {
15684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	ret=0
16684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	case "$1" in
17684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	(-N) startapps=0;;
18684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	(-A) unset appList;;
19684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	(-L) appList=$2; shift; ret=1;;
20684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	(-T) capturesystrace=1;;
21a87980f7eba9f0d6119fe0e2200087266c514973Todd Kjos	(-B) echo $$ > /dev/cpuset/background/tasks;;
22684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	(*)
23684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos		echo "$0: unrecognized option: $1"
24684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos		echo; echo "Usage: $0 [options]"
25684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos		echo "-A : use all known applications"
26a87980f7eba9f0d6119fe0e2200087266c514973Todd Kjos		echo "-B : run in background cpuset"
27684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos		echo "-L applist : list of applications"
28684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos		echo "   default: $appList"
29684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos		echo "-N : no app startups, just fling"
30684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos		echo "-g : generate activity strings"
31684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos		echo "-i iterations"
32684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos		echo "-T : capture systrace on each iteration"
33684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos		exit 1;;
34684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	esac
35684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	return $ret
36684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos}
37684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos
38684f65f8602d1e1a79170984acc18421fb8f4c98Todd KjosCMDDIR=$(dirname $0 2>/dev/null)
39684f65f8602d1e1a79170984acc18421fb8f4c98Todd KjosCMDDIR=${CMDDIR:=.}
40684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos. $CMDDIR/defs.sh
41684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos
42684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjoscase $DEVICE in
43684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos(shamu|hammerhead)
44684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	flingtime=300
45684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	downCount=2
46684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	upCount=6
47684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	UP="70 400 70 100 $flingtime"
48684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	DOWN="70 100 70 400 $flingtime";;
49a87980f7eba9f0d6119fe0e2200087266c514973Todd Kjos(angler|ariel|mtp8996)
5099eb5eaeb69a8ebb496daa55dc92df4caf268947Todd Kjos	flingtime=150
5199eb5eaeb69a8ebb496daa55dc92df4caf268947Todd Kjos	downCount=4
5299eb5eaeb69a8ebb496daa55dc92df4caf268947Todd Kjos	upCount=3
5399eb5eaeb69a8ebb496daa55dc92df4caf268947Todd Kjos	UP="500 1200 500 550 $flingtime"
5499eb5eaeb69a8ebb496daa55dc92df4caf268947Todd Kjos	DOWN="500 550 500 1200 $flingtime";;
55ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos(bullhead)
56ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos	flingtime=200
57ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos	downCount=5
58ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos	upCount=5
59ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos	UP="500 1200 500 550 $flingtime"
60ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos	DOWN="500 550 500 1200 $flingtime";;
61684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos(volantis)
62684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	flingtime=400
63684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	downCount=5
64684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	upCount=6
65684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	UP="70 400 70 70 $flingtime"
66684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	DOWN="70 70 70 400 $flingtime";;
67684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos(*)
68684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	echo "Error: No display information available for $DEVICE"
69684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	exit 1;;
70684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjosesac
71684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos
72684f65f8602d1e1a79170984acc18421fb8f4c98Todd KjosdoKeyevent HOME
73684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjosif [ $startapps -gt 0 ]; then
74684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos
75684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	# start a bunch of apps
76684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	for app in $appList
77684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	do
78684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos		echo Starting $app ...
79684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos		t=$(startActivity $app)
80684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	done
81684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjosfi
82684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos
83684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjosfunction swipe {
84684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	count=0
85684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	while [ $count -lt $2 ]
86684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	do
87684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos		doSwipe $1
88684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos		((count=count+1))
89684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	done
90684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos}
91684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos
92ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjoscur=1
93ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd KjosframeSum=0
94ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd KjosjankSum=0
95ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjoslatency90Sum=0
96ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjoslatency95Sum=0
97ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjoslatency99Sum=0
98ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos
99684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjosecho Fling recents...
100ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd KjosdoKeyevent HOME
101ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjossleep 0.5
102ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd KjosresetJankyFrames
103684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos
104684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjoswhile [ $cur -le $iterations ]
105684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjosdo
106684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	if [ $capturesystrace -gt 0 ]; then
107684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos		${ADB}atrace --async_start -z -c -b 16000 freq gfx view idle sched
108684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	fi
109ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos	doKeyevent APP_SWITCH
110ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos	sleep 0.5
111684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	swipe "$DOWN" $downCount
112684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	sleep 1
113684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	swipe "$UP" $upCount
114684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	sleep 1
115684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	swipe "$DOWN" $downCount
116684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	sleep 1
117684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	swipe "$UP" $upCount
118684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	sleep 1
119684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	if [ $capturesystrace -gt 0 ]; then
120684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos		${ADB}atrace --async_dump -z -c -b 16000 freq gfx view idle sched > trace.${cur}.out
121684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	fi
122ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos	doKeyevent HOME
123ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos	sleep 0.5
124684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos
125684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	set -- $(getJankyFrames)
126ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos	totalDiff=$1
127ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos	jankyDiff=$2
128ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos	latency90=$3
129ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos	latency95=$4
130ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos	latency99=$5
131ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos	if [ ${totalDiff:=0} -eq 0 ]; then
132ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos		echo Error: could not read frame info with \"dumpsys gfxinfo\"
133ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos	fi
134ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos
135684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	((frameSum=frameSum+totalDiff))
136684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	((jankSum=jankSum+jankyDiff))
137ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos	((latency90Sum=latency90Sum+latency90))
138ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos	((latency95Sum=latency95Sum+latency95))
139ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos	((latency99Sum=latency99Sum+latency99))
140684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	if [ "$totalDiff" -eq 0 ]; then
141684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos		echo Error: no frames detected. Is the display off?
142684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	fi
143684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	((jankPct=jankyDiff*100/totalDiff))
144ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos	resetJankyFrames
145684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos
146ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos	echo Frames: $totalDiff latency: $latency90/$latency95/$latency99 Janks: $jankyDiff\(${jankPct}%\)
147684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos	((cur=cur+1))
148684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjosdone
149684f65f8602d1e1a79170984acc18421fb8f4c98Todd KjosdoKeyevent HOME
150684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos((aveJankPct=jankSum*100/frameSum))
151ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos((aveJanks=jankSum/iterations))
152ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos((aveFrames=frameSum/iterations))
153ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos((aveLatency90=latency90Sum/iterations))
154ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos((aveLatency95=latency95Sum/iterations))
155ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos((aveLatency99=latency99Sum/iterations))
156ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjosecho AVE: Frames: $aveFrames latency: $aveLatency90/$aveLatency95/$aveLatency99 Janks: $aveJanks\(${aveJankPct}%\)
157