Skip to content

Commit

Permalink
Replace hand-maintained list of previous benchmarks with pkg:build (f…
Browse files Browse the repository at this point in the history
…lutter#128)

MUCH easier to maintain
  • Loading branch information
kevmoo authored Sep 25, 2018
1 parent 74648d3 commit feab39e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 34 deletions.
24 changes: 0 additions & 24 deletions benchmark/data/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,3 @@ const String pubspecYamlName = "pubspec.link.yaml";
const String pubspecLockName = "pubspec.link.lock";

const String hostfileName = "hostname.txt";

List<String> allReportNames = const [
latestVMReportName,
"skybrian5/0.4.2/json_chrome.pb.json",
"skybrian5/0.4.2/json_vm.pb.json",
"skybrian5/0.4.2/props_chrome.pb.json",
"skybrian5/0.4.2/props_vm.pb.json",
"skybrian5/head/json_chrome.pb.json",
"skybrian5/head/json_vm.pb.json",
"skybrian5/head/props_chrome.pb.json",
"skybrian5/head/props_vm.pb.json",
"skybrian-macbookpro/0.4.2/json_chrome.pb.json",
"skybrian-macbookpro/0.4.2/json_vm.pb.json",
"skybrian-macbookpro/0.4.2/props_chrome.pb.json",
"skybrian-macbookpro/0.4.2/props_vm.pb.json",
"skybrian-macbookpro/0.5.0/json_chrome.pb.json",
"skybrian-macbookpro/0.5.0/json_vm.pb.json",
"skybrian-macbookpro/0.5.0/props_chrome.pb.json",
"skybrian-macbookpro/0.5.0/props_vm.pb.json",
"skybrian-macbookpro/head/json_chrome.pb.json",
"skybrian-macbookpro/head/json_vm.pb.json",
"skybrian-macbookpro/head/props_chrome.pb.json",
"skybrian-macbookpro/head/props_vm.pb.json",
];
18 changes: 9 additions & 9 deletions benchmark/lib/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
library protoc.benchmark.html_runner;

import 'dart:async' show Future;
import 'dart:convert';
import 'dart:html';
import 'dart:js' show context, JsObject;

Expand Down Expand Up @@ -127,15 +128,14 @@ Future<pb.Env> loadBrowserEnv() async {
/// Loads all the reports saved to benchmark/data.
Future<Map<String, pb.Report>> loadReports(pb.Suite suite) async {
var out = <String, pb.Report>{};
// TODO: maybe parallelize?
for (var name in data.allReportNames) {
String json =
await _loadDataFile(name, optional: (name == data.latestVMReportName));
if (json != null) {
var report = new pb.Report.fromJson(json);
if (isCompatibleBaseline(suite, report)) {
out[name] = report;
}

var dataJsonContent = await _loadDataFile('data.json');
var dataJson = jsonDecode(dataJsonContent) as Map<String, dynamic>;

for (var entry in dataJson.entries) {
var report = new pb.Report.fromJson(entry.value);
if (isCompatibleBaseline(suite, report)) {
out[entry.key] = report;
}
}
print("loaded ${out.length} reports");
Expand Down
9 changes: 8 additions & 1 deletion build.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Configuration for Dart build system - https://github.com/dart-lang/build
# Read about `build.yaml` at https://pub.dartlang.org/packages/build_config
# Enables running benchmarks via browser: `pub run build_runner serve`
targets:
$default:
Expand All @@ -11,3 +11,10 @@ targets:
- --minify
#- --trust-primitives
#- --omit-implicit-checks

builders:
benchmarkBuilder:
import: "tool/builder.dart"
builder_factories: ["benchmarkBuilder"]
build_extensions: {"lib/$lib$": ["benchmark/data/data.json"]}
auto_apply: root_package
37 changes: 37 additions & 0 deletions tool/builder.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. 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';

import 'package:build/build.dart';
import 'package:glob/glob.dart';

Builder benchmarkBuilder(BuilderOptions options) => _BenchmarkBuilder();

class _BenchmarkBuilder implements Builder {
@override
Future build(BuildStep buildStep) async {
var data = <String, String>{};

await for (var item in buildStep
.findAssets(Glob('benchmark/**/*.pb.json'))
.where((id) =>
id.pathSegments.length > 2 &&
id.pathSegments[0] == 'benchmark' &&
id.pathSegments[1] == 'data')) {
data[item.pathSegments.skip(2).join('/')] =
await buildStep.readAsString(item);
}

await buildStep.writeAsString(
AssetId(buildStep.inputId.package, 'benchmark/data/data.json'),
JsonEncoder.withIndent(' ').convert(data));
}

@override
final buildExtensions = const {
r'lib/$lib$': ['benchmark/data/data.json']
};
}

0 comments on commit feab39e

Please sign in to comment.