| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 vm_view_element; | 5 library vm_view_element; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'observatory_element.dart'; | 8 import 'dart:html'; |
| 9 import 'package:observatory/service.dart'; | 9 import 'package:observatory/models.dart' as M; |
| 10 import 'package:polymer/polymer.dart'; | 10 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; |
| 11 import 'package:observatory/src/elements/helpers/tag.dart'; |
| 12 import 'package:observatory/src/elements/helpers/uris.dart'; |
| 13 import 'package:observatory/src/elements/isolate/summary.dart'; |
| 14 import 'package:observatory/src/elements/nav/bar.dart'; |
| 15 import 'package:observatory/src/elements/nav/notify.dart'; |
| 16 import 'package:observatory/src/elements/nav/refresh.dart'; |
| 17 import 'package:observatory/src/elements/nav/top_menu.dart'; |
| 18 import 'package:observatory/src/elements/nav/vm_menu.dart'; |
| 19 import 'package:observatory/src/elements/view_footer.dart'; |
| 11 | 20 |
| 12 @CustomTag('vm-view') | 21 class VMViewElement extends HtmlElement implements Renderable { |
| 13 class VMViewElement extends ObservatoryElement { | 22 static const tag = const Tag<VMViewElement>('vm-view', |
| 14 @published VM vm; | 23 dependencies: const [ |
| 15 @published DartError error; | 24 IsolateSummaryElement.tag, |
| 25 NavBarElement.tag, |
| 26 NavTopMenuElement.tag, |
| 27 NavVMMenuElement.tag, |
| 28 NavRefreshElement.tag, |
| 29 NavNotifyElement.tag, |
| 30 ViewFooterElement.tag |
| 31 ]); |
| 32 |
| 33 RenderingScheduler<VMViewElement> _r; |
| 34 |
| 35 Stream<RenderedEvent<VMViewElement>> get onRendered => _r.onRendered; |
| 36 |
| 37 M.VM _vm; |
| 38 M.EventRepository _events; |
| 39 M.NotificationRepository _notifications; |
| 40 M.IsolateRepository _isolates; |
| 41 M.ScriptRepository _scripts; |
| 42 StreamSubscription _vmSubscription; |
| 43 StreamSubscription _startSubscription; |
| 44 StreamSubscription _exitSubscription; |
| 45 |
| 46 M.VMRef get vm => _vm; |
| 47 M.NotificationRepository get notifications => _notifications; |
| 48 |
| 49 factory VMViewElement(M.VM vm, M.EventRepository events, |
| 50 M.NotificationRepository notifications, |
| 51 M.IsolateRepository isolates, |
| 52 M.ScriptRepository scripts, |
| 53 {RenderingQueue queue}) { |
| 54 assert(vm != null); |
| 55 assert(events != null); |
| 56 assert(notifications != null); |
| 57 VMViewElement e = document.createElement(tag.name); |
| 58 e._r = new RenderingScheduler(e, queue: queue); |
| 59 e._vm = vm; |
| 60 e._events = events; |
| 61 e._notifications = notifications; |
| 62 e._isolates = isolates; |
| 63 e._scripts = scripts; |
| 64 return e; |
| 65 } |
| 16 | 66 |
| 17 VMViewElement.created() : super.created(); | 67 VMViewElement.created() : super.created(); |
| 18 | 68 |
| 19 Future refresh() { | 69 @override |
| 20 return vm.reload().then((vm) => vm.reloadIsolates()); | 70 attached() { |
| 71 super.attached(); |
| 72 _r.enable(); |
| 73 _vmSubscription = _events.onVMUpdate.listen((e) { |
| 74 _vm = e.vm; |
| 75 _r.dirty(); |
| 76 }); |
| 77 _startSubscription = _events.onIsolateStart.listen((_) => _r.dirty()); |
| 78 _exitSubscription = _events.onIsolateExit.listen((_) => _r.dirty()); |
| 79 } |
| 80 |
| 81 @override |
| 82 detached() { |
| 83 super.detached(); |
| 84 _r.disable(notify: true); |
| 85 children = []; |
| 86 _vmSubscription.cancel(); |
| 87 _startSubscription.cancel(); |
| 88 _exitSubscription.cancel(); |
| 89 } |
| 90 |
| 91 void render() { |
| 92 final uptime = new DateTime.now().difference(_vm.startTime); |
| 93 final isolates = _vm.isolates.toList(); |
| 94 children = [ |
| 95 new NavBarElement(queue: _r.queue) |
| 96 ..children = [ |
| 97 new NavTopMenuElement(queue: _r.queue), |
| 98 new NavVMMenuElement(_vm, _events, last: true, queue: _r.queue), |
| 99 new NavRefreshElement(queue: _r.queue) |
| 100 ..onRefresh.listen((e) async { |
| 101 e.element.disabled = true; |
| 102 _r.dirty(); |
| 103 }), |
| 104 new NavNotifyElement(_notifications, queue: _r.queue) |
| 105 ], |
| 106 new DivElement()..classes = ['content-centered-big'] |
| 107 ..children = [ |
| 108 new HeadingElement.h1()..text = 'VM', |
| 109 new HRElement(), |
| 110 new DivElement()..classes = ['memberList'] |
| 111 ..children = [ |
| 112 new DivElement()..classes = ['memberItem'] |
| 113 ..children = [ |
| 114 new DivElement()..classes = ['memberName'] |
| 115 ..text = 'name', |
| 116 new DivElement()..classes = ['memberValue'] |
| 117 ..text = _vm.displayName |
| 118 ], |
| 119 new DivElement()..classes = ['memberItem'] |
| 120 ..children = [ |
| 121 new DivElement()..classes = ['memberName'] |
| 122 ..text = 'version', |
| 123 new DivElement()..classes = ['memberValue'] |
| 124 ..text = _vm.version |
| 125 ], |
| 126 new DivElement()..classes = ['memberItem'] |
| 127 ..children = [ |
| 128 new DivElement()..classes = ['memberName'] |
| 129 ..text = 'started at', |
| 130 new DivElement()..classes = ['memberValue'] |
| 131 ..text = '${_vm.startTime}' |
| 132 ], |
| 133 new DivElement()..classes = ['memberItem'] |
| 134 ..children = [ |
| 135 new DivElement()..classes = ['memberName'] |
| 136 ..text = 'uptime', |
| 137 new DivElement()..classes = ['memberValue'] |
| 138 ..text = '$uptime' |
| 139 ], |
| 140 new DivElement()..classes = ['memberItem'] |
| 141 ..children = [ |
| 142 new DivElement()..classes = ['memberName'] |
| 143 ..text = 'refreshed at', |
| 144 new DivElement()..classes = ['memberValue'] |
| 145 ..text = '${new DateTime.now()}' |
| 146 ], |
| 147 new DivElement()..classes = ['memberItem'] |
| 148 ..children = [ |
| 149 new DivElement()..classes = ['memberName'] |
| 150 ..text = 'pid', |
| 151 new DivElement()..classes = ['memberValue'] |
| 152 ..text = '${_vm.pid}' |
| 153 ], |
| 154 new DivElement()..classes = ['memberItem'] |
| 155 ..children = [ |
| 156 new DivElement()..classes = ['memberName'] |
| 157 ..text = 'maxRSS', |
| 158 new DivElement()..classes = ['memberValue'] |
| 159 ..text = '${_vm.maxRSS}' |
| 160 ], |
| 161 new BRElement(), |
| 162 new DivElement()..classes = ['memberItem'] |
| 163 ..children = [ |
| 164 new DivElement()..classes = ['memberName'] |
| 165 ..children = [ |
| 166 new SpanElement()..text = 'see ', |
| 167 new AnchorElement(href: Uris.flags())..text = 'flags' |
| 168 ], |
| 169 new DivElement()..classes = ['memberValue'] |
| 170 ..children = [ |
| 171 new SpanElement()..text = 'view ', |
| 172 new AnchorElement(href: Uris.timeline())..text = 'timeline
' |
| 173 ] |
| 174 ] |
| 175 ], |
| 176 new BRElement(), |
| 177 new HeadingElement.h1()..text = 'Isolates (${isolates.length})', |
| 178 new HRElement(), |
| 179 new UListElement()..classes = ['list-group'] |
| 180 ..children = isolates.expand((i) => [ |
| 181 new LIElement()..classes = ['list-group-item'] |
| 182 ..children = [ |
| 183 new IsolateSummaryElement(i, _isolates, _events, _scripts, |
| 184 queue: _r.queue) |
| 185 ], |
| 186 new HRElement() |
| 187 ]).toList(), |
| 188 new ViewFooterElement(queue: _r.queue) |
| 189 ] |
| 190 ]; |
| 21 } | 191 } |
| 22 } | 192 } |
| OLD | NEW |