Chromium Code Reviews| 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 import 'dart:async'; | |
| 6 import 'dart:html'; | |
| 7 import 'package:observatory/models.dart' as M; | |
| 8 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; | |
| 9 import 'package:observatory/src/elements/helpers/tag.dart'; | |
| 10 import 'package:observatory/src/elements/helpers/uris.dart'; | |
| 11 import 'package:observatory/utils.dart'; | |
| 12 | |
| 13 class SampleBufferControlChangedElement { | |
| 14 final SampleBufferControlElement element; | |
| 15 SampleBufferControlChangedElement(this.element); | |
| 16 } | |
| 17 | |
| 18 class SampleBufferControlElement extends HtmlElement implements Renderable { | |
| 19 static const tag = | |
| 20 const Tag<SampleBufferControlElement>('sample-buffer-control'); | |
| 21 | |
| 22 RenderingScheduler<SampleBufferControlElement> _r; | |
| 23 | |
| 24 Stream<RenderedEvent<SampleBufferControlElement>> get onRendered => | |
| 25 _r.onRendered; | |
| 26 | |
| 27 StreamController<SampleBufferControlChangedElement> _onTagChange = | |
| 28 new StreamController<SampleBufferControlChangedElement>.broadcast(); | |
| 29 Stream<SampleBufferControlChangedElement> get onTagChange => | |
| 30 _onTagChange.stream; | |
| 31 | |
| 32 M.SampleProfileLoadingProgress _progress; | |
| 33 M.SampleProfileTag _tag; | |
| 34 bool _showTag = false; | |
| 35 bool _profileVM = false; | |
| 36 StreamSubscription _subscription; | |
| 37 | |
| 38 M.SampleProfileLoadingProgress get progress => _progress; | |
| 39 M.SampleProfileTag get selectedTag => _tag; | |
| 40 bool get showTag => _showTag; | |
| 41 bool get profileVM => _profileVM; | |
| 42 | |
| 43 set selectedTag(M.SampleProfileTag value) => | |
| 44 _tag = _r.checkAndReact(_tag, value); | |
| 45 set showTag(bool value) => _showTag = _r.checkAndReact(_showTag, value); | |
| 46 set profileVM(bool value) => _profileVM = _r.checkAndReact(_profileVM, value); | |
| 47 | |
| 48 | |
| 49 factory SampleBufferControlElement(M.SampleProfileLoadingProgress progress, | |
| 50 {M.SampleProfileTag selectedTag: M.SampleProfileTag.None, | |
| 51 bool showTag: true, RenderingQueue queue}) { | |
| 52 assert(progress != null); | |
| 53 assert(selectedTag != null); | |
| 54 assert(showTag != null); | |
| 55 SampleBufferControlElement e = document.createElement(tag.name); | |
| 56 e._r = new RenderingScheduler(e, queue: queue); | |
| 57 e._progress = progress; | |
| 58 e._tag = selectedTag; | |
| 59 e._showTag = showTag; | |
| 60 return e; | |
| 61 } | |
| 62 | |
| 63 SampleBufferControlElement.created() : super.created(); | |
| 64 | |
| 65 @override | |
| 66 void attached() { | |
| 67 super.attached(); | |
| 68 _r.enable(); | |
| 69 _subscription = _progress.onProgress.listen((_) => _r.dirty()); | |
| 70 } | |
| 71 | |
| 72 @override | |
| 73 void detached() { | |
| 74 super.detached(); _r.disable(notify: true); | |
| 75 children = const []; | |
| 76 _subscription.cancel(); | |
| 77 } | |
| 78 | |
| 79 void render() { | |
| 80 var content = <Element>[ | |
| 81 new HeadingElement.h2()..text = 'Sample buffer', | |
| 82 new HRElement() | |
| 83 ]; | |
| 84 switch (_progress.status) { | |
| 85 case M.SampleProfileLoadingStatus.Fetching : | |
| 86 content.addAll(_createStatusMessage('Fetching profile from VM...')); | |
| 87 break; | |
| 88 case M.SampleProfileLoadingStatus.Loading : | |
| 89 content.addAll(_createStatusMessage('Loading profile...', | |
| 90 progress: _progress.progress)); | |
| 91 break; | |
| 92 case M.SampleProfileLoadingStatus.Disabled : | |
| 93 content.addAll(_createDisabledMessage()); | |
| 94 break; | |
| 95 case M.SampleProfileLoadingStatus.Loaded: | |
| 96 content.addAll(_createStatusReport()); | |
| 97 break; | |
| 98 } | |
| 99 children = [ | |
| 100 new DivElement()..classes = ['content-centered-big'] | |
| 101 ..children = content | |
| 102 ]; | |
| 103 } | |
| 104 | |
| 105 static List<Element> _createStatusMessage(String message, | |
| 106 {double progress: 0.0}) { | |
| 107 return [new DivElement()..classes = ['statusBox', 'shadow', 'center'] | |
| 108 ..children = [ | |
| 109 new DivElement()..classes = ['statusMessage'] | |
| 110 ..text = message, | |
| 111 new DivElement()..style.background = '#0489c3' | |
| 112 ..style.width = '$progress%' | |
| 113 ..style.height = '15px' | |
| 114 ..style.borderRadius = '4px' | |
| 115 ] | |
| 116 ]; | |
| 117 } | |
| 118 | |
| 119 static List<Element> _createDisabledMessage() { | |
| 120 return [new DivElement()..classes = ['statusBox' 'shadow' 'center'] | |
| 121 ..children = [ | |
| 122 new DivElement() | |
| 123 ..children = [ | |
| 124 new HeadingElement.h1() | |
| 125 ..text = 'Profiling is disabled', | |
| 126 new BRElement(), | |
| 127 new DivElement() | |
| 128 ..innerHtml = 'Perhaps the <b>profile</b> ' | |
| 129 'flag has been disabled for this VM.', | |
| 130 new BRElement(), | |
| 131 new SpanElement()..text = 'See all', | |
| 132 new AnchorElement(href: Uris.flags())..text = 'vm flags' | |
| 133 ] | |
| 134 ] | |
| 135 ]; | |
| 136 } | |
| 137 | |
| 138 List<Element> _createStatusReport() { | |
| 139 final fetchT = Utils.formatDurationInSeconds(_progress.fetchingTime); | |
| 140 final loadT = Utils.formatDurationInSeconds(_progress.loadingTime); | |
| 141 final sampleCount = _progress.profile.sampleCount; | |
| 142 final refreshT = new DateTime.now(); | |
| 143 final stackDepth = _progress.profile.stackDepth; | |
| 144 final sampleRate = _progress.profile.sampleRate.toStringAsFixed(0); | |
| 145 final timeSpan = _progress.profile.sampleCount == 0 ? '0s' | |
| 146 : Utils.formatTimePrecise(_progress.profile.timeSpan); | |
| 147 | |
| 148 var content = <Element>[ | |
| 149 new DivElement()..classes = ['memberItem'] | |
| 150 ..children = [ | |
| 151 new DivElement()..classes = ['memberName'] | |
| 152 ..text = 'Refreshed at', | |
| 153 new DivElement()..classes = ['memberValue'] | |
| 154 ..text = '$refreshT (fetched in ${fetchT}s) (loaded in ${loadT}s)' | |
| 155 ], | |
| 156 new DivElement()..classes = ['memberItem'] | |
| 157 ..children = [ | |
| 158 new DivElement()..classes = ['memberName'] | |
| 159 ..text = 'Profile contains ', | |
| 160 new DivElement()..classes = ['memberValue'] | |
| 161 ..text = '$sampleCount samples (spanning $timeSpan)' | |
| 162 ], | |
| 163 new DivElement()..classes = ['memberItem'] | |
| 164 ..children = [ | |
| 165 new DivElement()..classes = ['memberName'] | |
| 166 ..text = 'Sampling', | |
| 167 new DivElement()..classes = ['memberValue'] | |
| 168 ..text = '$stackDepth stack frames @ ${sampleRate}Hz' | |
| 169 ], | |
| 170 ]; | |
| 171 if (_showTag) { | |
| 172 content.add( | |
| 173 new DivElement()..classes = ['memberItem'] | |
| 174 ..children = [ | |
| 175 new DivElement()..classes = ['memberName'] | |
| 176 ..text = 'Tag Order', | |
| 177 new DivElement()..classes = ['memberValue'] | |
| 178 ..children = _createTagSelect() | |
| 179 ] | |
| 180 ); | |
| 181 } | |
| 182 return [ | |
| 183 new DivElement()..classes = ['memberList'] | |
| 184 ..children = content | |
| 185 ]; | |
| 186 } | |
| 187 | |
| 188 List<Element> _createTagSelect() { | |
| 189 var values = M.SampleProfileTag.values; | |
| 190 if (!_profileVM) { | |
| 191 values = const [M.SampleProfileTag.UserOnly, M.SampleProfileTag.None]; | |
| 192 } | |
| 193 var s; | |
| 194 return [ | |
| 195 s = new SelectElement()..value = tagToString(_tag) | |
| 196 ..children = values.map((tag) { | |
| 197 return new OptionElement(value : tagToString(tag), | |
| 198 selected: _tag == tag) | |
| 199 ..text = tagToString(tag); | |
| 200 }).toList(growable: false) | |
| 201 ..onChange.listen((_) { | |
| 202 _tag = values[s.selectedIndex]; | |
| 203 }) | |
| 204 ..onChange.map(_toEvent).listen(_triggerModeChange), | |
| 205 ]; | |
| 206 } | |
| 207 | |
| 208 static String tagToString(M.SampleProfileTag tag) { | |
| 209 switch (tag) { | |
| 210 case M.SampleProfileTag.UserVM: return 'User > VM'; | |
| 211 case M.SampleProfileTag.UserOnly: return 'User'; | |
| 212 case M.SampleProfileTag.VMUser: return 'VM > User'; | |
| 213 case M.SampleProfileTag.VMOnly: return 'VM'; | |
| 214 case M.SampleProfileTag.None: return 'None'; | |
| 215 } | |
| 216 throw new Exception('Unknown tagToString'); | |
| 217 } | |
| 218 | |
| 219 SampleBufferControlChangedElement _toEvent(_) { | |
| 220 return new SampleBufferControlChangedElement(this); | |
| 221 } | |
| 222 | |
| 223 void _triggerModeChange(e) => _onTagChange.add(e); | |
| 224 | |
| 225 /*Future _changeState(SampleBufferState newState, [exception, stackTrace]) { | |
|
Cutch
2016/08/02 15:52:20
delete commented out code
cbernaschina
2016/08/02 17:40:24
Done.
| |
| 226 if ((newState == Sampl | |
| 227 } else if (newState == SampleBufferState.Loading) { | |
| 228 fetchTime = formatTimeMilliseconds(_stopWatch.elapsedMilliseconds); | |
| 229 loadTime = ''; | |
| 230 } else if (newState == SampleBufferState.Loaded) { | |
| 231 loadTime = formatTimeMilliseconds(_stopWatch.elapsedMilliseconds); | |
| 232 } | |
| 233 state = newState; | |
| 234 this.exception = exception; | |
| 235 this.stackTrace = stackTrace; | |
| 236 _stopWatch.reset(); | |
| 237 return window.animationFrame; | |
| 238 } | |
| 239 | |
| 240 _update(CpuProfile sampleBuffer) { | |
| 241 sampleCount = profile.sampleCount.toString(); | |
| 242 refreshTime = new DateTime.now().toString(); | |
| 243 stackDepth = profile.stackDepth.toString(); | |
| 244 sampleRate = profile.sampleRate.toStringAsFixed(0); | |
| 245 if (profile.sampleCount == 0) { | |
| 246 timeSpan = '0s'; | |
| 247 } else { | |
| 248 timeSpan = formatTime(profile.timeSpan); | |
| 249 } | |
| 250 } | |
| 251 | |
| 252 void tagSelectorChanged(oldValue) { | |
| 253 reload(profile.isolate); | |
| 254 } | |
| 255 | |
| 256 Function onSampleBufferUpdate; | |
| 257 bool showTagSelector = true; | |
| 258 bool profileVM = false; | |
| 259 String sampleCount = ''; | |
| 260 String refreshTime = ''; | |
| 261 String sampleRate = ''; | |
| 262 String stackDepth = ''; | |
| 263 String timeSpan = ''; | |
| 264 String fetchTime = ''; | |
| 265 String loadTime = ''; | |
| 266 String tagSelector; | |
| 267 SampleBufferState state = SampleBufferState.Fetching; | |
| 268 var exception; | |
| 269 var stackTrace; | |
| 270 | |
| 271 Class allocationProfileClass; | |
| 272 | |
| 273 final Stopwatch _stopWatch = new Stopwatch();*/ | |
| 274 } | |
| 275 | |
| 276 /*<polymer-element name="sample-buffer-control"> | |
| 277 <template> | |
| 278 <link rel="stylesheet" href="css/shared.css"> | |
| 279 <style> | |
| 280 .statusMessage { | |
| 281 font-size: 150%; | |
| 282 font-weight: bold; | |
| 283 } | |
| 284 | |
| 285 .statusBox { | |
| 286 height: 100%; | |
| 287 padding: 1em; | |
| 288 } | |
| 289 | |
| 290 .center { | |
| 291 align-items: center; | |
| 292 justify-content: center; | |
| 293 } | |
| 294 | |
| 295 .notice { | |
| 296 background-color: #fcf8e3; | |
| 297 } | |
| 298 | |
| 299 .red { | |
| 300 background-color: #f2dede; | |
| 301 } | |
| 302 </style> | |
| 303 <div class="content-centered-big"> | |
| 304 <template if="{{ state != 'kNotLoaded' }}"> | |
| 305 <h2>Sample buffer</h2> | |
| 306 <hr> | |
| 307 </template> | |
| 308 <template if="{{ state == 'kFetching' }}"> | |
| 309 <div class="statusBox shadow center"> | |
| 310 <div class="statusMessage">Fetching profile from VM...</div> | |
| 311 </div> | |
| 312 </template> | |
| 313 <template if="{{ state == 'kLoading' }}"> | |
| 314 <div class="statusBox shadow center"> | |
| 315 <div class="statusMessage">Loading profile...</div> | |
| 316 </div> | |
| 317 </template> | |
| 318 <template if="{{ state == 'kDisabled' }}"> | |
| 319 <div class="statusBox shadow center"> | |
| 320 <div> | |
| 321 <h1>Profiling is disabled</h1> | |
| 322 <br> | |
| 323 Perhaps the <b>profile</b> flag has been disabled for this VM. | |
| 324 <br><br> | |
| 325 See all | |
| 326 <a on-click="{{ goto }}" _href="{{ gotoLink('/flags') }}">vm flags</ a> | |
| 327 </div> | |
| 328 </div> | |
| 329 </template> | |
| 330 <template if="{{ state == 'kException' }}"> | |
| 331 <div class="statusBox shadow center"> | |
| 332 <div class="statusMessage"> | |
| 333 <h1>Profiling is disabled due to unexpected exception:</h1> | |
| 334 <br> | |
| 335 <pre>{{ exception.toString() }}</pre> | |
| 336 <br> | |
| 337 <h1>Stack trace:</h1> | |
| 338 <br> | |
| 339 <pre>{{ stackTrace.toString() }}</pre> | |
| 340 </div> | |
| 341 </div> | |
| 342 </template> | |
| 343 <template if="{{ state == 'kLoaded' }}"> | |
| 344 <div class="memberList"> | |
| 345 <div class="memberItem"> | |
| 346 <div class="memberName">Refreshed at </div> | |
| 347 <div class="memberValue">{{ refreshTime }} (fetched in {{ fetchTime }}) (loaded in {{ loadTime }})</div> | |
| 348 </div> | |
| 349 <div class="memberItem"> | |
| 350 <div class="memberName">Profile contains</div> | |
| 351 <div class="memberValue">{{ sampleCount }} samples (spanning {{ time Span }})</div> | |
| 352 </div> | |
| 353 <div class="memberItem"> | |
| 354 <div class="memberName">Sampling</div> | |
| 355 <div class="memberValue">{{ stackDepth }} stack frames @ {{ sampleRa te }} Hz</div> | |
| 356 </div> | |
| 357 <template if="{{ showTagSelector }}"> | |
| 358 <div class="memberItem"> | |
| 359 <div class="memberName">Tag Order</div> | |
| 360 <div class="memberValue"> | |
| 361 <template if="{{ profileVM }}"> | |
| 362 <select value="{{tagSelector}}"> | |
| 363 <option value="UserVM">User > VM</option> | |
| 364 <option value="UserOnly">User</option> | |
| 365 <option value="VMUser">VM > User</option> | |
| 366 <option value="VMOnly">VM</option> | |
| 367 <option value="None">None</option> | |
| 368 </select> | |
| 369 </template> | |
| 370 <template if="{{ !profileVM }}"> | |
| 371 <select value="{{tagSelector}}"> | |
| 372 <option value="UserOnly">User</option> | |
| 373 <option value="None">None</option> | |
| 374 </select> | |
| 375 </template> | |
| 376 </div> | |
| 377 </div> | |
| 378 </template> | |
| 379 </div> | |
| 380 </template> | |
| 381 </div> | |
| 382 </template> | |
| 383 </polymer-element>*/ | |
| OLD | NEW |