OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 true)); | 139 true)); |
140 this._collapsedTopNodeIdToFunctionInfo[nodeId] = info; | 140 this._collapsedTopNodeIdToFunctionInfo[nodeId] = info; |
141 } | 141 } |
142 result.sort(function(a, b) { | 142 result.sort(function(a, b) { |
143 return b.size - a.size; | 143 return b.size - a.size; |
144 }); | 144 }); |
145 return result; | 145 return result; |
146 }, | 146 }, |
147 | 147 |
148 /** | 148 /** |
149 * @param {string} nodeId | 149 * @param {number} nodeId |
150 * @return {!WebInspector.HeapSnapshotCommon.AllocationNodeCallers} | 150 * @return {!WebInspector.HeapSnapshotCommon.AllocationNodeCallers} |
151 */ | 151 */ |
152 serializeCallers: function(nodeId) | 152 serializeCallers: function(nodeId) |
153 { | 153 { |
154 var node = this._idToNode[nodeId]; | 154 var node = this._ensureBottomUpNode(nodeId); |
155 if (!node) { | |
156 var functionInfo = this._collapsedTopNodeIdToFunctionInfo[nodeId]; | |
157 node = functionInfo.bottomUpRoot(); | |
158 delete this._collapsedTopNodeIdToFunctionInfo[nodeId]; | |
159 this._idToNode[nodeId] = node; | |
160 } | |
161 | |
162 var nodesWithSingleCaller = []; | 155 var nodesWithSingleCaller = []; |
163 while (node.callers().length === 1) { | 156 while (node.callers().length === 1) { |
164 node = node.callers()[0]; | 157 node = node.callers()[0]; |
165 nodesWithSingleCaller.push(this._serializeCaller(node)); | 158 nodesWithSingleCaller.push(this._serializeCaller(node)); |
166 } | 159 } |
167 | 160 |
168 var branchingCallers = []; | 161 var branchingCallers = []; |
169 var callers = node.callers(); | 162 var callers = node.callers(); |
170 for (var i = 0; i < callers.length; i++) { | 163 for (var i = 0; i < callers.length; i++) { |
171 branchingCallers.push(this._serializeCaller(callers[i])); | 164 branchingCallers.push(this._serializeCaller(callers[i])); |
172 } | 165 } |
173 return new WebInspector.HeapSnapshotCommon.AllocationNodeCallers(nodesWi
thSingleCaller, branchingCallers); | 166 return new WebInspector.HeapSnapshotCommon.AllocationNodeCallers(nodesWi
thSingleCaller, branchingCallers); |
174 }, | 167 }, |
175 | 168 |
| 169 /** |
| 170 * @param {number} allocationNodeId |
| 171 * @return {!Array.<number>} |
| 172 */ |
| 173 traceIds: function(allocationNodeId) |
| 174 { |
| 175 return this._ensureBottomUpNode(allocationNodeId).traceTopIds; |
| 176 }, |
| 177 |
| 178 /** |
| 179 * @param {number} nodeId |
| 180 * @return {!WebInspector.BottomUpAllocationNode} |
| 181 */ |
| 182 _ensureBottomUpNode: function(nodeId) |
| 183 { |
| 184 var node = this._idToNode[nodeId]; |
| 185 if (!node) { |
| 186 var functionInfo = this._collapsedTopNodeIdToFunctionInfo[nodeId]; |
| 187 node = functionInfo.bottomUpRoot(); |
| 188 delete this._collapsedTopNodeIdToFunctionInfo[nodeId]; |
| 189 this._idToNode[nodeId] = node; |
| 190 } |
| 191 return node; |
| 192 }, |
| 193 |
176 _serializeCaller: function(node) | 194 _serializeCaller: function(node) |
177 { | 195 { |
178 var callerId = this._nextNodeId++; | 196 var callerId = this._nextNodeId++; |
179 this._idToNode[callerId] = node; | 197 this._idToNode[callerId] = node; |
180 return this._serializeNode( | 198 return this._serializeNode( |
181 callerId, | 199 callerId, |
182 node.functionInfo, | 200 node.functionInfo, |
183 node.allocationCount, | 201 node.allocationCount, |
184 node.allocationSize, | 202 node.allocationSize, |
185 node.liveCount, | 203 node.liveCount, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 * @constructor | 260 * @constructor |
243 * @param {!WebInspector.FunctionAllocationInfo} functionInfo | 261 * @param {!WebInspector.FunctionAllocationInfo} functionInfo |
244 */ | 262 */ |
245 WebInspector.BottomUpAllocationNode = function(functionInfo) | 263 WebInspector.BottomUpAllocationNode = function(functionInfo) |
246 { | 264 { |
247 this.functionInfo = functionInfo; | 265 this.functionInfo = functionInfo; |
248 this.allocationCount = 0; | 266 this.allocationCount = 0; |
249 this.allocationSize = 0; | 267 this.allocationSize = 0; |
250 this.liveCount = 0; | 268 this.liveCount = 0; |
251 this.liveSize = 0; | 269 this.liveSize = 0; |
| 270 this.traceTopIds = []; |
252 this._callers = []; | 271 this._callers = []; |
253 } | 272 } |
254 | 273 |
255 | 274 |
256 WebInspector.BottomUpAllocationNode.prototype = { | 275 WebInspector.BottomUpAllocationNode.prototype = { |
257 /** | 276 /** |
258 * @param {!WebInspector.TopDownAllocationNode} traceNode | 277 * @param {!WebInspector.TopDownAllocationNode} traceNode |
259 * @return {!WebInspector.TopDownAllocationNode} | 278 * @return {!WebInspector.BottomUpAllocationNode} |
260 */ | 279 */ |
261 addCaller: function(traceNode) | 280 addCaller: function(traceNode) |
262 { | 281 { |
263 var functionInfo = traceNode.functionInfo; | 282 var functionInfo = traceNode.functionInfo; |
264 var result; | 283 var result; |
265 for (var i = 0; i < this._callers.length; i++) { | 284 for (var i = 0; i < this._callers.length; i++) { |
266 var caller = this._callers[i]; | 285 var caller = this._callers[i]; |
267 if (caller.functionInfo === functionInfo) { | 286 if (caller.functionInfo === functionInfo) { |
268 result = caller; | 287 result = caller; |
269 break; | 288 break; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 { | 366 { |
348 this._bottomUpTree = new WebInspector.BottomUpAllocationNode(this); | 367 this._bottomUpTree = new WebInspector.BottomUpAllocationNode(this); |
349 | 368 |
350 for (var i = 0; i < this._traceTops.length; i++) { | 369 for (var i = 0; i < this._traceTops.length; i++) { |
351 var node = this._traceTops[i]; | 370 var node = this._traceTops[i]; |
352 var bottomUpNode = this._bottomUpTree; | 371 var bottomUpNode = this._bottomUpTree; |
353 var count = node.allocationCount; | 372 var count = node.allocationCount; |
354 var size = node.allocationSize; | 373 var size = node.allocationSize; |
355 var liveCount = node.liveCount; | 374 var liveCount = node.liveCount; |
356 var liveSize = node.liveSize; | 375 var liveSize = node.liveSize; |
| 376 var traceId = node.id; |
357 while (true) { | 377 while (true) { |
358 bottomUpNode.allocationCount += count; | 378 bottomUpNode.allocationCount += count; |
359 bottomUpNode.allocationSize += size; | 379 bottomUpNode.allocationSize += size; |
360 bottomUpNode.liveCount += liveCount; | 380 bottomUpNode.liveCount += liveCount; |
361 bottomUpNode.liveSize += liveSize; | 381 bottomUpNode.liveSize += liveSize; |
| 382 bottomUpNode.traceTopIds.push(traceId); |
362 node = node.parent; | 383 node = node.parent; |
363 if (node === null) { | 384 if (node === null) { |
364 break; | 385 break; |
365 } | 386 } |
366 bottomUpNode = bottomUpNode.addCaller(node); | 387 bottomUpNode = bottomUpNode.addCaller(node); |
367 } | 388 } |
368 } | 389 } |
369 } | 390 } |
370 } | 391 } |
OLD | NEW |