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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library protoc.benchmark.html_runner;
6
7 import 'dart:async' show Future;
8 import 'dart:html';
9
10 import 'generated/benchmark.pb.dart' as pb;
11 import 'dashboard_model.dart' show DashboardModel;
12 import 'dashboard_view.dart' show DashboardView;
13 import 'report.dart' show createPlatform, createPackages, encodeReport;
14 import 'suite.dart' show runSuite;
15
16 import '../data/index.dart' as data;
17
18 /// Displays a dashboard that can be used to run benchmarks.
19 Future showDashboard(pb.Suite suite, Element container) async {
20
21 // set up model
22
23 var env = await loadBrowserEnv();
24 var reports = await loadReports();
25
26 var defaultReport = new pb.Report()
27 ..env = env;
28 var model =
29 new DashboardModel(reports, chooseBaseline(env, reports), defaultReport);
30
31 var view = new DashboardView();
32
33 // set up event handlers
34
35 bool running = false;
36 void runBenchmarks() {
37 if (running) return;
38 running = true;
39 () async {
40 for (pb.Report report in runSuite(suite)) {
41 report.env = env;
42 model = model.withReport(report);
43 await window.animationFrame;
44 view.render(model);
45 await new Future(() => null); // exit to regular timer task
46 }
47 running = false;
48 }();
49 }
50
51 view.onRunButtonClick.listen((_) => runBenchmarks());
52
53 view.onMenuChange.listen((String item) {
54 model = model.withBaseline(item);
55 view.render(model);
56 });
57
58 // show the view
59
60 view.render(model);
61 container.children.clear();
62 container.append(view.elt);
63 }
64
65 Future<pb.Env> loadBrowserEnv() async {
66 const advice = "Run a VM benchmark to create this file.";
67 var pubspecYaml = await _loadDataFile(data.pubspecYamlName, advice: advice);
68 var pubspecLock = await _loadDataFile(data.pubspecLockName, advice: advice);
69 var hostname = await _loadDataFile(data.hostfileName, advice: advice);
70
71 var platform = createPlatform()
72 ..hostname = hostname
73 ..userAgent = window.navigator.userAgent;
74
75 return new pb.Env()
76 ..page = window.location.pathname
77 ..platform = platform
78 ..packages = createPackages(pubspecYaml, pubspecLock);
79 }
80
81 /// Loads all the reports saved to benchmark/data.
82 Future<Map<String, pb.Report>> loadReports() async {
83 var out = <String, pb.Report>{};
84 // TODO: maybe parallelize?
85 for (var name in data.allReportNames) {
86 String json =
87 await _loadDataFile(name, optional: (name == data.latestVMReportName));
88 if (json != null) {
89 out[name] = new pb.Report.fromJson(json);
90 }
91 }
92 print("loaded ${out.length} reports");
93 return out;
94 }
95
96 /// Choose the report to display on the left side for comparison.
97 /// Returns null if no comparable report is found.
98 String chooseBaseline(pb.Env env, Map<String, pb.Report> reports) {
99 for (var name in reports.keys) {
100 var candidate = reports[name];
101 if (candidate.env.platform == env.platform) return name;
102 }
103 return null;
104 }
105
106 Future<String> _loadDataFile(String name,
107 {bool optional: false, String advice}) async {
108 try {
109 return await HttpRequest.getString("/data/$name");
110 } catch (e) {
111 if (optional) return null;
112 String error = "File is missing in benchmark/data: $name";
113 if (advice != null) {
114 error += ". $advice";
115 }
116 throw error;
117 }
118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698