mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
A devicelab memory test for Android app suspend and resume (#7164)
This commit is contained in:
parent
7536404b20
commit
2fd786b567
@ -0,0 +1,12 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_devicelab/tasks/perf_tests.dart';
|
||||
import 'package:flutter_devicelab/framework/framework.dart';
|
||||
|
||||
Future<Null> main() async {
|
||||
await task(createGalleryBackButtonMemoryTest());
|
||||
}
|
@ -60,6 +60,13 @@ TaskFunction createGalleryNavigationMemoryTest() {
|
||||
);
|
||||
}
|
||||
|
||||
TaskFunction createGalleryBackButtonMemoryTest() {
|
||||
return new AndroidBackButtonMemoryTest(
|
||||
'${flutterDirectory.path}/examples/flutter_gallery',
|
||||
'io.flutter.examples.gallery',
|
||||
);
|
||||
}
|
||||
|
||||
/// Measure application startup performance.
|
||||
class StartupTest {
|
||||
static const Duration _startupTimeout = const Duration(minutes: 2);
|
||||
@ -256,3 +263,55 @@ class MemoryTest {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Measure application memory usage after pausing and resuming the app
|
||||
/// with the Android back button.
|
||||
class AndroidBackButtonMemoryTest {
|
||||
final String testDirectory;
|
||||
final String packageName;
|
||||
|
||||
AndroidBackButtonMemoryTest(this.testDirectory, this.packageName);
|
||||
|
||||
Future<TaskResult> call() {
|
||||
return inDirectory(testDirectory, () async {
|
||||
if (deviceOperatingSystem != DeviceOperatingSystem.android) {
|
||||
throw 'This test is only supported on Android';
|
||||
}
|
||||
|
||||
AndroidDevice device = await devices.workingDevice;
|
||||
await device.unlock();
|
||||
String deviceId = device.deviceId;
|
||||
await flutter('packages', options: <String>['get']);
|
||||
|
||||
await flutter('run', options: <String>[
|
||||
'-v',
|
||||
'--profile',
|
||||
'--trace-startup', // wait for the first frame to render
|
||||
'-d',
|
||||
deviceId,
|
||||
]);
|
||||
|
||||
Map<String, dynamic> startData = await device.getMemoryStats(packageName);
|
||||
|
||||
Map<String, dynamic> data = <String, dynamic>{
|
||||
'start_total_kb': startData['total_kb'],
|
||||
};
|
||||
|
||||
// Perform a series of back button suspend and resume cycles.
|
||||
for (int i = 0; i < 10; i++) {
|
||||
device.shellExec('input', <String>['keyevent', 'KEYCODE_BACK']);
|
||||
await new Future<Null>.delayed(new Duration(milliseconds: 1000));
|
||||
device.shellExec('am', <String>['start', '-n', 'io.flutter.examples.gallery/org.domokit.sky.shell.SkyActivity']);
|
||||
await new Future<Null>.delayed(new Duration(milliseconds: 1000));
|
||||
}
|
||||
|
||||
Map<String, dynamic> endData = await device.getMemoryStats(packageName);
|
||||
data['end_total_kb'] = endData['total_kb'];
|
||||
data['diff_total_kb'] = endData['total_kb'] - startData['total_kb'];
|
||||
|
||||
await device.stop(packageName);
|
||||
|
||||
return new TaskResult.success(data, benchmarkScoreKeys: data.keys.toList());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -127,6 +127,12 @@ tasks:
|
||||
stage: devicelab
|
||||
required_agent_capabilities: ["has-android-device"]
|
||||
|
||||
flutter_gallery__back_button_memory:
|
||||
description: >
|
||||
Measures memory usage after Android app suspend and resume.
|
||||
stage: devicelab
|
||||
required_agent_capabilities: ["has-android-device"]
|
||||
|
||||
|
||||
# iOS on-device tests
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user