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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:html'; | 6 import 'dart:html'; |
7 import 'package:observatory/models.dart' as M; | 7 import 'package:observatory/models.dart' as M; |
8 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; | 8 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; |
9 import 'package:observatory/src/elements/helpers/tag.dart'; | 9 import 'package:observatory/src/elements/helpers/tag.dart'; |
10 import 'package:observatory/src/elements/helpers/uris.dart'; | 10 import 'package:observatory/src/elements/helpers/uris.dart'; |
11 import 'package:observatory/utils.dart'; | 11 import 'package:observatory/utils.dart'; |
12 | 12 |
13 class SampleBufferControlChangedElement { | 13 class SampleBufferControlChangedElement { |
14 final SampleBufferControlElement element; | 14 final SampleBufferControlElement element; |
15 SampleBufferControlChangedElement(this.element); | 15 SampleBufferControlChangedElement(this.element); |
16 } | 16 } |
17 | 17 |
18 class SampleBufferControlElement extends HtmlElement implements Renderable { | 18 class SampleBufferControlElement extends HtmlElement implements Renderable { |
19 static const tag = | 19 static const tag = |
20 const Tag<SampleBufferControlElement>('sample-buffer-control'); | 20 const Tag<SampleBufferControlElement>('sample-buffer-control'); |
21 | 21 |
22 RenderingScheduler<SampleBufferControlElement> _r; | 22 RenderingScheduler<SampleBufferControlElement> _r; |
23 | 23 |
24 Stream<RenderedEvent<SampleBufferControlElement>> get onRendered => | 24 Stream<RenderedEvent<SampleBufferControlElement>> get onRendered => |
25 _r.onRendered; | 25 _r.onRendered; |
26 | 26 |
27 StreamController<SampleBufferControlChangedElement> _onTagChange = | 27 StreamController<SampleBufferControlChangedElement> _onTagChange = |
28 new StreamController<SampleBufferControlChangedElement>.broadcast(); | 28 new StreamController<SampleBufferControlChangedElement>.broadcast(); |
29 Stream<SampleBufferControlChangedElement> get onTagChange => | 29 Stream<SampleBufferControlChangedElement> get onTagChange => |
30 _onTagChange.stream; | 30 _onTagChange.stream; |
31 | 31 |
32 Stream<M.SampleProfileLoadingProgressEvent> _progressStream; | 32 Stream<M.SampleProfileLoadingProgressEvent> _progressStream; |
33 M.SampleProfileLoadingProgress _progress; | 33 M.SampleProfileLoadingProgress _progress; |
34 M.SampleProfileTag _tag; | 34 M.SampleProfileTag _tag; |
35 bool _showTag = false; | 35 bool _showTag = false; |
36 bool _profileVM = false; | 36 bool _profileVM = false; |
37 StreamSubscription _subscription; | 37 StreamSubscription _subscription; |
38 | 38 |
39 M.SampleProfileLoadingProgress get progress => _progress; | 39 M.SampleProfileLoadingProgress get progress => _progress; |
40 M.SampleProfileTag get selectedTag => _tag; | 40 M.SampleProfileTag get selectedTag => _tag; |
41 bool get showTag => _showTag; | 41 bool get showTag => _showTag; |
42 bool get profileVM => _profileVM; | 42 bool get profileVM => _profileVM; |
43 | 43 |
44 set selectedTag(M.SampleProfileTag value) => | 44 set selectedTag(M.SampleProfileTag value) => |
45 _tag = _r.checkAndReact(_tag, value); | 45 _tag = _r.checkAndReact(_tag, value); |
46 set showTag(bool value) => _showTag = _r.checkAndReact(_showTag, value); | 46 set showTag(bool value) => _showTag = _r.checkAndReact(_showTag, value); |
47 set profileVM(bool value) => _profileVM = _r.checkAndReact(_profileVM, value); | 47 set profileVM(bool value) => _profileVM = _r.checkAndReact(_profileVM, value); |
48 | 48 |
49 | |
50 factory SampleBufferControlElement(M.SampleProfileLoadingProgress progress, | 49 factory SampleBufferControlElement(M.SampleProfileLoadingProgress progress, |
51 Stream<M.SampleProfileLoadingProgressEvent> progressStream, | 50 Stream<M.SampleProfileLoadingProgressEvent> progressStream, |
52 {M.SampleProfileTag selectedTag: M.SampleProfileTag.none, | 51 {M.SampleProfileTag selectedTag: M.SampleProfileTag.none, |
53 bool showTag: true, RenderingQueue queue}) { | 52 bool showTag: true, |
| 53 RenderingQueue queue}) { |
54 assert(progress != null); | 54 assert(progress != null); |
55 assert(progressStream != null); | 55 assert(progressStream != null); |
56 assert(selectedTag != null); | 56 assert(selectedTag != null); |
57 assert(showTag != null); | 57 assert(showTag != null); |
58 SampleBufferControlElement e = document.createElement(tag.name); | 58 SampleBufferControlElement e = document.createElement(tag.name); |
59 e._r = new RenderingScheduler(e, queue: queue); | 59 e._r = new RenderingScheduler(e, queue: queue); |
60 e._progress = progress; | 60 e._progress = progress; |
61 e._progressStream = progressStream; | 61 e._progressStream = progressStream; |
62 e._tag = selectedTag; | 62 e._tag = selectedTag; |
63 e._showTag = showTag; | 63 e._showTag = showTag; |
64 return e; | 64 return e; |
65 } | 65 } |
66 | 66 |
67 SampleBufferControlElement.created() : super.created(); | 67 SampleBufferControlElement.created() : super.created(); |
68 | 68 |
69 @override | 69 @override |
70 void attached() { | 70 void attached() { |
71 super.attached(); | 71 super.attached(); |
72 _r.enable(); | 72 _r.enable(); |
73 _subscription = _progressStream.listen((e) { | 73 _subscription = _progressStream.listen((e) { |
74 _progress = e.progress; | 74 _progress = e.progress; |
75 _r.dirty(); | 75 _r.dirty(); |
76 }); | 76 }); |
77 } | 77 } |
78 | 78 |
79 @override | 79 @override |
80 void detached() { | 80 void detached() { |
81 super.detached(); _r.disable(notify: true); | 81 super.detached(); |
| 82 _r.disable(notify: true); |
82 children = const []; | 83 children = const []; |
83 _subscription.cancel(); | 84 _subscription.cancel(); |
84 } | 85 } |
85 | 86 |
86 void render() { | 87 void render() { |
87 var content = <Element>[ | 88 var content = <Element>[ |
88 new HeadingElement.h2()..text = 'Sample buffer', | 89 new HeadingElement.h2()..text = 'Sample buffer', |
89 new HRElement() | 90 new HRElement() |
90 ]; | 91 ]; |
91 switch (_progress.status) { | 92 switch (_progress.status) { |
92 case M.SampleProfileLoadingStatus.fetching : | 93 case M.SampleProfileLoadingStatus.fetching: |
93 content.addAll(_createStatusMessage('Fetching profile from VM...')); | 94 content.addAll(_createStatusMessage('Fetching profile from VM...')); |
94 break; | 95 break; |
95 case M.SampleProfileLoadingStatus.loading : | 96 case M.SampleProfileLoadingStatus.loading: |
96 content.addAll(_createStatusMessage('Loading profile...', | 97 content.addAll(_createStatusMessage('Loading profile...', |
97 progress: _progress.progress)); | 98 progress: _progress.progress)); |
98 break; | 99 break; |
99 case M.SampleProfileLoadingStatus.disabled : | 100 case M.SampleProfileLoadingStatus.disabled: |
100 content.addAll(_createDisabledMessage()); | 101 content.addAll(_createDisabledMessage()); |
101 break; | 102 break; |
102 case M.SampleProfileLoadingStatus.loaded: | 103 case M.SampleProfileLoadingStatus.loaded: |
103 content.addAll(_createStatusReport()); | 104 content.addAll(_createStatusReport()); |
104 break; | 105 break; |
105 } | 106 } |
106 children = [ | 107 children = [ |
107 new DivElement()..classes = ['content-centered-big'] | 108 new DivElement() |
| 109 ..classes = ['content-centered-big'] |
108 ..children = content | 110 ..children = content |
109 ]; | 111 ]; |
110 } | 112 } |
111 | 113 |
112 static List<Element> _createStatusMessage(String message, | 114 static List<Element> _createStatusMessage(String message, |
113 {double progress: 0.0}) { | 115 {double progress: 0.0}) { |
114 return [new DivElement()..classes = ['statusBox', 'shadow', 'center'] | 116 return [ |
115 ..children = [ | 117 new DivElement() |
116 new DivElement()..classes = ['statusMessage'] | 118 ..classes = ['statusBox', 'shadow', 'center'] |
117 ..text = message, | 119 ..children = [ |
118 new DivElement()..style.background = '#0489c3' | 120 new DivElement() |
119 ..style.width = '$progress%' | 121 ..classes = ['statusMessage'] |
120 ..style.height = '15px' | 122 ..text = message, |
121 ..style.borderRadius = '4px' | 123 new DivElement() |
122 ] | 124 ..style.background = '#0489c3' |
| 125 ..style.width = '$progress%' |
| 126 ..style.height = '15px' |
| 127 ..style.borderRadius = '4px' |
| 128 ] |
123 ]; | 129 ]; |
124 } | 130 } |
125 | 131 |
126 static List<Element> _createDisabledMessage() { | 132 static List<Element> _createDisabledMessage() { |
127 return [new DivElement()..classes = ['statusBox' 'shadow' 'center'] | 133 return [ |
128 ..children = [ | 134 new DivElement() |
129 new DivElement() | 135 ..classes = ['statusBox' 'shadow' 'center'] |
130 ..children = [ | 136 ..children = [ |
131 new HeadingElement.h1() | 137 new DivElement() |
132 ..text = 'Profiling is disabled', | 138 ..children = [ |
133 new BRElement(), | 139 new HeadingElement.h1()..text = 'Profiling is disabled', |
134 new DivElement() | 140 new BRElement(), |
135 ..innerHtml = 'Perhaps the <b>profile</b> ' | 141 new DivElement() |
136 'flag has been disabled for this VM.', | 142 ..innerHtml = 'Perhaps the <b>profile</b> ' |
137 new BRElement(), | 143 'flag has been disabled for this VM.', |
138 new SpanElement()..text = 'See all', | 144 new BRElement(), |
139 new AnchorElement(href: Uris.flags())..text = 'vm flags' | 145 new SpanElement()..text = 'See all', |
140 ] | 146 new AnchorElement(href: Uris.flags())..text = 'vm flags' |
141 ] | 147 ] |
| 148 ] |
142 ]; | 149 ]; |
143 } | 150 } |
144 | 151 |
145 List<Element> _createStatusReport() { | 152 List<Element> _createStatusReport() { |
146 final fetchT = Utils.formatDurationInSeconds(_progress.fetchingTime); | 153 final fetchT = Utils.formatDurationInSeconds(_progress.fetchingTime); |
147 final loadT = Utils.formatDurationInSeconds(_progress.loadingTime); | 154 final loadT = Utils.formatDurationInSeconds(_progress.loadingTime); |
148 final sampleCount = _progress.profile.sampleCount; | 155 final sampleCount = _progress.profile.sampleCount; |
149 final refreshT = new DateTime.now(); | 156 final refreshT = new DateTime.now(); |
150 final stackDepth = _progress.profile.stackDepth; | 157 final stackDepth = _progress.profile.stackDepth; |
151 final sampleRate = _progress.profile.sampleRate.toStringAsFixed(0); | 158 final sampleRate = _progress.profile.sampleRate.toStringAsFixed(0); |
152 final timeSpan = _progress.profile.sampleCount == 0 ? '0s' | 159 final timeSpan = _progress.profile.sampleCount == 0 |
| 160 ? '0s' |
153 : Utils.formatTimePrecise(_progress.profile.timeSpan); | 161 : Utils.formatTimePrecise(_progress.profile.timeSpan); |
154 | 162 |
155 var content = <Element>[ | 163 var content = <Element>[ |
156 new DivElement()..classes = ['memberItem'] | 164 new DivElement() |
| 165 ..classes = ['memberItem'] |
157 ..children = [ | 166 ..children = [ |
158 new DivElement()..classes = ['memberName'] | 167 new DivElement() |
| 168 ..classes = ['memberName'] |
159 ..text = 'Refreshed at', | 169 ..text = 'Refreshed at', |
160 new DivElement()..classes = ['memberValue'] | 170 new DivElement() |
| 171 ..classes = ['memberValue'] |
161 ..text = '$refreshT (fetched in ${fetchT}s) (loaded in ${loadT}s)' | 172 ..text = '$refreshT (fetched in ${fetchT}s) (loaded in ${loadT}s)' |
162 ], | 173 ], |
163 new DivElement()..classes = ['memberItem'] | 174 new DivElement() |
| 175 ..classes = ['memberItem'] |
164 ..children = [ | 176 ..children = [ |
165 new DivElement()..classes = ['memberName'] | 177 new DivElement() |
| 178 ..classes = ['memberName'] |
166 ..text = 'Profile contains ', | 179 ..text = 'Profile contains ', |
167 new DivElement()..classes = ['memberValue'] | 180 new DivElement() |
| 181 ..classes = ['memberValue'] |
168 ..text = '$sampleCount samples (spanning $timeSpan)' | 182 ..text = '$sampleCount samples (spanning $timeSpan)' |
169 ], | 183 ], |
170 new DivElement()..classes = ['memberItem'] | 184 new DivElement() |
| 185 ..classes = ['memberItem'] |
171 ..children = [ | 186 ..children = [ |
172 new DivElement()..classes = ['memberName'] | 187 new DivElement() |
| 188 ..classes = ['memberName'] |
173 ..text = 'Sampling', | 189 ..text = 'Sampling', |
174 new DivElement()..classes = ['memberValue'] | 190 new DivElement() |
| 191 ..classes = ['memberValue'] |
175 ..text = '$stackDepth stack frames @ ${sampleRate}Hz' | 192 ..text = '$stackDepth stack frames @ ${sampleRate}Hz' |
176 ], | 193 ], |
177 ]; | 194 ]; |
178 if (_showTag) { | 195 if (_showTag) { |
179 content.add( | 196 content.add(new DivElement() |
180 new DivElement()..classes = ['memberItem'] | 197 ..classes = ['memberItem'] |
181 ..children = [ | 198 ..children = [ |
182 new DivElement()..classes = ['memberName'] | 199 new DivElement() |
183 ..text = 'Tag Order', | 200 ..classes = ['memberName'] |
184 new DivElement()..classes = ['memberValue'] | 201 ..text = 'Tag Order', |
185 ..children = _createTagSelect() | 202 new DivElement() |
186 ] | 203 ..classes = ['memberValue'] |
187 ); | 204 ..children = _createTagSelect() |
| 205 ]); |
188 } | 206 } |
189 return [ | 207 return [ |
190 new DivElement()..classes = ['memberList'] | 208 new DivElement() |
| 209 ..classes = ['memberList'] |
191 ..children = content | 210 ..children = content |
192 ]; | 211 ]; |
193 } | 212 } |
194 | 213 |
195 List<Element> _createTagSelect() { | 214 List<Element> _createTagSelect() { |
196 var values = M.SampleProfileTag.values; | 215 var values = M.SampleProfileTag.values; |
197 if (!_profileVM) { | 216 if (!_profileVM) { |
198 values = const [M.SampleProfileTag.userOnly, M.SampleProfileTag.none]; | 217 values = const [M.SampleProfileTag.userOnly, M.SampleProfileTag.none]; |
199 } | 218 } |
200 var s; | 219 var s; |
201 return [ | 220 return [ |
202 s = new SelectElement()..classes = ['tag-select'] | 221 s = new SelectElement() |
| 222 ..classes = ['tag-select'] |
203 ..value = tagToString(_tag) | 223 ..value = tagToString(_tag) |
204 ..children = values.map((tag) { | 224 ..children = values.map((tag) { |
205 return new OptionElement(value : tagToString(tag), | 225 return new OptionElement( |
206 selected: _tag == tag) | 226 value: tagToString(tag), |
207 ..text = tagToString(tag); | 227 selected: _tag == tag)..text = tagToString(tag); |
208 }).toList(growable: false) | 228 }).toList(growable: false) |
209 ..onChange.listen((_) { | 229 ..onChange.listen((_) { |
210 _tag = values[s.selectedIndex]; | 230 _tag = values[s.selectedIndex]; |
211 }) | 231 }) |
212 ..onChange.map(_toEvent).listen(_triggerModeChange), | 232 ..onChange.map(_toEvent).listen(_triggerModeChange), |
213 ]; | 233 ]; |
214 } | 234 } |
215 | 235 |
216 static String tagToString(M.SampleProfileTag tag) { | 236 static String tagToString(M.SampleProfileTag tag) { |
217 switch (tag) { | 237 switch (tag) { |
218 case M.SampleProfileTag.userVM: return 'User > VM'; | 238 case M.SampleProfileTag.userVM: |
219 case M.SampleProfileTag.userOnly: return 'User'; | 239 return 'User > VM'; |
220 case M.SampleProfileTag.vmUser: return 'VM > User'; | 240 case M.SampleProfileTag.userOnly: |
221 case M.SampleProfileTag.vmOnly: return 'VM'; | 241 return 'User'; |
222 case M.SampleProfileTag.none: return 'None'; | 242 case M.SampleProfileTag.vmUser: |
| 243 return 'VM > User'; |
| 244 case M.SampleProfileTag.vmOnly: |
| 245 return 'VM'; |
| 246 case M.SampleProfileTag.none: |
| 247 return 'None'; |
223 } | 248 } |
224 throw new Exception('Unknown tagToString'); | 249 throw new Exception('Unknown tagToString'); |
225 } | 250 } |
226 | 251 |
227 SampleBufferControlChangedElement _toEvent(_) { | 252 SampleBufferControlChangedElement _toEvent(_) { |
228 return new SampleBufferControlChangedElement(this); | 253 return new SampleBufferControlChangedElement(this); |
229 } | 254 } |
230 | 255 |
231 void _triggerModeChange(e) => _onTagChange.add(e); | 256 void _triggerModeChange(e) => _onTagChange.add(e); |
232 } | 257 } |
OLD | NEW |