OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, 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:html'; |
| 6 import 'dart:async'; |
| 7 import 'package:observatory/models.dart' as M; |
| 8 import 'package:observatory/src/elements/cpu_profile/virtual_tree.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/sample_buffer_control.dart'; |
| 12 import 'package:observatory/src/elements/stack_trace_tree_config.dart'; |
| 13 |
| 14 class ClassAllocationProfileElement extends HtmlElement implements Renderable { |
| 15 static const tag = const Tag<ClassAllocationProfileElement>( |
| 16 'class-allocation-profile', |
| 17 dependencies: const [ |
| 18 SampleBufferControlElement.tag, |
| 19 StackTraceTreeConfigElement.tag, |
| 20 CpuProfileVirtualTreeElement.tag, |
| 21 ]); |
| 22 |
| 23 RenderingScheduler<ClassAllocationProfileElement> _r; |
| 24 |
| 25 Stream<RenderedEvent<ClassAllocationProfileElement>> get onRendered => |
| 26 _r.onRendered; |
| 27 |
| 28 M.IsolateRef _isolate; |
| 29 M.Class _cls; |
| 30 M.ClassSampleProfileRepository _profiles; |
| 31 Stream<M.SampleProfileLoadingProgressEvent> _progressStream; |
| 32 M.SampleProfileLoadingProgress _progress; |
| 33 M.SampleProfileTag _tag = M.SampleProfileTag.none; |
| 34 ProfileTreeMode _mode = ProfileTreeMode.function; |
| 35 M.ProfileTreeDirection _direction = M.ProfileTreeDirection.exclusive; |
| 36 |
| 37 |
| 38 |
| 39 M.IsolateRef get isolate => _isolate; |
| 40 M.Class get cls => _cls; |
| 41 |
| 42 factory ClassAllocationProfileElement(M.IsolateRef isolate, M.Class cls, |
| 43 M.ClassSampleProfileRepository profiles, {RenderingQueue queue}) { |
| 44 assert(isolate != null); |
| 45 assert(cls != null); |
| 46 assert(profiles != null); |
| 47 ClassAllocationProfileElement e = document.createElement(tag.name); |
| 48 e._r = new RenderingScheduler(e, queue: queue); |
| 49 e._isolate = isolate; |
| 50 e._cls = cls; |
| 51 e._profiles = profiles; |
| 52 return e; |
| 53 } |
| 54 |
| 55 ClassAllocationProfileElement.created() : super.created(); |
| 56 |
| 57 @override |
| 58 void attached() { |
| 59 super.attached(); |
| 60 _r.enable(); |
| 61 _request(); |
| 62 } |
| 63 |
| 64 @override |
| 65 void detached() { |
| 66 super.detached(); |
| 67 children = []; |
| 68 _r.disable(notify: true); |
| 69 } |
| 70 |
| 71 void render() { |
| 72 if (_progress == null) { |
| 73 children = const []; |
| 74 return; |
| 75 } |
| 76 final content = [ |
| 77 new SampleBufferControlElement(_progress, _progressStream, |
| 78 selectedTag: _tag, queue: _r.queue) |
| 79 ..onTagChange.listen((e) { |
| 80 _tag = e.element.selectedTag; |
| 81 _request(); |
| 82 }) |
| 83 ]; |
| 84 if (_progress.status == M.SampleProfileLoadingStatus.loaded) { |
| 85 CpuProfileVirtualTreeElement tree; |
| 86 content.addAll([ |
| 87 new BRElement(), |
| 88 new StackTraceTreeConfigElement(mode: _mode, direction: _direction, |
| 89 showFilter: false, queue: _r.queue) |
| 90 ..onModeChange.listen((e) { |
| 91 _mode = tree.mode = e.element.mode; |
| 92 }) |
| 93 ..onDirectionChange.listen((e) { |
| 94 _direction = tree.direction = e.element.direction; |
| 95 }), |
| 96 new BRElement(), |
| 97 tree = new CpuProfileVirtualTreeElement(_isolate, _progress.profile, |
| 98 queue: _r.queue) |
| 99 ]); |
| 100 } |
| 101 children = content; |
| 102 } |
| 103 |
| 104 Future _request() async { |
| 105 _progress = null; |
| 106 _progressStream = _profiles.get(_isolate, _cls, _tag); |
| 107 _r.dirty(); |
| 108 _progress = (await _progressStream.first).progress; |
| 109 _r.dirty(); |
| 110 if (M.isSampleProcessRunning(_progress.status)) { |
| 111 _progress = (await _progressStream.last).progress; |
| 112 _r.dirty(); |
| 113 } |
| 114 } |
| 115 } |
OLD | NEW |