Commit d06051a5 authored by alph@chromium.org's avatar alph@chromium.org

DevTools: Smooth CPU utilization overview chart on timeline

NOTRY=true

Review URL: https://codereview.chromium.org/1311013004

git-svn-id: svn://svn.chromium.org/blink/trunk@201167 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 30951718
...@@ -312,11 +312,12 @@ WebInspector.TimelineEventOverview.CPUActivity.prototype = { ...@@ -312,11 +312,12 @@ WebInspector.TimelineEventOverview.CPUActivity.prototype = {
{ {
WebInspector.TimelineEventOverview.prototype.update.call(this); WebInspector.TimelineEventOverview.prototype.update.call(this);
var /** @const */ quantSizePx = 4 * window.devicePixelRatio; var /** @const */ quantSizePx = 4 * window.devicePixelRatio;
var width = this._canvas.width;
var height = this._canvas.height; var height = this._canvas.height;
var baseLine = height; var baseLine = height;
var timeOffset = this._model.minimumRecordTime(); var timeOffset = this._model.minimumRecordTime();
var timeSpan = this._model.maximumRecordTime() - timeOffset; var timeSpan = this._model.maximumRecordTime() - timeOffset;
var scale = this._canvas.width / timeSpan; var scale = width / timeSpan;
var quantTime = quantSizePx / scale; var quantTime = quantSizePx / scale;
var categories = WebInspector.TimelineUIUtils.categories(); var categories = WebInspector.TimelineUIUtils.categories();
var categoryOrder = ["idle", "loading", "painting", "rendering", "scripting", "other"]; var categoryOrder = ["idle", "loading", "painting", "rendering", "scripting", "other"];
...@@ -337,24 +338,28 @@ WebInspector.TimelineEventOverview.CPUActivity.prototype = { ...@@ -337,24 +338,28 @@ WebInspector.TimelineEventOverview.CPUActivity.prototype = {
*/ */
function drawThreadEvents(ctx, events) function drawThreadEvents(ctx, events)
{ {
var quantizer = new WebInspector.Quantizer(timeOffset, quantTime, drawSample.bind(this)); var quantizer = new WebInspector.Quantizer(timeOffset, quantTime, drawSample);
var x = 0; var x = 0;
var categoryIndexStack = []; var categoryIndexStack = [];
var paths = [];
var lastY = [];
for (var i = 0; i < categoryOrder.length; ++i) {
paths[i] = new Path2D();
paths[i].moveTo(0, height);
lastY[i] = height;
}
/** /**
* @param {!Array<number>} counters * @param {!Array<number>} counters
* @this {WebInspector.TimelineEventOverview}
*/ */
function drawSample(counters) function drawSample(counters)
{ {
var y = baseLine; var y = baseLine;
for (var i = idleIndex + 1; i < counters.length; ++i) { for (var i = idleIndex + 1; i < categoryOrder.length; ++i) {
if (!counters[i]) var h = (counters[i] || 0) / quantTime * height;
continue;
var h = counters[i] / quantTime * height;
ctx.fillStyle = this._categoryColor(categories[categoryOrder[i]]);
ctx.fillRect(x, y - h, quantSizePx, h);
y -= h; y -= h;
paths[i].bezierCurveTo(x, lastY[i], x, y, x + quantSizePx / 2, y);
lastY[i] = y;
} }
x += quantSizePx; x += quantSizePx;
} }
...@@ -379,6 +384,11 @@ WebInspector.TimelineEventOverview.CPUActivity.prototype = { ...@@ -379,6 +384,11 @@ WebInspector.TimelineEventOverview.CPUActivity.prototype = {
WebInspector.TimelineModel.forEachEvent(events, onEventStart, onEventEnd); WebInspector.TimelineModel.forEachEvent(events, onEventStart, onEventEnd);
quantizer.appendInterval(timeOffset + timeSpan + quantTime, idleIndex); // Kick drawing the last bucket. quantizer.appendInterval(timeOffset + timeSpan + quantTime, idleIndex); // Kick drawing the last bucket.
for (var i = categoryOrder.length - 1; i > 0; --i) {
paths[i].lineTo(width, height);
ctx.fillStyle = this._categoryColor(categories[categoryOrder[i]]);
ctx.fill(paths[i]);
}
} }
}, },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment