OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library native_memory_profile; | |
6 | |
7 import 'dart:async'; | |
8 import 'dart:html'; | |
9 import 'package:observatory/models.dart' as M; | |
10 import 'package:observatory/src/elements/cpu_profile/virtual_tree.dart'; | |
11 import 'package:observatory/src/elements/helpers/nav_bar.dart'; | |
12 import 'package:observatory/src/elements/helpers/nav_menu.dart'; | |
13 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; | |
14 import 'package:observatory/src/elements/helpers/tag.dart'; | |
15 import 'package:observatory/src/elements/helpers/uris.dart'; | |
16 import 'package:observatory/src/elements/nav/notify.dart'; | |
17 import 'package:observatory/src/elements/nav/refresh.dart'; | |
18 import 'package:observatory/src/elements/nav/top_menu.dart'; | |
19 import 'package:observatory/src/elements/nav/vm_menu.dart'; | |
20 import 'package:observatory/src/elements/sample_buffer_control.dart'; | |
21 import 'package:observatory/src/elements/stack_trace_tree_config.dart'; | |
22 | |
23 class NativeMemoryProfileElement extends HtmlElement implements Renderable { | |
24 static const tag = const Tag<NativeMemoryProfileElement>( | |
25 'native-memory-profile', | |
26 dependencies: const [ | |
27 NavTopMenuElement.tag, | |
28 NavVMMenuElement.tag, | |
29 NavRefreshElement.tag, | |
30 NavNotifyElement.tag, | |
31 SampleBufferControlElement.tag, | |
32 StackTraceTreeConfigElement.tag, | |
33 CpuProfileVirtualTreeElement.tag, | |
34 ]); | |
35 | |
36 RenderingScheduler<NativeMemoryProfileElement> _r; | |
37 | |
38 Stream<RenderedEvent<NativeMemoryProfileElement>> get onRendered => | |
39 _r.onRendered; | |
40 | |
41 M.VM _vm; | |
42 M.EventRepository _events; | |
43 M.NotificationRepository _notifications; | |
44 M.NativeMemorySampleProfileRepository _profiles; | |
45 Stream<M.SampleProfileLoadingProgressEvent> _progressStream; | |
46 M.SampleProfileLoadingProgress _progress; | |
47 M.SampleProfileTag _tag = M.SampleProfileTag.none; | |
48 ProfileTreeMode _mode = ProfileTreeMode.function; | |
49 M.ProfileTreeDirection _direction = M.ProfileTreeDirection.exclusive; | |
50 String _filter = ''; | |
51 | |
52 M.NotificationRepository get notifications => _notifications; | |
53 M.NativeMemorySampleProfileRepository get profiles => _profiles; | |
54 // With non-isolate version. | |
55 M.VMRef get vm => _vm; | |
56 | |
57 factory NativeMemoryProfileElement( | |
58 M.VM vm, | |
59 M.EventRepository events, | |
60 M.NotificationRepository notifications, | |
61 M.NativeMemorySampleProfileRepository profiles, | |
62 {RenderingQueue queue}) { | |
63 assert(vm != null); | |
64 assert(events != null); | |
65 assert(notifications != null); | |
66 assert(profiles != null); | |
67 NativeMemoryProfileElement e = document.createElement(tag.name); | |
68 e._r = new RenderingScheduler(e, queue: queue); | |
69 e._vm = vm; | |
70 e._events = events; | |
71 e._notifications = notifications; | |
72 e._profiles = profiles; | |
73 return e; | |
74 } | |
75 | |
76 NativeMemoryProfileElement.created() : super.created(); | |
77 | |
78 @override | |
79 attached() { | |
80 super.attached(); | |
81 _r.enable(); | |
82 _request(); | |
83 } | |
84 | |
85 @override | |
86 detached() { | |
87 super.detached(); | |
88 _r.disable(notify: true); | |
89 children = []; | |
90 } | |
91 | |
92 void render() { | |
93 var content = [ | |
94 navBar([ | |
95 new NavTopMenuElement(queue: _r.queue), | |
96 new NavVMMenuElement(_vm, _events, queue: _r.queue), | |
97 navMenu('native memory profile', link: Uris.nativeMemory()), | |
98 new NavRefreshElement(queue: _r.queue)..onRefresh.listen(_refresh), | |
99 new NavNotifyElement(_notifications, queue: _r.queue) | |
100 ]), | |
101 ]; | |
102 if (_progress == null) { | |
103 children = content; | |
104 return; | |
105 } | |
106 content.add(new SampleBufferControlElement(_progress, _progressStream, | |
107 selectedTag: _tag, queue: _r.queue) | |
108 ..onTagChange.listen((e) { | |
109 _tag = e.element.selectedTag; | |
110 _request(); | |
111 })); | |
112 if (_progress.status == M.SampleProfileLoadingStatus.loaded) { | |
113 CpuProfileVirtualTreeElement tree; | |
114 content.addAll([ | |
115 new BRElement(), | |
116 new StackTraceTreeConfigElement( | |
117 mode: _mode, | |
118 direction: _direction, | |
119 filter: _filter, | |
120 queue: _r.queue) | |
121 ..onModeChange.listen((e) { | |
122 _mode = tree.mode = e.element.mode; | |
123 }) | |
124 ..onFilterChange.listen((e) { | |
125 _filter = e.element.filter.trim(); | |
126 tree.filters = _filter.isNotEmpty | |
127 ? [ | |
128 (node) { | |
129 return node.name.contains(_filter); | |
130 } | |
131 ] | |
132 : const []; | |
133 }) | |
134 ..onDirectionChange.listen((e) { | |
135 _direction = tree.direction = e.element.direction; | |
136 }), | |
137 new BRElement(), | |
138 tree = new CpuProfileVirtualTreeElement(_vm, _progress.profile, | |
139 queue: _r.queue, type: M.SampleProfileType.memory) | |
140 ]); | |
141 } | |
142 children = content; | |
143 } | |
144 | |
145 Future _request({bool forceFetch: false}) async { | |
146 _progress = null; | |
147 _progressStream = _profiles.get(_vm, _tag, forceFetch: forceFetch); | |
148 _r.dirty(); | |
149 _progress = (await _progressStream.first).progress; | |
150 _r.dirty(); | |
151 if (M.isSampleProcessRunning(_progress.status)) { | |
152 _progress = (await _progressStream.last).progress; | |
153 _r.dirty(); | |
154 } | |
155 } | |
156 | |
157 Future _refresh(e) async { | |
158 e.element.disabled = true; | |
159 await _request(forceFetch: true); | |
160 e.element.disabled = false; | |
161 } | |
162 } | |
OLD | NEW |