Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(812)

Unified Diff: benchmark/lib/dashboard.dart

Issue 1330723003: Implement a better dashboard for running benchmarks (Closed) Base URL: git@github.com:dart-lang/dart-protoc-plugin.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: benchmark/lib/dashboard.dart
diff --git a/benchmark/lib/dashboard.dart b/benchmark/lib/dashboard.dart
new file mode 100644
index 0000000000000000000000000000000000000000..8d15e9ec74bbd0377bc54b5547e7b42531d4b975
--- /dev/null
+++ b/benchmark/lib/dashboard.dart
@@ -0,0 +1,118 @@
+// Copyright (c) 2015, 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.
+
+library protoc.benchmark.html_runner;
+
+import 'dart:async' show Future;
+import 'dart:html';
+
+import 'generated/benchmark.pb.dart' as pb;
+import 'dashboard_model.dart' show DashboardModel;
+import 'dashboard_view.dart' show DashboardView;
+import 'report.dart' show createPlatform, createPackages, encodeReport;
+import 'suite.dart' show runSuite;
+
+import '../data/index.dart' as data;
+
+/// Displays a dashboard that can be used to run benchmarks.
+Future showDashboard(pb.Suite suite, Element container) async {
+
+ // set up model
+
+ var env = await loadBrowserEnv();
+ var reports = await loadReports();
+
+ var defaultReport = new pb.Report()
+ ..env = env;
+ var model =
+ new DashboardModel(reports, chooseBaseline(env, reports), defaultReport);
+
+ var view = new DashboardView();
+
+ // set up event handlers
+
+ bool running = false;
+ void runBenchmarks() {
+ if (running) return;
+ running = true;
+ () async {
+ for (pb.Report report in runSuite(suite)) {
+ report.env = env;
+ model = model.withReport(report);
+ await window.animationFrame;
+ view.render(model);
+ await new Future(() => null); // exit to regular timer task
+ }
+ running = false;
+ }();
+ }
+
+ view.onRunButtonClick.listen((_) => runBenchmarks());
+
+ view.onMenuChange.listen((String item) {
+ model = model.withBaseline(item);
+ view.render(model);
+ });
+
+ // show the view
+
+ view.render(model);
+ container.children.clear();
+ container.append(view.elt);
+}
+
+Future<pb.Env> loadBrowserEnv() async {
+ const advice = "Run a VM benchmark to create this file.";
+ var pubspecYaml = await _loadDataFile(data.pubspecYamlName, advice: advice);
+ var pubspecLock = await _loadDataFile(data.pubspecLockName, advice: advice);
+ var hostname = await _loadDataFile(data.hostfileName, advice: advice);
+
+ var platform = createPlatform()
+ ..hostname = hostname
+ ..userAgent = window.navigator.userAgent;
+
+ return new pb.Env()
+ ..page = window.location.pathname
+ ..platform = platform
+ ..packages = createPackages(pubspecYaml, pubspecLock);
+}
+
+/// Loads all the reports saved to benchmark/data.
+Future<Map<String, pb.Report>> loadReports() 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) {
+ out[name] = new pb.Report.fromJson(json);
+ }
+ }
+ print("loaded ${out.length} reports");
+ return out;
+}
+
+/// Choose the report to display on the left side for comparison.
+/// Returns null if no comparable report is found.
+String chooseBaseline(pb.Env env, Map<String, pb.Report> reports) {
+ for (var name in reports.keys) {
+ var candidate = reports[name];
+ if (candidate.env.platform == env.platform) return name;
+ }
+ return null;
+}
+
+Future<String> _loadDataFile(String name,
+ {bool optional: false, String advice}) async {
+ try {
+ return await HttpRequest.getString("/data/$name");
+ } catch (e) {
+ if (optional) return null;
+ String error = "File is missing in benchmark/data: $name";
+ if (advice != null) {
+ error += ". $advice";
+ }
+ throw error;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698