Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
|
koda
2014/08/11 16:34:53
2014
Cutch
2014/08/27 22:25:39
Done.
| |
| 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 metrics; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 import 'dart:html'; | |
| 9 import 'observatory_element.dart'; | |
| 10 import 'package:observatory/app.dart'; | |
| 11 import 'package:observatory/service.dart'; | |
| 12 import 'package:polymer/polymer.dart'; | |
| 13 | |
| 14 @CustomTag('metrics-page') | |
| 15 class MetricsPageElement extends ObservatoryElement { | |
| 16 MetricsPageElement.created() : super.created(); | |
| 17 | |
| 18 @observable MetricsPage page; | |
| 19 @observable Isolate isolate; | |
| 20 @observable Metric selectedMetric; | |
| 21 | |
| 22 void isolateChanged(oldValue) { | |
| 23 if (isolate != null) { | |
| 24 isolate.refreshMetrics(); | |
| 25 } | |
| 26 } | |
| 27 | |
| 28 void refresh(var done) { | |
| 29 isolate.refreshMetrics().whenComplete(done); | |
| 30 } | |
| 31 | |
| 32 void selectMetric(Event e, var detail, Element target) { | |
| 33 String name = target.attributes['data-name']; | |
| 34 selectedMetric = isolate.metrics[name]; | |
| 35 } | |
| 36 } | |
| 37 | |
| 38 @CustomTag('metric-details') | |
| 39 class MetricDetailsElement extends ObservatoryElement { | |
| 40 MetricDetailsElement.created() : super.created(); | |
| 41 @published MetricsPage page; | |
| 42 @published Metric metric; | |
| 43 | |
| 44 int _findIndex(SelectElement element, int value) { | |
| 45 if (element == null) { | |
| 46 return null; | |
| 47 } | |
| 48 for (var i = 0; i < element.options.length; i++) { | |
| 49 var optionElement = element.options[i]; | |
| 50 int optionValue = int.parse(optionElement.value); | |
| 51 if (optionValue == value) { | |
| 52 return i; | |
| 53 } | |
| 54 } | |
| 55 return null; | |
| 56 } | |
| 57 | |
| 58 metricChanged(oldValue) { | |
| 59 SelectElement refreshRateElement = shadowRoot.querySelector('#refreshrate'); | |
| 60 if (refreshRateElement == null) { | |
| 61 // Race between shadowRoot setup and metricChanged event. | |
| 62 return; | |
| 63 } | |
| 64 int period = 0; | |
| 65 if (metric.poller != null) { | |
| 66 period = metric.poller.period; | |
| 67 } | |
| 68 var index = _findIndex(refreshRateElement, period); | |
| 69 assert(index != null); | |
| 70 refreshRateElement.selectedIndex = index; | |
| 71 SelectElement bufferSizeElement = shadowRoot.querySelector('#buffersize'); | |
| 72 index = _findIndex(bufferSizeElement, metric.sampleBufferSize); | |
| 73 assert(index != null); | |
| 74 bufferSizeElement.selectedIndex = index; | |
| 75 } | |
| 76 | |
| 77 void refreshRateChange(Event e, var detail, Element target) { | |
| 78 var value = int.parse((target as SelectElement).value); | |
| 79 if (metric == null) { | |
| 80 return; | |
| 81 } | |
| 82 page.setRefreshPeriod(value, metric); | |
| 83 } | |
| 84 | |
| 85 void sampleBufferSizeChange(Event e, var detail, Element target) { | |
| 86 var value = int.parse((target as SelectElement).value); | |
| 87 if (metric == null) { | |
| 88 return; | |
| 89 } | |
| 90 metric.sampleBufferSize = value; | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 @CustomTag('metrics-graph') | |
| 95 class MetricsGraphElement extends ObservatoryElement { | |
| 96 MetricsGraphElement.created() : super.created(); | |
| 97 | |
| 98 final DataTable _table = new DataTable(); | |
| 99 Chart _chart; | |
| 100 | |
| 101 @published Metric metric; | |
| 102 @observable Isolate isolate; | |
| 103 | |
| 104 void attached() { | |
| 105 // Redraw once a second. | |
| 106 pollPeriod = new Duration(milliseconds: 1000); | |
|
koda
2014/08/11 16:34:53
seconds: 1
Cutch
2014/08/27 22:25:39
Done.
| |
| 107 super.attached(); | |
| 108 } | |
| 109 | |
| 110 void detached() { | |
| 111 super.detached(); | |
| 112 } | |
| 113 | |
| 114 void onPoll() { | |
| 115 draw(); | |
| 116 } | |
| 117 | |
| 118 void draw() { | |
| 119 if (_chart == null) { | |
| 120 // Construct chart. | |
| 121 var element = shadowRoot.querySelector('#graph'); | |
| 122 if (element == null) { | |
| 123 // Bail. | |
| 124 return; | |
| 125 } | |
| 126 _chart = new Chart('LineChart', element); | |
| 127 } | |
| 128 if (metric == null) { | |
| 129 return; | |
| 130 } | |
| 131 _update(); | |
| 132 _chart.draw(_table); | |
| 133 } | |
| 134 | |
| 135 void _setupInitialDataTable() { | |
| 136 _table.clearColumns(); | |
| 137 // Only one metric right now. | |
| 138 _table.addColumn('timeofday', 'time'); | |
| 139 _table.addColumn('number', metric.name); | |
| 140 } | |
| 141 | |
| 142 void _update() { | |
| 143 _table.clearRows(); | |
| 144 for (var i = 0; i < metric.samples.length; i++) { | |
| 145 var sample = metric.samples[i]; | |
| 146 _table.addTimeOfDayValue(sample.time, sample.value); | |
| 147 } | |
| 148 } | |
| 149 | |
| 150 metricChanged(oldValue) { | |
| 151 if (oldValue != metric) { | |
| 152 _setupInitialDataTable(); | |
| 153 } | |
| 154 } | |
| 155 } | |
| OLD | NEW |