| 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 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 * Builds a profile view for the specified call tree. | 46 * Builds a profile view for the specified call tree. |
| 47 * | 47 * |
| 48 * @param {devtools.profiler.CallTree} callTree A call tree. | 48 * @param {devtools.profiler.CallTree} callTree A call tree. |
| 49 * @param {boolean} opt_bottomUpViewWeights Whether remapping | 49 * @param {boolean} opt_bottomUpViewWeights Whether remapping |
| 50 * of self weights for a bottom up view is needed. | 50 * of self weights for a bottom up view is needed. |
| 51 */ | 51 */ |
| 52 devtools.profiler.ViewBuilder.prototype.buildView = function( | 52 devtools.profiler.ViewBuilder.prototype.buildView = function( |
| 53 callTree, opt_bottomUpViewWeights) { | 53 callTree, opt_bottomUpViewWeights) { |
| 54 var head; | 54 var head; |
| 55 var samplingRate = this.samplingRate; | 55 var samplingRate = this.samplingRate; |
| 56 var createViewNode = this.createViewNode; |
| 56 callTree.traverse(function(node, viewParent) { | 57 callTree.traverse(function(node, viewParent) { |
| 57 var totalWeight = node.totalWeight * samplingRate; | 58 var totalWeight = node.totalWeight * samplingRate; |
| 58 var selfWeight = node.selfWeight * samplingRate; | 59 var selfWeight = node.selfWeight * samplingRate; |
| 59 if (opt_bottomUpViewWeights === true) { | 60 if (opt_bottomUpViewWeights === true) { |
| 60 if (viewParent === head) { | 61 if (viewParent === head) { |
| 61 selfWeight = totalWeight; | 62 selfWeight = totalWeight; |
| 62 } else { | 63 } else { |
| 63 selfWeight = 0; | 64 selfWeight = 0; |
| 64 } | 65 } |
| 65 } | 66 } |
| 66 var viewNode = new devtools.profiler.ProfileView.Node( | 67 var viewNode = createViewNode(node.label, totalWeight, selfWeight, head); |
| 67 node.label, totalWeight, selfWeight, head); | |
| 68 if (viewParent) { | 68 if (viewParent) { |
| 69 viewParent.addChild(viewNode); | 69 viewParent.addChild(viewNode); |
| 70 } else { | 70 } else { |
| 71 head = viewNode; | 71 head = viewNode; |
| 72 } | 72 } |
| 73 return viewNode; | 73 return viewNode; |
| 74 }); | 74 }); |
| 75 var view = new devtools.profiler.ProfileView(head); | 75 var view = this.createView(head); |
| 76 return view; | 76 return view; |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 | 79 |
| 80 /** | 80 /** |
| 81 * Factory method for a profile view. |
| 82 * |
| 83 * @param {devtools.profiler.ProfileView.Node} head View head node. |
| 84 * @return {devtools.profiler.ProfileView} Profile view. |
| 85 */ |
| 86 devtools.profiler.ViewBuilder.prototype.createView = function(head) { |
| 87 return new devtools.profiler.ProfileView(head); |
| 88 }; |
| 89 |
| 90 |
| 91 /** |
| 92 * Factory method for a profile view node. |
| 93 * |
| 94 * @param {string} internalFuncName A fully qualified function name. |
| 95 * @param {number} totalTime Amount of time that application spent in the |
| 96 * corresponding function and its descendants (not that depending on |
| 97 * profile they can be either callees or callers.) |
| 98 * @param {number} selfTime Amount of time that application spent in the |
| 99 * corresponding function only. |
| 100 * @param {devtools.profiler.ProfileView.Node} head Profile view head. |
| 101 * @return {devtools.profiler.ProfileView.Node} Profile view node. |
| 102 */ |
| 103 devtools.profiler.ViewBuilder.prototype.createViewNode = function( |
| 104 funcName, totalTime, selfTime, head) { |
| 105 return new devtools.profiler.ProfileView.Node( |
| 106 funcName, totalTime, selfTime, head); |
| 107 }; |
| 108 |
| 109 |
| 110 /** |
| 81 * Creates a Profile View object. It allows to perform sorting | 111 * Creates a Profile View object. It allows to perform sorting |
| 82 * and filtering actions on the profile. Profile View mimicks | 112 * and filtering actions on the profile. Profile View mimicks |
| 83 * the Profile object from WebKit's JSC profiler. | 113 * the Profile object from WebKit's JSC profiler. |
| 84 * | 114 * |
| 85 * @param {devtools.profiler.ProfileView.Node} head Head (root) node. | 115 * @param {devtools.profiler.ProfileView.Node} head Head (root) node. |
| 86 * @constructor | 116 * @constructor |
| 87 */ | 117 */ |
| 88 devtools.profiler.ProfileView = function(head) { | 118 devtools.profiler.ProfileView = function(head) { |
| 89 this.head = head; | 119 this.head = head; |
| 90 this.title = ''; | 120 this.title = ''; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 * @param {number} totalTime Amount of time that application spent in the | 163 * @param {number} totalTime Amount of time that application spent in the |
| 134 * corresponding function and its descendants (not that depending on | 164 * corresponding function and its descendants (not that depending on |
| 135 * profile they can be either callees or callers.) | 165 * profile they can be either callees or callers.) |
| 136 * @param {number} selfTime Amount of time that application spent in the | 166 * @param {number} selfTime Amount of time that application spent in the |
| 137 * corresponding function only. | 167 * corresponding function only. |
| 138 * @param {devtools.profiler.ProfileView.Node} head Profile view head. | 168 * @param {devtools.profiler.ProfileView.Node} head Profile view head. |
| 139 * @constructor | 169 * @constructor |
| 140 */ | 170 */ |
| 141 devtools.profiler.ProfileView.Node = function( | 171 devtools.profiler.ProfileView.Node = function( |
| 142 internalFuncName, totalTime, selfTime, head) { | 172 internalFuncName, totalTime, selfTime, head) { |
| 143 this.callIdentifier = 0; | |
| 144 this.internalFuncName = internalFuncName; | 173 this.internalFuncName = internalFuncName; |
| 145 this.initFuncInfo(); | |
| 146 this.totalTime = totalTime; | 174 this.totalTime = totalTime; |
| 147 this.selfTime = selfTime; | 175 this.selfTime = selfTime; |
| 148 this.head = head; | 176 this.head = head; |
| 149 this.parent = null; | 177 this.parent = null; |
| 150 this.children = []; | 178 this.children = []; |
| 151 this.visible = true; | |
| 152 }; | 179 }; |
| 153 | 180 |
| 154 | 181 |
| 155 /** | |
| 156 * RegEx for stripping V8's prefixes of compiled functions. | |
| 157 */ | |
| 158 devtools.profiler.ProfileView.Node.FUNC_NAME_STRIP_RE = | |
| 159 /^(?:LazyCompile|Function): (.*)$/; | |
| 160 | |
| 161 | |
| 162 /** | |
| 163 * RegEx for extracting script source URL and line number. | |
| 164 */ | |
| 165 devtools.profiler.ProfileView.Node.FUNC_NAME_PARSE_RE = /^([^ ]+) (.*):(\d+)$/; | |
| 166 | |
| 167 | |
| 168 /** | |
| 169 * RegEx for removing protocol name from URL. | |
| 170 */ | |
| 171 devtools.profiler.ProfileView.Node.URL_PARSE_RE = /^(?:http:\/)?.*\/([^/]+)$/; | |
| 172 | |
| 173 | |
| 174 /** | |
| 175 * Inits 'functionName', 'url', and 'lineNumber' fields using 'internalFuncName' | |
| 176 * field. | |
| 177 */ | |
| 178 devtools.profiler.ProfileView.Node.prototype.initFuncInfo = function() { | |
| 179 var nodeAlias = devtools.profiler.ProfileView.Node; | |
| 180 this.functionName = this.internalFuncName; | |
| 181 | |
| 182 var strippedName = nodeAlias.FUNC_NAME_STRIP_RE.exec(this.functionName); | |
| 183 if (strippedName) { | |
| 184 this.functionName = strippedName[1]; | |
| 185 } | |
| 186 | |
| 187 var parsedName = nodeAlias.FUNC_NAME_PARSE_RE.exec(this.functionName); | |
| 188 if (parsedName) { | |
| 189 this.url = parsedName[2]; | |
| 190 var parsedUrl = nodeAlias.URL_PARSE_RE.exec(this.url); | |
| 191 if (parsedUrl) { | |
| 192 this.url = parsedUrl[1]; | |
| 193 } | |
| 194 this.functionName = parsedName[1]; | |
| 195 this.lineNumber = parsedName[3]; | |
| 196 } else { | |
| 197 this.url = ''; | |
| 198 this.lineNumber = 0; | |
| 199 } | |
| 200 }; | |
| 201 | |
| 202 | |
| 203 /** | 182 /** |
| 204 * Returns a share of the function's total time in application's total time. | 183 * Returns a share of the function's total time in application's total time. |
| 205 */ | 184 */ |
| 206 devtools.profiler.ProfileView.Node.prototype.__defineGetter__( | 185 devtools.profiler.ProfileView.Node.prototype.__defineGetter__( |
| 207 'totalPercent', | 186 'totalPercent', |
| 208 function() { return this.totalTime / | 187 function() { return this.totalTime / |
| 209 (this.head ? this.head.totalTime : this.totalTime) * 100.0; }); | 188 (this.head ? this.head.totalTime : this.totalTime) * 100.0; }); |
| 210 | 189 |
| 211 | 190 |
| 212 /** | 191 /** |
| (...skipping 29 matching lines...) Expand all Loading... |
| 242 * Sorts all the node's children recursively. | 221 * Sorts all the node's children recursively. |
| 243 * | 222 * |
| 244 * @param {function(devtools.profiler.ProfileView.Node, | 223 * @param {function(devtools.profiler.ProfileView.Node, |
| 245 * devtools.profiler.ProfileView.Node):number} sortFunc A sorting | 224 * devtools.profiler.ProfileView.Node):number} sortFunc A sorting |
| 246 * functions. Must comply with Array.sort sorting function requirements. | 225 * functions. Must comply with Array.sort sorting function requirements. |
| 247 */ | 226 */ |
| 248 devtools.profiler.ProfileView.Node.prototype.sortChildren = function( | 227 devtools.profiler.ProfileView.Node.prototype.sortChildren = function( |
| 249 sortFunc) { | 228 sortFunc) { |
| 250 this.children.sort(sortFunc); | 229 this.children.sort(sortFunc); |
| 251 }; | 230 }; |
| OLD | NEW |