OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library metrics; | 5 library metrics; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:html'; | 8 import 'dart:html'; |
9 import 'package:observatory/models.dart' as M; | 9 import 'package:observatory/models.dart' as M; |
10 import 'package:observatory/src/elements/helpers/nav_bar.dart'; | 10 import 'package:observatory/src/elements/helpers/nav_bar.dart'; |
11 import 'package:observatory/src/elements/helpers/nav_menu.dart'; | 11 import 'package:observatory/src/elements/helpers/nav_menu.dart'; |
12 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; | 12 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; |
13 import 'package:observatory/src/elements/helpers/tag.dart'; | 13 import 'package:observatory/src/elements/helpers/tag.dart'; |
14 import 'package:observatory/src/elements/metric/details.dart'; | 14 import 'package:observatory/src/elements/metric/details.dart'; |
15 import 'package:observatory/src/elements/metric/graph.dart'; | 15 import 'package:observatory/src/elements/metric/graph.dart'; |
16 import 'package:observatory/src/elements/nav/isolate_menu.dart'; | 16 import 'package:observatory/src/elements/nav/isolate_menu.dart'; |
17 import 'package:observatory/src/elements/nav/notify.dart'; | 17 import 'package:observatory/src/elements/nav/notify.dart'; |
18 import 'package:observatory/src/elements/nav/refresh.dart'; | 18 import 'package:observatory/src/elements/nav/refresh.dart'; |
19 import 'package:observatory/src/elements/nav/top_menu.dart'; | 19 import 'package:observatory/src/elements/nav/top_menu.dart'; |
20 import 'package:observatory/src/elements/nav/vm_menu.dart'; | 20 import 'package:observatory/src/elements/nav/vm_menu.dart'; |
21 | 21 |
22 class MetricsPageElement extends HtmlElement implements Renderable { | 22 class MetricsPageElement extends HtmlElement implements Renderable { |
23 static const tag = const Tag<MetricsPageElement>('metrics-page', | 23 static const tag = |
24 dependencies: const [ | 24 const Tag<MetricsPageElement>('metrics-page', dependencies: const [ |
25 MetricDetailsElement.tag, | 25 MetricDetailsElement.tag, |
26 MetricGraphElement.tag, | 26 MetricGraphElement.tag, |
27 NavTopMenuElement.tag, | 27 NavTopMenuElement.tag, |
28 NavVMMenuElement.tag, | 28 NavVMMenuElement.tag, |
29 NavIsolateMenuElement.tag, | 29 NavIsolateMenuElement.tag, |
30 NavRefreshElement.tag, | 30 NavRefreshElement.tag, |
31 NavNotifyElement.tag, | 31 NavNotifyElement.tag, |
32 ]); | 32 ]); |
33 | 33 |
34 RenderingScheduler<MetricsPageElement> _r; | 34 RenderingScheduler<MetricsPageElement> _r; |
35 | 35 |
36 Stream<RenderedEvent<MetricsPageElement>> get onRendered => _r.onRendered; | 36 Stream<RenderedEvent<MetricsPageElement>> get onRendered => _r.onRendered; |
37 | 37 |
38 M.VM _vm; | 38 M.VM _vm; |
39 M.IsolateRef _isolate; | 39 M.IsolateRef _isolate; |
40 M.EventRepository _events; | 40 M.EventRepository _events; |
41 M.NotificationRepository _notifications; | 41 M.NotificationRepository _notifications; |
42 M.MetricRepository _metrics; | 42 M.MetricRepository _metrics; |
43 List<M.Metric> _available; | 43 List<M.Metric> _available; |
44 M.Metric _selected; | 44 M.Metric _selected; |
45 | 45 |
46 | |
47 M.VMRef get vm => _vm; | 46 M.VMRef get vm => _vm; |
48 M.IsolateRef get isolate => _isolate; | 47 M.IsolateRef get isolate => _isolate; |
49 M.NotificationRepository get notifications => _notifications; | 48 M.NotificationRepository get notifications => _notifications; |
50 | 49 |
51 factory MetricsPageElement(M.VM vm, M.IsolateRef isolate, | 50 factory MetricsPageElement( |
52 M.EventRepository events, | 51 M.VM vm, |
53 M.NotificationRepository notifications, | 52 M.IsolateRef isolate, |
54 M.MetricRepository metrics, | 53 M.EventRepository events, |
55 {RenderingQueue queue}) { | 54 M.NotificationRepository notifications, |
| 55 M.MetricRepository metrics, |
| 56 {RenderingQueue queue}) { |
56 assert(vm != null); | 57 assert(vm != null); |
57 assert(isolate != null); | 58 assert(isolate != null); |
58 assert(events != null); | 59 assert(events != null); |
59 assert(notifications != null); | 60 assert(notifications != null); |
60 MetricsPageElement e = document.createElement(tag.name); | 61 MetricsPageElement e = document.createElement(tag.name); |
61 e._r = new RenderingScheduler(e, queue: queue); | 62 e._r = new RenderingScheduler(e, queue: queue); |
62 e._vm = vm; | 63 e._vm = vm; |
63 e._isolate = isolate; | 64 e._isolate = isolate; |
64 e._events = events; | 65 e._events = events; |
65 e._notifications = notifications; | 66 e._notifications = notifications; |
(...skipping 18 matching lines...) Expand all Loading... |
84 } | 85 } |
85 | 86 |
86 void render() { | 87 void render() { |
87 children = [ | 88 children = [ |
88 navBar([ | 89 navBar([ |
89 new NavTopMenuElement(queue: _r.queue), | 90 new NavTopMenuElement(queue: _r.queue), |
90 new NavVMMenuElement(_vm, _events, queue: _r.queue), | 91 new NavVMMenuElement(_vm, _events, queue: _r.queue), |
91 new NavIsolateMenuElement(_isolate, _events, queue: _r.queue), | 92 new NavIsolateMenuElement(_isolate, _events, queue: _r.queue), |
92 navMenu('metrics'), | 93 navMenu('metrics'), |
93 new NavRefreshElement(queue: _r.queue) | 94 new NavRefreshElement(queue: _r.queue) |
94 ..onRefresh.listen((e) { | 95 ..onRefresh.listen((e) { |
95 e.element.disabled = true; | 96 e.element.disabled = true; |
96 _refresh(); | 97 _refresh(); |
97 }), | 98 }), |
98 new NavNotifyElement(_notifications, queue: _r.queue) | 99 new NavNotifyElement(_notifications, queue: _r.queue) |
99 ]), | 100 ]), |
100 new DivElement()..classes = ['content-centered-big'] | 101 new DivElement() |
| 102 ..classes = ['content-centered-big'] |
101 ..children = [ | 103 ..children = [ |
102 new HeadingElement.h2()..text = 'Metrics', | 104 new HeadingElement.h2()..text = 'Metrics', |
103 new HRElement(), | 105 new HRElement(), |
104 new DivElement()..classes = ['memberList'] | 106 new DivElement() |
| 107 ..classes = ['memberList'] |
105 ..children = [ | 108 ..children = [ |
106 new DivElement()..classes = ['memberItem'] | 109 new DivElement() |
| 110 ..classes = ['memberItem'] |
107 ..children = [ | 111 ..children = [ |
108 new DivElement()..classes = ['memberName'] | 112 new DivElement() |
| 113 ..classes = ['memberName'] |
109 ..text = 'Metric', | 114 ..text = 'Metric', |
110 new DivElement()..classes = ['memberValue'] | 115 new DivElement() |
| 116 ..classes = ['memberValue'] |
111 ..children = _available == null | 117 ..children = _available == null |
112 ? [new SpanElement()..text = 'Loading..'] | 118 ? [new SpanElement()..text = 'Loading..'] |
113 : _createMetricSelect() | 119 : _createMetricSelect() |
114 ] | 120 ] |
115 ], | 121 ], |
116 new HRElement(), | 122 new HRElement(), |
117 new DivElement() | 123 new DivElement() |
118 ..children = _selected == null ? const [] | 124 ..children = _selected == null |
119 : [ | 125 ? const [] |
120 new MetricDetailsElement(_isolate, _selected, _metrics, | 126 : [ |
121 queue: _r.queue) | 127 new MetricDetailsElement(_isolate, _selected, _metrics, |
122 ], | 128 queue: _r.queue) |
| 129 ], |
123 new HRElement(), | 130 new HRElement(), |
124 new DivElement()..classes = ['graph'] | 131 new DivElement() |
125 ..children = _selected == null ? const [] | 132 ..classes = ['graph'] |
126 : [ | 133 ..children = _selected == null |
127 new MetricGraphElement(_isolate, _selected, _metrics, | 134 ? const [] |
128 queue: _r.queue) | 135 : [ |
129 ] | 136 new MetricGraphElement(_isolate, _selected, _metrics, |
| 137 queue: _r.queue) |
| 138 ] |
130 ], | 139 ], |
131 ]; | 140 ]; |
132 } | 141 } |
133 | 142 |
134 Future _refresh() async { | 143 Future _refresh() async { |
135 _available = (await _metrics.list(_isolate)).toList(); | 144 _available = (await _metrics.list(_isolate)).toList(); |
136 if (!_available.contains(_selected)) { | 145 if (!_available.contains(_selected)) { |
137 _selected = _available.first; | 146 _selected = _available.first; |
138 } | 147 } |
139 _r.dirty(); | 148 _r.dirty(); |
140 } | 149 } |
141 | 150 |
142 List<Element> _createMetricSelect() { | 151 List<Element> _createMetricSelect() { |
143 var s; | 152 var s; |
144 return [ | 153 return [ |
145 s = new SelectElement() | 154 s = new SelectElement() |
146 ..value = _selected.name | 155 ..value = _selected.name |
147 ..children = _available.map((metric) { | 156 ..children = _available.map((metric) { |
148 return new OptionElement(value: metric.name, | 157 return new OptionElement( |
149 selected: _selected == metric) | 158 value: metric.name, |
150 ..text = metric.name; | 159 selected: _selected == metric)..text = metric.name; |
151 }).toList(growable: false) | 160 }).toList(growable: false) |
152 ..onChange.listen((_) { | 161 ..onChange.listen((_) { |
153 _selected = _available[s.selectedIndex]; | 162 _selected = _available[s.selectedIndex]; |
154 _r.dirty(); | 163 _r.dirty(); |
155 }) | 164 }) |
156 ]; | 165 ]; |
157 } | 166 } |
158 } | 167 } |
OLD | NEW |