| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 | 28 |
| 29 // Initlialize namespaces | |
| 30 var devtools = devtools || {}; | |
| 31 devtools.profiler = devtools.profiler || {}; | |
| 32 | |
| 33 | |
| 34 /** | 29 /** |
| 35 * Creates a Profile View builder object. | 30 * Creates a Profile View builder object. |
| 36 * | 31 * |
| 37 * @param {number} samplingRate Number of ms between profiler ticks. | 32 * @param {number} samplingRate Number of ms between profiler ticks. |
| 38 * @constructor | 33 * @constructor |
| 39 */ | 34 */ |
| 40 devtools.profiler.ViewBuilder = function(samplingRate) { | 35 function ViewBuilder(samplingRate) { |
| 41 this.samplingRate = samplingRate; | 36 this.samplingRate = samplingRate; |
| 42 }; | 37 }; |
| 43 | 38 |
| 44 | 39 |
| 45 /** | 40 /** |
| 46 * Builds a profile view for the specified call tree. | 41 * Builds a profile view for the specified call tree. |
| 47 * | 42 * |
| 48 * @param {devtools.profiler.CallTree} callTree A call tree. | 43 * @param {CallTree} callTree A call tree. |
| 49 * @param {boolean} opt_bottomUpViewWeights Whether remapping | 44 * @param {boolean} opt_bottomUpViewWeights Whether remapping |
| 50 * of self weights for a bottom up view is needed. | 45 * of self weights for a bottom up view is needed. |
| 51 */ | 46 */ |
| 52 devtools.profiler.ViewBuilder.prototype.buildView = function( | 47 ViewBuilder.prototype.buildView = function( |
| 53 callTree, opt_bottomUpViewWeights) { | 48 callTree, opt_bottomUpViewWeights) { |
| 54 var head; | 49 var head; |
| 55 var samplingRate = this.samplingRate; | 50 var samplingRate = this.samplingRate; |
| 56 var createViewNode = this.createViewNode; | 51 var createViewNode = this.createViewNode; |
| 57 callTree.traverse(function(node, viewParent) { | 52 callTree.traverse(function(node, viewParent) { |
| 58 var totalWeight = node.totalWeight * samplingRate; | 53 var totalWeight = node.totalWeight * samplingRate; |
| 59 var selfWeight = node.selfWeight * samplingRate; | 54 var selfWeight = node.selfWeight * samplingRate; |
| 60 if (opt_bottomUpViewWeights === true) { | 55 if (opt_bottomUpViewWeights === true) { |
| 61 if (viewParent === head) { | 56 if (viewParent === head) { |
| 62 selfWeight = totalWeight; | 57 selfWeight = totalWeight; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 73 return viewNode; | 68 return viewNode; |
| 74 }); | 69 }); |
| 75 var view = this.createView(head); | 70 var view = this.createView(head); |
| 76 return view; | 71 return view; |
| 77 }; | 72 }; |
| 78 | 73 |
| 79 | 74 |
| 80 /** | 75 /** |
| 81 * Factory method for a profile view. | 76 * Factory method for a profile view. |
| 82 * | 77 * |
| 83 * @param {devtools.profiler.ProfileView.Node} head View head node. | 78 * @param {ProfileView.Node} head View head node. |
| 84 * @return {devtools.profiler.ProfileView} Profile view. | 79 * @return {ProfileView} Profile view. |
| 85 */ | 80 */ |
| 86 devtools.profiler.ViewBuilder.prototype.createView = function(head) { | 81 ViewBuilder.prototype.createView = function(head) { |
| 87 return new devtools.profiler.ProfileView(head); | 82 return new ProfileView(head); |
| 88 }; | 83 }; |
| 89 | 84 |
| 90 | 85 |
| 91 /** | 86 /** |
| 92 * Factory method for a profile view node. | 87 * Factory method for a profile view node. |
| 93 * | 88 * |
| 94 * @param {string} internalFuncName A fully qualified function name. | 89 * @param {string} internalFuncName A fully qualified function name. |
| 95 * @param {number} totalTime Amount of time that application spent in the | 90 * @param {number} totalTime Amount of time that application spent in the |
| 96 * corresponding function and its descendants (not that depending on | 91 * corresponding function and its descendants (not that depending on |
| 97 * profile they can be either callees or callers.) | 92 * profile they can be either callees or callers.) |
| 98 * @param {number} selfTime Amount of time that application spent in the | 93 * @param {number} selfTime Amount of time that application spent in the |
| 99 * corresponding function only. | 94 * corresponding function only. |
| 100 * @param {devtools.profiler.ProfileView.Node} head Profile view head. | 95 * @param {ProfileView.Node} head Profile view head. |
| 101 * @return {devtools.profiler.ProfileView.Node} Profile view node. | 96 * @return {ProfileView.Node} Profile view node. |
| 102 */ | 97 */ |
| 103 devtools.profiler.ViewBuilder.prototype.createViewNode = function( | 98 ViewBuilder.prototype.createViewNode = function( |
| 104 funcName, totalTime, selfTime, head) { | 99 funcName, totalTime, selfTime, head) { |
| 105 return new devtools.profiler.ProfileView.Node( | 100 return new ProfileView.Node( |
| 106 funcName, totalTime, selfTime, head); | 101 funcName, totalTime, selfTime, head); |
| 107 }; | 102 }; |
| 108 | 103 |
| 109 | 104 |
| 110 /** | 105 /** |
| 111 * Creates a Profile View object. It allows to perform sorting | 106 * Creates a Profile View object. It allows to perform sorting |
| 112 * and filtering actions on the profile. | 107 * and filtering actions on the profile. |
| 113 * | 108 * |
| 114 * @param {devtools.profiler.ProfileView.Node} head Head (root) node. | 109 * @param {ProfileView.Node} head Head (root) node. |
| 115 * @constructor | 110 * @constructor |
| 116 */ | 111 */ |
| 117 devtools.profiler.ProfileView = function(head) { | 112 function ProfileView(head) { |
| 118 this.head = head; | 113 this.head = head; |
| 119 }; | 114 }; |
| 120 | 115 |
| 121 | 116 |
| 122 /** | 117 /** |
| 123 * Sorts the profile view using the specified sort function. | 118 * Sorts the profile view using the specified sort function. |
| 124 * | 119 * |
| 125 * @param {function(devtools.profiler.ProfileView.Node, | 120 * @param {function(ProfileView.Node, |
| 126 * devtools.profiler.ProfileView.Node):number} sortFunc A sorting | 121 * ProfileView.Node):number} sortFunc A sorting |
| 127 * functions. Must comply with Array.sort sorting function requirements. | 122 * functions. Must comply with Array.sort sorting function requirements. |
| 128 */ | 123 */ |
| 129 devtools.profiler.ProfileView.prototype.sort = function(sortFunc) { | 124 ProfileView.prototype.sort = function(sortFunc) { |
| 130 this.traverse(function (node) { | 125 this.traverse(function (node) { |
| 131 node.sortChildren(sortFunc); | 126 node.sortChildren(sortFunc); |
| 132 }); | 127 }); |
| 133 }; | 128 }; |
| 134 | 129 |
| 135 | 130 |
| 136 /** | 131 /** |
| 137 * Traverses profile view nodes in preorder. | 132 * Traverses profile view nodes in preorder. |
| 138 * | 133 * |
| 139 * @param {function(devtools.profiler.ProfileView.Node)} f Visitor function. | 134 * @param {function(ProfileView.Node)} f Visitor function. |
| 140 */ | 135 */ |
| 141 devtools.profiler.ProfileView.prototype.traverse = function(f) { | 136 ProfileView.prototype.traverse = function(f) { |
| 142 var nodesToTraverse = new ConsArray(); | 137 var nodesToTraverse = new ConsArray(); |
| 143 nodesToTraverse.concat([this.head]); | 138 nodesToTraverse.concat([this.head]); |
| 144 while (!nodesToTraverse.atEnd()) { | 139 while (!nodesToTraverse.atEnd()) { |
| 145 var node = nodesToTraverse.next(); | 140 var node = nodesToTraverse.next(); |
| 146 f(node); | 141 f(node); |
| 147 nodesToTraverse.concat(node.children); | 142 nodesToTraverse.concat(node.children); |
| 148 } | 143 } |
| 149 }; | 144 }; |
| 150 | 145 |
| 151 | 146 |
| 152 /** | 147 /** |
| 153 * Constructs a Profile View node object. Each node object corresponds to | 148 * Constructs a Profile View node object. Each node object corresponds to |
| 154 * a function call. | 149 * a function call. |
| 155 * | 150 * |
| 156 * @param {string} internalFuncName A fully qualified function name. | 151 * @param {string} internalFuncName A fully qualified function name. |
| 157 * @param {number} totalTime Amount of time that application spent in the | 152 * @param {number} totalTime Amount of time that application spent in the |
| 158 * corresponding function and its descendants (not that depending on | 153 * corresponding function and its descendants (not that depending on |
| 159 * profile they can be either callees or callers.) | 154 * profile they can be either callees or callers.) |
| 160 * @param {number} selfTime Amount of time that application spent in the | 155 * @param {number} selfTime Amount of time that application spent in the |
| 161 * corresponding function only. | 156 * corresponding function only. |
| 162 * @param {devtools.profiler.ProfileView.Node} head Profile view head. | 157 * @param {ProfileView.Node} head Profile view head. |
| 163 * @constructor | 158 * @constructor |
| 164 */ | 159 */ |
| 165 devtools.profiler.ProfileView.Node = function( | 160 ProfileView.Node = function( |
| 166 internalFuncName, totalTime, selfTime, head) { | 161 internalFuncName, totalTime, selfTime, head) { |
| 167 this.internalFuncName = internalFuncName; | 162 this.internalFuncName = internalFuncName; |
| 168 this.totalTime = totalTime; | 163 this.totalTime = totalTime; |
| 169 this.selfTime = selfTime; | 164 this.selfTime = selfTime; |
| 170 this.head = head; | 165 this.head = head; |
| 171 this.parent = null; | 166 this.parent = null; |
| 172 this.children = []; | 167 this.children = []; |
| 173 }; | 168 }; |
| 174 | 169 |
| 175 | 170 |
| 176 /** | 171 /** |
| 177 * Returns a share of the function's total time in application's total time. | 172 * Returns a share of the function's total time in application's total time. |
| 178 */ | 173 */ |
| 179 devtools.profiler.ProfileView.Node.prototype.__defineGetter__( | 174 ProfileView.Node.prototype.__defineGetter__( |
| 180 'totalPercent', | 175 'totalPercent', |
| 181 function() { return this.totalTime / | 176 function() { return this.totalTime / |
| 182 (this.head ? this.head.totalTime : this.totalTime) * 100.0; }); | 177 (this.head ? this.head.totalTime : this.totalTime) * 100.0; }); |
| 183 | 178 |
| 184 | 179 |
| 185 /** | 180 /** |
| 186 * Returns a share of the function's self time in application's total time. | 181 * Returns a share of the function's self time in application's total time. |
| 187 */ | 182 */ |
| 188 devtools.profiler.ProfileView.Node.prototype.__defineGetter__( | 183 ProfileView.Node.prototype.__defineGetter__( |
| 189 'selfPercent', | 184 'selfPercent', |
| 190 function() { return this.selfTime / | 185 function() { return this.selfTime / |
| 191 (this.head ? this.head.totalTime : this.totalTime) * 100.0; }); | 186 (this.head ? this.head.totalTime : this.totalTime) * 100.0; }); |
| 192 | 187 |
| 193 | 188 |
| 194 /** | 189 /** |
| 195 * Returns a share of the function's total time in its parent's total time. | 190 * Returns a share of the function's total time in its parent's total time. |
| 196 */ | 191 */ |
| 197 devtools.profiler.ProfileView.Node.prototype.__defineGetter__( | 192 ProfileView.Node.prototype.__defineGetter__( |
| 198 'parentTotalPercent', | 193 'parentTotalPercent', |
| 199 function() { return this.totalTime / | 194 function() { return this.totalTime / |
| 200 (this.parent ? this.parent.totalTime : this.totalTime) * 100.0; }); | 195 (this.parent ? this.parent.totalTime : this.totalTime) * 100.0; }); |
| 201 | 196 |
| 202 | 197 |
| 203 /** | 198 /** |
| 204 * Adds a child to the node. | 199 * Adds a child to the node. |
| 205 * | 200 * |
| 206 * @param {devtools.profiler.ProfileView.Node} node Child node. | 201 * @param {ProfileView.Node} node Child node. |
| 207 */ | 202 */ |
| 208 devtools.profiler.ProfileView.Node.prototype.addChild = function(node) { | 203 ProfileView.Node.prototype.addChild = function(node) { |
| 209 node.parent = this; | 204 node.parent = this; |
| 210 this.children.push(node); | 205 this.children.push(node); |
| 211 }; | 206 }; |
| 212 | 207 |
| 213 | 208 |
| 214 /** | 209 /** |
| 215 * Sorts all the node's children recursively. | 210 * Sorts all the node's children recursively. |
| 216 * | 211 * |
| 217 * @param {function(devtools.profiler.ProfileView.Node, | 212 * @param {function(ProfileView.Node, |
| 218 * devtools.profiler.ProfileView.Node):number} sortFunc A sorting | 213 * ProfileView.Node):number} sortFunc A sorting |
| 219 * functions. Must comply with Array.sort sorting function requirements. | 214 * functions. Must comply with Array.sort sorting function requirements. |
| 220 */ | 215 */ |
| 221 devtools.profiler.ProfileView.Node.prototype.sortChildren = function( | 216 ProfileView.Node.prototype.sortChildren = function( |
| 222 sortFunc) { | 217 sortFunc) { |
| 223 this.children.sort(sortFunc); | 218 this.children.sort(sortFunc); |
| 224 }; | 219 }; |
| OLD | NEW |