| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 heap_map_element; | 5 library heap_map_element; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:html'; | 8 import 'dart:html'; |
| 9 import 'dart:math'; | 9 import 'dart:math'; |
| 10 import 'observatory_element.dart'; | 10 import 'observatory_element.dart'; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 var _classIdToName = {}; | 59 var _classIdToName = {}; |
| 60 | 60 |
| 61 static final _freeColor = [255, 255, 255, 255]; | 61 static final _freeColor = [255, 255, 255, 255]; |
| 62 static final _pageSeparationColor = [0, 0, 0, 255]; | 62 static final _pageSeparationColor = [0, 0, 0, 255]; |
| 63 static const _PAGE_SEPARATION_HEIGHT = 4; | 63 static const _PAGE_SEPARATION_HEIGHT = 4; |
| 64 // Many browsers will not display a very tall canvas. | 64 // Many browsers will not display a very tall canvas. |
| 65 // TODO(koda): Improve interface for huge heaps. | 65 // TODO(koda): Improve interface for huge heaps. |
| 66 static const _MAX_CANVAS_HEIGHT = 6000; | 66 static const _MAX_CANVAS_HEIGHT = 6000; |
| 67 | 67 |
| 68 @observable String status; | 68 @observable String status; |
| 69 @published ServiceMap fragmentation; | 69 @published Isolate isolate; |
| 70 @observable ServiceMap fragmentation; |
| 70 | 71 |
| 71 HeapMapElement.created() : super.created() { | 72 HeapMapElement.created() : super.created() { |
| 72 } | 73 } |
| 73 | 74 |
| 74 @override | 75 @override |
| 75 void attached() { | 76 void attached() { |
| 76 super.attached(); | 77 super.attached(); |
| 77 _fragmentationCanvas = shadowRoot.querySelector("#fragmentation"); | 78 _fragmentationCanvas = shadowRoot.querySelector("#fragmentation"); |
| 78 _fragmentationCanvas.onMouseMove.listen(_handleMouseMove); | 79 _fragmentationCanvas.onMouseMove.listen(_handleMouseMove); |
| 79 _fragmentationCanvas.onMouseDown.listen(_handleClick); | 80 _fragmentationCanvas.onMouseDown.listen(_handleClick); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 90 | 91 |
| 91 void _addClass(int classId, String name, Iterable<int> color) { | 92 void _addClass(int classId, String name, Iterable<int> color) { |
| 92 _classIdToName[classId] = name.split('@')[0]; | 93 _classIdToName[classId] = name.split('@')[0]; |
| 93 _classIdToColor[classId] = color; | 94 _classIdToColor[classId] = color; |
| 94 _colorToClassId[_packColor(color)] = classId; | 95 _colorToClassId[_packColor(color)] = classId; |
| 95 } | 96 } |
| 96 | 97 |
| 97 void _updateClassList(classList, int freeClassId) { | 98 void _updateClassList(classList, int freeClassId) { |
| 98 for (var member in classList['members']) { | 99 for (var member in classList['members']) { |
| 99 if (member is! Class) { | 100 if (member is! Class) { |
| 100 Logger.root.info('$member'); | 101 // TODO(turnidge): The printing for some of these non-class |
| 102 // members is broken. Fix this: |
| 103 // |
| 104 // Logger.root.info('$member'); |
| 105 Logger.root.info('Ignoring non-class in class list'); |
| 101 continue; | 106 continue; |
| 102 } | 107 } |
| 103 var classId = int.parse(member.id.split('/').last); | 108 var classId = int.parse(member.id.split('/').last); |
| 104 var color = _classIdToRGBA(classId); | 109 var color = _classIdToRGBA(classId); |
| 105 _addClass(classId, member.name, color); | 110 _addClass(classId, member.name, color); |
| 106 } | 111 } |
| 107 _addClass(freeClassId, 'Free', _freeColor); | 112 _addClass(freeClassId, 'Free', _freeColor); |
| 108 _addClass(0, '', _pageSeparationColor); | 113 _addClass(0, '', _pageSeparationColor); |
| 109 } | 114 } |
| 110 | 115 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 void _handleMouseMove(MouseEvent event) { | 154 void _handleMouseMove(MouseEvent event) { |
| 150 var info = _objectAt(event.offset); | 155 var info = _objectAt(event.offset); |
| 151 var addressString = '${info.size}B @ 0x${info.address.toRadixString(16)}'; | 156 var addressString = '${info.size}B @ 0x${info.address.toRadixString(16)}'; |
| 152 var className = _classNameAt(event.offset); | 157 var className = _classNameAt(event.offset); |
| 153 status = (className == '') ? '-' : '$className $addressString'; | 158 status = (className == '') ? '-' : '$className $addressString'; |
| 154 } | 159 } |
| 155 | 160 |
| 156 void _handleClick(MouseEvent event) { | 161 void _handleClick(MouseEvent event) { |
| 157 var address = _objectAt(event.offset).address.toRadixString(16); | 162 var address = _objectAt(event.offset).address.toRadixString(16); |
| 158 app.locationManager.go(app.locationManager.makeLink( | 163 app.locationManager.go(app.locationManager.makeLink( |
| 159 "${fragmentation.isolate.relativeLink('address/$address')}")); | 164 "${isolate.relativeLink('address/$address')}")); |
| 160 } | 165 } |
| 161 | 166 |
| 162 void _updateFragmentationData() { | 167 void _updateFragmentationData() { |
| 163 if (fragmentation == null || _fragmentationCanvas == null) { | 168 if (fragmentation == null || _fragmentationCanvas == null) { |
| 164 return; | 169 return; |
| 165 } | 170 } |
| 166 _updateClassList( | 171 _updateClassList( |
| 167 fragmentation['class_list'], fragmentation['free_class_id']); | 172 fragmentation['class_list'], fragmentation['free_class_id']); |
| 168 var pages = fragmentation['pages']; | 173 var pages = fragmentation['pages']; |
| 169 var width = _fragmentationCanvas.parent.client.width; | 174 var width = _fragmentationCanvas.parent.client.width; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 pixel = pixel.next(); | 209 pixel = pixel.next(); |
| 205 } | 210 } |
| 206 _fragmentationCanvas.context2D.putImageData( | 211 _fragmentationCanvas.context2D.putImageData( |
| 207 _fragmentationData, 0, 0, 0, startY, _fragmentationData.width, endY); | 212 _fragmentationData, 0, 0, 0, startY, _fragmentationData.width, endY); |
| 208 // Continue with the next page, asynchronously. | 213 // Continue with the next page, asynchronously. |
| 209 new Future(() { | 214 new Future(() { |
| 210 _renderPages(startPage + 1); | 215 _renderPages(startPage + 1); |
| 211 }); | 216 }); |
| 212 } | 217 } |
| 213 | 218 |
| 219 void isolateChanged(oldValue) { |
| 220 if (isolate == null) { |
| 221 fragmentation = null; |
| 222 return; |
| 223 } |
| 224 isolate.invokeRpc('getHeapMap', {}).then((ServiceMap response) { |
| 225 assert(response['type'] == 'HeapMap'); |
| 226 fragmentation = response; |
| 227 }).catchError((e, st) { |
| 228 Logger.root.info('$e $st'); |
| 229 }); |
| 230 } |
| 231 |
| 214 void refresh(var done) { | 232 void refresh(var done) { |
| 215 if (fragmentation == null) { | 233 if (isolate == null) { |
| 216 return; | 234 return; |
| 217 } | 235 } |
| 218 fragmentation.isolate.get('heapmap').then((ServiceMap response) { | 236 isolate.invokeRpc('getHeapMap', {}).then((ServiceMap response) { |
| 219 assert(response['type'] == 'HeapMap'); | 237 assert(response['type'] == 'HeapMap'); |
| 220 fragmentation = response; | 238 fragmentation = response; |
| 221 }).catchError((e, st) { | 239 }).catchError((e, st) { |
| 222 Logger.root.info('$e $st'); | 240 Logger.root.info('$e $st'); |
| 223 }).whenComplete(done); | 241 }).whenComplete(done); |
| 224 } | 242 } |
| 225 | 243 |
| 226 void fragmentationChanged(oldValue) { | 244 void fragmentationChanged(oldValue) { |
| 227 // Async, in case attached has not yet run (observed in JS version). | 245 // Async, in case attached has not yet run (observed in JS version). |
| 228 new Future(() { | 246 new Future(() { |
| 229 _updateFragmentationData(); | 247 _updateFragmentationData(); |
| 230 }); | 248 }); |
| 231 } | 249 } |
| 232 } | 250 } |
| OLD | NEW |