Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2017, 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 | |
|
siva
2017/08/03 18:14:51
For all these new files it might be nice to add a
cbernaschina
2017/08/03 22:32:53
Done.
| |
| 5 import 'dart:async'; | |
| 6 import 'dart:html'; | |
| 7 import 'package:observatory/models.dart' as M; | |
| 8 import 'package:observatory/src/elements/helpers/nav_bar.dart'; | |
| 9 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; | |
| 10 import 'package:observatory/src/elements/helpers/tag.dart'; | |
| 11 import 'package:observatory/src/elements/nav/notify.dart'; | |
| 12 import 'package:observatory/src/elements/memory/graph.dart'; | |
| 13 import 'package:observatory/src/elements/memory/profile.dart'; | |
| 14 | |
| 15 class MemoryDashboardElement extends HtmlElement implements Renderable { | |
| 16 static const tag = const Tag<MemoryDashboardElement>('memory-dashboard', | |
| 17 dependencies: const [ | |
| 18 NavNotifyElement.tag, | |
| 19 MemoryGraphElement.tag, | |
| 20 MemoryProfileElement.tag | |
| 21 ]); | |
| 22 | |
| 23 RenderingScheduler<MemoryDashboardElement> _r; | |
| 24 | |
| 25 Stream<RenderedEvent<MemoryDashboardElement>> get onRendered => _r.onRendered; | |
| 26 | |
| 27 M.VMRef _vm; | |
| 28 M.IsolateRepository _isolates; | |
| 29 M.EditorRepository _editor; | |
| 30 M.AllocationProfileRepository _allocations; | |
| 31 M.EventRepository _events; | |
| 32 M.NotificationRepository _notifications; | |
| 33 | |
| 34 M.VM get vm => _vm; | |
|
siva
2017/08/03 18:14:51
How does this work? _vm is a M.VMRef type and the
cbernaschina
2017/08/03 22:32:53
Done
(see mail about the strong mode analyzer)
| |
| 35 M.NotificationRepository get notifications => _notifications; | |
| 36 | |
| 37 factory MemoryDashboardElement( | |
| 38 M.VM vm, | |
| 39 M.IsolateRepository isolates, | |
| 40 M.EditorRepository editor, | |
| 41 M.AllocationProfileRepository allocations, | |
| 42 M.EventRepository events, | |
| 43 M.NotificationRepository notifications, | |
| 44 {RenderingQueue queue}) { | |
| 45 assert(vm != null); | |
| 46 assert(isolates != null); | |
| 47 assert(editor != null); | |
| 48 assert(allocations != null); | |
| 49 assert(events != null); | |
| 50 assert(notifications != null); | |
| 51 MemoryDashboardElement e = document.createElement(tag.name); | |
| 52 e._r = new RenderingScheduler(e, queue: queue); | |
| 53 e._vm = vm; | |
| 54 e._isolates = isolates; | |
| 55 e._editor = editor; | |
| 56 e._allocations = allocations; | |
| 57 e._events = events; | |
| 58 e._notifications = notifications; | |
| 59 return e; | |
| 60 } | |
| 61 | |
| 62 MemoryDashboardElement.created() : super.created(); | |
| 63 | |
| 64 @override | |
| 65 attached() { | |
| 66 super.attached(); | |
| 67 _r.enable(); | |
| 68 } | |
| 69 | |
| 70 @override | |
| 71 detached() { | |
| 72 super.detached(); | |
| 73 _r.disable(notify: true); | |
| 74 children = []; | |
| 75 } | |
| 76 | |
| 77 M.IsolateRef _isolate; | |
| 78 | |
| 79 MemoryGraphElement _graph; | |
| 80 | |
| 81 void render() { | |
| 82 if (_graph == null) { | |
| 83 _graph = new MemoryGraphElement(vm, _isolates, _events, queue: _r.queue) | |
| 84 ..onIsolateSelected.listen(_onIsolateSelected); | |
| 85 } | |
| 86 children = [ | |
| 87 navBar([new NavNotifyElement(_notifications, queue: _r.queue)]), | |
| 88 new DivElement() | |
| 89 ..classes = ['content-centered-big'] | |
| 90 ..children = [ | |
| 91 new HeadingElement.h2()..text = 'Memory Dashboard', | |
| 92 new HRElement(), | |
| 93 _graph, | |
| 94 new HRElement(), | |
| 95 ], | |
| 96 ]; | |
| 97 if (_isolate == null) { | |
| 98 children.add(new DivElement() | |
| 99 ..classes = ['content-centered-big'] | |
| 100 ..children = [new HeadingElement.h1()..text = "No isolate selected"]); | |
| 101 } else { | |
| 102 final MemoryProfileElement profile = | |
| 103 new MemoryProfileElement(_isolate, _editor, _events, _allocations); | |
| 104 final ButtonElement reload = new ButtonElement(); | |
| 105 final ButtonElement gc = new ButtonElement(); | |
| 106 children.addAll([ | |
| 107 new DivElement() | |
| 108 ..classes = ['content-centered-big'] | |
| 109 ..children = [ | |
| 110 new HeadingElement.h1() | |
| 111 ..children = [ | |
| 112 new Text("Isolate ${_isolate.name}"), | |
| 113 reload | |
| 114 ..classes = ['link', 'big'] | |
| 115 ..text = ' ↺ ' | |
| 116 ..title = 'Refresh' | |
| 117 ..onClick.listen((e) async { | |
| 118 gc.disabled = true; | |
| 119 reload.disabled = true; | |
| 120 await profile.reload(); | |
| 121 gc.disabled = false; | |
| 122 reload.disabled = false; | |
| 123 }), | |
| 124 gc | |
| 125 ..classes = ['link', 'big'] | |
| 126 ..text = ' ♺ ' | |
| 127 ..title = 'Collect Garbage' | |
| 128 ..onClick.listen((e) async { | |
| 129 gc.disabled = true; | |
| 130 reload.disabled = true; | |
| 131 await profile.reload(gc: true); | |
| 132 gc.disabled = false; | |
| 133 reload.disabled = false; | |
| 134 }), | |
| 135 ] | |
| 136 ], | |
| 137 profile | |
| 138 ]); | |
| 139 } | |
| 140 } | |
| 141 | |
| 142 void _onIsolateSelected(IsolateSelectedEvent e) { | |
| 143 _r.checkAndReact(_isolate, e.isolate); | |
| 144 _isolate = e.isolate; | |
| 145 } | |
| 146 } | |
| OLD | NEW |