OLD | NEW |
(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.dashboard_model; |
| 6 |
| 7 import 'generated/benchmark.pb.dart' as pb; |
| 8 |
| 9 /// Contains the viewable state of the dashboard. (Immutable.) |
| 10 class DashboardModel { |
| 11 final Map<String, pb.Report> savedReports; |
| 12 // The name of the saved report to display. |
| 13 final String baselineName; |
| 14 |
| 15 final pb.Report latest; |
| 16 |
| 17 DashboardModel(this.savedReports, this.baselineName, this.latest); |
| 18 |
| 19 DashboardModel withBaseline(String name) => |
| 20 new DashboardModel(savedReports, name, latest); |
| 21 |
| 22 DashboardModel withReport(pb.Report right) => |
| 23 new DashboardModel(savedReports, baselineName, right); |
| 24 |
| 25 /// Returns true if the Run button should be enabled. |
| 26 bool get canRun => !latest.hasStatus() || latest.status != pb.Status.RUNNING; |
| 27 |
| 28 /// Returns the samples to use for comparison. |
| 29 BaselineSamples getBaselineSamples() { |
| 30 var r = savedReports[baselineName]; |
| 31 if (r == null) return new BaselineSamples([]); |
| 32 return new BaselineSamples(r.responses); |
| 33 } |
| 34 } |
| 35 |
| 36 class BaselineSamples { |
| 37 final samples = <String, pb.Sample>{}; |
| 38 BaselineSamples(List<pb.Response> responses) { |
| 39 for (var response in responses) { |
| 40 samples[_key(response.request)] = medianSample(response); |
| 41 } |
| 42 } |
| 43 |
| 44 pb.Sample getSample(pb.Request request) => samples[_key(request)]; |
| 45 |
| 46 String _key(pb.Request request) => |
| 47 request.id.name + "-" + request.params.toString(); |
| 48 } |
| 49 |
| 50 /// Returns the sample with the median ints reads per second. |
| 51 pb.Sample medianSample(pb.Response response) { |
| 52 if (response.samples.isEmpty) return null; |
| 53 var samples = []..addAll(response.samples); |
| 54 samples.sort((a, b) { |
| 55 return intReadsPerSecond(a).compareTo(intReadsPerSecond(b)); |
| 56 }); |
| 57 int index = samples.length ~/ 2; |
| 58 print("length: ${samples.length} index: $index"); |
| 59 return samples[index]; |
| 60 } |
| 61 |
| 62 /// Returns the sample with the best int reads per second. |
| 63 pb.Sample maxSample(pb.Response response) { |
| 64 pb.Sample best; |
| 65 for (var s in response.samples) { |
| 66 if (best == null) best = s; |
| 67 if (intReadsPerSecond(best) < intReadsPerSecond(s)) { |
| 68 best = s; |
| 69 } |
| 70 } |
| 71 return best; |
| 72 } |
| 73 |
| 74 double intReadsPerSecond(pb.Sample s) => |
| 75 s.counts.int32Reads * 1000000 / s.duration; |
OLD | NEW |