Skip to content

Commit 67b5bdf

Browse files
authored
Reland "Measure iOS CPU/GPU percentage (flutter#41234)" (flutter#41426)
This reverts commit f1e7fe8. This fix is in flutter/packages#39
1 parent 0223565 commit 67b5bdf

11 files changed

Lines changed: 143 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
);

‎dev/benchmarks/macrobenchmarks/lib/src/backdrop_filter.dart‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
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+
15
import 'dart:ui';
26

37
import 'package:flutter/material.dart';
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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/material.dart';
6+
7+
class SimpleAnimationPage extends StatelessWidget {
8+
@override
9+
Widget build(BuildContext context) {
10+
return const Center(child: LinearProgressIndicator());
11+
}
12+
}
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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,3 +622,46 @@ 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+
String deviceId,
648+
}) async {
649+
await _execAndCheck('pub', <String>[
650+
'global',
651+
'activate',
652+
'gauge',
653+
'0.1.4',
654+
]);
655+
656+
await _execAndCheck('pub', <String>[
657+
'global',
658+
'run',
659+
'gauge',
660+
'ioscpugpu',
661+
'new',
662+
if (deviceId != null) ...<String>['-w', deviceId],
663+
'-l',
664+
'${duration.inMilliseconds}',
665+
]);
666+
return json.decode(file('$cwd/result.json').readAsStringSync());
667+
}

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

Lines changed: 26 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,12 @@ class PerfTest {
202218
);
203219
}
204220

221+
if (needsMeasureCpuGPu) {
222+
await inDirectory<void>('$testDirectory/build', () async {
223+
data.addAll(await measureIosCpuGpu(deviceId: deviceId));
224+
});
225+
}
226+
205227
return TaskResult.success(data, benchmarkScoreKeys: <String>[
206228
'average_frame_build_time_millis',
207229
'worst_frame_build_time_millis',
@@ -213,6 +235,8 @@ class PerfTest {
213235
'missed_frame_rasterizer_budget_count',
214236
'90th_percentile_frame_rasterizer_time_millis',
215237
'99th_percentile_frame_rasterizer_time_millis',
238+
if (needsMeasureCpuGPu) 'cpu_percentage',
239+
if (needsMeasureCpuGPu) 'gpu_percentage',
216240
]);
217241
});
218242
}

0 commit comments

Comments
 (0)