Migrate devicelab framework code to null safety. (#86325)

(Attempt to reland #85993)
This commit is contained in:
Darren Austin
2021-07-13 12:14:50 -07:00
committed by GitHub
parent 43ed3b6bed
commit ef5ffd08f6
28 changed files with 406 additions and 470 deletions

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:io';
import 'package:path/path.dart' as path;

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:io';
import 'package:args/args.dart';
@@ -18,10 +16,9 @@ import '../framework/utils.dart';
abstract class BuildTestTask {
BuildTestTask(this.args, {this.workingDirectory, this.runFlutterClean = true,}) {
final ArgResults argResults = argParser.parse(args);
applicationBinaryPath = argResults[kApplicationBinaryPathOption] as String;
applicationBinaryPath = argResults[kApplicationBinaryPathOption] as String?;
buildOnly = argResults[kBuildOnlyFlag] as bool;
testOnly = argResults[kTestOnlyFlag] as bool;
}
static const String kApplicationBinaryPathOption = 'application-binary-path';
@@ -48,10 +45,10 @@ abstract class BuildTestTask {
/// Path to a built application to use in [test].
///
/// If not given, will default to child's expected location.
String applicationBinaryPath;
String? applicationBinaryPath;
/// Where the test artifacts are stored, such as performance results.
final Directory workingDirectory;
final Directory? workingDirectory;
/// Run Flutter build to create [applicationBinaryPath].
Future<void> build() async {
@@ -93,7 +90,7 @@ abstract class BuildTestTask {
///
/// Tasks can override to support default values. Otherwise, it will default
/// to needing to be passed as an argument in the test runner.
String getApplicationBinaryPath() => applicationBinaryPath;
String? getApplicationBinaryPath() => applicationBinaryPath;
/// Run this task.
///

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:async';
import 'dart:convert';
import 'dart:io';
@@ -15,8 +13,8 @@ import 'package:flutter_devicelab/framework/utils.dart';
import 'package:path/path.dart' as path;
TaskFunction dartPluginRegistryTest({
String deviceIdOverride,
Map<String, String> environment,
String? deviceIdOverride,
Map<String, String>? environment,
}) {
final Directory tempDir = Directory.systemTemp
.createTempSync('flutter_devicelab_dart_plugin_test.');

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:convert';
import 'dart:io';
import 'dart:math' as math;
@@ -55,9 +53,9 @@ class GalleryTransitionTest {
final bool needFullTimeline;
final String testFile;
final String timelineSummaryFile;
final String timelineTraceFile;
final String transitionDurationFile;
final String driverFile;
final String? timelineTraceFile;
final String? transitionDurationFile;
final String? driverFile;
Future<TaskResult> call() async {
final Device device = await devices.workingDevice;
@@ -65,7 +63,7 @@ class GalleryTransitionTest {
final String deviceId = device.deviceId;
final Directory galleryDirectory = dir('${flutterDirectory.path}/dev/integration_tests/flutter_gallery');
await inDirectory<void>(galleryDirectory, () async {
String applicationBinaryPath;
String? applicationBinaryPath;
if (deviceOperatingSystem == DeviceOperatingSystem.android) {
section('BUILDING APPLICATION');
await flutter(

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:async';
import 'dart:convert';
import 'dart:io';
@@ -20,7 +18,7 @@ final Directory flutterGalleryDir = dir(path.join(flutterDirectory.path, 'dev/in
const String kSourceLine = 'fontSize: (orientation == Orientation.portrait) ? 32.0 : 24.0';
const String kReplacementLine = 'fontSize: (orientation == Orientation.portrait) ? 34.0 : 24.0';
TaskFunction createHotModeTest({String deviceIdOverride, Map<String, String> environment}) {
TaskFunction createHotModeTest({String? deviceIdOverride, Map<String, String>? environment}) {
// This file is modified during the test and needs to be restored at the end.
final File flutterFrameworkSource = file(path.join(
flutterDirectory.path, 'packages/flutter/lib/src/widgets/framework.dart',
@@ -35,13 +33,13 @@ TaskFunction createHotModeTest({String deviceIdOverride, Map<String, String> env
final File benchmarkFile = file(path.join(_editedFlutterGalleryDir.path, 'hot_benchmark.json'));
rm(benchmarkFile);
final List<String> options = <String>[
'--hot', '-d', deviceIdOverride, '--benchmark', '--resident', '--no-android-gradle-daemon', '--no-publish-port', '--verbose',
'--hot', '-d', deviceIdOverride!, '--benchmark', '--resident', '--no-android-gradle-daemon', '--no-publish-port', '--verbose',
];
int hotReloadCount = 0;
Map<String, dynamic> smallReloadData;
Map<String, dynamic> mediumReloadData;
Map<String, dynamic> largeReloadData;
Map<String, dynamic> freshRestartReloadsData;
late Map<String, dynamic> smallReloadData;
late Map<String, dynamic> mediumReloadData;
late Map<String, dynamic> largeReloadData;
late Map<String, dynamic> freshRestartReloadsData;
await inDirectory<void>(flutterDirectory, () async {
@@ -215,9 +213,9 @@ TaskFunction createHotModeTest({String deviceIdOverride, Map<String, String> env
};
}
Future<Map<String, Object>> captureReloadData(
Future<Map<String, dynamic>> captureReloadData(
List<String> options,
Map<String, String> environment,
Map<String, String>? environment,
File benchmarkFile,
void Function(String, Process) onLine,
) async {
@@ -247,7 +245,7 @@ Future<Map<String, Object>> captureReloadData(
await Future.wait<void>(<Future<void>>[stdoutDone.future, stderrDone.future]);
await process.exitCode;
final Map<String, dynamic> result = json.decode(benchmarkFile.readAsStringSync()) as Map<String, dynamic>;
final Map<String, Object> result = json.decode(benchmarkFile.readAsStringSync()) as Map<String, Object>;
benchmarkFile.deleteSync();
return result;
}

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import '../framework/devices.dart';
import '../framework/framework.dart';
import '../framework/task_result.dart';

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:async';
import 'dart:io';

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:io';
import 'package:flutter_devicelab/tasks/perf_tests.dart';

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:async';
import 'dart:convert' show LineSplitter, json, utf8;
import 'dart:io';
@@ -516,7 +514,7 @@ class StartupTest {
final List<Map<String, dynamic>> results = <Map<String, dynamic>>[];
section('Building application');
String applicationBinaryPath;
String? applicationBinaryPath;
switch (deviceOperatingSystem) {
case DeviceOperatingSystem.android:
await flutter('build', options: <String>[
@@ -586,7 +584,7 @@ class StartupTest {
'-d',
device.deviceId,
'--out',
hostAgent.dumpDirectory
hostAgent.dumpDirectory!
.childFile('screenshot_startup_failure_$currentFailures.png')
.path,
],
@@ -630,7 +628,7 @@ class DevtoolsStartupTest {
final Device device = await devices.workingDevice;
section('Building application');
String applicationBinaryPath;
String? applicationBinaryPath;
switch (deviceOperatingSystem) {
case DeviceOperatingSystem.android:
await flutter('build', options: <String>[
@@ -733,7 +731,7 @@ class PerfTest {
this.needsFullTimeline = true,
this.benchmarkScoreKeys,
this.dartDefine = '',
String resultFilename,
String? resultFilename,
}): _resultFilename = resultFilename;
const PerfTest.e2e(
@@ -753,12 +751,12 @@ class PerfTest {
/// The main entry-point file of the application, as run on the device.
final String testTarget;
// The prefix name of the filename such as `<timelineFileName>.timeline_summary.json`.
final String timelineFileName;
final String? timelineFileName;
String get traceFilename => '$timelineFileName.timeline';
String get resultFilename => _resultFilename ?? '$timelineFileName.timeline_summary';
final String _resultFilename;
final String? _resultFilename;
/// The test file to run on the host.
final String testDriver;
final String? testDriver;
/// Whether to collect CPU and GPU metrics.
final bool measureCpuGpu;
/// Whether to collect memory metrics.
@@ -788,7 +786,7 @@ class PerfTest {
/// if (measureCpuGpu) 'average_gpu_usage',
/// ]
/// ```
final List<String> benchmarkScoreKeys;
final List<String>? benchmarkScoreKeys;
/// Additional flags for `--dart-define` to control the test
final String dartDefine;
@@ -800,8 +798,8 @@ class PerfTest {
@protected
Future<TaskResult> internalRun({
bool cacheSkSL = false,
String existingApp,
String writeSkslFileName,
String? existingApp,
String? writeSkslFileName,
}) {
return inDirectory<TaskResult>(testDirectory, () async {
final Device device = await devices.workingDevice;
@@ -818,7 +816,7 @@ class PerfTest {
'--trace-startup', // Enables "endless" timeline event buffering.
'-t', testTarget,
if (testDriver != null)
...<String>['--driver', testDriver],
...<String>['--driver', testDriver!],
if (existingApp != null)
...<String>['--use-existing-app', existingApp],
if (writeSkslFileName != null)
@@ -890,9 +888,9 @@ class PerfTestWithSkSL extends PerfTest {
String testTarget,
String timelineFileName, {
bool measureCpuGpu = false,
String testDriver,
String? testDriver,
bool needsFullTimeline = true,
List<String> benchmarkScoreKeys,
List<String>? benchmarkScoreKeys,
}) : super(
testDirectory,
testTarget,
@@ -964,7 +962,7 @@ class PerfTestWithSkSL extends PerfTest {
);
}
Future<String> _runApp({String appBinary, bool cacheSkSL = false, String skslPath}) async {
Future<String> _runApp({String? appBinary, bool cacheSkSL = false, String? skslPath}) async {
if (File(_vmserviceFileName).existsSync()) {
File(_vmserviceFileName).deleteSync();
}
@@ -1027,9 +1025,9 @@ class PerfTestWithSkSL extends PerfTest {
});
}
String _flutterPath;
Device _device;
Process _runProcess;
late String _flutterPath;
late Device _device;
late Process _runProcess;
static const String _kVmserviceOutFileName = 'vmservice.out';
}
@@ -1073,12 +1071,16 @@ class WebCompileTest {
///
/// Run a single web compile test for the app under [directory], and store
/// its metrics with prefix [metric].
static Future<Map<String, int>> runSingleBuildTest({String directory, String metric, bool measureBuildTime = false}) {
static Future<Map<String, int>> runSingleBuildTest({
required String directory,
required String metric,
bool measureBuildTime = false,
}) {
return inDirectory<Map<String, int>>(directory, () async {
final Map<String, int> metrics = <String, int>{};
await flutter('packages', options: <String>['get']);
final Stopwatch watch = measureBuildTime ? Stopwatch() : null;
final Stopwatch? watch = measureBuildTime ? Stopwatch() : null;
watch?.start();
await evalFlutter('build', options: <String>[
'web',
@@ -1091,7 +1093,7 @@ class WebCompileTest {
metrics.addAll(await getSize(outputFileName, metric: metric));
if (measureBuildTime) {
metrics['${metric}_dart2js_millis'] = watch.elapsedMilliseconds;
metrics['${metric}_dart2js_millis'] = watch!.elapsedMilliseconds;
}
return metrics;
@@ -1099,7 +1101,7 @@ class WebCompileTest {
}
/// Obtains the size and gzipped size of a file given by [fileName].
static Future<Map<String, int>> getSize(String fileName, {String metric}) async {
static Future<Map<String, int>> getSize(String fileName, {required String metric}) async {
final Map<String, int> sizeMetrics = <String, int>{};
final ProcessResult result = await Process.run('du', <String>['-k', fileName]);
@@ -1168,10 +1170,12 @@ class CompileTest {
await flutter('build', options: options);
watch.stop();
final Directory appBuildDirectory = dir(path.join(cwd, 'build/ios/Release-iphoneos'));
final Directory appBundle = appBuildDirectory
final Directory? appBundle = appBuildDirectory
.listSync()
.whereType<Directory>()
.singleWhere((Directory directory) => path.extension(directory.path) == '.app', orElse: () => null);
.whereType<Directory?>()
.singleWhere((Directory? directory) =>
directory != null && path.extension(directory.path) == '.app',
orElse: () => null);
if (appBundle == null) {
throw 'Failed to find app bundle in ${appBuildDirectory.path}';
}
@@ -1226,8 +1230,8 @@ class CompileTest {
}
static Future<Map<String, dynamic>> _compileDebug({
@required bool clean,
@required String metricKey,
required bool clean,
required String metricKey,
}) async {
if (clean) {
await flutter('clean');
@@ -1290,9 +1294,9 @@ class CompileTest {
fileToMetadata[entry.path] = entry;
}
final _UnzipListEntry libflutter = fileToMetadata['lib/armeabi-v7a/libflutter.so'];
final _UnzipListEntry libapp = fileToMetadata['lib/armeabi-v7a/libapp.so'];
final _UnzipListEntry license = fileToMetadata['assets/flutter_assets/NOTICES.Z'];
final _UnzipListEntry libflutter = fileToMetadata['lib/armeabi-v7a/libflutter.so']!;
final _UnzipListEntry libapp = fileToMetadata['lib/armeabi-v7a/libapp.so']!;
final _UnzipListEntry license = fileToMetadata['assets/flutter_assets/NOTICES.Z']!;
return <String, dynamic>{
'libflutter_uncompressed_bytes': libflutter.uncompressedSize,
@@ -1315,9 +1319,9 @@ class MemoryTest {
/// Completes when the log line specified in the last call to
/// [prepareForNextMessage] is seen by `adb logcat`.
Future<void> get receivedNextMessage => _receivedNextMessage?.future;
Completer<void> _receivedNextMessage;
String _nextMessage;
Future<void>? get receivedNextMessage => _receivedNextMessage?.future;
Completer<void>? _receivedNextMessage;
String? _nextMessage;
/// Prepares the [receivedNextMessage] future such that it will complete
/// when `adb logcat` sees a log line with the given `message`.
@@ -1328,8 +1332,8 @@ class MemoryTest {
int get iterationCount => 10;
Device get device => _device;
Device _device;
Device? get device => _device;
Device? _device;
Future<TaskResult> run() {
return inDirectory<TaskResult>(project, () async {
@@ -1337,13 +1341,13 @@ class MemoryTest {
// device.getMemoryStats, etc, aren't implemented for iOS.
_device = await devices.workingDevice;
await device.unlock();
await device!.unlock();
await flutter('packages', options: <String>['get']);
final StreamSubscription<String> adb = device.logcat.listen(
final StreamSubscription<String> adb = device!.logcat.listen(
(String data) {
if (data.contains('==== MEMORY BENCHMARK ==== $_nextMessage ===='))
_receivedNextMessage.complete();
_receivedNextMessage?.complete();
},
);
@@ -1356,12 +1360,12 @@ class MemoryTest {
assert(_endMemory.length == iteration + 1);
assert(_diffMemory.length == iteration + 1);
print('terminating...');
await device.stop(package);
await device!.stop(package);
await Future<void>.delayed(const Duration(milliseconds: 10));
}
await adb.cancel();
await flutter('install', options: <String>['--uninstall-only', '-d', device.deviceId]);
await flutter('install', options: <String>['--uninstall-only', '-d', device!.deviceId]);
final ListStatistics startMemoryStatistics = ListStatistics(_startMemory);
final ListStatistics endMemoryStatistics = ListStatistics(_endMemory);
@@ -1392,7 +1396,7 @@ class MemoryTest {
'--verbose',
'--release',
'--no-resident',
'-d', device.deviceId,
'-d', device!.deviceId,
test,
]);
print('awaiting "ready" message...');
@@ -1411,7 +1415,7 @@ class MemoryTest {
prepareForNextMessage('DONE');
print('tapping device...');
await device.tap(100, 100);
await device!.tap(100, 100);
print('awaiting "done" message...');
await receivedNextMessage;
@@ -1422,23 +1426,23 @@ class MemoryTest {
final List<int> _endMemory = <int>[];
final List<int> _diffMemory = <int>[];
Map<String, dynamic> _startMemoryUsage;
Map<String, dynamic>? _startMemoryUsage;
@protected
Future<void> recordStart() async {
assert(_startMemoryUsage == null);
print('snapshotting memory usage...');
_startMemoryUsage = await device.getMemoryStats(package);
_startMemoryUsage = await device!.getMemoryStats(package);
}
@protected
Future<void> recordEnd() async {
assert(_startMemoryUsage != null);
print('snapshotting memory usage...');
final Map<String, dynamic> endMemoryUsage = await device.getMemoryStats(package);
_startMemory.add(_startMemoryUsage['total_kb'] as int);
final Map<String, dynamic> endMemoryUsage = await device!.getMemoryStats(package);
_startMemory.add(_startMemoryUsage!['total_kb'] as int);
_endMemory.add(endMemoryUsage['total_kb'] as int);
_diffMemory.add((endMemoryUsage['total_kb'] as int) - (_startMemoryUsage['total_kb'] as int));
_diffMemory.add((endMemoryUsage['total_kb'] as int) - (_startMemoryUsage!['total_kb'] as int));
}
}
@@ -1487,7 +1491,7 @@ class DevToolsMemoryTest {
});
}
Device _device;
late Device _device;
static const String _kJsonFileName = 'devtools_memory.json';
}
@@ -1505,7 +1509,6 @@ String _reportedDurationTestToString(ReportedDurationTestFlavor flavor) {
case ReportedDurationTestFlavor.release:
return 'release';
}
throw ArgumentError('Unexpected value for enum $flavor');
}
class ReportedDurationTest {
@@ -1521,8 +1524,8 @@ class ReportedDurationTest {
int get iterationCount => 10;
Device get device => _device;
Device _device;
Device? get device => _device;
Device? _device;
Future<TaskResult> run() {
return inDirectory<TaskResult>(project, () async {
@@ -1530,13 +1533,13 @@ class ReportedDurationTest {
// device.getMemoryStats, etc, aren't implemented for iOS.
_device = await devices.workingDevice;
await device.unlock();
await device!.unlock();
await flutter('packages', options: <String>['get']);
final StreamSubscription<String> adb = device.logcat.listen(
final StreamSubscription<String> adb = device!.logcat.listen(
(String data) {
if (durationPattern.hasMatch(data))
durationCompleter.complete(int.parse(durationPattern.firstMatch(data).group(1)));
durationCompleter.complete(int.parse(durationPattern.firstMatch(data)!.group(1)!));
},
);
print('launching $project$test on device...');
@@ -1546,13 +1549,13 @@ class ReportedDurationTest {
'--no-fast-start',
'--${_reportedDurationTestToString(flavor)}',
'--no-resident',
'-d', device.deviceId,
'-d', device!.deviceId,
test,
]);
final int duration = await durationCompleter.future;
print('terminating...');
await device.stop(package);
await device!.stop(package);
await adb.cancel();
_device = null;
@@ -1607,9 +1610,9 @@ class _UnzipListEntry {
}
_UnzipListEntry._({
@required this.uncompressedSize,
@required this.compressedSize,
@required this.path,
required this.uncompressedSize,
required this.compressedSize,
required this.path,
}) : assert(uncompressedSize != null),
assert(compressedSize != null),
assert(compressedSize <= uncompressedSize),
@@ -1633,7 +1636,7 @@ Future<File> waitForFile(String path) async {
throw StateError('Did not find vmservice out file after 400 seconds');
}
String _findIosAppInBuildDirectory(String searchDirectory) {
String? _findIosAppInBuildDirectory(String searchDirectory) {
for (final FileSystemEntity entity in Directory(searchDirectory).listSync()) {
if (entity.path.endsWith('.app')) {
return entity.path;

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:io' show Process, Directory;
import 'package:flutter_devicelab/framework/devices.dart' as adb;

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:io';
import 'package:flutter_devicelab/framework/framework.dart';
@@ -31,8 +29,8 @@ class PluginTest {
final String buildTarget;
final List<String> options;
final Map<String, String> pluginCreateEnvironment;
final Map<String, String> appCreateEnvironment;
final Map<String, String>? pluginCreateEnvironment;
final Map<String, String>? appCreateEnvironment;
Future<TaskResult> call() async {
final Directory tempDir =
@@ -77,7 +75,7 @@ class _FlutterProject {
String get rootPath => path.join(parent.path, name);
Future<void> addPlugin(String plugin, {String pluginPath}) async {
Future<void> addPlugin(String plugin, {String? pluginPath}) async {
final File pubspec = File(path.join(rootPath, 'pubspec.yaml'));
String content = await pubspec.readAsString();
final String dependency =
@@ -100,9 +98,9 @@ class _FlutterProject {
List<String> options,
String target,
{
String name,
String template,
Map<String, String> environment,
required String name,
required String template,
Map<String, String>? environment,
}) async {
await inDirectory(directory, () async {
await flutter(

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:async';
import 'dart:convert' show json;
import 'dart:io' as io;
@@ -13,7 +11,6 @@ import 'package:flutter_devicelab/framework/browser.dart';
import 'package:flutter_devicelab/framework/task_result.dart';
import 'package:flutter_devicelab/framework/utils.dart';
import 'package:logging/logging.dart';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as path;
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as shelf_io;
@@ -23,7 +20,7 @@ import 'package:shelf_static/shelf_static.dart';
const int benchmarkServerPort = 9999;
const int chromeDebugPort = 10000;
Future<TaskResult> runWebBenchmark({ @required bool useCanvasKit }) async {
Future<TaskResult> runWebBenchmark({ required bool useCanvasKit }) async {
// Reduce logging level. Otherwise, package:webkit_inspection_protocol is way too spammy.
Logger.root.level = Level.INFO;
final String macrobenchmarksDirectory = path.join(flutterDirectory.path, 'dev', 'benchmarks', 'macrobenchmarks');
@@ -38,17 +35,17 @@ Future<TaskResult> runWebBenchmark({ @required bool useCanvasKit }) async {
]);
final Completer<List<Map<String, dynamic>>> profileData = Completer<List<Map<String, dynamic>>>();
final List<Map<String, dynamic>> collectedProfiles = <Map<String, dynamic>>[];
List<String> benchmarks;
Iterator<String> benchmarkIterator;
List<String>? benchmarks;
late Iterator<String> benchmarkIterator;
// This future fixes a race condition between the web-page loading and
// asking to run a benchmark, and us connecting to Chrome's DevTools port.
// Sometime one wins. Other times, the other wins.
Future<Chrome> whenChromeIsReady;
Chrome chrome;
io.HttpServer server;
Future<Chrome>? whenChromeIsReady;
Chrome? chrome;
late io.HttpServer server;
Cascade cascade = Cascade();
List<Map<String, dynamic>> latestPerformanceTrace;
List<Map<String, dynamic>>? latestPerformanceTrace;
cascade = cascade.add((Request request) async {
try {
chrome ??= await whenChromeIsReady;
@@ -66,7 +63,7 @@ Future<TaskResult> runWebBenchmark({ @required bool useCanvasKit }) async {
// Trace data is null when the benchmark is not frame-based, such as RawRecorder.
if (latestPerformanceTrace != null) {
final BlinkTraceSummary traceSummary = BlinkTraceSummary.fromJson(latestPerformanceTrace);
final BlinkTraceSummary traceSummary = BlinkTraceSummary.fromJson(latestPerformanceTrace!)!;
profile['totalUiFrame.average'] = traceSummary.averageTotalUIFrameTime.inMicroseconds;
profile['scoreKeys'] ??= <dynamic>[]; // using dynamic for consistency with JSON
(profile['scoreKeys'] as List<dynamic>).add('totalUiFrame.average');
@@ -76,10 +73,10 @@ Future<TaskResult> runWebBenchmark({ @required bool useCanvasKit }) async {
return Response.ok('Profile received');
} else if (request.requestedUri.path.endsWith('/start-performance-tracing')) {
latestPerformanceTrace = null;
await chrome.beginRecordingPerformance(request.requestedUri.queryParameters['label']);
await chrome!.beginRecordingPerformance(request.requestedUri.queryParameters['label']!);
return Response.ok('Started performance tracing');
} else if (request.requestedUri.path.endsWith('/stop-performance-tracing')) {
latestPerformanceTrace = await chrome.endRecordingPerformance();
latestPerformanceTrace = await chrome!.endRecordingPerformance();
return Response.ok('Stopped performance tracing');
} else if (request.requestedUri.path.endsWith('/on-error')) {
final Map<String, dynamic> errorDetails = json.decode(await request.readAsString()) as Map<String, dynamic>;
@@ -90,7 +87,7 @@ Future<TaskResult> runWebBenchmark({ @required bool useCanvasKit }) async {
} else if (request.requestedUri.path.endsWith('/next-benchmark')) {
if (benchmarks == null) {
benchmarks = (json.decode(await request.readAsString()) as List<dynamic>).cast<String>();
benchmarkIterator = benchmarks.iterator;
benchmarkIterator = benchmarks!.iterator;
}
if (benchmarkIterator.moveNext()) {
final String nextBenchmark = benchmarkIterator.current;
@@ -186,7 +183,7 @@ Future<TaskResult> runWebBenchmark({ @required bool useCanvasKit }) async {
}
return TaskResult.success(taskResult, benchmarkScoreKeys: benchmarkScoreKeys);
} finally {
unawaited(server?.close());
unawaited(server.close());
chrome?.stop();
}
});

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:async';
import 'dart:convert';
import 'dart:io';