Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: Source/devtools/front_end/timeline/TimelineEventOverview.js

Issue 921333006: DevTools: Merge main thread strips on timeline overview into a single one. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Put background activities onto their own strips. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/devtools/front_end/timeline/TimelinePanel.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 23 matching lines...) Expand all
34 * @param {!WebInspector.TimelineModel} model 34 * @param {!WebInspector.TimelineModel} model
35 */ 35 */
36 WebInspector.TimelineEventOverview = function(model) 36 WebInspector.TimelineEventOverview = function(model)
37 { 37 {
38 WebInspector.TimelineOverviewBase.call(this, model); 38 WebInspector.TimelineOverviewBase.call(this, model);
39 this.element.id = "timeline-overview-events"; 39 this.element.id = "timeline-overview-events";
40 40
41 this._fillStyles = {}; 41 this._fillStyles = {};
42 var categories = WebInspector.TimelineUIUtils.categories(); 42 var categories = WebInspector.TimelineUIUtils.categories();
43 for (var category in categories) { 43 for (var category in categories) {
44 this._fillStyles[category] = WebInspector.TimelineUIUtils.createFillStyl eForCategory(this._context, 0, WebInspector.TimelineEventOverview._stripGradient Height, categories[category]); 44 this._fillStyles[category] = categories[category].fillColorStop1;
45 categories[category].addEventListener(WebInspector.TimelineCategory.Even ts.VisibilityChanged, this._onCategoryVisibilityChanged, this); 45 categories[category].addEventListener(WebInspector.TimelineCategory.Even ts.VisibilityChanged, this._onCategoryVisibilityChanged, this);
46 } 46 }
47 47
48 this._disabledCategoryFillStyle = WebInspector.TimelineUIUtils.createFillSty le(this._context, 0, WebInspector.TimelineEventOverview._stripGradientHeight, 48 this._disabledCategoryFillStyle = "hsl(0, 0%, 67%)";
49 "hsl(0, 0%, 85%)", "hsl(0, 0%, 67%)", "hsl(0, 0%, 56%)");
50
51 this._disabledCategoryBorderStyle = "rgb(143, 143, 143)";
52 } 49 }
53 50
54 /** @const */ 51 /** @const */
55 WebInspector.TimelineEventOverview._numberOfStrips = 3; 52 WebInspector.TimelineEventOverview._stripHeight = 10;
56
57 /** @const */
58 WebInspector.TimelineEventOverview._stripGradientHeight = 120;
59 53
60 /** 54 /**
61 * @constructor 55 * @constructor
62 * @template T 56 * @template T
63 */ 57 */
64 WebInspector.Dithering = function() 58 WebInspector.Dithering = function()
65 { 59 {
66 /** @type {!Map.<?T,number>} */ 60 /** @type {!Map.<?T,number>} */
67 this._groupError = new Map(); 61 this._groupError = new Map();
68 this._position = 0; 62 this._position = 0;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 var categories = WebInspector.TimelineUIUtils.categories(); 138 var categories = WebInspector.TimelineUIUtils.categories();
145 for (var category in categories) 139 for (var category in categories)
146 categories[category].removeEventListener(WebInspector.TimelineCatego ry.Events.VisibilityChanged, this._onCategoryVisibilityChanged, this); 140 categories[category].removeEventListener(WebInspector.TimelineCatego ry.Events.VisibilityChanged, this._onCategoryVisibilityChanged, this);
147 }, 141 },
148 142
149 /** 143 /**
150 * @override 144 * @override
151 */ 145 */
152 update: function() 146 update: function()
153 { 147 {
148 var /** @const */ topPadding = 2;
154 this.resetCanvas(); 149 this.resetCanvas();
150 var threads = this._model.virtualThreads();
151 var estimatedHeight = (1 + threads.length) * WebInspector.TimelineEventO verview._stripHeight;
152 this._canvas.height = estimatedHeight * window.devicePixelRatio;
153 this._canvas.style.height = estimatedHeight + "px";
154 var position = topPadding;
155 position += this._drawEvents(this._model.mainThreadEvents(), position);
156 for (var thread of threads)
157 position += this._drawEvents(thread.events, position);
158 position = Math.max(position, topPadding + WebInspector.TimelineEventOve rview._stripHeight);
159 this.element.style.flexBasis = position + "px";
160 },
155 161
156 var stripHeight = Math.round(this._canvas.height / WebInspector.Timelin eEventOverview._numberOfStrips); 162 /**
163 * @param {!Array.<!WebInspector.TracingModel.Event>} events
164 * @param {number} position
165 * @return {number}
166 */
167 _drawEvents: function(events, position)
168 {
169 var stripHeight = WebInspector.TimelineEventOverview._stripHeight;
157 var timeOffset = this._model.minimumRecordTime(); 170 var timeOffset = this._model.minimumRecordTime();
158 var timeSpan = this._model.maximumRecordTime() - timeOffset; 171 var timeSpan = this._model.maximumRecordTime() - timeOffset;
159 var scale = this._canvas.width / timeSpan; 172 var scale = this._canvas.width / timeSpan;
160 173 var ditherer = new WebInspector.Dithering();
161 var categories = WebInspector.TimelineUIUtils.categories(); 174 var categoryStack = [];
162 var ditherers = new Map(); 175 var lastX = 0;
163 for (var category in categories) 176 var drawn = false;
164 ditherers.set(categories[category].overviewStripGroupIndex, new WebI nspector.Dithering());
165
166 this._context.fillStyle = "rgba(0, 0, 0, 0.05)";
167 for (var i = 1; i < WebInspector.TimelineEventOverview._numberOfStrips; i += 2)
168 this._context.fillRect(0, i * stripHeight, this._canvas.width, strip Height);
169 177
170 /** 178 /**
171 * @param {!WebInspector.TimelineModel.Record} record 179 * @param {!WebInspector.TracingModel.Event} e
172 * @this {WebInspector.TimelineEventOverview} 180 * @this {WebInspector.TimelineEventOverview}
173 */ 181 */
174 function appendRecord(record) 182 function onEventStart(e)
175 { 183 {
176 if (record.type() === WebInspector.TimelineModel.RecordType.BeginFra me) 184 var pos = (e.startTime - timeOffset) * scale;
177 return; 185 if (categoryStack.length) {
178 var recordStart = (record.startTime() - timeOffset) * scale; 186 var category = categoryStack.peekLast();
179 var recordEnd = (record.endTime() - timeOffset) * scale; 187 var bar = ditherer.appendInterval(category, lastX, pos);
180 var category = WebInspector.TimelineUIUtils.categoryForRecord(record ); 188 if (bar) {
181 if (category.overviewStripGroupIndex < 0) 189 this._renderBar(bar.start, bar.end, position, stripHeight, c ategory);
182 return; 190 drawn = true;
183 var bar = ditherers.get(category.overviewStripGroupIndex).appendInte rval(category, recordStart, recordEnd); 191 }
184 if (bar) 192 }
185 this._renderBar(bar.start, bar.end, stripHeight, category); 193 categoryStack.push(WebInspector.TimelineUIUtils.eventStyle(e).catego ry);
194 lastX = pos;
186 } 195 }
187 this._model.forAllRecords(appendRecord.bind(this)); 196
197 /**
198 * @param {!WebInspector.TracingModel.Event} e
199 * @this {WebInspector.TimelineEventOverview}
200 */
201 function onEventEnd(e)
202 {
203 var category = categoryStack.pop();
204 var pos = (e.endTime - timeOffset) * scale;
205 var bar = ditherer.appendInterval(category, lastX, pos);
206 if (bar) {
207 this._renderBar(bar.start, bar.end, position, stripHeight, categ ory);
208 drawn = true;
209 }
210 }
211
212 WebInspector.TimelineModel.forEachEvent(events, onEventStart.bind(this), onEventEnd.bind(this));
213 return drawn ? stripHeight : 0;
188 }, 214 },
189 215
190 _onCategoryVisibilityChanged: function() 216 _onCategoryVisibilityChanged: function()
191 { 217 {
192 this.update(); 218 this.update();
193 }, 219 },
194 220
195 /** 221 /**
196 * @param {number} begin 222 * @param {number} begin
197 * @param {number} end 223 * @param {number} end
224 * @param {number} position
198 * @param {number} height 225 * @param {number} height
199 * @param {!WebInspector.TimelineCategory} category 226 * @param {!WebInspector.TimelineCategory} category
200 */ 227 */
201 _renderBar: function(begin, end, height, category) 228 _renderBar: function(begin, end, position, height, category)
202 { 229 {
203 const stripPadding = 4 * window.devicePixelRatio; 230 var /** @const */ stripPadding = 1;
204 const innerStripHeight = height - 2 * stripPadding; 231 var innerStripHeight = (height - stripPadding) * window.devicePixelRatio ;
205
206 var x = begin; 232 var x = begin;
207 var y = category.overviewStripGroupIndex * height + stripPadding + 0.5; 233 var y = position * window.devicePixelRatio;
208 var width = Math.max(end - begin, 1); 234 var width = end - begin;
209
210 this._context.save();
211 this._context.translate(x, y);
212 this._context.beginPath();
213 this._context.scale(1, innerStripHeight / WebInspector.TimelineEventOver view._stripGradientHeight);
214 this._context.fillStyle = category.hidden ? this._disabledCategoryFillSt yle : this._fillStyles[category.name]; 235 this._context.fillStyle = category.hidden ? this._disabledCategoryFillSt yle : this._fillStyles[category.name];
215 this._context.fillRect(0, 0, width, WebInspector.TimelineEventOverview._ stripGradientHeight); 236 this._context.fillRect(x, y, width, innerStripHeight);
216 this._context.strokeStyle = category.hidden ? this._disabledCategoryBord erStyle : category.borderColor;
217 this._context.moveTo(0, 0);
218 this._context.lineTo(width, 0);
219 this._context.moveTo(0, WebInspector.TimelineEventOverview._stripGradien tHeight);
220 this._context.lineTo(width, WebInspector.TimelineEventOverview._stripGra dientHeight);
221 this._context.stroke();
222 this._context.restore();
223 }, 237 },
224 238
225 __proto__: WebInspector.TimelineOverviewBase.prototype 239 __proto__: WebInspector.TimelineOverviewBase.prototype
226 } 240 }
OLDNEW
« no previous file with comments | « no previous file | Source/devtools/front_end/timeline/TimelinePanel.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698