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

Side by Side Diff: Source/devtools/front_end/HeapSnapshot.js

Issue 207523004: Always use global indexes for nodes and edges in the heap snapshot representation (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @constructor 32 * @constructor
33 * @param {!WebInspector.HeapSnapshot} snapshot 33 * @param {!WebInspector.HeapSnapshot} snapshot
34 * @param {!Uint32Array} edges
35 * @param {number=} edgeIndex 34 * @param {number=} edgeIndex
36 */ 35 */
37 WebInspector.HeapSnapshotEdge = function(snapshot, edges, edgeIndex) 36 WebInspector.HeapSnapshotEdge = function(snapshot, edgeIndex)
38 { 37 {
39 this._snapshot = snapshot; 38 this._snapshot = snapshot;
40 this._edges = edges; 39 this._edges = snapshot._containmentEdges;
41 this.edgeIndex = edgeIndex || 0; 40 this.edgeIndex = edgeIndex || 0;
42 } 41 }
43 42
44 /** 43 /**
45 * @constructor 44 * @constructor
46 * @param {string} name 45 * @param {string} name
47 * @param {!WebInspector.HeapSnapshotNode.Serialized} node 46 * @param {!WebInspector.HeapSnapshotNode.Serialized} node
48 * @param {number} nodeIndex 47 * @param {number} nodeIndex
49 * @param {string} type 48 * @param {string} type
50 * @param {number} distance 49 * @param {number} distance
51 */ 50 */
52 WebInspector.HeapSnapshotEdge.Serialized = function(name, node, nodeIndex, type, distance) { 51 WebInspector.HeapSnapshotEdge.Serialized = function(name, node, nodeIndex, type, distance) {
53 this.name = name; 52 this.name = name;
54 this.node = node; 53 this.node = node;
55 this.nodeIndex = nodeIndex; 54 this.nodeIndex = nodeIndex;
56 this.type = type; 55 this.type = type;
57 this.distance = distance; 56 this.distance = distance;
58 }; 57 };
59 58
60 WebInspector.HeapSnapshotEdge.prototype = { 59 WebInspector.HeapSnapshotEdge.prototype = {
61 /** 60 /**
62 * @return {!WebInspector.HeapSnapshotEdge} 61 * @return {!WebInspector.HeapSnapshotEdge}
63 */ 62 */
64 clone: function() 63 clone: function()
65 { 64 {
66 return new WebInspector.HeapSnapshotEdge(this._snapshot, this._edges, th is.edgeIndex); 65 return new WebInspector.HeapSnapshotEdge(this._snapshot, this.edgeIndex) ;
67 }, 66 },
68 67
69 /** 68 /**
70 * @return {boolean} 69 * @return {boolean}
71 */ 70 */
72 hasStringName: function() 71 hasStringName: function()
73 { 72 {
74 throw new Error("Not implemented"); 73 throw new Error("Not implemented");
75 }, 74 },
76 75
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 item: function() { }, 157 item: function() { },
159 158
160 next: function() { } 159 next: function() { }
161 }; 160 };
162 161
163 162
164 163
165 /** 164 /**
166 * @constructor 165 * @constructor
167 * @implements {WebInspector.HeapSnapshotItemIterator} 166 * @implements {WebInspector.HeapSnapshotItemIterator}
168 * @param {!WebInspector.HeapSnapshotEdge} edge 167 * @param {!WebInspector.HeapSnapshotNode} node
169 */ 168 */
170 WebInspector.HeapSnapshotEdgeIterator = function(edge) 169 WebInspector.HeapSnapshotEdgeIterator = function(node)
171 { 170 {
172 this.edge = edge; 171 this._sourceNode = node;
172 this.edge = node._snapshot.createEdge(node._edgeIndexesStart());
173 } 173 }
174 174
175 WebInspector.HeapSnapshotEdgeIterator.prototype = { 175 WebInspector.HeapSnapshotEdgeIterator.prototype = {
176 /** 176 /**
177 * @return {boolean} 177 * @return {boolean}
178 */ 178 */
179 hasNext: function() 179 hasNext: function()
180 { 180 {
181 return this.edge.edgeIndex < this.edge._edges.length; 181 return this.edge.edgeIndex < this._sourceNode._edgeIndexesEnd();
182 }, 182 },
183 183
184 /** 184 /**
185 * @return {number} 185 * @return {number}
186 */ 186 */
187 index: function() 187 index: function()
188 { 188 {
189 return this.edge.edgeIndex; 189 return this.edge.edgeIndex;
190 }, 190 },
191 191
(...skipping 14 matching lines...) Expand all
206 }, 206 },
207 207
208 next: function() 208 next: function()
209 { 209 {
210 this.edge.edgeIndex += this.edge._snapshot._edgeFieldsCount; 210 this.edge.edgeIndex += this.edge._snapshot._edgeFieldsCount;
211 } 211 }
212 }; 212 };
213 213
214 /** 214 /**
215 * @constructor 215 * @constructor
216 * @param {!WebInspector.HeapSnapshot} snapshot
217 * @param {number} retainerIndex
216 */ 218 */
217 WebInspector.HeapSnapshotRetainerEdge = function(snapshot, retainedNodeIndex, re tainerIndex) 219 WebInspector.HeapSnapshotRetainerEdge = function(snapshot, retainerIndex)
218 { 220 {
219 this._snapshot = snapshot; 221 this._snapshot = snapshot;
220 this._retainedNodeIndex = retainedNodeIndex;
221
222 var retainedNodeOrdinal = retainedNodeIndex / snapshot._nodeFieldCount;
223 this._firstRetainer = snapshot._firstRetainerIndex[retainedNodeOrdinal];
224 this._retainersCount = snapshot._firstRetainerIndex[retainedNodeOrdinal + 1] - this._firstRetainer;
225
226 this.setRetainerIndex(retainerIndex); 222 this.setRetainerIndex(retainerIndex);
227 } 223 }
228 224
229 /** 225 /**
230 * @constructor 226 * @constructor
231 * @param {string} name 227 * @param {string} name
232 * @param {!WebInspector.HeapSnapshotNode.Serialized} node 228 * @param {!WebInspector.HeapSnapshotNode.Serialized} node
233 * @param {number} nodeIndex 229 * @param {number} nodeIndex
234 * @param {string} type 230 * @param {string} type
235 * @param {number} distance 231 * @param {number} distance
236 */ 232 */
237 WebInspector.HeapSnapshotRetainerEdge.Serialized = function(name, node, nodeInde x, type, distance) { 233 WebInspector.HeapSnapshotRetainerEdge.Serialized = function(name, node, nodeInde x, type, distance) {
238 this.name = name; 234 this.name = name;
239 this.node = node; 235 this.node = node;
240 this.nodeIndex = nodeIndex; 236 this.nodeIndex = nodeIndex;
241 this.type = type; 237 this.type = type;
242 this.distance = distance; 238 this.distance = distance;
243 } 239 }
244 240
245 WebInspector.HeapSnapshotRetainerEdge.prototype = { 241 WebInspector.HeapSnapshotRetainerEdge.prototype = {
246 /** 242 /**
247 * @return {!WebInspector.HeapSnapshotRetainerEdge} 243 * @return {!WebInspector.HeapSnapshotRetainerEdge}
248 */ 244 */
249 clone: function() 245 clone: function()
250 { 246 {
251 return new WebInspector.HeapSnapshotRetainerEdge(this._snapshot, this._r etainedNodeIndex, this.retainerIndex()); 247 return new WebInspector.HeapSnapshotRetainerEdge(this._snapshot, this.re tainerIndex());
252 }, 248 },
253 249
254 /** 250 /**
255 * @return {boolean} 251 * @return {boolean}
256 */ 252 */
257 hasStringName: function() 253 hasStringName: function()
258 { 254 {
259 return this._edge().hasStringName(); 255 return this._edge().hasStringName();
260 }, 256 },
261 257
(...skipping 11 matching lines...) Expand all
273 node: function() 269 node: function()
274 { 270 {
275 return this._node(); 271 return this._node();
276 }, 272 },
277 273
278 /** 274 /**
279 * @return {number} 275 * @return {number}
280 */ 276 */
281 nodeIndex: function() 277 nodeIndex: function()
282 { 278 {
283 return this._nodeIndex; 279 return this._retainingNodeIndex;
284 }, 280 },
285 281
286 /** 282 /**
287 * @return {number} 283 * @return {number}
288 */ 284 */
289 retainerIndex: function() 285 retainerIndex: function()
290 { 286 {
291 return this._retainerIndex; 287 return this._retainerIndex;
292 }, 288 },
293 289
294 /** 290 /**
295 * @param {number} newIndex 291 * @param {number} retainerIndex
296 */ 292 */
297 setRetainerIndex: function(newIndex) 293 setRetainerIndex: function(retainerIndex)
298 { 294 {
299 if (newIndex !== this._retainerIndex) { 295 if (retainerIndex === this._retainerIndex)
300 this._retainerIndex = newIndex; 296 return;
301 this.edgeIndex = newIndex; 297 this._retainerIndex = retainerIndex;
302 } 298 this._globalEdgeIndex = this._snapshot._retainingEdges[retainerIndex];
299 this._retainingNodeIndex = this._snapshot._retainingNodes[retainerIndex] ;
300 this._edgeInstance = null;
301 this._nodeInstance = null;
303 }, 302 },
304 303
305 /** 304 /**
306 * @param {number} edgeIndex 305 * @param {number} edgeIndex
307 */ 306 */
308 set edgeIndex(edgeIndex) 307 set edgeIndex(edgeIndex)
309 { 308 {
310 var retainerIndex = this._firstRetainer + edgeIndex; 309 this.setRetainerIndex(edgeIndex);
311 this._globalEdgeIndex = this._snapshot._retainingEdges[retainerIndex];
312 this._nodeIndex = this._snapshot._retainingNodes[retainerIndex];
313 delete this._edgeInstance;
314 delete this._nodeInstance;
315 }, 310 },
316 311
317 _node: function() 312 _node: function()
318 { 313 {
319 if (!this._nodeInstance) 314 if (!this._nodeInstance)
320 this._nodeInstance = this._snapshot.createNode(this._nodeIndex); 315 this._nodeInstance = this._snapshot.createNode(this._retainingNodeIn dex);
321 return this._nodeInstance; 316 return this._nodeInstance;
322 }, 317 },
323 318
324 _edge: function() 319 _edge: function()
325 { 320 {
326 if (!this._edgeInstance) { 321 if (!this._edgeInstance)
327 var edgeIndex = this._globalEdgeIndex - this._node()._edgeIndexesSta rt(); 322 this._edgeInstance = this._snapshot.createEdge(this._globalEdgeIndex );
328 this._edgeInstance = this._snapshot.createEdge(this._node().rawEdges (), edgeIndex);
329 }
330 return this._edgeInstance; 323 return this._edgeInstance;
331 }, 324 },
332 325
333 /** 326 /**
334 * @return {string} 327 * @return {string}
335 */ 328 */
336 toString: function() 329 toString: function()
337 { 330 {
338 return this._edge().toString(); 331 return this._edge().toString();
339 }, 332 },
(...skipping 12 matching lines...) Expand all
352 */ 345 */
353 type: function() 346 type: function()
354 { 347 {
355 return this._edge().type(); 348 return this._edge().type();
356 } 349 }
357 } 350 }
358 351
359 /** 352 /**
360 * @constructor 353 * @constructor
361 * @implements {WebInspector.HeapSnapshotItemIterator} 354 * @implements {WebInspector.HeapSnapshotItemIterator}
362 * @param {!WebInspector.HeapSnapshotRetainerEdge} retainer 355 * @param {!WebInspector.HeapSnapshotNode} retainedNode
363 */ 356 */
364 WebInspector.HeapSnapshotRetainerEdgeIterator = function(retainer) 357 WebInspector.HeapSnapshotRetainerEdgeIterator = function(retainedNode)
365 { 358 {
366 this.retainer = retainer; 359 var snapshot = retainedNode._snapshot;
360 var retainedNodeOrdinal = retainedNode.nodeIndex / snapshot._nodeFieldCount;
alph 2014/03/21 08:30:39 _ordinal() ?
yurys 2014/03/21 08:33:20 Done.
361 var retainerIndex = snapshot._firstRetainerIndex[retainedNodeOrdinal];
362 this._retainersEnd = snapshot._firstRetainerIndex[retainedNodeOrdinal + 1];
363 this.retainer = snapshot.createRetainingEdge(retainerIndex);
367 } 364 }
368 365
369 WebInspector.HeapSnapshotRetainerEdgeIterator.prototype = { 366 WebInspector.HeapSnapshotRetainerEdgeIterator.prototype = {
370 /** 367 /**
371 * @return {boolean} 368 * @return {boolean}
372 */ 369 */
373 hasNext: function() 370 hasNext: function()
374 { 371 {
375 return this.retainer.retainerIndex() < this.retainer._retainersCount; 372 return this.retainer.retainerIndex() < this._retainersEnd;
376 }, 373 },
377 374
378 /** 375 /**
379 * @return {number} 376 * @return {number}
380 */ 377 */
381 index: function() 378 index: function()
382 { 379 {
383 return this.retainer.retainerIndex(); 380 return this.retainer.retainerIndex();
384 }, 381 },
385 382
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 { 465 {
469 var nodeFieldCount = this._snapshot._nodeFieldCount; 466 var nodeFieldCount = this._snapshot._nodeFieldCount;
470 return this._snapshot._dominatorsTree[this.nodeIndex / this._snapshot._n odeFieldCount] * nodeFieldCount; 467 return this._snapshot._dominatorsTree[this.nodeIndex / this._snapshot._n odeFieldCount] * nodeFieldCount;
471 }, 468 },
472 469
473 /** 470 /**
474 * @return {!WebInspector.HeapSnapshotEdgeIterator} 471 * @return {!WebInspector.HeapSnapshotEdgeIterator}
475 */ 472 */
476 edges: function() 473 edges: function()
477 { 474 {
478 return new WebInspector.HeapSnapshotEdgeIterator(this._snapshot.createEd ge(this.rawEdges(), 0)); 475 return new WebInspector.HeapSnapshotEdgeIterator(this);
479 }, 476 },
480 477
481 /** 478 /**
482 * @return {number} 479 * @return {number}
483 */ 480 */
484 edgesCount: function() 481 edgesCount: function()
485 { 482 {
486 return (this._edgeIndexesEnd() - this._edgeIndexesStart()) / this._snaps hot._edgeFieldsCount; 483 return (this._edgeIndexesEnd() - this._edgeIndexesStart()) / this._snaps hot._edgeFieldsCount;
487 }, 484 },
488 485
(...skipping 12 matching lines...) Expand all
501 498
502 /** 499 /**
503 * @return {string} 500 * @return {string}
504 */ 501 */
505 name: function() 502 name: function()
506 { 503 {
507 return this._snapshot._strings[this._name()]; 504 return this._snapshot._strings[this._name()];
508 }, 505 },
509 506
510 /** 507 /**
511 * @return {!Uint32Array}
512 */
513 rawEdges: function()
514 {
515 return this._snapshot._containmentEdges.subarray(this._edgeIndexesStart( ), this._edgeIndexesEnd());
516 },
517
518 /**
519 * @return {number} 508 * @return {number}
520 */ 509 */
521 retainedSize: function() 510 retainedSize: function()
522 { 511 {
523 return this._snapshot._retainedSizes[this._ordinal()]; 512 return this._snapshot._retainedSizes[this._ordinal()];
524 }, 513 },
525 514
526 /** 515 /**
527 * @return {!WebInspector.HeapSnapshotRetainerEdgeIterator} 516 * @return {!WebInspector.HeapSnapshotRetainerEdgeIterator}
528 */ 517 */
529 retainers: function() 518 retainers: function()
530 { 519 {
531 return new WebInspector.HeapSnapshotRetainerEdgeIterator(this._snapshot. createRetainingEdge(this.nodeIndex, 0)); 520 return new WebInspector.HeapSnapshotRetainerEdgeIterator(this);
532 }, 521 },
533 522
534 /** 523 /**
535 * @return {number} 524 * @return {number}
536 */ 525 */
537 retainersCount: function() 526 retainersCount: function()
538 { 527 {
539 var snapshot = this._snapshot; 528 var snapshot = this._snapshot;
540 var ordinal = this._ordinal(); 529 var ordinal = this._ordinal();
541 return snapshot._firstRetainerIndex[ordinal + 1] - snapshot._firstRetain erIndex[ordinal]; 530 return snapshot._firstRetainerIndex[ordinal + 1] - snapshot._firstRetain erIndex[ordinal];
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 }, 1022 },
1034 1023
1035 /** 1024 /**
1036 * @param {number=} nodeIndex 1025 * @param {number=} nodeIndex
1037 */ 1026 */
1038 createNode: function(nodeIndex) 1027 createNode: function(nodeIndex)
1039 { 1028 {
1040 throw new Error("Not implemented"); 1029 throw new Error("Not implemented");
1041 }, 1030 },
1042 1031
1043 createEdge: function(edges, edgeIndex) 1032 /**
1033 * @param {number} edgeIndex
1034 * @return {!WebInspector.JSHeapSnapshotEdge}
1035 */
1036 createEdge: function(edgeIndex)
1044 { 1037 {
1045 throw new Error("Not implemented"); 1038 throw new Error("Not implemented");
1046 }, 1039 },
1047 1040
1048 createRetainingEdge: function(retainedNodeIndex, retainerIndex) 1041 /**
1042 * @param {number} retainerIndex
1043 * @return {!WebInspector.JSHeapSnapshotRetainerEdge}
1044 */
1045 createRetainingEdge: function(retainerIndex)
1049 { 1046 {
1050 throw new Error("Not implemented"); 1047 throw new Error("Not implemented");
1051 }, 1048 },
1052 1049
1053 dispose: function() 1050 dispose: function()
1054 { 1051 {
1055 delete this._nodes; 1052 delete this._nodes;
1056 delete this._strings; 1053 delete this._strings;
1057 delete this._retainingEdges; 1054 delete this._retainingEdges;
1058 delete this._retainingNodes; 1055 delete this._retainingNodes;
(...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after
2283 * @param {number} windowRight 2280 * @param {number} windowRight
2284 */ 2281 */
2285 sort: function(comparator, leftBound, rightBound, windowLeft, windowRight) 2282 sort: function(comparator, leftBound, rightBound, windowLeft, windowRight)
2286 { 2283 {
2287 this._iterationOrder.sortRange(this._buildCompareFunction(comparator), l eftBound, rightBound, windowLeft, windowRight); 2284 this._iterationOrder.sortRange(this._buildCompareFunction(comparator), l eftBound, rightBound, windowLeft, windowRight);
2288 }, 2285 },
2289 2286
2290 __proto__: WebInspector.HeapSnapshotItemProvider.prototype 2287 __proto__: WebInspector.HeapSnapshotItemProvider.prototype
2291 } 2288 }
2292 2289
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698