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 28 matching lines...) Expand all Loading... |
39 */ | 39 */ |
40 devtools.profiler.ViewBuilder = function(samplingRate) { | 40 devtools.profiler.ViewBuilder = function(samplingRate) { |
41 this.samplingRate = samplingRate; | 41 this.samplingRate = samplingRate; |
42 }; | 42 }; |
43 | 43 |
44 | 44 |
45 /** | 45 /** |
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 |
| 50 * of self weights for a bottom up view is needed. |
49 */ | 51 */ |
50 devtools.profiler.ViewBuilder.prototype.buildView = function( | 52 devtools.profiler.ViewBuilder.prototype.buildView = function( |
51 callTree) { | 53 callTree, opt_bottomUpViewWeights) { |
52 var head; | 54 var head; |
53 var samplingRate = this.samplingRate; | 55 var samplingRate = this.samplingRate; |
54 callTree.traverse(function(node, viewParent) { | 56 callTree.traverse(function(node, viewParent) { |
| 57 var totalWeight = node.totalWeight * samplingRate; |
| 58 var selfWeight = node.selfWeight * samplingRate; |
| 59 if (opt_bottomUpViewWeights === true) { |
| 60 if (viewParent === head) { |
| 61 selfWeight = totalWeight; |
| 62 } else { |
| 63 selfWeight = 0; |
| 64 } |
| 65 } |
55 var viewNode = new devtools.profiler.ProfileView.Node( | 66 var viewNode = new devtools.profiler.ProfileView.Node( |
56 node.label, node.totalWeight * samplingRate, | 67 node.label, totalWeight, selfWeight, head); |
57 node.selfWeight * samplingRate, head); | |
58 if (viewParent) { | 68 if (viewParent) { |
59 viewParent.addChild(viewNode); | 69 viewParent.addChild(viewNode); |
60 } else { | 70 } else { |
61 head = viewNode; | 71 head = viewNode; |
62 } | 72 } |
63 return viewNode; | 73 return viewNode; |
64 }); | 74 }); |
65 var view = new devtools.profiler.ProfileView(head); | 75 var view = new devtools.profiler.ProfileView(head); |
66 return view; | 76 return view; |
67 }; | 77 }; |
(...skipping 11 matching lines...) Expand all Loading... |
79 this.head = head; | 89 this.head = head; |
80 this.title = ''; | 90 this.title = ''; |
81 this.uid = ''; | 91 this.uid = ''; |
82 this.heavyProfile = null; | 92 this.heavyProfile = null; |
83 this.treeProfile = null; | 93 this.treeProfile = null; |
84 this.flatProfile = null; | 94 this.flatProfile = null; |
85 }; | 95 }; |
86 | 96 |
87 | 97 |
88 /** | 98 /** |
89 * Updates references between profiles. This is needed for WebKit | |
90 * ProfileView. | |
91 */ | |
92 devtools.profiler.ProfileView.prototype.updateProfilesRefs = function() { | |
93 var profileNames = ["treeProfile", "heavyProfile", "flatProfile"]; | |
94 for (var i = 0; i < profileNames.length; ++i) { | |
95 var destProfile = this[profileNames[i]]; | |
96 for (var j = 0; j < profileNames.length; ++j) { | |
97 destProfile[profileNames[j]] = this[profileNames[j]]; | |
98 } | |
99 } | |
100 }; | |
101 | |
102 | |
103 /** | |
104 * Sorts the profile view using the specified sort function. | 99 * Sorts the profile view using the specified sort function. |
105 * | 100 * |
106 * @param {function(devtools.profiler.ProfileView.Node, | 101 * @param {function(devtools.profiler.ProfileView.Node, |
107 * devtools.profiler.ProfileView.Node):number} sortFunc A sorting | 102 * devtools.profiler.ProfileView.Node):number} sortFunc A sorting |
108 * functions. Must comply with Array.sort sorting function requirements. | 103 * functions. Must comply with Array.sort sorting function requirements. |
109 */ | 104 */ |
110 devtools.profiler.ProfileView.prototype.sort = function(sortFunc) { | 105 devtools.profiler.ProfileView.prototype.sort = function(sortFunc) { |
111 this.traverse(function (node) { | 106 this.traverse(function (node) { |
112 node.sortChildren(sortFunc); | 107 node.sortChildren(sortFunc); |
113 }); | 108 }); |
114 }; | 109 }; |
115 | 110 |
116 | 111 |
117 /** | 112 /** |
118 * Sorts the profile view by self time, ascending. | |
119 */ | |
120 devtools.profiler.ProfileView.prototype.sortSelfTimeAscending = function() { | |
121 this.sort(function (node1, node2) { | |
122 return node1.selfTime - node2.selfTime; }); | |
123 }; | |
124 | |
125 | |
126 /** | |
127 * Sorts the profile view by self time, descending. | |
128 */ | |
129 devtools.profiler.ProfileView.prototype.sortSelfTimeDescending = function() { | |
130 this.sort(function (node1, node2) { | |
131 return node2.selfTime - node1.selfTime; }); | |
132 }; | |
133 | |
134 | |
135 /** | |
136 * Sorts the profile view by total time, ascending. | |
137 */ | |
138 devtools.profiler.ProfileView.prototype.sortTotalTimeAscending = function() { | |
139 this.sort(function (node1, node2) { | |
140 return node1.totalTime - node2.totalTime; }); | |
141 }; | |
142 | |
143 | |
144 /** | |
145 * Sorts the profile view by total time, descending. | |
146 */ | |
147 devtools.profiler.ProfileView.prototype.sortTotalTimeDescending = function() { | |
148 this.sort(function (node1, node2) { | |
149 return node2.totalTime - node1.totalTime; }); | |
150 }; | |
151 | |
152 | |
153 /** | |
154 * String comparator compatible with Array.sort requirements. | |
155 * | |
156 * @param {string} s1 First string. | |
157 * @param {string} s2 Second string. | |
158 */ | |
159 devtools.profiler.ProfileView.compareStrings = function(s1, s2) { | |
160 return s1 < s2 ? -1 : (s1 > s2 ? 1 : 0); | |
161 }; | |
162 | |
163 | |
164 /** | |
165 * Sorts the profile view by function name, ascending. | |
166 */ | |
167 devtools.profiler.ProfileView.prototype.sortFunctionNameAscending = function() { | |
168 this.sort(function (node1, node2) { | |
169 return devtools.profiler.ProfileView.compareStrings( | |
170 node1.functionName, node2.functionName); }); | |
171 }; | |
172 | |
173 | |
174 /** | |
175 * Sorts the profile view by function name, descending. | |
176 */ | |
177 devtools.profiler.ProfileView.prototype.sortFunctionNameDescending = function()
{ | |
178 this.sort(function (node1, node2) { | |
179 return devtools.profiler.ProfileView.compareStrings( | |
180 node2.functionName, node1.functionName); }); | |
181 }; | |
182 | |
183 | |
184 /** | |
185 * Traverses profile view nodes in preorder. | 113 * Traverses profile view nodes in preorder. |
186 * | 114 * |
187 * @param {function(devtools.profiler.ProfileView.Node)} f Visitor function. | 115 * @param {function(devtools.profiler.ProfileView.Node)} f Visitor function. |
188 */ | 116 */ |
189 devtools.profiler.ProfileView.prototype.traverse = function(f) { | 117 devtools.profiler.ProfileView.prototype.traverse = function(f) { |
190 var nodesToTraverse = new ConsArray(); | 118 var nodesToTraverse = new ConsArray(); |
191 nodesToTraverse.concat([this.head]); | 119 nodesToTraverse.concat([this.head]); |
192 while (!nodesToTraverse.atEnd()) { | 120 while (!nodesToTraverse.atEnd()) { |
193 var node = nodesToTraverse.next(); | 121 var node = nodesToTraverse.next(); |
194 f(node); | 122 f(node); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 * Sorts all the node's children recursively. | 242 * Sorts all the node's children recursively. |
315 * | 243 * |
316 * @param {function(devtools.profiler.ProfileView.Node, | 244 * @param {function(devtools.profiler.ProfileView.Node, |
317 * devtools.profiler.ProfileView.Node):number} sortFunc A sorting | 245 * devtools.profiler.ProfileView.Node):number} sortFunc A sorting |
318 * functions. Must comply with Array.sort sorting function requirements. | 246 * functions. Must comply with Array.sort sorting function requirements. |
319 */ | 247 */ |
320 devtools.profiler.ProfileView.Node.prototype.sortChildren = function( | 248 devtools.profiler.ProfileView.Node.prototype.sortChildren = function( |
321 sortFunc) { | 249 sortFunc) { |
322 this.children.sort(sortFunc); | 250 this.children.sort(sortFunc); |
323 }; | 251 }; |
OLD | NEW |