Initial web benchmark harness and 3 benchmarks (#49460)
Initial web benchmark harness and 3 benchmarks
This commit is contained in:
15
dev/devicelab/bin/tasks/web_benchmarks_canvaskit.dart
Normal file
15
dev/devicelab/bin/tasks/web_benchmarks_canvaskit.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
// Copyright 2014 The Flutter 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/web_benchmarks.dart';
|
||||
|
||||
/// Runs all Web benchmarks using the CanvasKit rendering backend.
|
||||
Future<void> main() async {
|
||||
await task(() async {
|
||||
return await runWebBenchmark(useCanvasKit: true);
|
||||
});
|
||||
}
|
||||
15
dev/devicelab/bin/tasks/web_benchmarks_html.dart
Normal file
15
dev/devicelab/bin/tasks/web_benchmarks_html.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
// Copyright 2014 The Flutter 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/web_benchmarks.dart';
|
||||
|
||||
/// Runs all Web benchmarks using the HTML rendering backend.
|
||||
Future<void> main() async {
|
||||
await task(() async {
|
||||
return await runWebBenchmark(useCanvasKit: false);
|
||||
});
|
||||
}
|
||||
@@ -181,10 +181,10 @@ class TaskResult {
|
||||
if (benchmarkScoreKeys != null) {
|
||||
for (final String key in benchmarkScoreKeys) {
|
||||
if (!data.containsKey(key)) {
|
||||
throw 'Invalid Golem score key "$key". It does not exist in task '
|
||||
throw 'Invalid benchmark score key "$key". It does not exist in task '
|
||||
'result data ${prettyJson.convert(data)}';
|
||||
} else if (data[key] is! num) {
|
||||
throw 'Invalid Golem score for key "$key". It is expected to be a num '
|
||||
throw 'Invalid benchmark score for key "$key". It is expected to be a num '
|
||||
'but was ${data[key].runtimeType}: ${prettyJson.convert(data[key])}';
|
||||
}
|
||||
}
|
||||
@@ -212,17 +212,9 @@ class TaskResult {
|
||||
/// Task-specific JSON data
|
||||
final Map<String, dynamic> data;
|
||||
|
||||
/// Keys in [data] that store scores that will be submitted to Golem.
|
||||
/// Keys in [data] that store scores that will be submitted to Cocoon.
|
||||
///
|
||||
/// Each key is also part of a benchmark's name tracked by Golem.
|
||||
/// A benchmark name is computed by combining [Task.name] with a key
|
||||
/// separated by a dot. For example, if a task's name is
|
||||
/// `"complex_layout__start_up"` and score key is
|
||||
/// `"engineEnterTimestampMicros"`, the score will be submitted to Golem under
|
||||
/// `"complex_layout__start_up.engineEnterTimestampMicros"`.
|
||||
///
|
||||
/// This convention reduces the amount of configuration that needs to be done
|
||||
/// to submit benchmark scores to Golem.
|
||||
/// Each key is also part of a benchmark's name tracked by Cocoon.
|
||||
final List<String> benchmarkScoreKeys;
|
||||
|
||||
/// Whether the task failed.
|
||||
|
||||
@@ -304,7 +304,20 @@ Future<int> exec(
|
||||
String workingDirectory,
|
||||
}) async {
|
||||
final Process process = await startProcess(executable, arguments, environment: environment, workingDirectory: workingDirectory);
|
||||
await forwardStandardStreams(process);
|
||||
final int exitCode = await process.exitCode;
|
||||
|
||||
if (exitCode != 0 && !canFail)
|
||||
fail('Executable "$executable" failed with exit code $exitCode.');
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
/// Forwards standard out and standard error from [process] to this process'
|
||||
/// respective outputs.
|
||||
///
|
||||
/// Returns a future that completes when both out and error streams a closed.
|
||||
Future<void> forwardStandardStreams(Process process) {
|
||||
final Completer<void> stdoutDone = Completer<void>();
|
||||
final Completer<void> stderrDone = Completer<void>();
|
||||
process.stdout
|
||||
@@ -320,13 +333,7 @@ Future<int> exec(
|
||||
print('stderr: $line');
|
||||
}, onDone: () { stderrDone.complete(); });
|
||||
|
||||
await Future.wait<void>(<Future<void>>[stdoutDone.future, stderrDone.future]);
|
||||
final int exitCode = await process.exitCode;
|
||||
|
||||
if (exitCode != 0 && !canFail)
|
||||
fail('Executable "$executable" failed with exit code $exitCode.');
|
||||
|
||||
return exitCode;
|
||||
return Future.wait<void>(<Future<void>>[stdoutDone.future, stderrDone.future]);
|
||||
}
|
||||
|
||||
/// Executes a command and returns its standard output as a String.
|
||||
|
||||
166
dev/devicelab/lib/tasks/web_benchmarks.dart
Normal file
166
dev/devicelab/lib/tasks/web_benchmarks.dart
Normal file
@@ -0,0 +1,166 @@
|
||||
// Copyright 2014 The Flutter 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 'dart:convert' show json;
|
||||
import 'dart:io' as io;
|
||||
|
||||
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;
|
||||
import 'package:shelf_static/shelf_static.dart';
|
||||
|
||||
import 'package:flutter_devicelab/framework/framework.dart';
|
||||
import 'package:flutter_devicelab/framework/utils.dart';
|
||||
|
||||
/// The port number used by the local benchmark server.
|
||||
const int benchmarkServerPort = 9999;
|
||||
|
||||
Future<TaskResult> runWebBenchmark({ @required bool useCanvasKit }) async {
|
||||
final String macrobenchmarksDirectory = path.join('${flutterDirectory.path}', 'dev', 'benchmarks', 'macrobenchmarks');
|
||||
return await inDirectory(macrobenchmarksDirectory, () async {
|
||||
await evalFlutter('build', options: <String>[
|
||||
'web',
|
||||
if (useCanvasKit)
|
||||
'--dart-define=FLUTTER_WEB_USE_SKIA=true',
|
||||
'--profile',
|
||||
'-t',
|
||||
'lib/web_benchmarks.dart',
|
||||
], environment: <String, String>{
|
||||
'FLUTTER_WEB': 'true',
|
||||
});
|
||||
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;
|
||||
|
||||
io.HttpServer server;
|
||||
Cascade cascade = Cascade();
|
||||
cascade = cascade.add((Request request) async {
|
||||
if (request.requestedUri.path.endsWith('/profile-data')) {
|
||||
final Map<String, dynamic> profile = json.decode(await request.readAsString()) as Map<String, dynamic>;
|
||||
final String benchmarkName = profile['name'] as String;
|
||||
if (benchmarkName != benchmarkIterator.current) {
|
||||
profileData.completeError(Exception(
|
||||
'Browser returned benchmark results from a wrong benchmark.\n'
|
||||
'Requested to run bechmark ${benchmarkIterator.current}, but '
|
||||
'got results for $benchmarkName.',
|
||||
));
|
||||
server.close();
|
||||
}
|
||||
collectedProfiles.add(profile);
|
||||
return Response.ok('Profile received');
|
||||
} 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;
|
||||
}
|
||||
if (benchmarkIterator.moveNext()) {
|
||||
final String nextBenchmark = benchmarkIterator.current;
|
||||
print('Launching benchmark "$nextBenchmark"');
|
||||
return Response.ok(nextBenchmark);
|
||||
} else {
|
||||
profileData.complete(collectedProfiles);
|
||||
return Response.notFound('Finished running benchmarks.');
|
||||
}
|
||||
} else {
|
||||
return Response.notFound(
|
||||
'This request is not handled by the profile-data handler.');
|
||||
}
|
||||
}).add(createStaticHandler(
|
||||
path.join('$macrobenchmarksDirectory', 'build', 'web'),
|
||||
));
|
||||
|
||||
server = await io.HttpServer.bind('localhost', benchmarkServerPort);
|
||||
io.Process chromeProcess;
|
||||
try {
|
||||
shelf_io.serveRequests(server, cascade.handler);
|
||||
|
||||
final bool isChromeNoSandbox =
|
||||
io.Platform.environment['CHROME_NO_SANDBOX'] == 'true';
|
||||
|
||||
final String dartToolDirectory = path.join('$macrobenchmarksDirectory/.dart_tool');
|
||||
final String userDataDir = io.Directory(dartToolDirectory).createTempSync('chrome_user_data_').path;
|
||||
final List<String> args = <String>[
|
||||
'--user-data-dir=$userDataDir',
|
||||
'http://localhost:$benchmarkServerPort/index.html',
|
||||
if (isChromeNoSandbox)
|
||||
'--no-sandbox',
|
||||
'--window-size=1024,1024',
|
||||
'--disable-extensions',
|
||||
'--disable-popup-blocking',
|
||||
// Indicates that the browser is in "browse without sign-in" (Guest session) mode.
|
||||
'--bwsi',
|
||||
'--no-first-run',
|
||||
'--no-default-browser-check',
|
||||
'--disable-default-apps',
|
||||
'--disable-translate',
|
||||
];
|
||||
|
||||
final bool isUncalibratedSmokeTest =
|
||||
io.Platform.environment['UNCALIBRATED_SMOKE_TEST'] == 'true';
|
||||
if (isUncalibratedSmokeTest) {
|
||||
print('Running in headless mode because running on uncalibrated hardware.');
|
||||
args.add('--headless');
|
||||
// When running in headless mode Chrome exits immediately unless
|
||||
// a debug port is specified.
|
||||
args.add('--remote-debugging-port=${benchmarkServerPort + 1}');
|
||||
}
|
||||
|
||||
chromeProcess = await startProcess(
|
||||
_findSystemChromeExecutable(),
|
||||
args,
|
||||
workingDirectory: cwd,
|
||||
);
|
||||
|
||||
bool receivedProfileData = false;
|
||||
chromeProcess.exitCode.then((int exitCode) {
|
||||
if (!receivedProfileData) {
|
||||
profileData.completeError(Exception(
|
||||
'Chrome process existed prematurely with exit code $exitCode',
|
||||
));
|
||||
}
|
||||
});
|
||||
forwardStandardStreams(chromeProcess);
|
||||
|
||||
print('Waiting for the benchmark to report benchmark profile.');
|
||||
|
||||
final String backend = useCanvasKit ? 'canvaskit' : 'html';
|
||||
final Map<String, dynamic> taskResult = <String, dynamic>{};
|
||||
final List<String> benchmarkScoreKeys = <String>[];
|
||||
final List<Map<String, dynamic>> profiles = await profileData.future;
|
||||
print('Received profile data');
|
||||
receivedProfileData = true;
|
||||
for (final Map<String, dynamic> profile in profiles) {
|
||||
final String benchmarkName = profile['name'] as String;
|
||||
final String benchmarkScoreKey = '$benchmarkName.$backend.averageDrawFrameDuration';
|
||||
taskResult[benchmarkScoreKey] = profile['averageDrawFrameDuration'].toDouble(); // micros
|
||||
taskResult['$benchmarkName.$backend.drawFrameDurationNoise'] = profile['drawFrameDurationNoise'].toDouble(); // micros
|
||||
benchmarkScoreKeys.add(benchmarkScoreKey);
|
||||
}
|
||||
return TaskResult.success(taskResult, benchmarkScoreKeys: benchmarkScoreKeys);
|
||||
} finally {
|
||||
server.close();
|
||||
chromeProcess?.kill();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
String _findSystemChromeExecutable() {
|
||||
if (io.Platform.isLinux) {
|
||||
final io.ProcessResult which =
|
||||
io.Process.runSync('which', <String>['google-chrome']);
|
||||
|
||||
if (which.exitCode != 0) {
|
||||
throw Exception('Failed to locate system Chrome installation.');
|
||||
}
|
||||
|
||||
return (which.stdout as String).trim();
|
||||
} else if (io.Platform.isMacOS) {
|
||||
return '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
|
||||
} else {
|
||||
throw Exception('Web benchmarks cannot run on ${io.Platform.operatingSystem} yet.');
|
||||
}
|
||||
}
|
||||
@@ -703,6 +703,22 @@ tasks:
|
||||
stage: devicelab
|
||||
required_agent_capabilities: ["linux/android"]
|
||||
|
||||
web_benchmarks_html:
|
||||
description: >
|
||||
Runs Web benchmarks on Chrome on a Linux machine using the HTML rendering backend.
|
||||
stage: devicelab
|
||||
required_agent_capabilities: ["linux-vm"]
|
||||
# TODO(yjbanov): This is a new test. Marking temporarily as flaky while debugging on devicelab.
|
||||
flaky: true
|
||||
|
||||
web_benchmarks_canvaskit:
|
||||
description: >
|
||||
Runs Web benchmarks on Chrome on a Linux machine using the CanvasKit rendering backend.
|
||||
stage: devicelab
|
||||
required_agent_capabilities: ["linux-vm"]
|
||||
# TODO(yjbanov): This is a new test. Marking temporarily as flaky while debugging on devicelab.
|
||||
flaky: true
|
||||
|
||||
# run_without_leak_linux:
|
||||
# description: >
|
||||
# Checks that `flutter run` does not leak dart on Linux.
|
||||
|
||||
Reference in New Issue
Block a user