diff --git a/dev/devicelab/bin/tasks/build_benchmark.dart b/dev/devicelab/bin/tasks/build_benchmark.dart new file mode 100644 index 0000000000..5d65fe621e --- /dev/null +++ b/dev/devicelab/bin/tasks/build_benchmark.dart @@ -0,0 +1,12 @@ +// Copyright 2019 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/framework/framework.dart'; +import 'package:flutter_devicelab/tasks/build_benchmarks.dart'; + +Future main() async { + await task(createBuildbenchmarkTask()); +} diff --git a/dev/devicelab/lib/tasks/build_benchmarks.dart b/dev/devicelab/lib/tasks/build_benchmarks.dart new file mode 100644 index 0000000000..f6911ffe7e --- /dev/null +++ b/dev/devicelab/lib/tasks/build_benchmarks.dart @@ -0,0 +1,72 @@ +// Copyright 2017 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:io'; + +import 'package:flutter_devicelab/framework/framework.dart'; +import 'package:flutter_devicelab/framework/utils.dart'; +import 'package:path/path.dart' as path; + +final Directory helloWorldDir = dir(path.join(flutterDirectory.path, 'examples', 'hello_world')); + +/// Creates a device lab build benchmark. +TaskFunction createBuildbenchmarkTask() { + return () async { + return inDirectory(helloWorldDir, () async { + final Stopwatch stopwatch = Stopwatch() + ..start(); + final Process initialBuild = await startProcess( + path.join(flutterDirectory.path, 'bin', 'flutter'), + ['build', 'apk', '--debug'], + environment: null, + ); + int exitCode = await initialBuild.exitCode; + if (exitCode != 0) { + return TaskResult.failure('Failed to build debug APK'); + } + final int initialBuildMilliseconds = stopwatch.elapsedMilliseconds; + stopwatch + ..reset() + ..start(); + final Process secondBuild = await startProcess( + path.join(flutterDirectory.path, 'bin', 'flutter'), + ['build', 'apk', '--debug'], + environment: null, + ); + exitCode = await secondBuild.exitCode; + if (exitCode != 0) { + return TaskResult.failure('Failed to build debug APK'); + } + final int secondBuildMilliseconds = stopwatch.elapsedMilliseconds; + final Process newBuildConfig = await startProcess( + path.join(flutterDirectory.path, 'bin', 'flutter'), + ['build', 'apk', '--profile'], + environment: null, + ); + exitCode = await newBuildConfig.exitCode; + if (exitCode != 0) { + return TaskResult.failure('Failed to build profile APK'); + } + stopwatch + ..reset() + ..start(); + final Process thirdBuild = await startProcess( + path.join(flutterDirectory.path, 'bin', 'flutter'), + ['build', 'apk', '--debug'], + environment: null, + ); + exitCode = await thirdBuild.exitCode; + if (exitCode != 0) { + return TaskResult.failure('Failed to build debug APK'); + } + final int thirdBuildMilliseconds = stopwatch.elapsedMilliseconds; + stopwatch.stop(); + final Map allResults = {}; + allResults['first_build_debug_millis'] = initialBuildMilliseconds.toDouble(); + allResults['second_build_debug_millis'] = secondBuildMilliseconds.toDouble(); + allResults['after_config_change_build_debug_millis'] = thirdBuildMilliseconds.toDouble(); + return TaskResult.success(allResults, benchmarkScoreKeys: allResults.keys.toList()); + }); + }; +} diff --git a/dev/devicelab/manifest.yaml b/dev/devicelab/manifest.yaml index e715f7248d..8147fd55e9 100644 --- a/dev/devicelab/manifest.yaml +++ b/dev/devicelab/manifest.yaml @@ -358,6 +358,13 @@ tasks: required_agent_capabilities: ["linux/android"] flaky: true + build_benchmark: + description: > + Measures APK build performance across config changes. + stage: devicelab + required_agent_capabilities: ["linux/android"] + flaky: true + # iOS on-device tests flavors_test_ios: