Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[web_benchmarks] Make package compatible with Chromium v89+ #518

Merged
merged 15 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ task:
- format+analyze
- name: web_benchmarks_test
env:
matrix:
CHROMIUM_BUILD: "768968" # Chromium 84.0.4147.0
CHROMIUM_BUILD: "950363" # Chromium 98.0.4758.0
CHROME_NO_SANDBOX: true
install_chromium_script:
- ./script/install_chromium.sh
Expand Down
4 changes: 4 additions & 0 deletions packages/web_benchmarks/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.7

* Updates BlinkTraceEvents to match with changes in Chromium v89+

## 0.0.6

* Update implementation of `_RecordingWidgetsBinding` to match the [new Binding API](https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/foundation/binding.dart#L96-L128)
Expand Down
4 changes: 2 additions & 2 deletions packages/web_benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ benchmarks in Chrome.

# Writing a benchmark

An example benchmark can be found in [test/web_benchmark_test.dart][1].
An example benchmark can be found in [testing/web_benchmark_test.dart][1].

A web benchmark is made of two parts: a client and a server. The client is code
that runs in the browser together with the benchmark code. The server serves the
app's code and assets. Additionally, the server communicates with the browser to
extract the performance traces.

[1]: https://github.com/flutter/packages/blob/master/packages/web_benchmarks/test/web_benchmarks_test.dart
[1]: https://github.com/flutter/packages/blob/master/packages/web_benchmarks/testing/web_benchmarks_test.dart
7 changes: 5 additions & 2 deletions packages/web_benchmarks/lib/src/browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,8 @@ class BlinkTraceEvent {
bool get isBeginFrame =>
ph == 'X' &&
(name == 'WebViewImpl::beginFrame' ||
name == 'WebFrameWidgetBase::BeginMainFrame');
name == 'WebFrameWidgetBase::BeginMainFrame' ||
name == 'WebFrameWidgetImpl::BeginMainFrame');

/// An "update all lifecycle phases" event contains UI thread computations
/// related to an animation frame that's outside the scripting phase.
Expand All @@ -564,7 +565,9 @@ class BlinkTraceEvent {
///
/// This event is a duration event that has its `tdur` populated.
bool get isUpdateAllLifecyclePhases =>
ph == 'X' && name == 'WebViewImpl::updateAllLifecyclePhases';
ph == 'X' &&
(name == 'WebViewImpl::updateAllLifecyclePhases' ||
name == 'WebFrameWidgetImpl::UpdateLifecycle');

/// Whether this is the beginning of a "measured_frame" event.
///
Expand Down
2 changes: 1 addition & 1 deletion packages/web_benchmarks/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: web_benchmarks
description: A benchmark harness for performance-testing Flutter apps in Chrome.
repository: https://github.com/flutter/packages/tree/main/packages/web_benchmarks
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+web_benchmarks%22
version: 0.0.6
version: 0.0.7

environment:
sdk: ">=2.7.0 <3.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2013 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 'package:flutter_test/flutter_test.dart';

void main() {
test('Tell the user how to run tests within "testing" directory', () {
print('---');
print('This package also has client-server tests.');
print('Use `flutter test testing` to run them.');
print('---');
});
}
55 changes: 55 additions & 0 deletions packages/web_benchmarks/test/src/browser_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2013 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 'package:flutter_test/flutter_test.dart';

import 'package:web_benchmarks/src/browser.dart';

import 'browser_test_json_samples.dart';

void main() {
group('BlinkTraceEvent works with Chrome 89+', () {
ditman marked this conversation as resolved.
Show resolved Hide resolved
// Used to test 'false' results
final BlinkTraceEvent unrelatedPhX =
BlinkTraceEvent.fromJson(unrelatedPhXJson);
final BlinkTraceEvent anotherUnrelated =
BlinkTraceEvent.fromJson(anotherUnrelatedJson);

test('isBeginFrame', () {
final BlinkTraceEvent event =
BlinkTraceEvent.fromJson(beginMainFrameJson_89plus);

expect(event.isBeginFrame, isTrue);
expect(unrelatedPhX.isBeginFrame, isFalse);
expect(anotherUnrelated.isBeginFrame, isFalse);
});

test('isUpdateAllLifecyclePhases', () {
final BlinkTraceEvent event =
BlinkTraceEvent.fromJson(updateLifecycleJson_89plus);

expect(event.isUpdateAllLifecyclePhases, isTrue);
expect(unrelatedPhX.isUpdateAllLifecyclePhases, isFalse);
expect(anotherUnrelated.isUpdateAllLifecyclePhases, isFalse);
});

test('isBeginMeasuredFrame', () {
final BlinkTraceEvent event =
BlinkTraceEvent.fromJson(beginMeasuredFrameJson_89plus);

expect(event.isBeginMeasuredFrame, isTrue);
expect(unrelatedPhX.isBeginMeasuredFrame, isFalse);
expect(anotherUnrelated.isBeginMeasuredFrame, isFalse);
});

test('isEndMeasuredFrame', () {
final BlinkTraceEvent event =
BlinkTraceEvent.fromJson(endMeasuredFrameJson_89plus);

expect(event.isEndMeasuredFrame, isTrue);
expect(unrelatedPhX.isEndMeasuredFrame, isFalse);
expect(anotherUnrelated.isEndMeasuredFrame, isFalse);
});
});
}
103 changes: 103 additions & 0 deletions packages/web_benchmarks/test/src/browser_test_json_samples.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copyright 2013 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:convert' show jsonDecode;

// JSON Event samples taken from running an instrumented version of the
// integration tests of this package that dumped all the data as captured.

/// To test isBeginFrame. (Sampled from Chrome 89+)
final Map<String, dynamic> beginMainFrameJson_89plus = jsonDecode('''
{
"args": {
"frameTime": 2338687248768
},
"cat": "blink",
"dur": 6836,
"name": "WebFrameWidgetImpl::BeginMainFrame",
"ph": "X",
"pid": 1367081,
"tdur": 393,
"tid": 1,
"ts": 2338687258440,
"tts": 375499
}
''');

/// To test isUpdateAllLifecyclePhases. (Sampled from Chrome 89+)
final Map<String, dynamic> updateLifecycleJson_89plus = jsonDecode('''
{
"args": {},
"cat": "blink",
"dur": 103,
"name": "WebFrameWidgetImpl::UpdateLifecycle",
"ph": "X",
"pid": 1367081,
"tdur": 102,
"tid": 1,
"ts": 2338687265284,
"tts": 375900
}
''');

/// To test isBeginMeasuredFrame. (Sampled from Chrome 89+)
final Map<String, dynamic> beginMeasuredFrameJson_89plus = jsonDecode('''
{
"args": {},
"cat": "blink.user_timing",
"id": "0xea2a8b45",
"name": "measured_frame",
"ph": "b",
"pid": 1367081,
"scope": "blink.user_timing",
"tid": 1,
"ts": 2338687265932
}
''');

/// To test isEndMeasuredFrame. (Sampled from Chrome 89+)
final Map<String, dynamic> endMeasuredFrameJson_89plus = jsonDecode('''
{
"args": {},
"cat": "blink.user_timing",
"id": "0xea2a8b45",
"name": "measured_frame",
"ph": "e",
"pid": 1367081,
"scope": "blink.user_timing",
"tid": 1,
"ts": 2338687440485
}
''');

/// An unrelated data frame to test negative cases.
final Map<String, dynamic> unrelatedPhXJson = jsonDecode('''
{
"args": {},
"cat": "blink,rail",
"dur": 2,
"name": "PageAnimator::serviceScriptedAnimations",
"ph": "X",
"pid": 1367081,
"tdur": 2,
"tid": 1,
"ts": 2338691143317,
"tts": 1685405
}
''');

/// Another unrelated data frame to test negative cases.
final Map<String, dynamic> anotherUnrelatedJson = jsonDecode('''
{
"args": {
"sort_index": -1
},
"cat": "__metadata",
"name": "thread_sort_index",
"ph": "M",
"pid": 1367081,
"tid": 1,
"ts": 2338692906482
}
''');
72 changes: 72 additions & 0 deletions packages/web_benchmarks/testing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# `testing` README

## How to run the `testing` directory tests

The benchmarks contained in this directory use a client-server model, similar to
what the integration_test package does. In order to run the tests inside `testing`,
do the following:

* Install Chrome in a way that [tests can find it](https://github.com/flutter/packages/blob/a5a4479e176c5e909dd5d961c2c79b61ce1bf1bd/packages/web_benchmarks/lib/src/browser.dart#L216).

* Fetch dependencies for the `test_app` directory inside `testing`:

```bash
flutter pub get testing/test_app
```

* Fetch dependencies for the `web_benchmarks` directory:

```bash
flutter pub get
```

* Run the tests with `flutter test`:

```bash
$ flutter test testing

00:03 +0: Can run a web benchmark
Launching Chrome.
Launching Google Chrome 98.0.4758.102

Waiting for the benchmark to report benchmark profile.
[CHROME]: [0215/133233.327761:ERROR:socket_posix.cc(150)] bind() failed: Address already in use (98)
[CHROME]:
[CHROME]: DevTools listening on ws://[::1]:10000/devtools/browser/4ef82be6-9b68-4fd3-ab90-cd603d25ceb1
Connecting to DevTools: ws://localhost:10000/devtools/page/21E7271507E9BC796B957E075515520F
Connected to Chrome tab: (http://localhost:9999/index.html)
Launching benchmark "scroll"
Extracted 299 measured frames.
Skipped 1 non-measured frames.
Launching benchmark "page"
[APP] Testing round 0...
[APP] Testing round 1...
[APP] Testing round 2...
[APP] Testing round 3...
[APP] Testing round 4...
[APP] Testing round 5...
[APP] Testing round 6...
[APP] Testing round 7...
[APP] Testing round 8...
[APP] Testing round 9...
Extracted 490 measured frames.
Skipped 0 non-measured frames.
Launching benchmark "tap"
[APP] Testing round 0...
[APP] Testing round 1...
[APP] Testing round 2...
[APP] Testing round 3...
[APP] Testing round 4...
[APP] Testing round 5...
[APP] Testing round 6...
[APP] Testing round 7...
[APP] Testing round 8...
[APP] Testing round 9...
Extracted 299 measured frames.
Skipped 0 non-measured frames.
Received profile data
00:26 +1: All tests passed!
```

_(If the above stops working, take a look at what the [`web_benchmarks_test` Cirrus step](https://github.com/flutter/packages/blob/a5a4479e176c5e909dd5d961c2c79b61ce1bf1bd/.cirrus.yml#L102-L113)
is currently doing, and update this document accordingly!)_
6 changes: 5 additions & 1 deletion script/install_chromium.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ set -x
# The build of Chromium used to test web functionality.
#
# Chromium builds can be located here: https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Linux_x64/
CHROMIUM_BUILD=768968
#
# Set CHROMIUM_BUILD env-var to let the script know what to download.

: "${CHROMIUM_BUILD:=950363}" # Default value for the CHROMIUM_BUILD env.
echo "Downloading CHROMIUM_BUILD=${CHROMIUM_BUILD}"

mkdir .chromium
wget "https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F${CHROMIUM_BUILD}%2Fchrome-linux.zip?alt=media" -O .chromium/chromium.zip
Expand Down