/
app_loading_perf.go
289 lines (262 loc) · 9.18 KB
/
app_loading_perf.go
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package arc
import (
"context"
"math"
"strings"
"time"
"chromiumos/tast/common/perf"
"chromiumos/tast/errors"
"chromiumos/tast/local/arc"
"chromiumos/tast/local/bundles/cros/arc/apploading"
"chromiumos/tast/local/bundles/cros/arc/nethelper"
"chromiumos/tast/local/chrome"
"chromiumos/tast/local/power/setup"
"chromiumos/tast/local/sysutil"
"chromiumos/tast/testing"
"chromiumos/tast/testing/hwdep"
)
// testParameters contains all the data needed to run a single test iteration.
type testParameters struct {
binaryTranslation bool
}
var (
// arcAppLoadingBooted is a precondition similar to arc.Booted() with no opt-in and disables some heavy Android activities that use system resources.
arcAppLoadingBooted = arc.NewPrecondition("arcapploading_booted", nil /* GAIAVARS */, nil /* GAIALOGINPOOLVARS */, false /* O_DIRECT */, append(arc.DisableSyncFlags(), "--disable-features=FirmwareUpdaterApp")...)
// arcAppLoadingVirtioBlkVMBooted adds feature to boot ARC with virtio-blk /data is enabled.
arcAppLoadingVirtioBlkVMBooted = arc.NewPrecondition("arcapploading_virtio_blk_vmbooted", nil /* GAIAVARS */, nil /* GAIALOGINPOOLVARS */, false /* O_DIRECT */, append(arc.DisableSyncFlags(), "--enable-features=ArcEnableVirtioBlkForData", "--disable-features=FirmwareUpdaterApp")...)
)
func init() {
testing.AddTest(&testing.Test{
Func: AppLoadingPerf,
LacrosStatus: testing.LacrosVariantNeeded,
Desc: "Captures set of apploading performance metrics and uploads them as perf metrics",
Contacts: []string{
"alanding@chromium.org",
"khmel@chromium.org",
"arc-performance@google.com",
},
Attr: []string{"group:crosbolt", "crosbolt_perbuild"},
SoftwareDeps: []string{"chrome"},
Data: []string{apploading.X86ApkName, apploading.ArmApkName},
Timeout: 25 * time.Minute,
Params: []testing.Param{{
ExtraSoftwareDeps: []string{"android_p"},
Val: testParameters{
binaryTranslation: false,
},
Pre: arcAppLoadingBooted,
}, {
Name: "vm",
ExtraSoftwareDeps: []string{"android_vm"},
Val: testParameters{
binaryTranslation: false,
},
Pre: arcAppLoadingBooted,
}, {
Name: "virtio_blk_vm",
ExtraSoftwareDeps: []string{"android_vm"},
Val: testParameters{
binaryTranslation: false,
},
Pre: arcAppLoadingVirtioBlkVMBooted,
}, {
Name: "binarytranslation",
ExtraSoftwareDeps: []string{"android_p"},
ExtraHardwareDeps: hwdep.D(hwdep.X86()),
Val: testParameters{
binaryTranslation: true,
},
Pre: arcAppLoadingBooted,
}, {
Name: "vm_binarytranslation",
ExtraSoftwareDeps: []string{"android_vm"},
ExtraHardwareDeps: hwdep.D(hwdep.X86()),
Val: testParameters{
binaryTranslation: true,
},
Pre: arcAppLoadingBooted,
}},
VarDeps: []string{"arc.AppLoadingPerf.username", "arc.AppLoadingPerf.password"},
})
}
// AppLoadingPerf automates app loading benchmark measurements to simulate
// system resource utilization in terms of memory, file system, networking,
// graphics, ui, etc. that can found in a game or full-featured app. Each
// subflow will be tested separately including separate performance metrics
// uploads. The overall final benchmark score combined and uploaded as well.
func AppLoadingPerf(ctx context.Context, s *testing.State) {
const (
// tbfRateMbit* specifies how fast the data will leave the primary bucket (float).
tbfRateMbitX86 = 10
tbfRateMbitArm = 1.6
// tbfLatency is amount of time a packet can be delayed by token rate before drop (int).
tbfLatencyMs = 18
// tbfBurst is the size of the bucket used by rate option (int).
tbfBurstKbX86 = 10
tbfBurstKbArm = 8
)
// Start network helper to serve requests from the app.
conn, err := nethelper.Start(ctx, apploading.NethelperPort)
if err != nil {
s.Fatal("Failed to start nethelper: ", err)
}
defer func() {
if err := conn.Close(ctx); err != nil {
s.Logf("WARNING: Failed to close nethelper connection: %s", err)
}
}()
// Add initial traffic control queuing discipline settings (b/169947243) for
// traffic shaping based on experiments with netem, RTT latency, and iperf3
// bandwidth measurements. Only kernel version 4.4+ supports tc-tbf.
if ver, arch, err := sysutil.KernelVersionAndArch(); err != nil {
s.Fatal("Failed to get kernel version: ", err)
} else if ver.IsOrLater(4, 4) {
// TODO(b/215621884): Based on ARCVM network team's manual iperf3 bandwidth and Play
// Store game download tests on kukui vs. kukui-arc-r. Targeting simulated performance
// where VM is at ~50% of Container. Need to verify on more ARM boards with Crosbolt data.
var tbfRateMbit float64
var tbfBurstKb int
if strings.HasPrefix(arch, "x86") {
tbfRateMbit = tbfRateMbitX86
tbfBurstKb = tbfBurstKbX86
} else {
tbfRateMbit = tbfRateMbitArm
tbfBurstKb = tbfBurstKbArm
}
if err := conn.AddTcTbf(ctx, tbfRateMbit, tbfLatencyMs, tbfBurstKb); err != nil {
s.Fatal("Failed to add tc-tbf: ", err)
}
}
finalPerfValues := perf.NewValues()
param := s.Param().(testParameters)
// Geometric mean for tests in the same group are computed together. All
// tests where group is not defined will be computed separately using the
// geometric means from other groups.
tests := []struct {
name string
prefix string
subtest string
group string
}{{
name: "MemoryTest",
prefix: "memory",
}, {
name: "FileTest",
prefix: "file_obb",
subtest: "runObbTest",
group: "not_ext4_fs",
}, {
name: "FileTest",
prefix: "file_squashfs",
subtest: "runSquashFSTest",
group: "not_ext4_fs",
}, {
name: "FileTest",
prefix: "file_esd",
subtest: "runEsdTest",
group: "not_ext4_fs",
}, {
name: "FileTest",
prefix: "file_ext4",
subtest: "runExt4Test",
}, {
name: "NetworkTest",
prefix: "network",
}, {
name: "OpenGLTest",
prefix: "opengl",
}, {
name: "DecompressionTest",
prefix: "decompression",
}, {
name: "UITest",
prefix: "ui",
}}
// Obtain specific APK file name for the CPU architecture being tested.
a := s.PreValue().(arc.PreData).ARC
apkName, err := apploading.ApkNameForArch(ctx, a)
if err != nil {
s.Fatal("Failed to get APK name: ", err)
}
config := apploading.TestConfig{
PerfValues: finalPerfValues,
// Don't disable Wifi for network test since ethernet connection in lab is not guaranteed.
// Otherwise tc-tbf settings will not be applied since it would have been disabled and reset.
WifiInterfacesMode: setup.DoNotChangeWifiInterfaces,
ApkPath: s.DataPath(apkName),
OutDir: s.OutDir(),
}
// Many apps / games run with binary translation (b/169623350#comment8)
// and thus it's an important use case to exercise.
if param.binaryTranslation {
config.ApkPath = s.DataPath(apploading.ArmApkName)
}
var scores []float64
groups := make(map[string][]float64)
cr := s.PreValue().(arc.PreData).Chrome
for _, test := range tests {
config.ClassName = test.name
config.Prefix = test.prefix
config.Subtest = test.subtest
score, err := runAppLoadingTest(ctx, config, a, cr)
if err != nil {
s.Fatal("Failed to run apploading test: ", err)
}
// Put scores in the same group together, else add to top-level scores.
if test.group != "" {
groups[test.group] = append(groups[test.group], score)
} else {
scores = append(scores, score)
}
}
// Obtain geometric mean of each group and append to top-level scores.
for _, group := range groups {
score, err := calcGeometricMean(group)
if err != nil {
s.Fatal("Failed to process geometric mean: ", err)
}
scores = append(scores, score)
}
// Calculate grand mean (geometric) of top-level scores which includes the
// geometric means from each group.
totalScore, err := calcGeometricMean(scores)
if err != nil {
s.Fatal("Failed to process geometric mean: ", err)
}
finalPerfValues.Set(
perf.Metric{
Name: "total_score",
Unit: "None",
Direction: perf.BiggerIsBetter,
Multiple: false,
}, totalScore)
s.Logf("Finished all tests with total score: %.2f", totalScore)
s.Log("Uploading perf metrics")
if err := finalPerfValues.Save(s.OutDir()); err != nil {
s.Fatal("Failed to save final perf metrics: ", err)
}
}
// calcGeometricMean computes the geometric mean but use antilog method to
// prevent overflow: EXP((LOG(x1) + LOG(x2) + LOG(x3)) ... + LOG(xn)) / n)
func calcGeometricMean(scores []float64) (float64, error) {
if len(scores) == 0 {
return 0, errors.New("scores can not be empty")
}
var mean float64
for _, score := range scores {
mean += math.Log(score)
}
mean /= float64(len(scores))
return math.Exp(mean), nil
}
// runAppLoadingTest will test each app loading subflow with timeout.
func runAppLoadingTest(ctx context.Context, config apploading.TestConfig, a *arc.ARC, cr *chrome.Chrome) (float64, error) {
shorterCtx, cancel := context.WithTimeout(ctx, 510*time.Second)
defer cancel()
// Each subflow should take no longer than 8.5 minutes based on stainless
// data. If it takes longer, very likely the app is stuck (e.g. b/169367367).
return apploading.RunTest(shorterCtx, config, a, cr)
}