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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 this.enter('T: F3'); | 117 this.enter('T: F3'); |
118 this.enter('T: F3'); | 118 this.enter('T: F3'); |
119 this.enter('T: F3'); | 119 this.enter('T: F3'); |
120 this.leave(); | 120 this.leave(); |
121 this.enter('T: F2'); | 121 this.enter('T: F2'); |
122 this.stay(); | 122 this.stay(); |
123 this.leave(); | 123 this.leave(); |
124 this.leave(); | 124 this.leave(); |
125 this.leave(); | 125 this.leave(); |
126 this.leave(); | 126 this.leave(); |
| 127 this.enter('lib2-f1'); |
| 128 this.enter('lib1-f1'); |
| 129 this.leave(); |
| 130 this.leave(); |
127 this.stay(); | 131 this.stay(); |
128 this.leave(); | 132 this.leave(); |
129 }; | 133 }; |
130 | 134 |
131 | 135 |
132 function Inherits(childCtor, parentCtor) { | 136 function Inherits(childCtor, parentCtor) { |
133 function tempCtor() {}; | 137 function tempCtor() {}; |
134 tempCtor.prototype = parentCtor.prototype; | 138 tempCtor.prototype = parentCtor.prototype; |
135 childCtor.superClass_ = parentCtor.prototype; | 139 childCtor.superClass_ = parentCtor.prototype; |
136 childCtor.prototype = new tempCtor(); | 140 childCtor.prototype = new tempCtor(); |
137 childCtor.prototype.constructor = childCtor; | 141 childCtor.prototype.constructor = childCtor; |
138 }; | 142 }; |
139 | 143 |
140 | 144 |
141 (function testCallTreeBuilding() { | 145 (function testCallTreeBuilding() { |
142 function Driver() { | 146 function Driver() { |
143 ProfileTestDriver.call(this); | 147 ProfileTestDriver.call(this); |
144 this.namesTopDown = []; | 148 this.namesTopDown = []; |
145 this.namesBottomUp = []; | 149 this.namesBottomUp = []; |
146 }; | 150 }; |
147 Inherits(Driver, ProfileTestDriver); | 151 Inherits(Driver, ProfileTestDriver); |
148 | 152 |
149 Driver.prototype.enter = function(func) { | 153 Driver.prototype.enter = function(func) { |
150 this.namesTopDown.push(func); | 154 this.namesTopDown.push(func); |
151 this.namesBottomUp.unshift(func); | 155 this.namesBottomUp.unshift(func); |
152 assertNoPathExists(this.profile.getTopDownTreeRoot(), this.namesTopDown, | 156 assertNoPathExists(this.profile.getTopDownProfile().getRoot(), this.namesTop
Down, |
153 'pre enter/topDown'); | 157 'pre enter/topDown'); |
154 assertNoPathExists(this.profile.getBottomUpTreeRoot(), this.namesBottomUp, | 158 assertNoPathExists(this.profile.getBottomUpProfile().getRoot(), this.namesBo
ttomUp, |
155 'pre enter/bottomUp'); | 159 'pre enter/bottomUp'); |
156 Driver.superClass_.enter.call(this, func); | 160 Driver.superClass_.enter.call(this, func); |
157 assertPathExists(this.profile.getTopDownTreeRoot(), this.namesTopDown, | 161 assertPathExists(this.profile.getTopDownProfile().getRoot(), this.namesTopDo
wn, |
158 'post enter/topDown'); | 162 'post enter/topDown'); |
159 assertPathExists(this.profile.getBottomUpTreeRoot(), this.namesBottomUp, | 163 assertPathExists(this.profile.getBottomUpProfile().getRoot(), this.namesBott
omUp, |
160 'post enter/bottomUp'); | 164 'post enter/bottomUp'); |
161 }; | 165 }; |
162 | 166 |
163 Driver.prototype.stay = function() { | 167 Driver.prototype.stay = function() { |
164 var preTopDownNodes = countNodes(this.profile, this.profile.traverseTopDownT
ree); | 168 var preTopDownNodes = countNodes(this.profile, this.profile.traverseTopDownT
ree); |
165 var preBottomUpNodes = countNodes(this.profile, this.profile.traverseBottomU
pTree); | 169 var preBottomUpNodes = countNodes(this.profile, this.profile.traverseBottomU
pTree); |
166 Driver.superClass_.stay.call(this); | 170 Driver.superClass_.stay.call(this); |
167 var postTopDownNodes = countNodes(this.profile, this.profile.traverseTopDown
Tree); | 171 var postTopDownNodes = countNodes(this.profile, this.profile.traverseTopDown
Tree); |
168 var postBottomUpNodes = countNodes(this.profile, this.profile.traverseBottom
UpTree); | 172 var postBottomUpNodes = countNodes(this.profile, this.profile.traverseBottom
UpTree); |
169 // Must be no changes in tree layout. | 173 // Must be no changes in tree layout. |
(...skipping 19 matching lines...) Expand all Loading... |
189 assertEquals(selfTicks, node.selfWeight, 'self of ' + stack); | 193 assertEquals(selfTicks, node.selfWeight, 'self of ' + stack); |
190 assertEquals(totalTicks, node.totalWeight, 'total of ' + stack); | 194 assertEquals(totalTicks, node.totalWeight, 'total of ' + stack); |
191 }; | 195 }; |
192 | 196 |
193 | 197 |
194 (function testTopDownRootProfileTicks() { | 198 (function testTopDownRootProfileTicks() { |
195 var testDriver = new ProfileTestDriver(); | 199 var testDriver = new ProfileTestDriver(); |
196 testDriver.execute(); | 200 testDriver.execute(); |
197 | 201 |
198 var pathWeights = [ | 202 var pathWeights = [ |
199 [['lib1-f1'], 1, 14], | 203 [['lib1-f1'], 1, 16], |
200 [['lib1-f1', 'lib1-f2'], 2, 13], | 204 [['lib1-f1', 'lib1-f2'], 2, 15], |
201 [['lib1-f1', 'lib1-f2', 'T: F1'], 2, 11], | 205 [['lib1-f1', 'lib1-f2', 'T: F1'], 2, 11], |
202 [['lib1-f1', 'lib1-f2', 'T: F1', 'T: F2'], 1, 1], | 206 [['lib1-f1', 'lib1-f2', 'T: F1', 'T: F2'], 1, 1], |
203 [['lib1-f1', 'lib1-f2', 'T: F1', 'lib2-f1'], 2, 3], | 207 [['lib1-f1', 'lib1-f2', 'T: F1', 'lib2-f1'], 2, 3], |
204 [['lib1-f1', 'lib1-f2', 'T: F1', 'lib2-f1', 'lib2-f1'], 1, 1], | 208 [['lib1-f1', 'lib1-f2', 'T: F1', 'lib2-f1', 'lib2-f1'], 1, 1], |
205 [['lib1-f1', 'lib1-f2', 'T: F1', 'T: F3'], 1, 5], | 209 [['lib1-f1', 'lib1-f2', 'T: F1', 'T: F3'], 1, 5], |
206 [['lib1-f1', 'lib1-f2', 'T: F1', 'T: F3', 'T: F3'], 1, 4], | 210 [['lib1-f1', 'lib1-f2', 'T: F1', 'T: F3', 'T: F3'], 1, 4], |
207 [['lib1-f1', 'lib1-f2', 'T: F1', 'T: F3', 'T: F3', 'T: F3'], 1, 1], | 211 [['lib1-f1', 'lib1-f2', 'T: F1', 'T: F3', 'T: F3', 'T: F3'], 1, 1], |
208 [['lib1-f1', 'lib1-f2', 'T: F1', 'T: F3', 'T: F3', 'T: F2'], 2, 2] | 212 [['lib1-f1', 'lib1-f2', 'T: F1', 'T: F3', 'T: F3', 'T: F2'], 2, 2], |
| 213 [['lib1-f1', 'lib1-f2', 'lib2-f1'], 1, 2], |
| 214 [['lib1-f1', 'lib1-f2', 'lib2-f1', 'lib1-f1'], 1, 1] |
209 ]; | 215 ]; |
210 | 216 |
211 var root = testDriver.profile.getTopDownTreeRoot(); | 217 var root = testDriver.profile.getTopDownProfile().getRoot(); |
212 for (var i = 0; i < pathWeights.length; ++i) { | 218 for (var i = 0; i < pathWeights.length; ++i) { |
213 var data = pathWeights[i]; | 219 var data = pathWeights[i]; |
214 assertNodeWeights(root, data[0], data[1], data[2]); | 220 assertNodeWeights(root, data[0], data[1], data[2]); |
215 } | 221 } |
216 })(); | 222 })(); |
217 | 223 |
218 | 224 |
219 (function testRootFlatProfileTicks() { | 225 (function testRootFlatProfileTicks() { |
220 function Driver() { | 226 function Driver() { |
221 ProfileTestDriver.call(this); | 227 ProfileTestDriver.call(this); |
222 this.namesTopDown = ['']; | 228 this.namesTopDown = ['']; |
223 this.counters = {}; | 229 this.counters = {}; |
| 230 this.root = null; |
224 }; | 231 }; |
225 Inherits(Driver, ProfileTestDriver); | 232 Inherits(Driver, ProfileTestDriver); |
226 | 233 |
227 Driver.prototype.increment = function(func, self, total) { | 234 Driver.prototype.increment = function(func, self, total) { |
228 if (!(func in this.counters)) { | 235 if (!(func in this.counters)) { |
229 this.counters[func] = { self: 0, total: 0 }; | 236 this.counters[func] = { self: 0, total: 0 }; |
230 } | 237 } |
231 this.counters[func].self += self; | 238 this.counters[func].self += self; |
232 this.counters[func].total += total; | 239 this.counters[func].total += total; |
233 }; | 240 }; |
(...skipping 21 matching lines...) Expand all Loading... |
255 Driver.superClass_.stay.call(this); | 262 Driver.superClass_.stay.call(this); |
256 this.increment(this.namesTopDown[this.namesTopDown.length - 1], 1, 0); | 263 this.increment(this.namesTopDown[this.namesTopDown.length - 1], 1, 0); |
257 this.incrementTotals(); | 264 this.incrementTotals(); |
258 }; | 265 }; |
259 | 266 |
260 Driver.prototype.leave = function() { | 267 Driver.prototype.leave = function() { |
261 Driver.superClass_.leave.call(this); | 268 Driver.superClass_.leave.call(this); |
262 this.namesTopDown.pop(); | 269 this.namesTopDown.pop(); |
263 }; | 270 }; |
264 | 271 |
| 272 Driver.prototype.extractRoot = function() { |
| 273 assertTrue('' in this.counters); |
| 274 this.root = this.counters['']; |
| 275 delete this.counters['']; |
| 276 }; |
| 277 |
265 var testDriver = new Driver(); | 278 var testDriver = new Driver(); |
266 testDriver.execute(); | 279 testDriver.execute(); |
| 280 testDriver.extractRoot(); |
267 | 281 |
268 var counted = 0; | 282 var counted = 0; |
269 for (var c in testDriver.counters) { | 283 for (var c in testDriver.counters) { |
270 counted++; | 284 counted++; |
271 } | 285 } |
272 | 286 |
273 var flatProfile = | 287 var flatProfileRoot = testDriver.profile.getFlatProfile().getRoot(); |
274 testDriver.profile.getFlatProfile().getRoot().exportChildren(); | 288 assertEquals(testDriver.root.self, flatProfileRoot.selfWeight); |
| 289 assertEquals(testDriver.root.total, flatProfileRoot.totalWeight); |
| 290 |
| 291 var flatProfile = flatProfileRoot.exportChildren(); |
275 assertEquals(counted, flatProfile.length, 'counted vs. flatProfile'); | 292 assertEquals(counted, flatProfile.length, 'counted vs. flatProfile'); |
276 for (var i = 0; i < flatProfile.length; ++i) { | 293 for (var i = 0; i < flatProfile.length; ++i) { |
277 var rec = flatProfile[i]; | 294 var rec = flatProfile[i]; |
278 assertTrue(rec.label in testDriver.counters, 'uncounted: ' + rec.label); | 295 assertTrue(rec.label in testDriver.counters, 'uncounted: ' + rec.label); |
279 var reference = testDriver.counters[rec.label]; | 296 var reference = testDriver.counters[rec.label]; |
280 assertEquals(reference.self, rec.selfWeight, 'self of ' + rec.label); | 297 assertEquals(reference.self, rec.selfWeight, 'self of ' + rec.label); |
281 assertEquals(reference.total, rec.totalWeight, 'total of ' + rec.label); | 298 assertEquals(reference.total, rec.totalWeight, 'total of ' + rec.label); |
282 } | 299 } |
283 | 300 |
284 })(); | 301 })(); |
| 302 |
| 303 |
| 304 (function testFunctionCalleesProfileTicks() { |
| 305 var testDriver = new ProfileTestDriver(); |
| 306 testDriver.execute(); |
| 307 |
| 308 var pathWeights = [ |
| 309 [['lib2-f1'], 3, 5], |
| 310 [['lib2-f1', 'lib2-f1'], 1, 1], |
| 311 [['lib2-f1', 'lib1-f1'], 1, 1] |
| 312 ]; |
| 313 |
| 314 var profile = testDriver.profile.getTopDownProfile('lib2-f1'); |
| 315 var root = profile.getRoot(); |
| 316 for (var i = 0; i < pathWeights.length; ++i) { |
| 317 var data = pathWeights[i]; |
| 318 assertNodeWeights(root, data[0], data[1], data[2]); |
| 319 } |
| 320 })(); |
| 321 |
| 322 |
| 323 (function testFunctionFlatProfileTicks() { |
| 324 var testDriver = new ProfileTestDriver(); |
| 325 testDriver.execute(); |
| 326 |
| 327 var flatWeights = { |
| 328 'lib2-f1': [1, 1], |
| 329 'lib1-f1': [1, 1] |
| 330 }; |
| 331 |
| 332 var flatProfileRoot = |
| 333 testDriver.profile.getFlatProfile('lib2-f1').findOrAddChild('lib2-f1'); |
| 334 assertEquals(3, flatProfileRoot.selfWeight); |
| 335 assertEquals(5, flatProfileRoot.totalWeight); |
| 336 |
| 337 var flatProfile = flatProfileRoot.exportChildren(); |
| 338 assertEquals(2, flatProfile.length, 'counted vs. flatProfile'); |
| 339 for (var i = 0; i < flatProfile.length; ++i) { |
| 340 var rec = flatProfile[i]; |
| 341 assertTrue(rec.label in flatWeights, 'uncounted: ' + rec.label); |
| 342 var reference = flatWeights[rec.label]; |
| 343 assertEquals(reference[0], rec.selfWeight, 'self of ' + rec.label); |
| 344 assertEquals(reference[1], rec.totalWeight, 'total of ' + rec.label); |
| 345 } |
| 346 |
| 347 })(); |
| 348 |
OLD | NEW |