Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: runtime/observatory/lib/src/elements/object_common.dart

Issue 2265513003: Converted Observatory object-common element (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Addressed comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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() {
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 final button = new ButtonElement()..classes = ['reachable_size']
172 ..disabled = _loadingReachableBytes
173 ..text = '↺';
174 button.onClick.listen((_) async {
175 button.disabled = true;
176 _loadingReachableBytes = true;
177 _reachableSize = await _reachableSizes.get(_isolate, _object.id);
178 _r.dirty();
179 });
180 content.add(button);
181 return content;
182 }
183
184 List<Element> _createRetainedSizeValue() {
185 final content = <Element>[];
186 if (_retainedSize != null) {
187 if (_retainedSize.isSentinel) {
188 content.add(
189 new SentinelValueElement(_retainedSize.asSentinel, queue: _r.queue)
190 );
191 } else {
192 content.add(
193 new SpanElement()..text = Utils.formatSize(int.parse(
194 _retainedSize.asValue.valueAsString))
195 );
196 }
197 } else {
198 content.add(
199 new SpanElement()..text = '...'
200 );
201 }
202 final button = new ButtonElement()..classes = ['retained_size']
203 ..disabled = _loadingRetainedBytes
204 ..text = '↺';
205 button.onClick.listen((_) async {
206 button.disabled = true;
207 _loadingRetainedBytes = true;
208 _retainedSize = await _retainedSizes.get(_isolate, _object.id);
209 _r.dirty();
210 });
211 content.add(button);
212 return content;
52 } 213 }
53 } 214 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698