Chromium Code Reviews| 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 library object_common_element; | 5 import 'dart:html'; |
| 6 | |
| 7 import 'dart:async'; | 6 import 'dart:async'; |
| 8 import 'observatory_element.dart'; | 7 import 'package:observatory/models.dart' as M; |
| 9 import 'package:observatory/service.dart'; | 8 import 'package:observatory/src/elements/class_ref.dart'; |
| 10 import 'package:polymer/polymer.dart'; | 9 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; |
| 11 | 10 import 'package:observatory/src/elements/helpers/tag.dart'; |
| 12 @CustomTag('object-common') | 11 import 'package:observatory/src/elements/inbound_references.dart'; |
| 13 class ObjectCommonElement extends ObservatoryElement { | 12 import 'package:observatory/src/elements/retaining_path.dart'; |
| 14 @published ServiceObject object; | 13 import 'package:observatory/src/elements/sentinel_value.dart'; |
| 15 @published ServiceMap path; | 14 import 'package:observatory/utils.dart'; |
| 16 @published ServiceMap inboundReferences; | 15 |
| 17 @observable int retainedBytes = null; | 16 class ObjectCommonElement extends HtmlElement implements Renderable { |
| 18 @observable int reachableBytes = null; | 17 static const tag = const Tag<ObjectCommonElement>('object-common-wrapped', |
| 18 dependencies: const [ | |
| 19 ClassRefElement.tag, | |
| 20 InboundReferencesElement.tag, | |
| 21 RetainingPathElement.tag, | |
| 22 SentinelValueElement.tag | |
| 23 ]); | |
| 24 | |
| 25 RenderingScheduler<ObjectCommonElement> _r; | |
| 26 | |
| 27 Stream<RenderedEvent<ObjectCommonElement>> get onRendered => _r.onRendered; | |
| 28 | |
| 29 M.IsolateRef _isolate; | |
| 30 M.Object _object; | |
| 31 M.RetainedSizeRepository _retainedSizes; | |
| 32 M.ReachableSizeRepository _reachableSizes; | |
| 33 M.InboundReferencesRepository _references; | |
| 34 M.RetainingPathRepository _retainingPaths; | |
| 35 M.InstanceRepository _instances; | |
| 36 M.Guarded<M.Instance> _retainedSize = null; | |
| 37 bool _loadingRetainedBytes = false; | |
| 38 M.Guarded<M.Instance> _reachableSize = null; | |
| 39 bool _loadingReachableBytes = false; | |
| 40 | |
| 41 M.IsolateRef get isolate => _isolate; | |
| 42 M.Object get object => _object; | |
| 43 | |
| 44 factory ObjectCommonElement(M.IsolateRef isolate, M.Object object, | |
| 45 M.RetainedSizeRepository retainedSizes, | |
| 46 M.ReachableSizeRepository reachableSizes, | |
| 47 M.InboundReferencesRepository references, | |
| 48 M.RetainingPathRepository retainingPaths, | |
| 49 M.InstanceRepository instances, | |
| 50 {RenderingQueue queue}) { | |
| 51 assert(isolate != null); | |
| 52 assert(object != null); | |
| 53 assert(retainedSizes != null); | |
| 54 assert(reachableSizes != null); | |
| 55 assert(references != null); | |
| 56 assert(retainingPaths != null); | |
| 57 assert(instances != null); | |
| 58 ObjectCommonElement e = document.createElement(tag.name); | |
| 59 e._r = new RenderingScheduler(e, queue: queue); | |
| 60 e._isolate = isolate; | |
| 61 e._object = object; | |
| 62 e._retainedSizes = retainedSizes; | |
| 63 e._reachableSizes = reachableSizes; | |
| 64 e._references = references; | |
| 65 e._instances = instances; | |
| 66 e._retainingPaths = retainingPaths; | |
| 67 return e; | |
| 68 } | |
| 19 | 69 |
| 20 ObjectCommonElement.created() : super.created(); | 70 ObjectCommonElement.created() : super.created(); |
| 21 | 71 |
| 22 // TODO(koda): Add no-arg "calculate-link" instead of reusing "eval-link". | 72 @override |
| 23 Future<ServiceObject> reachableSize(var dummy) { | 73 void attached() { |
| 24 return object.isolate.getReachableSize(object).then((Instance obj) { | 74 super.attached(); |
| 25 // TODO(turnidge): Handle collected/expired objects gracefully. | 75 _r.enable(); |
| 26 reachableBytes = int.parse(obj.valueAsString); | 76 } |
| 27 }); | 77 |
| 28 } | 78 @override |
| 29 | 79 void detached() { |
| 30 Future<ServiceObject> retainedSize(var dummy) { | 80 super.detached(); |
| 31 return object.isolate.getRetainedSize(object).then((Instance obj) { | 81 _r.disable(notify: true); |
| 32 // TODO(turnidge): Handle collected/expired objects gracefully. | 82 children = []; |
| 33 retainedBytes = int.parse(obj.valueAsString); | 83 } |
| 34 }); | 84 |
| 35 } | 85 RetainingPathElement _path; |
| 36 | 86 InboundReferencesElement _inbounds; |
| 37 Future<ServiceObject> retainingPath(var limit) { | 87 |
| 38 return object.isolate.getRetainingPath(object, limit).then((ServiceObject ob j) { | 88 void render() { |
|
Cutch
2016/08/19 22:11:19
long line?
cbernaschina
2016/08/19 22:17:40
The long line was in the old file
Cutch
2016/08/19 22:21:38
It was a bug then :)
| |
| 39 path = obj; | 89 _path = _path ?? new RetainingPathElement(_isolate, _object, |
| 40 }); | 90 _retainingPaths, _instances, |
| 41 } | 91 queue: _r.queue); |
| 42 | 92 _inbounds = _inbounds ?? new InboundReferencesElement(_isolate, _object, |
| 43 Future<ServiceObject> fetchInboundReferences(var limit) { | 93 _references, |
| 44 return object.isolate.getInboundReferences(object, limit) | 94 _instances, |
| 45 .then((ServiceObject obj) { | 95 queue: _r.queue); |
| 46 inboundReferences = obj; | 96 children = [ |
| 47 }); | 97 new DivElement()..classes = const ['memberList'] |
| 48 } | 98 ..children = [ |
| 49 | 99 new DivElement()..classes = const ['memberItem'] |
| 50 Future refresh() { | 100 ..children = [ |
| 51 return object.reload(); | 101 new DivElement()..classes = const ['memberName'] |
| 102 ..text = 'Class ', | |
| 103 new DivElement()..classes = const ['memberValue'] | |
| 104 ..children = [ | |
| 105 new ClassRefElement(_isolate, _object.clazz, queue: _r.queue) | |
| 106 ] | |
| 107 ], | |
| 108 new DivElement()..classes = const ['memberItem'] | |
| 109 ..title = 'Space for this object in memory' | |
| 110 ..children = [ | |
| 111 new DivElement()..classes = const ['memberName'] | |
| 112 ..text = 'Shallow size ', | |
| 113 new DivElement()..classes = const ['memberValue'] | |
| 114 ..text = Utils.formatSize(_object.size) | |
| 115 ], | |
| 116 new DivElement()..classes = const ['memberItem'] | |
| 117 ..title = 'Space reachable from this object, ' | |
| 118 'excluding class references' | |
| 119 ..children = [ | |
| 120 new DivElement()..classes = const ['memberName'] | |
| 121 ..text = 'Reachable size ', | |
| 122 new DivElement()..classes = const ['memberValue'] | |
| 123 ..children = _createReachableSizeValue() | |
| 124 ], | |
| 125 new DivElement()..classes = const ['memberItem'] | |
| 126 ..title = 'Space that would be reclaimed if references to this ' | |
| 127 'object were replaced with null' | |
| 128 ..children = [ | |
| 129 new DivElement()..classes = const ['memberName'] | |
| 130 ..text = 'Retained size ', | |
| 131 new DivElement()..classes = const ['memberValue'] | |
| 132 ..children = _createRetainedSizeValue() | |
| 133 ], | |
| 134 new DivElement()..classes = const ['memberItem'] | |
| 135 ..children = [ | |
| 136 new DivElement()..classes = const ['memberName'] | |
| 137 ..text = 'Retaining path ', | |
| 138 new DivElement()..classes = const ['memberValue'] | |
| 139 ..children = [_path] | |
| 140 ], | |
| 141 new DivElement()..classes = const ['memberItem'] | |
| 142 ..title = 'Objects which directly reference this object' | |
| 143 ..children = [ | |
| 144 new DivElement()..classes = const ['memberName'] | |
| 145 ..text = 'Inbound references ', | |
| 146 new DivElement()..classes = const ['memberValue'] | |
| 147 ..children = [_inbounds] | |
| 148 ] | |
| 149 ] | |
| 150 ]; | |
| 151 } | |
| 152 | |
| 153 List<Element> _createReachableSizeValue() { | |
| 154 final content = <Element>[]; | |
| 155 if (_reachableSize != null) { | |
| 156 if (_reachableSize.isSentinel) { | |
| 157 content.add( | |
| 158 new SentinelValueElement(_reachableSize.asSentinel, queue: _r.queue) | |
| 159 ); | |
| 160 } else { | |
| 161 content.add( | |
| 162 new SpanElement()..text = Utils.formatSize(int.parse( | |
| 163 _reachableSize.asValue.valueAsString)) | |
| 164 ); | |
| 165 } | |
| 166 } else { | |
| 167 content.add( | |
| 168 new SpanElement()..text = '...' | |
| 169 ); | |
| 170 } | |
| 171 var button; | |
| 172 content.add( | |
|
Cutch
2016/08/19 22:11:19
don't assign inside a function call
cbernaschina
2016/08/19 22:17:40
Done.
| |
| 173 button = new ButtonElement()..classes = ['reachable_size'] | |
| 174 ..disabled = _loadingReachableBytes | |
| 175 ..text = '↺' | |
| 176 ..onClick.listen((_) async { | |
| 177 button.disabled = true; | |
| 178 _loadingReachableBytes = true; | |
| 179 _reachableSize = await _reachableSizes.get(_isolate, _object.id); | |
| 180 _r.dirty(); | |
| 181 }) | |
| 182 ); | |
| 183 return content; | |
| 184 } | |
| 185 | |
| 186 List<Element> _createRetainedSizeValue() { | |
| 187 final content = <Element>[]; | |
| 188 if (_retainedSize != null) { | |
| 189 if (_retainedSize.isSentinel) { | |
| 190 content.add( | |
| 191 new SentinelValueElement(_retainedSize.asSentinel, queue: _r.queue) | |
| 192 ); | |
| 193 } else { | |
| 194 content.add( | |
| 195 new SpanElement()..text = Utils.formatSize(int.parse( | |
| 196 _retainedSize.asValue.valueAsString)) | |
| 197 ); | |
| 198 } | |
| 199 } else { | |
| 200 content.add( | |
| 201 new SpanElement()..text = '...' | |
| 202 ); | |
| 203 } | |
| 204 var button; | |
| 205 content.add( | |
| 206 button = new ButtonElement()..classes = ['retained_size'] | |
|
Cutch
2016/08/19 22:11:19
don't assign inside a function call
cbernaschina
2016/08/19 22:17:40
Done.
| |
| 207 ..disabled = _loadingRetainedBytes | |
| 208 ..text = '↺' | |
| 209 ..onClick.listen((_) async { | |
| 210 button.disabled = true; | |
| 211 _loadingRetainedBytes = true; | |
| 212 _retainedSize = await _retainedSizes.get(_isolate, _object.id); | |
| 213 _r.dirty(); | |
| 214 }) | |
| 215 ); | |
| 216 return content; | |
| 52 } | 217 } |
| 53 } | 218 } |
| OLD | NEW |