Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 | 210 |
| 211 /** | 211 /** |
| 212 * @param {!number} index | 212 * @param {!number} index |
| 213 * @param {number=} sat | 213 * @param {number=} sat |
| 214 */ | 214 */ |
| 215 _createPair: function(index, sat) | 215 _createPair: function(index, sat) |
| 216 { | 216 { |
| 217 var hue = (index * 7 + 12 * (index % 2)) % 360; | 217 var hue = (index * 7 + 12 * (index % 2)) % 360; |
| 218 if (typeof sat !== "number") | 218 if (typeof sat !== "number") |
| 219 sat = 100; | 219 sat = 100; |
| 220 return {highlighted: "hsla(" + hue + ", " + sat + "%, 33%, 0.7)", normal : "hsla(" + hue + ", " + sat + "%, 66%, 0.7)"} | 220 return {index: index, highlighted: "hsla(" + hue + ", " + sat + "%, 33%, 0.7)", normal: "hsla(" + hue + ", " + sat + "%, 66%, 0.7)"} |
| 221 } | 221 } |
| 222 } | 222 } |
| 223 | 223 |
| 224 /** | 224 /** |
| 225 * @constructor | 225 * @constructor |
| 226 * @param {!Object} colorPair | 226 * @param {!Object} colorPair |
| 227 * @param {!number} depth | 227 * @param {!number} depth |
| 228 * @param {!number} duration | 228 * @param {!number} duration |
| 229 * @param {!number} startTime | 229 * @param {!number} startTime |
| 230 * @param {Object} node | 230 * @param {Object} node |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 for (var i = fromArray.length - 1; i >= 0; --i) | 309 for (var i = fromArray.length - 1; i >= 0; --i) |
| 310 toArray.push(fromArray[i]); | 310 toArray.push(fromArray[i]); |
| 311 } | 311 } |
| 312 | 312 |
| 313 var stack = []; | 313 var stack = []; |
| 314 appendReversedArray(stack, this._cpuProfileView.profileHead.children); | 314 appendReversedArray(stack, this._cpuProfileView.profileHead.children); |
| 315 | 315 |
| 316 var levelOffsets = /** @type {Array.<!number>} */ ([0]); | 316 var levelOffsets = /** @type {Array.<!number>} */ ([0]); |
| 317 var levelExitIndexes = /** @type {Array.<!number>} */ ([0]); | 317 var levelExitIndexes = /** @type {Array.<!number>} */ ([0]); |
| 318 var colorGenerator = WebInspector.FlameChart._colorGenerator; | 318 var colorGenerator = WebInspector.FlameChart._colorGenerator; |
| 319 var colorIndexEntryChains = []; | |
|
yurys
2013/09/05 11:43:25
Should we specify the size as the total number of
loislo
2013/09/06 08:15:57
Unfortunately we don't know the number of colors b
| |
| 319 | 320 |
| 320 while (stack.length) { | 321 while (stack.length) { |
| 321 var level = levelOffsets.length - 1; | 322 var level = levelOffsets.length - 1; |
| 322 var node = stack.pop(); | 323 var node = stack.pop(); |
| 323 var offset = levelOffsets[level]; | 324 var offset = levelOffsets[level]; |
| 324 | 325 |
| 325 var colorPair = colorGenerator._colorPairForID(node.functionName + " :" + node.url + ":" + node.lineNumber); | 326 var id = node.functionName + ":" + node.url + ":" + node.lineNumber; |
| 327 var colorPair = colorGenerator._colorPairForID(id); | |
| 328 var colorIndexEntries = colorIndexEntryChains[colorPair.index]; | |
| 329 if (!colorIndexEntries) | |
| 330 colorIndexEntries = colorIndexEntryChains[colorPair.index] = []; | |
| 326 | 331 |
| 327 entries.push(new WebInspector.FlameChart.Entry(colorPair, level, nod e.totalTime, offset, node)); | 332 var entry = new WebInspector.FlameChart.Entry(colorPair, level, node .totalTime, offset, node); |
| 333 entries.push(entry); | |
| 334 colorIndexEntries.push(entry); | |
| 328 | 335 |
| 329 ++index; | 336 ++index; |
| 330 | 337 |
| 331 levelOffsets[level] += node.totalTime; | 338 levelOffsets[level] += node.totalTime; |
| 332 if (node.children.length) { | 339 if (node.children.length) { |
| 333 levelExitIndexes.push(stack.length); | 340 levelExitIndexes.push(stack.length); |
| 334 levelOffsets.push(offset + node.selfTime / 2); | 341 levelOffsets.push(offset + node.selfTime / 2); |
| 335 appendReversedArray(stack, node.children); | 342 appendReversedArray(stack, node.children); |
| 336 } | 343 } |
| 337 | 344 |
| 338 while (stack.length === levelExitIndexes[levelExitIndexes.length - 1 ]) { | 345 while (stack.length === levelExitIndexes[levelExitIndexes.length - 1 ]) { |
| 339 levelOffsets.pop(); | 346 levelOffsets.pop(); |
| 340 levelExitIndexes.pop(); | 347 levelExitIndexes.pop(); |
| 341 } | 348 } |
| 342 } | 349 } |
| 343 | 350 |
| 344 this._timelineData = { | 351 this._timelineData = { |
| 345 entries: entries, | 352 entries: entries, |
| 353 colorIndexEntryChains: colorIndexEntryChains, | |
| 346 totalTime: this._cpuProfileView.profileHead.totalTime, | 354 totalTime: this._cpuProfileView.profileHead.totalTime, |
| 347 } | 355 } |
| 348 | 356 |
| 349 return this._timelineData; | 357 return this._timelineData; |
| 350 }, | 358 }, |
| 351 | 359 |
| 352 _calculateTimelineDataForSamples: function() | 360 _calculateTimelineDataForSamples: function() |
| 353 { | 361 { |
| 354 if (this._timelineData) | 362 if (this._timelineData) |
| 355 return this._timelineData; | 363 return this._timelineData; |
| 356 | 364 |
| 357 if (!this._cpuProfileView.profileHead) | 365 if (!this._cpuProfileView.profileHead) |
| 358 return null; | 366 return null; |
| 359 | 367 |
| 360 var samples = this._cpuProfileView.samples; | 368 var samples = this._cpuProfileView.samples; |
| 361 var idToNode = this._cpuProfileView._idToNode; | 369 var idToNode = this._cpuProfileView._idToNode; |
| 362 var gcNode = this._cpuProfileView._gcNode; | 370 var gcNode = this._cpuProfileView._gcNode; |
| 363 var samplesCount = samples.length; | 371 var samplesCount = samples.length; |
| 364 | 372 |
| 365 var index = 0; | 373 var index = 0; |
| 366 var entries = /** @type {Array.<!WebInspector.FlameChart.Entry>} */ ([]) ; | 374 var entries = /** @type {Array.<!WebInspector.FlameChart.Entry>} */ ([]) ; |
| 367 | 375 |
| 368 var openIntervals = []; | 376 var openIntervals = []; |
| 369 var stackTrace = []; | 377 var stackTrace = []; |
| 370 var colorGenerator = WebInspector.FlameChart._colorGenerator; | 378 var colorGenerator = WebInspector.FlameChart._colorGenerator; |
| 379 var colorIndexEntryChains = []; | |
| 371 for (var sampleIndex = 0; sampleIndex < samplesCount; sampleIndex++) { | 380 for (var sampleIndex = 0; sampleIndex < samplesCount; sampleIndex++) { |
| 372 var node = idToNode[samples[sampleIndex]]; | 381 var node = idToNode[samples[sampleIndex]]; |
| 373 stackTrace.length = 0; | 382 stackTrace.length = 0; |
| 374 while (node) { | 383 while (node) { |
| 375 stackTrace.push(node); | 384 stackTrace.push(node); |
| 376 node = node.parent; | 385 node = node.parent; |
| 377 } | 386 } |
| 378 stackTrace.pop(); // Remove (root) node | 387 stackTrace.pop(); // Remove (root) node |
| 379 | 388 |
| 380 var depth = 0; | 389 var depth = 0; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 403 } | 412 } |
| 404 if (depth < openIntervals.length) | 413 if (depth < openIntervals.length) |
| 405 openIntervals.length = depth; | 414 openIntervals.length = depth; |
| 406 if (!node) { | 415 if (!node) { |
| 407 entries[intervalIndex].selfTime += 1; | 416 entries[intervalIndex].selfTime += 1; |
| 408 continue; | 417 continue; |
| 409 } | 418 } |
| 410 | 419 |
| 411 while (node) { | 420 while (node) { |
| 412 var colorPair = colorGenerator._colorPairForID(node.functionName + ":" + node.url + ":" + node.lineNumber); | 421 var colorPair = colorGenerator._colorPairForID(node.functionName + ":" + node.url + ":" + node.lineNumber); |
| 422 var colorIndexEntries = colorIndexEntryChains[colorPair.index]; | |
| 423 if (!colorIndexEntries) | |
| 424 colorIndexEntries = colorIndexEntryChains[colorPair.index] = []; | |
| 413 | 425 |
| 414 entries.push(new WebInspector.FlameChart.Entry(colorPair, depth, 1, sampleIndex, node)); | 426 var entry = new WebInspector.FlameChart.Entry(colorPair, depth, 1, sampleIndex, node); |
| 427 entries.push(entry); | |
| 428 colorIndexEntries.push(entry); | |
| 415 openIntervals.push({node: node, index: index}); | 429 openIntervals.push({node: node, index: index}); |
| 416 ++index; | 430 ++index; |
| 417 | 431 |
| 418 node = stackTrace.pop(); | 432 node = stackTrace.pop(); |
| 419 ++depth; | 433 ++depth; |
| 420 } | 434 } |
| 421 entries[entries.length - 1].selfTime += 1; | 435 entries[entries.length - 1].selfTime += 1; |
| 422 } | 436 } |
| 423 | 437 |
| 424 this._timelineData = { | 438 this._timelineData = { |
| 425 entries: entries, | 439 entries: entries, |
| 440 colorIndexEntryChains: colorIndexEntryChains, | |
| 426 totalTime: samplesCount, | 441 totalTime: samplesCount, |
| 427 }; | 442 }; |
| 428 | 443 |
| 429 return this._timelineData; | 444 return this._timelineData; |
| 430 }, | 445 }, |
| 431 | 446 |
| 432 _onMouseMove: function(event) | 447 _onMouseMove: function(event) |
| 433 { | 448 { |
| 434 if (this._isDragging) | 449 if (this._isDragging) |
| 435 return; | 450 return; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 | 622 |
| 608 /** | 623 /** |
| 609 * @param {!number} height | 624 * @param {!number} height |
| 610 * @param {!number} width | 625 * @param {!number} width |
| 611 */ | 626 */ |
| 612 draw: function(width, height) | 627 draw: function(width, height) |
| 613 { | 628 { |
| 614 var timelineData = this._calculateTimelineData(); | 629 var timelineData = this._calculateTimelineData(); |
| 615 if (!timelineData) | 630 if (!timelineData) |
| 616 return; | 631 return; |
| 617 var timelineEntries = timelineData.entries; | 632 var colorIndexEntryChains = timelineData.colorIndexEntryChains; |
| 618 | 633 |
| 619 var ratio = window.devicePixelRatio; | 634 var ratio = window.devicePixelRatio; |
| 620 var canvasWidth = width * ratio; | 635 var canvasWidth = width * ratio; |
| 621 var canvasHeight = height * ratio; | 636 var canvasHeight = height * ratio; |
| 622 this._canvas.width = canvasWidth; | 637 this._canvas.width = canvasWidth; |
| 623 this._canvas.height = canvasHeight; | 638 this._canvas.height = canvasHeight; |
| 624 this._canvas.style.width = width + "px"; | 639 this._canvas.style.width = width + "px"; |
| 625 this._canvas.style.height = height + "px"; | 640 this._canvas.style.height = height + "px"; |
| 626 | 641 |
| 627 var barHeight = this._barHeight; | 642 var barHeight = this._barHeight; |
| 628 | 643 |
| 629 var context = this._canvas.getContext("2d"); | 644 var context = this._canvas.getContext("2d"); |
| 630 context.scale(ratio, ratio); | 645 context.scale(ratio, ratio); |
| 631 var visibleTimeLeft = this._timeWindowLeft - this._paddingLeftTime; | 646 var visibleTimeLeft = this._timeWindowLeft - this._paddingLeftTime; |
| 632 var timeWindowRight = this._timeWindowRight; | 647 var timeWindowRight = this._timeWindowRight; |
| 648 var lastUsedColor = ""; | |
| 633 | 649 |
| 634 function forEachEntry(flameChart, callback) | 650 function forEachEntry(flameChart, callback) |
| 635 { | 651 { |
| 636 var anchorBox = new AnchorBox(); | 652 var anchorBox = new AnchorBox(); |
| 637 for (var i = 0; i < timelineEntries.length; ++i) { | 653 for (var j = 1; j < colorIndexEntryChains.length; ++j) { |
|
yurys
2013/09/05 11:43:25
Starting from 1 is unusual, can you change WebInsp
loislo
2013/09/06 08:15:57
Done.
| |
| 638 var entry = timelineEntries[i]; | 654 var entries = colorIndexEntryChains[j]; |
| 639 var startTime = entry.startTime; | 655 if (!entries) |
| 640 if (startTime > timeWindowRight) | |
| 641 break; | |
| 642 if ((startTime + entry.duration) < visibleTimeLeft) | |
| 643 continue; | 656 continue; |
| 644 flameChart._entryToAnchorBox(entry, anchorBox); | 657 for (var i = 0; i < entries.length; ++i) { |
| 658 var entry = entries[i]; | |
| 659 var startTime = entry.startTime; | |
| 660 if (startTime > timeWindowRight) | |
| 661 break; | |
| 662 if ((startTime + entry.duration) < visibleTimeLeft) | |
| 663 continue; | |
| 664 flameChart._entryToAnchorBox(entry, anchorBox); | |
| 645 | 665 |
| 646 callback(flameChart, context, entry, anchorBox, flameChart._high lightedEntryIndex === i); | 666 callback(flameChart, context, entry, anchorBox, flameChart._ highlightedEntryIndex === i); |
| 667 } | |
| 647 } | 668 } |
| 648 } | 669 } |
| 649 | 670 |
| 650 function drawBar(flameChart, context, entry, anchorBox, highlighted) | 671 function drawBar(flameChart, context, entry, anchorBox, highlighted) |
| 651 { | 672 { |
| 652 context.beginPath(); | 673 context.beginPath(); |
| 653 context.rect(anchorBox.x, anchorBox.y, anchorBox.width - 1, anchorBo x.height - 1); | 674 context.rect(anchorBox.x, anchorBox.y, anchorBox.width - 1, anchorBo x.height - 1); |
| 654 var colorPair = entry.colorPair; | 675 var color = highlighted ? entry.colorPair.highlighted : entry.colorP air.normal; |
| 655 context.fillStyle = highlighted ? colorPair.highlighted : colorPair. normal; | 676 if (lastUsedColor !== color) { |
| 677 lastUsedColor = color; | |
| 678 context.fillStyle = color; | |
| 679 } | |
| 656 context.fill(); | 680 context.fill(); |
| 657 } | 681 } |
| 658 | 682 |
| 659 forEachEntry(this, drawBar); | 683 forEachEntry(this, drawBar); |
| 660 | 684 |
| 661 context.font = (barHeight - 4) + "px " + window.getComputedStyle(this.el ement, null).getPropertyValue("font-family"); | 685 context.font = (barHeight - 4) + "px " + window.getComputedStyle(this.el ement, null).getPropertyValue("font-family"); |
| 662 context.textBaseline = "alphabetic"; | 686 context.textBaseline = "alphabetic"; |
| 663 context.fillStyle = "#333"; | 687 context.fillStyle = "#333"; |
| 664 this._dotsWidth = context.measureText("\u2026").width; | 688 this._dotsWidth = context.measureText("\u2026").width; |
| 665 var textPaddingLeft = 2; | 689 var textPaddingLeft = 2; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 794 this._timelineGrid.updateDividers(this._calculator); | 818 this._timelineGrid.updateDividers(this._calculator); |
| 795 this._overviewGrid.updateDividers(this._overviewCalculator); | 819 this._overviewGrid.updateDividers(this._overviewCalculator); |
| 796 if (this._updateOverviewCanvas) { | 820 if (this._updateOverviewCanvas) { |
| 797 this._drawOverviewCanvas(this._overviewContainer.clientWidth, this._ overviewContainer.clientHeight - 20); | 821 this._drawOverviewCanvas(this._overviewContainer.clientWidth, this._ overviewContainer.clientHeight - 20); |
| 798 this._updateOverviewCanvas = false; | 822 this._updateOverviewCanvas = false; |
| 799 } | 823 } |
| 800 }, | 824 }, |
| 801 | 825 |
| 802 __proto__: WebInspector.View.prototype | 826 __proto__: WebInspector.View.prototype |
| 803 }; | 827 }; |
| OLD | NEW |