Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit b64b1f8

Browse files
committed
Run and collect benchmarks
1 parent ca799fa commit b64b1f8

File tree

7 files changed

+158
-0
lines changed

7 files changed

+158
-0
lines changed

.cirrus.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ task:
1919
FRAMEWORK_PATH: "/tmp/master_framework"
2020
PATH: "$FLUTTER_ENGINE/third_party/dart/tools/sdks/dart-sdk/bin:$DEPOT_TOOLS:$PATH"
2121
USE_ANDROID: "False"
22+
BENCHMARK_GCP_CREDENTIALS: ENCRYPTED[da76d2b7b39894de70fae1fc9182c97cc41400adc93f0f1c49bc7442f15fb933da8d756ed88523810a9a77c34f51a693]
2223
setup_script: |
2324
git clone --depth 1 https://chromium.googlesource.com/chromium/tools/depot_tools.git $DEPOT_TOOLS
2425
mkdir -p $ENGINE_PATH/src
@@ -29,6 +30,18 @@ task:
2930
mv $CIRRUS_WORKING_DIR flutter
3031
gclient sync
3132
matrix:
33+
- name: build_and_benchmark_linux_release
34+
only_if: $CIRRUS_BRANCH == 'master' # Only run for post-submit commits.
35+
compile_host_script: |
36+
cd $ENGINE_PATH/src
37+
./flutter/tools/gn --runtime-mode=release
38+
ninja -C out/host_release
39+
benchmark_host_script: |
40+
cd $ENGINE_PATH/src/out/host_release/
41+
./txt_benchmarks --benchmark_format=json > txt_benchmarks.json
42+
cd $ENGINE_PATH/src/flutter/testing/benchmark
43+
pub get
44+
dart bin/parse_and_send.dart ../../../out/host_release/txt_benchmarks.json
3245
- name: build_and_test_linux_unopt_debug
3346
compile_host_script: |
3447
cd $ENGINE_PATH/src

testing/benchmark/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
secret

testing/benchmark/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This is a Dart project that runs the engine benchmarks, and send the metrics to
2+
the cloud for storage and analysis.
3+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import 'dart:convert';
2+
import 'dart:io';
3+
4+
import 'package:git/git.dart';
5+
import 'package:metrics_center/flutter.dart';
6+
7+
const String kNameKey = 'name';
8+
const String kTimeUnitKey = 'time_unit';
9+
const String kSubResultKey = 'sub_result';
10+
11+
const List<String> kSkippedSubResults = <String>[
12+
kNameKey,
13+
kTimeUnitKey,
14+
'iterations',
15+
'big_o',
16+
];
17+
18+
Future<List<FlutterEngineMetricsPoint>> _parse(String jsonFileName) async {
19+
final GitDir gitDir = await GitDir.fromExisting('../../');
20+
// Somehow gitDir.currentBranch() doesn't work in Cirrus with "fatal: 'HEAD' -
21+
// not a valid ref". Therefore, we use "git log" to get the revision manually.
22+
final ProcessResult logResult = await gitDir
23+
.runCommand(<String>['log', '--pretty=format:%H]', '-n', '1']);
24+
if (logResult.exitCode != 0) {
25+
throw 'Unexpected exit code ${logResult.exitCode}';
26+
}
27+
final String gitRevision = logResult.stdout.toString();
28+
29+
final Map<String, dynamic> jsonResult =
30+
jsonDecode(File(jsonFileName).readAsStringSync());
31+
32+
final Map<String, dynamic> rawContext = jsonResult['context'];
33+
final Map<String, String> context = rawContext.map<String, String>(
34+
(String k, dynamic v) => MapEntry<String, String>(k, v.toString()),
35+
);
36+
37+
final List<FlutterEngineMetricsPoint> points = <FlutterEngineMetricsPoint>[];
38+
for (Map<String, dynamic> item in jsonResult['benchmarks']) {
39+
final String name = item[kNameKey];
40+
final Map<String, String> timeUnitMap = <String, String>{
41+
kUnitKey: item[kTimeUnitKey]
42+
};
43+
for (String subResult in item.keys) {
44+
if (!kSkippedSubResults.contains(subResult)) {
45+
num rawValue;
46+
try {
47+
rawValue = item[subResult];
48+
} catch (e) {
49+
print(
50+
'$subResult: ${item[subResult]} (${item[subResult].runtimeType}) is not a number');
51+
continue;
52+
}
53+
54+
final double value = rawValue is int ? rawValue.toDouble() : rawValue;
55+
points.add(
56+
FlutterEngineMetricsPoint(name, value, gitRevision,
57+
moreTags: <String, String>{kSubResultKey: subResult}
58+
..addAll(context)
59+
..addAll(subResult.endsWith('time')
60+
? timeUnitMap
61+
: <String, String>{})),
62+
);
63+
}
64+
}
65+
}
66+
67+
return points;
68+
}
69+
70+
Future<void> main(List<String> args) async {
71+
if (args.length != 1) {
72+
throw 'Must have one argument: <benchmark_json_file>';
73+
}
74+
final List<FlutterEngineMetricsPoint> points = await _parse(args[0]);
75+
final FlutterDestination destination =
76+
await FlutterDestination.makeFromCredentialsJson(
77+
jsonDecode(Platform.environment['BENCHMARK_GCP_CREDENTIALS']),
78+
);
79+
await destination.update(points);
80+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"context": {
3+
"date": "2019-12-17 15:14:14",
4+
"num_cpus": 56,
5+
"mhz_per_cpu": 2594,
6+
"cpu_scaling_enabled": true,
7+
"library_build_type": "release"
8+
},
9+
"benchmarks": [
10+
{
11+
"name": "BM_PaintRecordInit",
12+
"iterations": 6749079,
13+
"real_time": 101,
14+
"cpu_time": 101,
15+
"time_unit": "ns"
16+
},
17+
{
18+
"name": "BM_ParagraphShortLayout",
19+
"iterations": 151761,
20+
"real_time": 4460,
21+
"cpu_time": 4460,
22+
"time_unit": "ns"
23+
},
24+
{
25+
"name": "BM_ParagraphStylesBigO_BigO",
26+
"cpu_coefficient": 6548,
27+
"real_coefficient": 6548,
28+
"big_o": "N",
29+
"time_unit": "ns"
30+
}
31+
]
32+
}

testing/benchmark/pubspec.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: flutter_engine_benchmark
2+
3+
dependencies:
4+
git: any
5+
metrics_center:
6+
git: https://github.com/liyuqian/metrics_center.git
7+
8+
dev_dependencies:
9+
test: any
10+
pedantic: ^1.8.0
11+
12+
environment:
13+
sdk: ">=2.2.2 <3.0.0"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import 'dart:io';
2+
3+
import 'package:test/test.dart';
4+
5+
void main() {
6+
test('parse_and_send with example json does not crash.', () async {
7+
final String testCred =
8+
File('secret/test_gcp_credentials.json').readAsStringSync();
9+
Process.runSync('dart', <String>[
10+
'bin/parse_and_send.dart',
11+
'example/txt_benchmarks.json',
12+
], environment: <String, String>{
13+
'BENCHMARK_GCP_CREDENTIALS': testCred,
14+
});
15+
});
16+
}

0 commit comments

Comments
 (0)