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

Side by Side Diff: Source/devtools/front_end/sdk/TracingModel.js

Issue 1305373004: DevTools: move session logic from TracingModel to TimelineModel (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 3 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
OLDNEW
1 /* 1 /*
2 * Copyright 2014 The Chromium Authors. All rights reserved. 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 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 /** 7 /**
8 * @constructor 8 * @constructor
9 * @param {!WebInspector.BackingStorage} backingStorage 9 * @param {!WebInspector.BackingStorage} backingStorage
10 */ 10 */
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } 48 }
49 49
50 WebInspector.TracingModel.TopLevelEventCategory = "toplevel"; 50 WebInspector.TracingModel.TopLevelEventCategory = "toplevel";
51 WebInspector.TracingModel.DevToolsMetadataEventCategory = "disabled-by-default-d evtools.timeline"; 51 WebInspector.TracingModel.DevToolsMetadataEventCategory = "disabled-by-default-d evtools.timeline";
52 WebInspector.TracingModel.DevToolsTimelineEventCategory = "disabled-by-default-d evtools.timeline"; 52 WebInspector.TracingModel.DevToolsTimelineEventCategory = "disabled-by-default-d evtools.timeline";
53 53
54 WebInspector.TracingModel.ConsoleEventCategory = "blink.console"; 54 WebInspector.TracingModel.ConsoleEventCategory = "blink.console";
55 55
56 WebInspector.TracingModel.FrameLifecycleEventCategory = "cc,devtools"; 56 WebInspector.TracingModel.FrameLifecycleEventCategory = "cc,devtools";
57 57
58 WebInspector.TracingModel.DevToolsMetadataEvent = {
59 TracingStartedInPage: "TracingStartedInPage",
60 TracingSessionIdForWorker: "TracingSessionIdForWorker",
61 };
62
63 WebInspector.TracingModel._nestableAsyncEventsString = 58 WebInspector.TracingModel._nestableAsyncEventsString =
64 WebInspector.TracingModel.Phase.NestableAsyncBegin + 59 WebInspector.TracingModel.Phase.NestableAsyncBegin +
65 WebInspector.TracingModel.Phase.NestableAsyncEnd + 60 WebInspector.TracingModel.Phase.NestableAsyncEnd +
66 WebInspector.TracingModel.Phase.NestableAsyncInstant; 61 WebInspector.TracingModel.Phase.NestableAsyncInstant;
67 62
68 WebInspector.TracingModel._legacyAsyncEventsString = 63 WebInspector.TracingModel._legacyAsyncEventsString =
69 WebInspector.TracingModel.Phase.AsyncBegin + 64 WebInspector.TracingModel.Phase.AsyncBegin +
70 WebInspector.TracingModel.Phase.AsyncEnd + 65 WebInspector.TracingModel.Phase.AsyncEnd +
71 WebInspector.TracingModel.Phase.AsyncStepInto + 66 WebInspector.TracingModel.Phase.AsyncStepInto +
72 WebInspector.TracingModel.Phase.AsyncStepPast; 67 WebInspector.TracingModel.Phase.AsyncStepPast;
73 68
74 WebInspector.TracingModel._flowEventsString = 69 WebInspector.TracingModel._flowEventsString =
75 WebInspector.TracingModel.Phase.FlowBegin + 70 WebInspector.TracingModel.Phase.FlowBegin +
76 WebInspector.TracingModel.Phase.FlowStep + 71 WebInspector.TracingModel.Phase.FlowStep +
77 WebInspector.TracingModel.Phase.FlowEnd; 72 WebInspector.TracingModel.Phase.FlowEnd;
78 73
79 WebInspector.TracingModel._rendererMainThreadName = "CrRendererMain";
80
81 WebInspector.TracingModel._asyncEventsString = WebInspector.TracingModel._nestab leAsyncEventsString + WebInspector.TracingModel._legacyAsyncEventsString; 74 WebInspector.TracingModel._asyncEventsString = WebInspector.TracingModel._nestab leAsyncEventsString + WebInspector.TracingModel._legacyAsyncEventsString;
82 75
83 /** 76 /**
84 * @param {string} phase 77 * @param {string} phase
85 * @return {boolean} 78 * @return {boolean}
86 */ 79 */
87 WebInspector.TracingModel.isNestableAsyncPhase = function(phase) 80 WebInspector.TracingModel.isNestableAsyncPhase = function(phase)
88 { 81 {
89 return WebInspector.TracingModel._nestableAsyncEventsString.indexOf(phase) > = 0; 82 return WebInspector.TracingModel._nestableAsyncEventsString.indexOf(phase) > = 0;
90 } 83 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 finishWriting: function() { }, 141 finishWriting: function() { },
149 142
150 reset: function() { }, 143 reset: function() { },
151 } 144 }
152 145
153 146
154 WebInspector.TracingModel.prototype = { 147 WebInspector.TracingModel.prototype = {
155 /** 148 /**
156 * @return {!Array.<!WebInspector.TracingModel.Event>} 149 * @return {!Array.<!WebInspector.TracingModel.Event>}
157 */ 150 */
158 devtoolsPageMetadataEvents: function() 151 devToolsMetadataEvents: function()
159 { 152 {
160 return this._devtoolsPageMetadataEvents; 153 return this._devToolsMetadataEvents;
161 }, 154 },
162 155
163 /** 156 /**
164 * @return {!Array.<!WebInspector.TracingModel.Event>}
165 */
166 devtoolsWorkerMetadataEvents: function()
167 {
168 return this._devtoolsWorkerMetadataEvents;
169 },
170
171 /**
172 * @return {?string}
173 */
174 sessionId: function()
175 {
176 return this._sessionId;
177 },
178
179 /**
180 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events 157 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events
181 */ 158 */
182 setEventsForTest: function(events) 159 setEventsForTest: function(events)
183 { 160 {
184 this.reset(); 161 this.reset();
185 this.addEvents(events); 162 this.addEvents(events);
186 this.tracingComplete(); 163 this.tracingComplete();
187 }, 164 },
188 165
189 /** 166 /**
190 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events 167 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events
191 */ 168 */
192 addEvents: function(events) 169 addEvents: function(events)
193 { 170 {
194 for (var i = 0; i < events.length; ++i) 171 for (var i = 0; i < events.length; ++i)
195 this._addEvent(events[i]); 172 this._addEvent(events[i]);
196 }, 173 },
197 174
198 tracingComplete: function() 175 tracingComplete: function()
199 { 176 {
200 this._processMetadataEvents();
201 this._processPendingAsyncEvents(); 177 this._processPendingAsyncEvents();
202 this._backingStorage.finishWriting(); 178 this._backingStorage.finishWriting();
203 for (var process of Object.values(this._processById)) { 179 for (var process of Object.values(this._processById)) {
204 for (var thread of Object.values(process._threads)) 180 for (var thread of Object.values(process._threads))
205 thread.tracingComplete(); 181 thread.tracingComplete();
206 } 182 }
207 }, 183 },
208 184
209 reset: function() 185 reset: function()
210 { 186 {
211 /** @type {!Object.<(number|string), !WebInspector.TracingModel.Process> } */ 187 /** @type {!Object.<(number|string), !WebInspector.TracingModel.Process> } */
212 this._processById = {}; 188 this._processById = {};
213 this._processByName = new Map(); 189 this._processByName = new Map();
214 this._minimumRecordTime = 0; 190 this._minimumRecordTime = 0;
215 this._maximumRecordTime = 0; 191 this._maximumRecordTime = 0;
216 this._sessionId = null; 192 this._devToolsMetadataEvents = [];
217 this._devtoolsPageMetadataEvents = [];
218 this._devtoolsWorkerMetadataEvents = [];
219 this._backingStorage.reset(); 193 this._backingStorage.reset();
220 this._appendDelimiter = false; 194 this._appendDelimiter = false;
221 this._loadedFromFile = false;
222 /** @type {!Array<!WebInspector.TracingModel.Event>} */ 195 /** @type {!Array<!WebInspector.TracingModel.Event>} */
223 this._asyncEvents = []; 196 this._asyncEvents = [];
224 /** @type {!Map<string, !WebInspector.TracingModel.AsyncEvent>} */ 197 /** @type {!Map<string, !WebInspector.TracingModel.AsyncEvent>} */
225 this._openAsyncEvents = new Map(); 198 this._openAsyncEvents = new Map();
226 /** @type {!Map<string, !Array<!WebInspector.TracingModel.AsyncEvent>>} */ 199 /** @type {!Map<string, !Array<!WebInspector.TracingModel.AsyncEvent>>} */
227 this._openNestableAsyncEvents = new Map(); 200 this._openNestableAsyncEvents = new Map();
228 /** @type {!Map<string, !Set<string>>} */ 201 /** @type {!Map<string, !Set<string>>} */
229 this._parsedCategories = new Map(); 202 this._parsedCategories = new Map();
230 }, 203 },
231 204
205
alph 2015/09/01 21:11:41 revert plz
232 /** 206 /**
233 * @param {!WebInspector.TracingManager.EventPayload} payload 207 * @param {!WebInspector.TracingManager.EventPayload} payload
234 */ 208 */
235 _addEvent: function(payload) 209 _addEvent: function(payload)
236 { 210 {
237 var process = this._processById[payload.pid]; 211 var process = this._processById[payload.pid];
238 if (!process) { 212 if (!process) {
239 process = new WebInspector.TracingModel.Process(this, payload.pid); 213 process = new WebInspector.TracingModel.Process(this, payload.pid);
240 this._processById[payload.pid] = process; 214 this._processById[payload.pid] = process;
241 } 215 }
(...skipping 21 matching lines...) Expand all
263 this._maximumRecordTime = Math.max(this._maximumRecordTime, endTimeS tamp); 237 this._maximumRecordTime = Math.max(this._maximumRecordTime, endTimeS tamp);
264 var event = process._addEvent(payload); 238 var event = process._addEvent(payload);
265 if (!event) 239 if (!event)
266 return; 240 return;
267 // Build async event when we've got events from all threads & proces ses, so we can sort them and process in the 241 // Build async event when we've got events from all threads & proces ses, so we can sort them and process in the
268 // chronological order. However, also add individual async events to the thread flow (above), so we can easily 242 // chronological order. However, also add individual async events to the thread flow (above), so we can easily
269 // display them on the same chart as other events, should we choose so. 243 // display them on the same chart as other events, should we choose so.
270 if (WebInspector.TracingModel.isAsyncPhase(payload.ph)) 244 if (WebInspector.TracingModel.isAsyncPhase(payload.ph))
271 this._asyncEvents.push(event); 245 this._asyncEvents.push(event);
272 event._setBackingStorage(backingStorage); 246 event._setBackingStorage(backingStorage);
273 if (event.name === WebInspector.TracingModel.DevToolsMetadataEvent.T racingStartedInPage && 247 if (event.hasCategory(WebInspector.TracingModel.DevToolsMetadataEven tCategory))
274 event.hasCategory(WebInspector.TracingModel.DevToolsMetadataEven tCategory)) { 248 this._devToolsMetadataEvents.push(event);
275 this._devtoolsPageMetadataEvents.push(event);
276 }
277 if (event.name === WebInspector.TracingModel.DevToolsMetadataEvent.T racingSessionIdForWorker &&
278 event.hasCategory(WebInspector.TracingModel.DevToolsMetadataEven tCategory)) {
279 this._devtoolsWorkerMetadataEvents.push(event);
280 }
281 return; 249 return;
282 } 250 }
283 switch (payload.name) { 251 switch (payload.name) {
284 case WebInspector.TracingModel.MetadataEvent.ProcessSortIndex: 252 case WebInspector.TracingModel.MetadataEvent.ProcessSortIndex:
285 process._setSortIndex(payload.args["sort_index"]); 253 process._setSortIndex(payload.args["sort_index"]);
286 break; 254 break;
287 case WebInspector.TracingModel.MetadataEvent.ProcessName: 255 case WebInspector.TracingModel.MetadataEvent.ProcessName:
288 var processName = payload.args["name"]; 256 var processName = payload.args["name"];
289 process._setName(processName); 257 process._setName(processName);
290 this._processByName.set(processName, process); 258 this._processByName.set(processName, process);
291 break; 259 break;
292 case WebInspector.TracingModel.MetadataEvent.ThreadSortIndex: 260 case WebInspector.TracingModel.MetadataEvent.ThreadSortIndex:
293 process.threadById(payload.tid)._setSortIndex(payload.args["sort_ind ex"]); 261 process.threadById(payload.tid)._setSortIndex(payload.args["sort_ind ex"]);
294 break; 262 break;
295 case WebInspector.TracingModel.MetadataEvent.ThreadName: 263 case WebInspector.TracingModel.MetadataEvent.ThreadName:
296 process.threadById(payload.tid)._setName(payload.args["name"]); 264 process.threadById(payload.tid)._setName(payload.args["name"]);
297 break; 265 break;
298 } 266 }
299 }, 267 },
300 268
301 _processMetadataEvents: function()
302 {
303 this._devtoolsPageMetadataEvents.sort(WebInspector.TracingModel.Event.co mpareStartTime);
304 if (!this._devtoolsPageMetadataEvents.length) {
305 // The trace is probably coming not from DevTools. Make a mock Metad ata event.
306 var pageMetaEvent = this._loadedFromFile ? this._makeMockPageMetadat aEvent() : null;
307 if (!pageMetaEvent) {
308 console.error(WebInspector.TracingModel.DevToolsMetadataEvent.Tr acingStartedInPage + " event not found.");
309 return;
310 }
311 this._devtoolsPageMetadataEvents.push(pageMetaEvent);
312 }
313 var sessionId = this._devtoolsPageMetadataEvents[0].args["sessionId"] || this._devtoolsPageMetadataEvents[0].args["data"]["sessionId"];
314 this._sessionId = sessionId;
315
316 var mismatchingIds = {};
317 function checkSessionId(event)
318 {
319 var args = event.args;
320 // FIXME: put sessionId into args["data"] for TracingStartedInPage e vent.
321 if (args["data"])
322 args = args["data"];
323 var id = args["sessionId"];
324 if (id === sessionId)
325 return true;
326 mismatchingIds[id] = true;
327 return false;
328 }
329 this._devtoolsPageMetadataEvents = this._devtoolsPageMetadataEvents.filt er(checkSessionId);
330 this._devtoolsWorkerMetadataEvents = this._devtoolsWorkerMetadataEvents. filter(checkSessionId);
331
332 var idList = Object.keys(mismatchingIds);
333 if (idList.length)
334 WebInspector.console.error("Timeline recording was started in more t han one page simultaneously. Session id mismatch: " + this._sessionId + " and " + idList + ".");
335 },
336
337 /**
338 * @return {?WebInspector.TracingModel.Event}
339 */
340 _makeMockPageMetadataEvent: function()
341 {
342 var rendererMainThreadName = WebInspector.TracingModel._rendererMainThre adName;
343 // FIXME: pick up the first renderer process for now.
344 var process = Object.values(this._processById).filter(function(p) { retu rn p.threadByName(rendererMainThreadName); })[0];
345 var thread = process && process.threadByName(rendererMainThreadName);
346 if (!thread)
347 return null;
348 var pageMetaEvent = new WebInspector.TracingModel.Event(
349 WebInspector.TracingModel.DevToolsMetadataEventCategory,
350 WebInspector.TracingModel.DevToolsMetadataEvent.TracingStartedInPage ,
351 WebInspector.TracingModel.Phase.Metadata,
352 this._minimumRecordTime, thread);
353 pageMetaEvent.addArgs({"data": {"sessionId": "mockSessionId"}});
354 return pageMetaEvent;
355 },
356
357 /** 269 /**
358 * @return {number} 270 * @return {number}
359 */ 271 */
360 minimumRecordTime: function() 272 minimumRecordTime: function()
361 { 273 {
362 return this._minimumRecordTime; 274 return this._minimumRecordTime;
363 }, 275 },
364 276
365 /** 277 /**
366 * @return {number} 278 * @return {number}
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 if (!parsedCategories) { 417 if (!parsedCategories) {
506 parsedCategories = new Set(str.split(",")); 418 parsedCategories = new Set(str.split(","));
507 this._parsedCategories.set(str, parsedCategories); 419 this._parsedCategories.set(str, parsedCategories);
508 } 420 }
509 return parsedCategories; 421 return parsedCategories;
510 } 422 }
511 } 423 }
512 424
513 /** 425 /**
514 * @constructor 426 * @constructor
515 * @param {!WebInspector.TracingModel} tracingModel
516 */
517 WebInspector.TracingModel.Loader = function(tracingModel)
518 {
519 this._tracingModel = tracingModel;
520 this._firstChunkReceived = false;
521 }
522
523 WebInspector.TracingModel.Loader.prototype = {
524 /**
525 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events
526 */
527 loadNextChunk: function(events)
528 {
529 if (!this._firstChunkReceived) {
530 this._tracingModel.reset();
531 this._firstChunkReceived = true;
532 }
533 this._tracingModel.addEvents(events);
534 },
535
536 finish: function()
537 {
538 this._tracingModel._loadedFromFile = true;
539 this._tracingModel.tracingComplete();
540 }
541 }
542
543
544 /**
545 * @constructor
546 * @param {string} categories 427 * @param {string} categories
547 * @param {string} name 428 * @param {string} name
548 * @param {!WebInspector.TracingModel.Phase} phase 429 * @param {!WebInspector.TracingModel.Phase} phase
549 * @param {number} startTime 430 * @param {number} startTime
550 * @param {!WebInspector.TracingModel.Thread} thread 431 * @param {!WebInspector.TracingModel.Thread} thread
551 */ 432 */
552 WebInspector.TracingModel.Event = function(categories, name, phase, startTime, t hread) 433 WebInspector.TracingModel.Event = function(categories, name, phase, startTime, t hread)
553 { 434 {
554 /** @type {string} */ 435 /** @type {string} */
555 this.categoriesString = categories; 436 this.categoriesString = categories;
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 WebInspector.TracingModel.NamedObject.call(this); 819 WebInspector.TracingModel.NamedObject.call(this);
939 this._process = process; 820 this._process = process;
940 this._setName("Thread " + id); 821 this._setName("Thread " + id);
941 this._events = []; 822 this._events = [];
942 this._asyncEvents = []; 823 this._asyncEvents = [];
943 this._id = id; 824 this._id = id;
944 this._model = process._model; 825 this._model = process._model;
945 } 826 }
946 827
947 WebInspector.TracingModel.Thread.prototype = { 828 WebInspector.TracingModel.Thread.prototype = {
948 /**
949 * @return {?WebInspector.Target}
950 */
951 target: function()
952 {
953 //FIXME: correctly specify target
954 if (this.name() === WebInspector.TracingModel._rendererMainThreadName)
955 return WebInspector.targetManager.targets()[0] || null;
956 else
957 return null;
958 },
959
960 tracingComplete: function() 829 tracingComplete: function()
961 { 830 {
962 this._asyncEvents.stableSort(WebInspector.TracingModel.Event.compareStar tTime); 831 this._asyncEvents.stableSort(WebInspector.TracingModel.Event.compareStar tTime);
963 this._events.stableSort(WebInspector.TracingModel.Event.compareStartTime ); 832 this._events.stableSort(WebInspector.TracingModel.Event.compareStartTime );
964 var phases = WebInspector.TracingModel.Phase; 833 var phases = WebInspector.TracingModel.Phase;
965 var stack = []; 834 var stack = [];
966 for (var i = 0; i < this._events.length; ++i) { 835 for (var i = 0; i < this._events.length; ++i) {
967 var e = this._events[i]; 836 var e = this._events[i];
968 e.ordinal = i; 837 e.ordinal = i;
969 switch (e.phase) { 838 switch (e.phase) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 /** 919 /**
1051 * @return {!Array.<!WebInspector.TracingModel.AsyncEvent>} 920 * @return {!Array.<!WebInspector.TracingModel.AsyncEvent>}
1052 */ 921 */
1053 asyncEvents: function() 922 asyncEvents: function()
1054 { 923 {
1055 return this._asyncEvents; 924 return this._asyncEvents;
1056 }, 925 },
1057 926
1058 __proto__: WebInspector.TracingModel.NamedObject.prototype 927 __proto__: WebInspector.TracingModel.NamedObject.prototype
1059 } 928 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698