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

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

Issue 1291873002: Fix heap map (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | runtime/observatory/lib/src/elements/heap_map.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 } 44 }
45 45
46 class ObjectInfo { 46 class ObjectInfo {
47 final address; 47 final address;
48 final size; 48 final size;
49 ObjectInfo(this.address, this.size); 49 ObjectInfo(this.address, this.size);
50 } 50 }
51 51
52 @CustomTag('heap-map') 52 @CustomTag('heap-map')
53 class HeapMapElement extends ObservatoryElement { 53 class HeapMapElement extends ObservatoryElement {
54 var _fragmentationCanvas; 54 CanvasElement _fragmentationCanvas;
55 var _fragmentationData; 55 var _fragmentationData;
56 var _pageHeight; 56 var _pageHeight;
57 var _classIdToColor = {}; 57 var _classIdToColor = {};
58 var _colorToClassId = {}; 58 var _colorToClassId = {};
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.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 var rng = new Random(classId); 118 var rng = new Random(classId);
119 return [rng.nextInt(128), rng.nextInt(128), rng.nextInt(128), 255]; 119 return [rng.nextInt(128), rng.nextInt(128), rng.nextInt(128), 255];
120 } 120 }
121 121
122 String _classNameAt(Point<int> point) { 122 String _classNameAt(Point<int> point) {
123 var color = new PixelReference(_fragmentationData, point).color; 123 var color = new PixelReference(_fragmentationData, point).color;
124 return _classIdToName[_colorToClassId[_packColor(color)]]; 124 return _classIdToName[_colorToClassId[_packColor(color)]];
125 } 125 }
126 126
127 ObjectInfo _objectAt(Point<int> point) { 127 ObjectInfo _objectAt(Point<int> point) {
128 if (fragmentation == null || _fragmentationCanvas == null) {
129 return null;
130 }
128 var pagePixels = _pageHeight * _fragmentationData.width; 131 var pagePixels = _pageHeight * _fragmentationData.width;
129 var index = new PixelReference(_fragmentationData, point).index; 132 var index = new PixelReference(_fragmentationData, point).index;
130 var pageIndex = index ~/ pagePixels; 133 var pageIndex = index ~/ pagePixels;
131 var pageOffset = index % pagePixels; 134 var pageOffset = index % pagePixels;
132 var pages = fragmentation['pages']; 135 var pages = fragmentation['pages'];
133 if (pageIndex < 0 || pageIndex >= pages.length) { 136 if (pageIndex < 0 || pageIndex >= pages.length) {
134 return null; 137 return null;
135 } 138 }
136 // Scan the page to find start and size. 139 // Scan the page to find start and size.
137 var page = pages[pageIndex]; 140 var page = pages[pageIndex];
138 var objects = page['objects']; 141 var objects = page['objects'];
139 var offset = 0; 142 var offset = 0;
140 var size = 0; 143 var size = 0;
141 for (var i = 0; i < objects.length; i += 2) { 144 for (var i = 0; i < objects.length; i += 2) {
142 size = objects[i]; 145 size = objects[i];
143 offset += size; 146 offset += size;
144 if (offset > pageOffset) { 147 if (offset > pageOffset) {
145 pageOffset = offset - size; 148 pageOffset = offset - size;
146 break; 149 break;
147 } 150 }
148 } 151 }
149 return new ObjectInfo(int.parse(page['objectStart']) + 152 return new ObjectInfo(int.parse(page['objectStart']) +
150 pageOffset * fragmentation['unitSizeBytes'], 153 pageOffset * fragmentation['unitSizeBytes'],
151 size * fragmentation['unitSizeBytes']); 154 size * fragmentation['unitSizeBytes']);
152 } 155 }
153 156
154 void _handleMouseMove(MouseEvent event) { 157 void _handleMouseMove(MouseEvent event) {
155 var info = _objectAt(event.offset); 158 var info = _objectAt(event.offset);
159 if (info == null) {
160 status = '';
161 return;
162 }
156 var addressString = '${info.size}B @ 0x${info.address.toRadixString(16)}'; 163 var addressString = '${info.size}B @ 0x${info.address.toRadixString(16)}';
157 var className = _classNameAt(event.offset); 164 var className = _classNameAt(event.offset);
158 status = (className == '') ? '-' : '$className $addressString'; 165 status = (className == '') ? '-' : '$className $addressString';
159 } 166 }
160 167
161 void _handleClick(MouseEvent event) { 168 void _handleClick(MouseEvent event) {
162 var address = _objectAt(event.offset).address.toRadixString(16); 169 var address = _objectAt(event.offset).address.toRadixString(16);
163 isolate.getObjectByAddress(address).then((result) { 170 isolate.getObjectByAddress(address).then((result) {
164 if (result.type != 'Sentinel') { 171 if (result.type != 'Sentinel') {
165 app.locationManager.go(gotoLink('/inspect', result)); 172 app.locationManager.go(gotoLink('/inspect', result));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 }); 249 });
243 } 250 }
244 251
245 void fragmentationChanged(oldValue) { 252 void fragmentationChanged(oldValue) {
246 // Async, in case attached has not yet run (observed in JS version). 253 // Async, in case attached has not yet run (observed in JS version).
247 new Future(() { 254 new Future(() {
248 _updateFragmentationData(); 255 _updateFragmentationData();
249 }); 256 });
250 } 257 }
251 } 258 }
OLDNEW
« no previous file with comments | « no previous file | runtime/observatory/lib/src/elements/heap_map.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698