Commit 2563636d authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

A devicelab test of memory usage for a minimal app (#7126)

parent 45a4f639
// 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(createHelloWorldMemoryTest());
}
......@@ -20,9 +20,8 @@ TaskFunction createComplexLayoutScrollPerfTest() {
TaskFunction createComplexLayoutScrollMemoryTest() {
return new MemoryTest(
'${flutterDirectory.path}/dev/benchmarks/complex_layout',
'test_driver/scroll_perf.dart',
'complex_layout_scroll_perf',
'com.yourcompany.complexLayout',
testTarget: 'test_driver/scroll_perf.dart',
);
}
......@@ -46,6 +45,13 @@ TaskFunction createComplexLayoutBuildTest() {
return new BuildTest('${flutterDirectory.path}/dev/benchmarks/complex_layout');
}
TaskFunction createHelloWorldMemoryTest() {
return new MemoryTest(
'${flutterDirectory.path}/examples/hello_world',
'io.flutter.examples.HelloWorld',
);
}
/// Measure application startup performance.
class StartupTest {
static const Duration _startupTimeout = const Duration(minutes: 2);
......@@ -174,14 +180,18 @@ class BuildTest {
}
}
/// Measure application memory usage.
class MemoryTest {
MemoryTest(this.testDirectory, this.testTarget, this.timelineFileName, this.packageName);
MemoryTest(this.testDirectory, this.packageName, { this.testTarget });
final String testDirectory;
final String testTarget;
final String timelineFileName;
final String packageName;
/// Path to a flutter driver script that will run after starting the app.
///
/// If not specified, then the test will start the app, gather statistics, and then exit.
final String testTarget;
Future<TaskResult> call() {
return inDirectory(testDirectory, () async {
Device device = await devices.workingDevice;
......@@ -196,47 +206,45 @@ class MemoryTest {
int debugPort = await findAvailablePort();
await flutter('run', options: <String>[
List<String> runOptions = <String>[
'-v',
'--profile',
'--trace-startup', // wait for the first frame to render
'-t',
testTarget,
'-d',
deviceId,
'--debug-port',
debugPort.toString(),
]);
];
if (testTarget != null)
runOptions.addAll(<String>['-t', testTarget]);
await flutter('run', options: runOptions);
Map<String, dynamic> startData = await device.getMemoryStats(packageName);
await flutter('drive', options: <String>[
'-v',
'-t',
testTarget,
'-d',
deviceId,
'--use-existing-app',
//'--keep-app-running',
], env: <String, String> {
'VM_SERVICE_URL': 'http://localhost:$debugPort'
});
Map<String, dynamic> endData = await device.getMemoryStats(packageName);
Map<String, dynamic> data = <String, dynamic>{
'start_total_kb': startData['total_kb'],
'end_total_kb': endData['total_kb'],
'diff_total_kb': endData['total_kb'] - startData['total_kb'],
};
if (testTarget != null) {
await flutter('drive', options: <String>[
'-v',
'-t',
testTarget,
'-d',
deviceId,
'--use-existing-app',
], env: <String, String> {
'VM_SERVICE_URL': 'http://localhost:$debugPort'
});
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: <String>[
'start_total_kb',
'end_total_kb',
'diff_total_kb',
]);
return new TaskResult.success(data, benchmarkScoreKeys: data.keys.toList());
});
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment