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 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/class_ref.dart'; | 8 import 'package:observatory/src/elements/class_ref.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/inbound_references.dart'; | 11 import 'package:observatory/src/elements/inbound_references.dart'; |
12 import 'package:observatory/src/elements/retaining_path.dart'; | 12 import 'package:observatory/src/elements/retaining_path.dart'; |
13 import 'package:observatory/src/elements/sentinel_value.dart'; | 13 import 'package:observatory/src/elements/sentinel_value.dart'; |
| 14 import 'package:observatory/src/elements/strongly_reachable_instances.dart'; |
| 15 import 'package:observatory/src/elements/top_retaining_instances.dart'; |
14 import 'package:observatory/utils.dart'; | 16 import 'package:observatory/utils.dart'; |
15 | 17 |
16 class ObjectCommonElement extends HtmlElement implements Renderable { | 18 class ClassInstancesElement extends HtmlElement implements Renderable { |
17 static const tag = const Tag<ObjectCommonElement>('object-common-wrapped', | 19 static const tag = const Tag<ClassInstancesElement>('class-instances', |
18 dependencies: const [ | 20 dependencies: const [ |
19 ClassRefElement.tag, | 21 ClassRefElement.tag, |
20 InboundReferencesElement.tag, | 22 InboundReferencesElement.tag, |
21 RetainingPathElement.tag, | 23 RetainingPathElement.tag, |
22 SentinelValueElement.tag | 24 TopRetainingInstancesElement.tag |
23 ]); | 25 ]); |
24 | 26 |
25 RenderingScheduler<ObjectCommonElement> _r; | 27 RenderingScheduler<ClassInstancesElement> _r; |
26 | 28 |
27 Stream<RenderedEvent<ObjectCommonElement>> get onRendered => _r.onRendered; | 29 Stream<RenderedEvent<ClassInstancesElement>> get onRendered => _r.onRendered; |
28 | 30 |
29 M.IsolateRef _isolate; | 31 M.IsolateRef _isolate; |
30 M.Object _object; | 32 M.Class _cls; |
31 M.RetainedSizeRepository _retainedSizes; | 33 M.RetainedSizeRepository _retainedSizes; |
32 M.ReachableSizeRepository _reachableSizes; | 34 M.ReachableSizeRepository _reachableSizes; |
33 M.InboundReferencesRepository _references; | 35 M.StronglyReachableInstancesRepository _stronglyReachableInstances; |
34 M.RetainingPathRepository _retainingPaths; | 36 M.TopRetainingInstancesRepository _topRetainingInstances; |
35 M.InstanceRepository _instances; | 37 M.InstanceRepository _instances; |
36 M.Guarded<M.Instance> _retainedSize = null; | 38 M.Guarded<M.Instance> _retainedSize = null; |
37 bool _loadingRetainedBytes = false; | 39 bool _loadingRetainedBytes = false; |
38 M.Guarded<M.Instance> _reachableSize = null; | 40 M.Guarded<M.Instance> _reachableSize = null; |
39 bool _loadingReachableBytes = false; | 41 bool _loadingReachableBytes = false; |
40 | 42 |
41 M.IsolateRef get isolate => _isolate; | 43 M.IsolateRef get isolate => _isolate; |
42 M.Object get object => _object; | 44 M.Class get cls => _cls; |
43 | 45 |
44 factory ObjectCommonElement(M.IsolateRef isolate, M.Object object, | 46 factory ClassInstancesElement(M.IsolateRef isolate, M.Class cls, |
45 M.RetainedSizeRepository retainedSizes, | 47 M.RetainedSizeRepository retainedSizes, |
46 M.ReachableSizeRepository reachableSizes, | 48 M.ReachableSizeRepository reachableSizes, |
47 M.InboundReferencesRepository references, | 49 M.StronglyReachableInstancesRepository stronglyReachableInstances, |
48 M.RetainingPathRepository retainingPaths, | 50 M.TopRetainingInstancesRepository topRetainingInstances, |
49 M.InstanceRepository instances, | 51 M.InstanceRepository instances, |
50 {RenderingQueue queue}) { | 52 {RenderingQueue queue}) { |
51 assert(isolate != null); | 53 assert(isolate != null); |
52 assert(object != null); | 54 assert(cls != null); |
53 assert(retainedSizes != null); | 55 assert(retainedSizes != null); |
54 assert(reachableSizes != null); | 56 assert(reachableSizes != null); |
55 assert(references != null); | 57 assert(stronglyReachableInstances != null); |
56 assert(retainingPaths != null); | 58 assert(topRetainingInstances != null); |
57 assert(instances != null); | 59 assert(instances != null); |
58 ObjectCommonElement e = document.createElement(tag.name); | 60 ClassInstancesElement e = document.createElement(tag.name); |
59 e._r = new RenderingScheduler(e, queue: queue); | 61 e._r = new RenderingScheduler(e, queue: queue); |
60 e._isolate = isolate; | 62 e._isolate = isolate; |
61 e._object = object; | 63 e._cls = cls; |
62 e._retainedSizes = retainedSizes; | 64 e._retainedSizes = retainedSizes; |
63 e._reachableSizes = reachableSizes; | 65 e._reachableSizes = reachableSizes; |
64 e._references = references; | 66 e._stronglyReachableInstances = stronglyReachableInstances; |
| 67 e._topRetainingInstances = topRetainingInstances; |
65 e._instances = instances; | 68 e._instances = instances; |
66 e._retainingPaths = retainingPaths; | |
67 return e; | 69 return e; |
68 } | 70 } |
69 | 71 |
70 ObjectCommonElement.created() : super.created(); | 72 ClassInstancesElement.created() : super.created(); |
71 | 73 |
72 @override | 74 @override |
73 void attached() { | 75 void attached() { |
74 super.attached(); | 76 super.attached(); |
75 _r.enable(); | 77 _r.enable(); |
76 } | 78 } |
77 | 79 |
78 @override | 80 @override |
79 void detached() { | 81 void detached() { |
80 super.detached(); | 82 super.detached(); |
81 _r.disable(notify: true); | 83 _r.disable(notify: true); |
82 children = []; | 84 children = []; |
83 } | 85 } |
84 | 86 |
85 RetainingPathElement _path; | 87 StronglyReachableInstancesElement _strong; |
86 InboundReferencesElement _inbounds; | 88 TopRetainingInstancesElement _topRetainig; |
87 | 89 |
88 void render() { | 90 void render() { |
89 _path = _path ?? new RetainingPathElement(_isolate, _object, | 91 _strong = _strong ?? new StronglyReachableInstancesElement(_isolate, |
90 _retainingPaths, _instances, | 92 _cls, _stronglyReachableInstances, _instances, queue: _r.queue); |
91 queue: _r.queue); | 93 _topRetainig = _topRetainig ?? new TopRetainingInstancesElement(_isolate, |
92 _inbounds = _inbounds ?? new InboundReferencesElement(_isolate, _object, | 94 _cls, _topRetainingInstances, _instances, queue: _r.queue); |
93 _references, | 95 final instanceCount = _cls.newSpace.current.instances + |
94 _instances, | 96 _cls.oldSpace.current.instances; |
95 queue: _r.queue); | 97 final size = Utils.formatSize(_cls.newSpace.current.bytes + |
| 98 _cls.oldSpace.current.bytes); |
96 children = [ | 99 children = [ |
97 new DivElement()..classes = ['memberList'] | 100 new DivElement()..classes = ['memberList'] |
98 ..children = [ | 101 ..children = [ |
| 102 new DivElement()..classes = const ['memberItem'] |
| 103 ..children = [ |
| 104 new DivElement()..classes = const ['memberName'] |
| 105 ..text = 'currently allocated', |
| 106 new DivElement()..classes = const ['memberValue'] |
| 107 ..text = 'count ${instanceCount} (shallow size ${size})' |
| 108 ], |
99 new DivElement()..classes = ['memberItem'] | 109 new DivElement()..classes = ['memberItem'] |
100 ..children = [ | 110 ..children = [ |
101 new DivElement()..classes = ['memberName'] | 111 new DivElement()..classes = ['memberName'] |
102 ..text = 'Class ', | 112 ..text = 'strongly reachable ', |
103 new DivElement()..classes = ['memberValue'] | 113 new DivElement()..classes = ['memberValue'] |
104 ..children = [ | 114 ..children = [_strong] |
105 _object.clazz == null | |
106 ? (new SpanElement()..text = '...') | |
107 : new ClassRefElement(_isolate, _object.clazz, | |
108 queue: _r.queue) | |
109 ] | |
110 ], | |
111 new DivElement()..classes = ['memberItem'] | |
112 ..title = 'Space for this object in memory' | |
113 ..children = [ | |
114 new DivElement()..classes = ['memberName'] | |
115 ..text = 'Shallow size ', | |
116 new DivElement()..classes = ['memberValue'] | |
117 ..text = Utils.formatSize(_object.size ?? 0) | |
118 ], | 115 ], |
119 new DivElement()..classes = ['memberItem'] | 116 new DivElement()..classes = ['memberItem'] |
120 ..title = 'Space reachable from this object, ' | 117 ..title = 'Space reachable from this object, ' |
121 'excluding class references' | 118 'excluding class references' |
122 ..children = [ | 119 ..children = [ |
123 new DivElement()..classes = ['memberName'] | 120 new DivElement()..classes = ['memberName'] |
124 ..text = 'Reachable size ', | 121 ..text = 'Reachable size ', |
125 new DivElement()..classes = ['memberValue'] | 122 new DivElement()..classes = ['memberValue'] |
126 ..children = _createReachableSizeValue() | 123 ..children = _createReachableSizeValue() |
127 ], | 124 ], |
128 new DivElement()..classes = ['memberItem'] | 125 new DivElement()..classes = ['memberItem'] |
129 ..title = 'Space that would be reclaimed if references to this ' | 126 ..title = 'Space that would be reclaimed if references to this ' |
130 'object were replaced with null' | 127 'object were replaced with null' |
131 ..children = [ | 128 ..children = [ |
132 new DivElement()..classes = ['memberName'] | 129 new DivElement()..classes = ['memberName'] |
133 ..text = 'Retained size ', | 130 ..text = 'Retained size ', |
134 new DivElement()..classes = ['memberValue'] | 131 new DivElement()..classes = ['memberValue'] |
135 ..children = _createRetainedSizeValue() | 132 ..children = _createRetainedSizeValue() |
136 ], | 133 ], |
137 new DivElement()..classes = ['memberItem'] | 134 new DivElement()..classes = ['memberItem'] |
138 ..children = [ | 135 ..children = [ |
139 new DivElement()..classes = ['memberName'] | 136 new DivElement()..classes = ['memberName'] |
140 ..text = 'Retaining path ', | 137 ..text = 'toplist by retained memory ', |
141 new DivElement()..classes = ['memberValue'] | 138 new DivElement()..classes = ['memberValue'] |
142 ..children = [_path] | 139 ..children = [_topRetainig] |
143 ], | |
144 new DivElement()..classes = ['memberItem'] | |
145 ..title = 'Objects which directly reference this object' | |
146 ..children = [ | |
147 new DivElement()..classes = ['memberName'] | |
148 ..text = 'Inbound references ', | |
149 new DivElement()..classes = ['memberValue'] | |
150 ..children = [_inbounds] | |
151 ] | 140 ] |
152 ] | 141 ] |
153 ]; | 142 ]; |
154 } | 143 } |
155 | 144 |
156 List<Element> _createReachableSizeValue() { | 145 List<Element> _createReachableSizeValue() { |
157 final content = <Element>[]; | 146 final content = <Element>[]; |
158 if (_reachableSize != null) { | 147 if (_reachableSize != null) { |
159 if (_reachableSize.isSentinel) { | 148 if (_reachableSize.isSentinel) { |
160 content.add( | 149 content.add( |
161 new SentinelValueElement(_reachableSize.asSentinel, queue: _r.queue) | 150 new SentinelValueElement(_reachableSize.asSentinel, queue: _r.queue) |
162 ); | 151 ); |
163 } else { | 152 } else { |
164 content.add( | 153 content.add( |
165 new SpanElement()..text = Utils.formatSize(int.parse( | 154 new SpanElement()..text = Utils.formatSize(int.parse( |
166 _reachableSize.asValue.valueAsString)) | 155 _reachableSize.asValue.valueAsString)) |
167 ); | 156 ); |
168 } | 157 } |
169 } else { | 158 } else { |
170 content.add( | 159 content.add( |
171 new SpanElement()..text = '...' | 160 new SpanElement()..text = '...' |
172 ); | 161 ); |
173 } | 162 } |
174 final button = new ButtonElement()..classes = ['reachable_size'] | 163 final button = new ButtonElement()..classes = ['reachable_size'] |
175 ..disabled = _loadingReachableBytes | 164 ..disabled = _loadingReachableBytes |
176 ..text = '↺'; | 165 ..text = '↺'; |
177 button.onClick.listen((_) async { | 166 button.onClick.listen((_) async { |
178 button.disabled = true; | 167 button.disabled = true; |
179 _loadingReachableBytes = true; | 168 _loadingReachableBytes = true; |
180 _reachableSize = await _reachableSizes.get(_isolate, _object.id); | 169 _reachableSize = await _reachableSizes.get(_isolate, _cls.id); |
181 _r.dirty(); | 170 _r.dirty(); |
182 }); | 171 }); |
183 content.add(button); | 172 content.add(button); |
184 return content; | 173 return content; |
185 } | 174 } |
186 | 175 |
187 List<Element> _createRetainedSizeValue() { | 176 List<Element> _createRetainedSizeValue() { |
188 final content = <Element>[]; | 177 final content = <Element>[]; |
189 if (_retainedSize != null) { | 178 if (_retainedSize != null) { |
190 if (_retainedSize.isSentinel) { | 179 if (_retainedSize.isSentinel) { |
(...skipping 10 matching lines...) Expand all Loading... |
201 content.add( | 190 content.add( |
202 new SpanElement()..text = '...' | 191 new SpanElement()..text = '...' |
203 ); | 192 ); |
204 } | 193 } |
205 final button = new ButtonElement()..classes = ['retained_size'] | 194 final button = new ButtonElement()..classes = ['retained_size'] |
206 ..disabled = _loadingRetainedBytes | 195 ..disabled = _loadingRetainedBytes |
207 ..text = '↺'; | 196 ..text = '↺'; |
208 button.onClick.listen((_) async { | 197 button.onClick.listen((_) async { |
209 button.disabled = true; | 198 button.disabled = true; |
210 _loadingRetainedBytes = true; | 199 _loadingRetainedBytes = true; |
211 _retainedSize = await _retainedSizes.get(_isolate, _object.id); | 200 _retainedSize = await _retainedSizes.get(_isolate, _cls.id); |
212 _r.dirty(); | 201 _r.dirty(); |
213 }); | 202 }); |
214 content.add(button); | 203 content.add(button); |
215 return content; | 204 return content; |
216 } | 205 } |
217 } | 206 } |
OLD | NEW |