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