1 /* 2 * Copyright (C) 2009 280 North Inc. All Rights Reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 /** 27 * @constructor 28 * @extends {WebInspector.ProfileDataGridNode} 29 * @param {!ProfilerAgent.CPUProfileNode} profileNode 30 * @param {!WebInspector.TopDownProfileDataGridTree} owningTree 31 */ 32 WebInspector.TopDownProfileDataGridNode = function(profileNode, owningTree) 33 { 34 var hasChildren = !!(profileNode.children && profileNode.children.length); 35 36 WebInspector.ProfileDataGridNode.call(this, profileNode, owningTree, hasChildren); 37 38 this._remainingChildren = profileNode.children; 39 this.buildData(); 40 } 41 42 WebInspector.TopDownProfileDataGridNode.prototype = { 43 /** 44 * @override 45 */ 46 populateChildren: function() 47 { 48 WebInspector.TopDownProfileDataGridNode._sharedPopulate(this); 49 }, 50 51 __proto__: WebInspector.ProfileDataGridNode.prototype 52 } 53 54 /** 55 * @param {!WebInspector.TopDownProfileDataGridNode|!WebInspector.TopDownProfileDataGridTree} container 56 */ 57 WebInspector.TopDownProfileDataGridNode._sharedPopulate = function(container) 58 { 59 var children = container._remainingChildren; 60 var childrenLength = children.length; 61 62 for (var i = 0; i < childrenLength; ++i) 63 container.appendChild(new WebInspector.TopDownProfileDataGridNode(children[i], /** @type {!WebInspector.TopDownProfileDataGridTree} */(container.tree))); 64 65 container._remainingChildren = null; 66 } 67 68 /** 69 * @param {!WebInspector.TopDownProfileDataGridNode|!WebInspector.TopDownProfileDataGridTree} container 70 * @param {number} aCallUID 71 */ 72 WebInspector.TopDownProfileDataGridNode._excludeRecursively = function(container, aCallUID) 73 { 74 if (container._remainingChildren) 75 container.populate(); 76 77 container.save(); 78 79 var children = container.children; 80 var index = container.children.length; 81 82 while (index--) 83 WebInspector.TopDownProfileDataGridNode._excludeRecursively(children[index], aCallUID); 84 85 var child = container.childrenByCallUID[aCallUID]; 86 87 if (child) 88 WebInspector.ProfileDataGridNode.merge(container, child, true); 89 } 90 91 /** 92 * @constructor 93 * @extends {WebInspector.ProfileDataGridTree} 94 * @param {!WebInspector.CPUProfileView} profileView 95 * @param {!ProfilerAgent.CPUProfileNode} rootProfileNode 96 */ 97 WebInspector.TopDownProfileDataGridTree = function(profileView, rootProfileNode) 98 { 99 WebInspector.ProfileDataGridTree.call(this, profileView, rootProfileNode); 100 101 this._remainingChildren = rootProfileNode.children; 102 103 WebInspector.ProfileDataGridNode.populate(this); 104 } 105 106 WebInspector.TopDownProfileDataGridTree.prototype = { 107 /** 108 * @param {!WebInspector.ProfileDataGridNode} profileDataGridNode 109 */ 110 focus: function(profileDataGridNode) 111 { 112 if (!profileDataGridNode) 113 return; 114 115 this.save(); 116 profileDataGridNode.savePosition(); 117 118 this.children = [profileDataGridNode]; 119 this.totalTime = profileDataGridNode.totalTime; 120 }, 121 122 /** 123 * @param {!WebInspector.ProfileDataGridNode} profileDataGridNode 124 */ 125 exclude: function(profileDataGridNode) 126 { 127 if (!profileDataGridNode) 128 return; 129 130 this.save(); 131 132 WebInspector.TopDownProfileDataGridNode._excludeRecursively(this, profileDataGridNode.callUID); 133 134 if (this.lastComparator) 135 this.sort(this.lastComparator, true); 136 }, 137 138 restore: function() 139 { 140 if (!this._savedChildren) 141 return; 142 143 this.children[0].restorePosition(); 144 145 WebInspector.ProfileDataGridTree.prototype.restore.call(this); 146 }, 147 148 /** 149 * @override 150 */ 151 populateChildren: function() 152 { 153 WebInspector.TopDownProfileDataGridNode._sharedPopulate(this); 154 }, 155 156 __proto__: WebInspector.ProfileDataGridTree.prototype 157 } 158