diff --git a/dev/devicelab/bin/tasks/hello_world__memory.dart b/dev/devicelab/bin/tasks/hello_world__memory.dart new file mode 100644 index 0000000000..16898ac77c --- /dev/null +++ b/dev/devicelab/bin/tasks/hello_world__memory.dart @@ -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 main() async { + await task(createHelloWorldMemoryTest()); +} diff --git a/dev/devicelab/lib/tasks/perf_tests.dart b/dev/devicelab/lib/tasks/perf_tests.dart index 5bd2ef22af..31d74c844c 100644 --- a/dev/devicelab/lib/tasks/perf_tests.dart +++ b/dev/devicelab/lib/tasks/perf_tests.dart @@ -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 call() { return inDirectory(testDirectory, () async { Device device = await devices.workingDevice; @@ -196,47 +206,45 @@ class MemoryTest { int debugPort = await findAvailablePort(); - await flutter('run', options: [ + List runOptions = [ '-v', '--profile', '--trace-startup', // wait for the first frame to render - '-t', - testTarget, '-d', deviceId, '--debug-port', debugPort.toString(), - ]); + ]; + if (testTarget != null) + runOptions.addAll(['-t', testTarget]); + await flutter('run', options: runOptions); Map startData = await device.getMemoryStats(packageName); - await flutter('drive', options: [ - '-v', - '-t', - testTarget, - '-d', - deviceId, - '--use-existing-app', - //'--keep-app-running', - ], env: { - 'VM_SERVICE_URL': 'http://localhost:$debugPort' - }); - - Map endData = await device.getMemoryStats(packageName); - Map data = { '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: [ + '-v', + '-t', + testTarget, + '-d', + deviceId, + '--use-existing-app', + ], env: { + 'VM_SERVICE_URL': 'http://localhost:$debugPort' + }); + + Map 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: [ - 'start_total_kb', - 'end_total_kb', - 'diff_total_kb', - ]); + return new TaskResult.success(data, benchmarkScoreKeys: data.keys.toList()); }); } }