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

Side by Side Diff: Source/devtools/front_end/TimelineTraceView.js

Issue 212683005: Timeline Trace viewer prototype (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fixed tracing.html Created 6 years, 9 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
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7 /**
8 * @constructor
9 * @implements {WebInspector.TimelineModeView}
10 * @implements {WebInspector.FlameChartDelegate}
11 * @extends {WebInspector.VBox}
12 * @param {!WebInspector.TimelineModeViewDelegate} delegate
13 * @param {!WebInspector.TracingModel} tracingModel
14 */
15 WebInspector.TimelineTraceView = function(delegate, tracingModel)
16 {
17 WebInspector.VBox.call(this);
18 this._delegate = delegate;
19 this._tracingModel = tracingModel;
pfeldman 2014/03/26 20:37:12 unused?
caseq 2014/03/28 17:13:41 used now :-)
20 this.element.classList.add("timeline-flamechart");
21 this.registerRequiredCSS("flameChart.css");
22 this._delegate = delegate;
23 this._model = tracingModel;
24 this._dataProvider = new WebInspector.TraceViewFlameChartDataProvider(tracin gModel);
25 this._mainView = new WebInspector.FlameChart.MainPane(this._dataProvider, th is, true, true);
26 this._mainView.show(this.element);
27 this._mainView.addEventListener(WebInspector.FlameChart.Events.EntrySelected , this._onEntrySelected, this);
28 }
29
30 WebInspector.TimelineTraceView.prototype = {
31 /**
32 * @param {number} windowStartTime
33 * @param {number} windowEndTime
34 */
35 requestWindowTimes: function(windowStartTime, windowEndTime)
36 {
37 this._delegate.requestWindowTimes(windowStartTime, windowEndTime);
38 },
39
40 wasShown: function()
41 {
42 this._mainView._scheduleUpdate();
43 },
44
45 reset: function()
46 {
47 this._dataProvider.reset();
48 this._mainView.setWindowTimes(0, Infinity);
49 },
50
51 /**
52 * @param {?RegExp} textFilter
53 */
54 refreshRecords: function(textFilter)
55 {
56 this._dataProvider.reset();
57 this._mainView._scheduleUpdate();
58 },
59
60 /**
61 * @param {!WebInspector.TimelineModel.Record} record
62 */
63 addRecord: function(record) {},
64
65 /**
66 * @param {?WebInspector.TimelineModel.Record} record
67 * @param {string=} regex
68 * @param {boolean=} selectRecord
69 */
70 highlightSearchResult: function(record, regex, selectRecord) {},
71
72 /**
73 * @param {number} startTime
74 * @param {number} endTime
75 */
76 setWindowTimes: function(startTime, endTime)
77 {
78 this._mainView.setWindowTimes(startTime, endTime);
pfeldman 2014/03/26 20:10:06 This does not work when applied.
caseq 2014/03/28 17:13:41 This requires https://codereview.chromium.org/2128
79 },
80
81 /**
82 * @param {number} width
83 */
84 setSidebarSize: function(width) {},
85
86 /**
87 * @param {?WebInspector.TimelineModel.Record} record
88 */
89 setSelectedRecord: function(record) {},
90
91 /**
92 * @param {!WebInspector.Event} event
93 */
94 _onEntrySelected: function(event)
95 {
96 },
97
98 __proto__: WebInspector.VBox.prototype
99 };
100
101 /**
102 * @constructor
103 * @implements {WebInspector.FlameChartDataProvider}
104 * @param {!WebInspector.TracingModel} model
105 */
106 WebInspector.TraceViewFlameChartDataProvider = function(model)
107 {
108 WebInspector.FlameChartDataProvider.call(this);
109 this._model = model;
110 this._font = "bold 12px " + WebInspector.fontFamily();
111 this._palette = new WebInspector.TraceViewPalette();
112 }
113
114 WebInspector.TraceViewFlameChartDataProvider.prototype = {
115 /**
116 * @return {number}
117 */
118 barHeight: function()
119 {
120 return 20;
121 },
122
123 /**
124 * @return {number}
125 */
126 textBaseline: function()
127 {
128 return 6;
129 },
130
131 /**
132 * @return {number}
133 */
134 textPadding: function()
135 {
136 return 5;
137 },
138
139 /**
140 * @param {number} entryIndex
141 * @return {string}
142 */
143 entryFont: function(entryIndex)
144 {
145 return this._font;
146 },
147
148 /**
149 * @param {number} entryIndex
150 * @return {?string}
151 */
152 entryTitle: function(entryIndex)
153 {
154 return this._records[entryIndex].name;
155 },
156
157 /**
158 * @param {number} startTime
159 * @param {number} endTime
160 * @return {?Array.<number>}
161 */
162 dividerOffsets: function(startTime, endTime)
163 {
164 return null;
165 },
166
167 reset: function()
168 {
169 this._timelineData = null;
170 /** @type {!Array.<!WebInspector.TracingModel.Event|!WebInspector.TraceV iewFlameChartDataProvider.FakeEventForDelimiter>} */
171 this._records = [];
172 },
173
174 /**
175 * @return {!WebInspector.FlameChart.TimelineData}
176 */
177 timelineData: function()
178 {
179 if (this._timelineData)
180 return this._timelineData;
181
182 /**
183 * @type {?WebInspector.FlameChart.TimelineData}
184 */
185 this._timelineData = {
186 entryLevels: [],
187 entryTotalTimes: [],
188 entryOffsets: []
189 };
190
191 this._currentLevel = 0;
192 this._zeroTime = this._model.minimumRecordTime() || 0;
pfeldman 2014/03/26 20:37:12 This is going to be relative to the CPU clock, whi
caseq 2014/03/28 17:13:41 With https://codereview.chromium.org/212893002/, t
193 this._timeSpan = Math.max((this._model.maximumRecordTime() || 0) - this. _zeroTime, 1000000);
194 var processes = this._model.sortedProcesses();
195 for (var i = 0; i < processes.length; ++i) {
196 this._appendDelimiterRecord(processes[i].name());
197 var threads = processes[i].sortedThreads();
198 for (var j = 0; j < threads.length; ++j) {
199 this._appendDelimiterRecord(threads[j].name());
200 var events = threads[j].events();
201 for (var k = 0; k < events.length; ++k) {
202 if (events[k].duration)
203 this._appendRecord(events[k]);
204 }
205 this._currentLevel += threads[j].maxStackDepth();
206 }
207 ++this._currentLevel;
208 }
209 return this._timelineData;
210 },
211
212 /**
213 * @return {number}
214 */
215 zeroTime: function()
216 {
217 return this._toTimelineTime(this._zeroTime);
218 },
219
220 /**
221 * @return {number}
222 */
223 totalTime: function()
224 {
225 return this._toTimelineTime(this._timeSpan);
226 },
227
228 /**
229 * @return {number}
230 */
231 maxStackDepth: function()
232 {
233 return this._currentLevel;
234 },
235
236 /**
237 * @param {number} entryIndex
238 * @return {?Array.<!{title: string, text: string}>}
239 */
240 prepareHighlightedEntryInfo: function(entryIndex)
241 {
242 return null;
243 },
244
245 /**
246 * @param {number} entryIndex
247 * @return {boolean}
248 */
249 canJumpToEntry: function(entryIndex)
250 {
251 return false;
252 },
253
254 /**
255 * @param {number} entryIndex
256 * @return {!string}
257 */
258 entryColor: function(entryIndex)
259 {
260 var record = this._records[entryIndex];
261 if (record instanceof WebInspector.TraceViewFlameChartDataProvider.FakeE ventForDelimiter)
pfeldman 2014/03/26 20:10:06 instanceof is way too expensive for the case of 2M
caseq 2014/03/28 17:13:41 Fixed.
262 return "#555";
263 return this._palette.colorForString(this._records[entryIndex].name);
264 },
265
266
267 /**
268 * @param {number} entryIndex
269 * @param {!CanvasRenderingContext2D} context
270 * @param {?string} text
271 * @param {number} barX
272 * @param {number} barY
273 * @param {number} barWidth
274 * @param {number} barHeight
275 * @param {function(number):number} offsetToPosition
276 * @return {boolean}
277 */
278 decorateEntry: function(entryIndex, context, text, barX, barY, barWidth, bar Height, offsetToPosition)
279 {
280 return false;
281 },
282
283 /**
284 * @param {number} entryIndex
285 * @return {boolean}
286 */
287 forceDecoration: function(entryIndex)
288 {
289 return false;
290 },
291
292 /**
293 * @param {number} entryIndex
294 * @return {?{startTimeOffset: number, endTimeOffset: number}}
295 */
296 highlightTimeRange: function(entryIndex)
297 {
298 return null;
299 },
300
301 /**
302 * @return {number}
303 */
304 paddingLeft: function()
305 {
306 return 0;
307 },
308
309 /**
310 * @param {number} entryIndex
311 * @return {!string}
312 */
313 textColor: function(entryIndex)
314 {
315 return "white";
316 },
317
318 /**
319 * @param {string} title
320 */
321 _appendDelimiterRecord: function(title)
322 {
323 var record = new WebInspector.TraceViewFlameChartDataProvider.FakeEventF orDelimiter(this._zeroTime, this._timeSpan, title, 0);
324 this._appendRecord(record);
325 ++this._currentLevel;
326 },
327
328 /**
329 * @param {!WebInspector.TracingModel.Event|!WebInspector.TraceViewFlameChar tDataProvider.FakeEventForDelimiter} record
330 */
331 _appendRecord: function(record)
332 {
333 var index = this._records.length;
334 this._records.push(record);
335 this._timelineData.entryLevels[index] = this._currentLevel + record.leve l;
336 this._timelineData.entryTotalTimes[index] = this._toTimelineTime(record. duration);
337 this._timelineData.entryOffsets[index] = this._toTimelineTime(record.sta rtTime - this._zeroTime);
338 },
339
340 /**
341 * @param {number} time
342 * @return {number}
343 */
344 _toTimelineTime: function(time)
345 {
346 return time / 1000;
347 }
348 }
349
350 /**
351 * @constructor
352 * @param {number} offset
353 * @param {number} duration
354 * @param {string} title
355 */
356 WebInspector.TraceViewFlameChartDataProvider.FakeEventForDelimiter = function(of fset, duration, title, level)
357 {
358 this.startTime = offset;
359 this.duration = duration;
360 this.name = title;
361 this.level = level;
362 }
363
364 // The below logic is shamelessly stolen from https://code.google.com/p/trace-vi ewer/source/browse/trunk/trace_viewer/tracing/color_scheme.js
365
366 /**
367 * @constructor
368 */
369 WebInspector.TraceViewPalette = function()
370 {
371 this._palette = WebInspector.TraceViewPalette._paletteBase.map(WebInspector. TraceViewPalette._rgbToString);
372 }
373
374 WebInspector.TraceViewPalette._paletteBase = [
375 {r: 138, g: 113, b: 152},
pfeldman 2014/03/26 20:10:06 See WebInspector.Color.Nicknames for how we define
caseq 2014/03/28 17:13:41 Changed objects to arrays, though I think we do no
376 {r: 175, g: 112, b: 133},
377 {r: 127, g: 135, b: 225},
378 {r: 93, g: 81, b: 137},
379 {r: 116, g: 143, b: 119},
380 {r: 178, g: 214, b: 122},
381 {r: 87, g: 109, b: 147},
382 {r: 119, g: 155, b: 95},
383 {r: 114, g: 180, b: 160},
384 {r: 132, g: 85, b: 103},
385 {r: 157, g: 210, b: 150},
386 {r: 148, g: 94, b: 86},
387 {r: 164, g: 108, b: 138},
388 {r: 139, g: 191, b: 150},
389 {r: 110, g: 99, b: 145},
390 {r: 80, g: 129, b: 109},
391 {r: 125, g: 140, b: 149},
392 {r: 93, g: 124, b: 132},
393 {r: 140, g: 85, b: 140},
394 {r: 104, g: 163, b: 162},
395 {r: 132, g: 141, b: 178},
396 {r: 131, g: 105, b: 147},
397 {r: 135, g: 183, b: 98},
398 {r: 152, g: 134, b: 177},
399 {r: 141, g: 188, b: 141},
400 {r: 133, g: 160, b: 210},
401 {r: 126, g: 186, b: 148},
402 {r: 112, g: 198, b: 205},
403 {r: 180, g: 122, b: 195},
404 {r: 203, g: 144, b: 152}
405 ];
406
407 /**
408 * @param {string} string
409 * @return {number}
410 */
411 WebInspector.TraceViewPalette._stringHash = function(string)
412 {
413 var hash = 0;
414 for (var i = 0; i < string.length; ++i)
415 hash = (hash + 37 * hash + 11 * string.charCodeAt(i)) % 0xFFFFFFFF;
416 return hash;
417 }
418
419 /**
420 * @param {!{r: number, g:number, b:number}} rgb
421 * @return {string}
422 */
423 WebInspector.TraceViewPalette._rgbToString = function(rgb)
424 {
425 return "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b +")";
426 }
427
428 WebInspector.TraceViewPalette.prototype = {
429 /**
430 * @param {string} string
431 * @return {string}
432 */
433 colorForString: function(string)
434 {
435 var hash = WebInspector.TraceViewPalette._stringHash(string);
436 return this._palette[hash % this._palette.length];
437 }
438 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698