OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 var dyingPoints = void 0; | 54 var dyingPoints = void 0; |
55 var scene = void 0; | 55 var scene = void 0; |
56 var renderingStartTime = void 0; | 56 var renderingStartTime = void 0; |
57 var scene = void 0; | 57 var scene = void 0; |
58 var pausePlot = void 0; | 58 var pausePlot = void 0; |
59 var splayTree = void 0; | 59 var splayTree = void 0; |
60 var numberOfFrames = 0; | 60 var numberOfFrames = 0; |
61 var sumOfSquaredPauses = 0; | 61 var sumOfSquaredPauses = 0; |
62 var benchmarkStartTime = void 0; | 62 var benchmarkStartTime = void 0; |
63 var benchmarkTimeLimit = void 0; | 63 var benchmarkTimeLimit = void 0; |
| 64 var autoScale = void 0; |
64 var pauseDistribution = []; | 65 var pauseDistribution = []; |
65 | 66 |
66 | 67 |
67 function Point(x, y, z, payload) { | 68 function Point(x, y, z, payload) { |
68 this.x = x; | 69 this.x = x; |
69 this.y = y; | 70 this.y = y; |
70 this.z = z; | 71 this.z = z; |
71 | 72 |
72 this.next = null; | 73 this.next = null; |
73 this.prev = null; | 74 this.prev = null; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } else { | 187 } else { |
187 var point = splayTree.remove(greatest.key).value; | 188 var point = splayTree.remove(greatest.key).value; |
188 } | 189 } |
189 livePoints.remove(point); | 190 livePoints.remove(point); |
190 point.payload = null; | 191 point.payload = null; |
191 dyingPoints.add(point); | 192 dyingPoints.add(point); |
192 } | 193 } |
193 } | 194 } |
194 | 195 |
195 | 196 |
196 function PausePlot(width, height, size) { | 197 function PausePlot(width, height, size, scale) { |
197 var canvas = document.createElement("canvas"); | 198 var canvas = document.createElement("canvas"); |
198 canvas.width = this.width = width; | 199 canvas.width = this.width = width; |
199 canvas.height = this.height = height; | 200 canvas.height = this.height = height; |
200 document.body.appendChild(canvas); | 201 document.body.appendChild(canvas); |
201 | 202 |
202 this.ctx = canvas.getContext('2d'); | 203 this.ctx = canvas.getContext('2d'); |
203 | 204 |
204 this.maxPause = 0; | 205 if (typeof scale !== "number") { |
| 206 this.autoScale = true; |
| 207 this.maxPause = 0; |
| 208 } else { |
| 209 this.autoScale = false; |
| 210 this.maxPause = scale; |
| 211 } |
| 212 |
205 this.size = size; | 213 this.size = size; |
206 | 214 |
207 // Initialize cyclic buffer for pauses. | 215 // Initialize cyclic buffer for pauses. |
208 this.pauses = new Array(this.size); | 216 this.pauses = new Array(this.size); |
209 this.start = this.size; | 217 this.start = this.size; |
210 this.idx = 0; | 218 this.idx = 0; |
211 } | 219 } |
212 | 220 |
213 | 221 |
214 PausePlot.prototype.addPause = function (p) { | 222 PausePlot.prototype.addPause = function (p) { |
(...skipping 26 matching lines...) Expand all Loading... |
241 var offs = this.size - this.start; | 249 var offs = this.size - this.start; |
242 for (var i = 0; i < this.idx; i++) { | 250 for (var i = 0; i < this.idx; i++) { |
243 f.call(this, i + offs, this.pauses[i]); | 251 f.call(this, i + offs, this.pauses[i]); |
244 } | 252 } |
245 } | 253 } |
246 }; | 254 }; |
247 | 255 |
248 | 256 |
249 PausePlot.prototype.draw = function () { | 257 PausePlot.prototype.draw = function () { |
250 var first = null; | 258 var first = null; |
251 this.iteratePauses(function (i, v) { | 259 |
252 if (first === null) { | 260 if (this.autoScale) { |
253 first = v; | 261 this.iteratePauses(function (i, v) { |
254 } | 262 if (first === null) { |
255 this.maxPause = Math.max(v, this.maxPause); | 263 first = v; |
256 }); | 264 } |
| 265 this.maxPause = Math.max(v, this.maxPause); |
| 266 }); |
| 267 } |
257 | 268 |
258 var dx = this.width / this.size; | 269 var dx = this.width / this.size; |
259 var dy = this.height / this.maxPause; | 270 var dy = this.height / this.maxPause; |
260 | 271 |
261 this.ctx.save(); | 272 this.ctx.save(); |
262 this.ctx.clearRect(0, 0, 480, 240); | 273 this.ctx.clearRect(0, 0, this.width, this.height); |
263 this.ctx.beginPath(); | 274 this.ctx.beginPath(); |
264 this.ctx.moveTo(1, dy * this.pauses[this.start]); | 275 this.ctx.moveTo(1, dy * this.pauses[this.start]); |
265 var p = first; | 276 var p = first; |
266 this.iteratePauses(function (i, v) { | 277 this.iteratePauses(function (i, v) { |
267 var delta = v - p; | 278 var delta = v - p; |
268 var x = 1 + dx * i; | 279 var x = 1 + dx * i; |
269 var y = dy * v; | 280 var y = dy * v; |
270 this.ctx.lineTo(x, y); | 281 this.ctx.lineTo(x, y); |
271 if (delta > 2 * (p / 3)) { | 282 if (delta > 2 * (p / 3)) { |
272 this.ctx.font = "bold 12px sans-serif"; | 283 this.ctx.font = "bold 12px sans-serif"; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 | 418 |
408 if (renderingEndTime < benchmarkStartTime + benchmarkTimeLimit) { | 419 if (renderingEndTime < benchmarkStartTime + benchmarkTimeLimit) { |
409 // Schedule next frame. | 420 // Schedule next frame. |
410 requestAnimationFrame(render); | 421 requestAnimationFrame(render); |
411 } else { | 422 } else { |
412 renderStats(); | 423 renderStats(); |
413 } | 424 } |
414 } | 425 } |
415 | 426 |
416 | 427 |
417 function renderForm() { | 428 function Form() { |
418 form = document.createElement("form"); | 429 function create(tag) { return document.createElement(tag); } |
419 form.setAttribute("action", "javascript:start()"); | 430 function text(value) { return document.createTextNode(value); } |
420 var label = document.createTextNode("Time limit in seconds "); | 431 |
421 var input = document.createElement("input"); | 432 this.form = create("form"); |
422 input.setAttribute("id", "timelimit"); | 433 this.form.setAttribute("action", "javascript:start()"); |
423 input.setAttribute("value", "60"); | 434 |
424 var button = document.createElement("input"); | 435 var table = create("table"); |
| 436 table.setAttribute("style", "margin-left: auto; margin-right: auto;"); |
| 437 |
| 438 function col(a) { |
| 439 var td = create("td"); |
| 440 td.appendChild(a); |
| 441 return td; |
| 442 } |
| 443 |
| 444 function row(a, b) { |
| 445 var tr = create("tr"); |
| 446 tr.appendChild(col(a)); |
| 447 tr.appendChild(col(b)); |
| 448 return tr; |
| 449 } |
| 450 |
| 451 this.timelimit = create("input"); |
| 452 this.timelimit.setAttribute("value", "60"); |
| 453 |
| 454 table.appendChild(row(text("Time limit in seconds"), this.timelimit)); |
| 455 |
| 456 this.autoscale = create("input"); |
| 457 this.autoscale.setAttribute("type", "checkbox"); |
| 458 this.autoscale.setAttribute("checked", "true"); |
| 459 table.appendChild(row(text("Autoscale pauses plot"), this.autoscale)); |
| 460 |
| 461 var button = create("input"); |
425 button.setAttribute("type", "submit"); | 462 button.setAttribute("type", "submit"); |
426 button.setAttribute("value", "Start"); | 463 button.setAttribute("value", "Start"); |
427 form.appendChild(label); | 464 this.form.appendChild(table); |
428 form.appendChild(input); | 465 this.form.appendChild(button); |
429 form.appendChild(button); | 466 |
430 document.body.appendChild(form); | 467 document.body.appendChild(this.form); |
431 } | 468 } |
432 | 469 |
433 | 470 |
| 471 Form.prototype.remove = function () { |
| 472 document.body.removeChild(this.form); |
| 473 }; |
| 474 |
| 475 |
434 function init() { | 476 function init() { |
435 livePoints = new PointsList; | 477 livePoints = new PointsList; |
436 dyingPoints = new PointsList; | 478 dyingPoints = new PointsList; |
437 | 479 |
438 splayTree = new SplayTree(); | 480 splayTree = new SplayTree(); |
439 | 481 |
440 scene = new Scene(640, 480); | 482 scene = new Scene(640, 480); |
441 | 483 |
442 div = document.createElement("div"); | 484 div = document.createElement("div"); |
443 document.body.appendChild(div); | 485 document.body.appendChild(div); |
444 | 486 |
445 pausePlot = new PausePlot(480, 240, 160); | 487 pausePlot = new PausePlot(480, autoScale ? 240 : 500, 160, autoScale ? void 0
: 500); |
446 } | 488 } |
447 | 489 |
448 function start() { | 490 function start() { |
449 benchmarkTimeLimit = document.getElementById("timelimit").value * 1000; | 491 benchmarkTimeLimit = form.timelimit.value * 1000; |
450 document.body.removeChild(form); | 492 autoScale = form.autoscale.checked; |
| 493 form.remove(); |
451 init(); | 494 init(); |
452 render(); | 495 render(); |
453 } | 496 } |
454 | 497 |
455 renderForm(); | 498 var form = new Form(); |
OLD | NEW |