Skip to content

Commit d055e77

Browse files
committed
Measure iOS CPU/GPU percentage
For flutter#33899 Test added: - simple_animation_perf_ios Test modified: - backdrop_filter_perf_ios__timeline_summary We'll add the CPU/GPU measurement to more iOS tests once it's proven to be non-flaky.
1 parent c37d06c commit d055e77

10 files changed

Lines changed: 146 additions & 6 deletions

File tree

‎dev/benchmarks/macrobenchmarks/lib/common.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
const String kCullOpacityRouteName = '/cull_opacity';
66
const String kCubicBezierRouteName = '/cubic_bezier';
77
const String kBackdropFilterRouteName = '/backdrop_filter';
8+
const String kSimpleAnimationRouteName = '/simple_animation';

‎dev/benchmarks/macrobenchmarks/lib/main.dart‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'common.dart';
88
import 'src/backdrop_filter.dart';
99
import 'src/cubic_bezier.dart';
1010
import 'src/cull_opacity.dart';
11+
import 'src/simple_animation.dart';
1112

1213
const String kMacrobenchmarks ='Macrobenchmarks';
1314

@@ -24,6 +25,7 @@ class MacrobenchmarksApp extends StatelessWidget {
2425
kCullOpacityRouteName: (BuildContext context) => CullOpacityPage(),
2526
kCubicBezierRouteName: (BuildContext context) => CubicBezierPage(),
2627
kBackdropFilterRouteName: (BuildContext context) => BackdropFilterPage(),
28+
kSimpleAnimationRouteName: (BuildContext conttext) => SimpleAnimationPage(),
2729
},
2830
);
2931
}
@@ -39,24 +41,31 @@ class HomePage extends StatelessWidget {
3941
RaisedButton(
4042
key: const Key(kCullOpacityRouteName),
4143
child: const Text('Cull opacity'),
42-
onPressed: (){
44+
onPressed: () {
4345
Navigator.pushNamed(context, kCullOpacityRouteName);
4446
},
4547
),
4648
RaisedButton(
4749
key: const Key(kCubicBezierRouteName),
4850
child: const Text('Cubic Bezier'),
49-
onPressed: (){
51+
onPressed: () {
5052
Navigator.pushNamed(context, kCubicBezierRouteName);
5153
},
5254
),
5355
RaisedButton(
5456
key: const Key(kBackdropFilterRouteName),
5557
child: const Text('Backdrop Filter'),
56-
onPressed: (){
58+
onPressed: () {
5759
Navigator.pushNamed(context, kBackdropFilterRouteName);
5860
},
5961
),
62+
RaisedButton(
63+
key: const Key(kSimpleAnimationRouteName),
64+
child: const Text('Simple Animation'),
65+
onPressed: () {
66+
Navigator.pushNamed(context, kSimpleAnimationRouteName);
67+
},
68+
),
6069
],
6170
),
6271
);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import 'package:flutter/material.dart';
2+
3+
class SimpleAnimationPage extends StatelessWidget {
4+
@override
5+
Widget build(BuildContext context) {
6+
return Center(child: const LinearProgressIndicator());
7+
}
8+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2019 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter_driver/driver_extension.dart';
6+
import 'package:macrobenchmarks/main.dart' as app;
7+
8+
void main() {
9+
enableFlutterDriverExtension();
10+
app.main();
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2019 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:macrobenchmarks/common.dart';
6+
7+
import 'util.dart';
8+
9+
void main() {
10+
macroPerfTest(
11+
'simple_animation_perf',
12+
kSimpleAnimationRouteName,
13+
);
14+
}

‎dev/devicelab/bin/tasks/backdrop_filter_perf_ios__timeline_summary.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ import 'package:flutter_devicelab/framework/framework.dart';
1010

1111
Future<void> main() async {
1212
deviceOperatingSystem = DeviceOperatingSystem.ios;
13-
await task(createBackdropFilterPerfTest());
13+
await task(createBackdropFilterPerfTest(needsMeasureCpuGpu: true));
1414
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2019 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
6+
import 'package:flutter_devicelab/framework/adb.dart';
7+
import 'package:flutter_devicelab/framework/framework.dart';
8+
import 'package:flutter_devicelab/tasks/perf_tests.dart';
9+
10+
Future<void> main() async {
11+
deviceOperatingSystem = DeviceOperatingSystem.ios;
12+
await task(createSimpleAnimationPerfTest(needsMeasureCpuGpu: true));
13+
}

‎dev/devicelab/lib/framework/utils.dart‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,3 +622,58 @@ void checkFileExists(String file) {
622622
throw FileSystemException('Expected file to exit.', file);
623623
}
624624
}
625+
626+
void _checkExitCode(int code) {
627+
if (code != 0) {
628+
throw Exception(
629+
'Unexpected exit code = $code!',
630+
);
631+
}
632+
}
633+
634+
Future<void> _execAndCheck(String executable, List<String> args) async {
635+
_checkExitCode(await exec(executable, args));
636+
}
637+
638+
// Measure the CPU/GPU percentage for [duration] while a Flutter app is running
639+
// on an iOS device (e.g., right after a Flutter driver test has finished, which
640+
// doesn't close the Flutter app, and the Flutter app has an indefinite
641+
// animation). The return should have a format like the following json
642+
// ```
643+
// {"gpu_percentage":12.6,"cpu_percentage":18.15}
644+
// ```
645+
Future<Map<String, dynamic>> measureIosCpuGpu({
646+
Duration duration = const Duration(seconds: 10),
647+
}) async {
648+
final String basePath = '${flutterDirectory.path}/bin/cache/pkg';
649+
await inDirectory('$basePath', () async {
650+
// We can do this more elegantly in the future (e.g., only delete and clone
651+
// the repo if there isn't a clean one with the expected version hash).
652+
// For now, this takes less than 1 second so we'll use brute-force to pull
653+
// everything every time.
654+
final Directory measureDir = dir('$basePath/measure').absolute;
655+
if (exists(measureDir)) {
656+
await measureDir.delete(recursive: true);
657+
}
658+
await _execAndCheck('git', <String>[
659+
'clone',
660+
'https://github.com/liyuqian/measure.git',
661+
]);
662+
});
663+
return await inDirectory<Map<String,dynamic>>('$basePath/measure', () async {
664+
await _execAndCheck('pub', <String>['get']);
665+
final int code = await dart(<String>[
666+
'bin/main.dart',
667+
'ioscpugpu',
668+
'new',
669+
'-u',
670+
'resources/TraceUtility',
671+
'-t',
672+
'resources/CpuGpuTemplate.tracetemplate',
673+
'-l',
674+
'${duration.inMilliseconds}',
675+
]);
676+
_checkExitCode(code);
677+
return json.decode(File('$basePath/measure/result.json').readAsStringSync());
678+
});
679+
}

‎dev/devicelab/lib/tasks/perf_tests.dart‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,21 @@ TaskFunction createCubicBezierPerfTest() {
5454
).run;
5555
}
5656

57-
TaskFunction createBackdropFilterPerfTest() {
57+
TaskFunction createBackdropFilterPerfTest({bool needsMeasureCpuGpu = false}) {
5858
return PerfTest(
5959
'${flutterDirectory.path}/dev/benchmarks/macrobenchmarks',
6060
'test_driver/backdrop_filter_perf.dart',
6161
'backdrop_filter_perf',
62+
needsMeasureCpuGPu: needsMeasureCpuGpu,
63+
).run;
64+
}
65+
66+
TaskFunction createSimpleAnimationPerfTest({bool needsMeasureCpuGpu = false}) {
67+
return PerfTest(
68+
'${flutterDirectory.path}/dev/benchmarks/macrobenchmarks',
69+
'test_driver/simple_animation_perf.dart',
70+
'simple_animation_perf',
71+
needsMeasureCpuGPu: needsMeasureCpuGpu,
6272
).run;
6373
}
6474

@@ -168,12 +178,18 @@ class StartupTest {
168178
/// Measures application runtime performance, specifically per-frame
169179
/// performance.
170180
class PerfTest {
171-
const PerfTest(this.testDirectory, this.testTarget, this.timelineFileName);
181+
const PerfTest(
182+
this.testDirectory,
183+
this.testTarget,
184+
this.timelineFileName,
185+
{this.needsMeasureCpuGPu = false});
172186

173187
final String testDirectory;
174188
final String testTarget;
175189
final String timelineFileName;
176190

191+
final bool needsMeasureCpuGPu;
192+
177193
Future<TaskResult> run() {
178194
return inDirectory<TaskResult>(testDirectory, () async {
179195
final Device device = await devices.workingDevice;
@@ -202,6 +218,10 @@ class PerfTest {
202218
);
203219
}
204220

221+
if (needsMeasureCpuGPu) {
222+
data.addAll(await measureIosCpuGpu());
223+
}
224+
205225
return TaskResult.success(data, benchmarkScoreKeys: <String>[
206226
'average_frame_build_time_millis',
207227
'worst_frame_build_time_millis',
@@ -213,6 +233,8 @@ class PerfTest {
213233
'missed_frame_rasterizer_budget_count',
214234
'90th_percentile_frame_rasterizer_time_millis',
215235
'99th_percentile_frame_rasterizer_time_millis',
236+
if (needsMeasureCpuGPu) 'cpu_percentage',
237+
if (needsMeasureCpuGPu) 'gpu_percentage',
216238
]);
217239
});
218240
}

‎dev/devicelab/manifest.yaml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,13 @@ tasks:
537537
stage: devicelab_ios
538538
required_agent_capabilities: ["mac/ios"]
539539

540+
simple_animation_perf_ios:
541+
description: >
542+
Measure CPU/GPU usage percentages of a simple animation.
543+
stage: devicelab_ios
544+
flaky: true
545+
required_agent_capabilities: ["mac/ios"]
546+
540547
smoke_catalina_start_up_ios:
541548
description: >
542549
A smoke test that runs on macOS Catalina, which is a clone of the Gallery startup latency test.

0 commit comments

Comments
 (0)