File: pwrsummary.sh

package info (click to toggle)
android-platform-system-extras 7.0.0%2Br33-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,136 kB
  • sloc: cpp: 28,180; ansic: 14,543; python: 5,376; sh: 2,441; java: 908; asm: 299; makefile: 19; xml: 12
file content (235 lines) | stat: -rwxr-xr-x 5,865 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# print summary of output generated by pwrtest.sh
#
# default results directories are <device>-<date>[-experiment]. By default
# match any device and the year 201*.
#
# Examples:
#
# - show output for all bullhead tests in july 2015:
#    ./pwrsummary.sh -r "bh-201507*"
#
# - generate CSV file for import into spreadsheet:
#    ./pwrsummary.sh -o csv
#

CMDDIR=$(dirname $0 2>/dev/null)
CMDDIR=${CMDDIR:=.}
cd $CMDDIR
CMDDIR=$(pwd)
cd -
POWERAVE="python $CMDDIR/powerave.py"

defaultPattern="*-201*"
defaultVoltage=4.3
defaultFrequency=5

function Usage {
	echo "$0 [-o format] [-v voltage] [-h freq] [-f resultsDirectories]"
}

while [ $# -gt 0 ]
do
	case "$1" in
	(-o) format=$2; shift;;
	(-v) voltage=$2; shift;;
	(-h) hz=$2; shift;;
	(-r) testResults="$2"; shift;;
	(--help) Usage; exit 0;;
	(--) shift; break;;
	(*)
		echo Unknown option: $1
		Usage
		exit 1;;
	esac
	shift
done

testResults=${testResults:=$defaultPattern}
voltage=${voltage:=$defaultVoltage}
hz=${hz:=$defaultFrequency}

function printHeader {
	workload=$1
	units="unknown"
	case $workload in
	(suntemple|shadowgrid2)
		units="FPS";;
	(recentfling|youtube|chrome)
		units="FPS from app point of view: 1/(90th percentile render time)";;
	(sysapps)
		units="App start/switch per second";;
	esac

	echo "Performance unit for $workload is: $units"
	if [ "$format" = csv ]; then
		printf "%s,%s,%s,%s,%s,%s,%s,%s,%s\n" " " build min ave max net-mA@${voltage}v base-mW net-mW perf/W
	else
		printf "%-30s %-8s %12.12s %12.12s %12.12s %12.12s %12.12s %12.12s %12.12s\n" " " build min ave max net-mA@${voltage}v base-mW net-mW perf/W
	fi
}

function average {
	awk 'BEGIN { count=0; sum=0; max=-1000000000; min=1000000000; }
	{
		cur = $1;
		sum = sum + cur; 
		if (cur > max) max = cur;
		if (cur < min) min = cur;
		count++;
	}

	END {
		if (count > 0) {
			ave = sum / count;
			printf "%.2f %.2f %.2f\n", min, ave, max; 
		}
	}'
}

function hwuiOutputParser {
	# Stats since: 60659316905953ns
	# Total frames rendered: 150
	# Janky frames: 89 (59.33%)
	# 90th percentile: 23ms
	# 95th percentile: 27ms
	# 99th percentile: 32ms
	# Number Missed Vsync: 0
	# Number High input latency: 0
	# Number Slow UI thread: 0
	# Number Slow bitmap uploads: 12
	# Number Slow draw: 89
	# use with "stdbuf -o0 " to disable pipe buffering
	# stdbuf -o0 adb shell /data/hwuitest shadowgrid2 400 | stdbuf -o0 ./hwuitestfilter.sh  | tee t.csv
	sed -e 's/ns//' -e 's/[\(\)%]/ /g' | awk '
	BEGIN { startTime=0; lastTime=0; }
	/^Stats since:/ {
		curTime = $3;
		if (startTime == 0) {
			startTime = curTime;
		}
		if (lastTime) {
			interval = curTime - lastTime;
			fps = totalFrames*1000000000 / interval;
			diffTime = curTime - startTime;
			printf "%.2f, %.2f, ",diffTime/1000000, fps;
		}
	}
	/^Total frames/ { totalFrames=$4; }
	/^Janky frames:/ {
		if (lastTime) {
			printf "%.2f\n",$4; lastTime=curTime;
		}
		lastTime = curTime;
	}'
}

function sysappOutputParser {
	awk '
	BEGIN { fmt=0; count=0; sum=0; }
	/^App/ {
		if (count != 0) {
			if (fmt > 2) printf "Ave: %0.2fms\n", sum/count;
			else printf " %0.2f\n", sum/count;
			count = 0;
			sum = 0;
		}
	}
	/^[a-z]/ { val=$2; if (val != 0) { count++; sum+=val; } }
	/^Iteration/ { if (fmt > 2) printf "%s : ", $0; else if (fmt) printf "%d ", $2; }
	'
}

function calcPerfData {
	testdir=$1
	workload=$2
	baselineCurrent=$3
	baselinePower=$4

	file=${workload}.out
	powerfile=${workload}-power.out
	build="$(cat build 2>/dev/null)"
	build=${build:="Unknown"}

	lines=$(wc -l $file 2>/dev/null | cut -f1 -d\ )

	if [ ${lines:=0} -eq -0 ]; then
		# No performance data captured
		if [ "$format" = csv ]; then
			printf "%s,%s,%s\n" $testdir "$build" "no data"
		else
			printf "%-30s %-8s %12.12s\n" $testdir "$build" "no data"
		fi
		return 1
	fi

	set -- $($POWERAVE $hz $voltage $powerfile)
	current=$(echo $1 $baselineCurrent | awk '{ printf "%.2f", $1-$2; }')
	power=$(echo $2 $baselinePower | awk '{ printf "%.2f", $1-$2; }')

	case $workload in
	(idle)
		set -- 0 0 0
		;;
	(suntemple)
		# units are fps
		set -- $(grep "FPS average" $file  | sed 's/^.*seconds for a //' | awk '{ print $1; }' | average)
		;;
	(recentfling|youtube|chrome)
		# units are ms, so need to convert to app/ms
		set -- $(grep ^Frames:  $file | tr "/" " " | awk '{ print $4; }' | average | awk '{ printf "%.3f %.3f %.3f\n", 1000/$3, 1000/$2, 1000/$1;}'  )
		;;
	(sysapps)
		# units are ms, so need to convert to app/ms
		set -- $(cat $file | sysappOutputParser | average | awk '{ printf "%.3f %.3f %.3f\n", 1000/$3, 1000/$2, 1000/$1;}'  )
		;;
	(shadowgrid2)
		# units are fps
		set -- $(cat $file | hwuiOutputParser | tr ',' ' ' | awk '{print $2;}' | average)
		;;
	esac

	minperf=$1
	aveperf=$2
	maxperf=$3
	perfPerWatt=$(echo $aveperf $power | awk '{ if ($2) { val=$1*1000/$2; printf "%.3f\n", val; } else print "unknown"; }')
	if [ "$format" = csv ]; then
		printf "%s,%s,%f,%f,%f,%f,%f,%f," $testdir "$build" $minperf $aveperf $maxperf $current $baselinePower $power
		printf "%s\n" $perfPerWatt
	else
		printf "%-30s %-8s %12.2f %12.2f %12.2f %12.2f %12.2f %12.2f " $testdir "$build" $minperf $aveperf $maxperf $current $baselinePower $power
		printf "%12s\n" $perfPerWatt
	fi
}

function calcBaselinePower {
	workload=$1
	defaultPowerFile="idle-display-power.out"
	powerFile=$defaultPowerFile
	case $workload in
	(shadowgrid2|suntemple|recentfling)
		powerFile="idle-airplane-display-power.out"
		if [ ! -f  $powerFile ]; then
			powerFile=$defaultPowerFile
		fi;;
	esac
	if [ -f  $powerFile ]; then
		$POWERAVE 5 4.3 $powerFile
	fi
}

for t in $(cat tests)
do
	echo .======================= $t ================================
	printHeader $t
	for i in $testResults
	do
		cd $i
		baseline="$(calcBaselinePower $t)"
		if [ "$baseline" != "" ]; then
	       		calcPerfData $i $t $baseline
		else
			echo "$i : no baseline current"
		fi
		cd - > /dev/null
	done
done