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

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

Issue 1211613002: Timeline: check category presence in list, not string equality (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fixed tracing-session-id.html Created 5 years, 6 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
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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 { 115 {
116 return WebInspector.TracingModel._flowEventsString.indexOf(phase) >= 0; 116 return WebInspector.TracingModel._flowEventsString.indexOf(phase) >= 0;
117 } 117 }
118 118
119 /** 119 /**
120 * @param {!WebInspector.TracingModel.Event} event 120 * @param {!WebInspector.TracingModel.Event} event
121 * @return {boolean} 121 * @return {boolean}
122 */ 122 */
123 WebInspector.TracingModel.isTopLevelEvent = function(event) 123 WebInspector.TracingModel.isTopLevelEvent = function(event)
124 { 124 {
125 return event.category === WebInspector.TracingModel.TopLevelEventCategory || 125 return event.hasCategory(WebInspector.TracingModel.TopLevelEventCategory) ||
126 event.category === WebInspector.TracingModel.DevToolsMetadataEventCatego ry && event.name === "Program"; // Older timelines may have this instead of topl evel. 126 event.hasCategory(WebInspector.TracingModel.DevToolsMetadataEventCategor y) && event.name === "Program"; // Older timelines may have this instead of topl evel.
127 } 127 }
128 128
129 /** 129 /**
130 * @interface 130 * @interface
131 */ 131 */
132 WebInspector.BackingStorage = function() 132 WebInspector.BackingStorage = function()
133 { 133 {
134 } 134 }
135 135
136 WebInspector.BackingStorage.prototype = { 136 WebInspector.BackingStorage.prototype = {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 this._devtoolsWorkerMetadataEvents = []; 218 this._devtoolsWorkerMetadataEvents = [];
219 this._backingStorage.reset(); 219 this._backingStorage.reset();
220 this._appendDelimiter = false; 220 this._appendDelimiter = false;
221 this._loadedFromFile = false; 221 this._loadedFromFile = false;
222 /** @type {!Array<!WebInspector.TracingModel.Event>} */ 222 /** @type {!Array<!WebInspector.TracingModel.Event>} */
223 this._asyncEvents = []; 223 this._asyncEvents = [];
224 /** @type {!Map<string, !WebInspector.TracingModel.AsyncEvent>} */ 224 /** @type {!Map<string, !WebInspector.TracingModel.AsyncEvent>} */
225 this._openAsyncEvents = new Map(); 225 this._openAsyncEvents = new Map();
226 /** @type {!Map<string, !Array<!WebInspector.TracingModel.AsyncEvent>>} */ 226 /** @type {!Map<string, !Array<!WebInspector.TracingModel.AsyncEvent>>} */
227 this._openNestableAsyncEvents = new Map(); 227 this._openNestableAsyncEvents = new Map();
228 /** @type {!Map<string, !Set<string>>} */
229 this._parsedCategories = new Map();
228 }, 230 },
229 231
230 /** 232 /**
231 * @param {!WebInspector.TracingManager.EventPayload} payload 233 * @param {!WebInspector.TracingManager.EventPayload} payload
232 */ 234 */
233 _addEvent: function(payload) 235 _addEvent: function(payload)
234 { 236 {
235 var process = this._processById[payload.pid]; 237 var process = this._processById[payload.pid];
236 if (!process) { 238 if (!process) {
237 process = new WebInspector.TracingModel.Process(payload.pid); 239 process = new WebInspector.TracingModel.Process(this, payload.pid);
238 this._processById[payload.pid] = process; 240 this._processById[payload.pid] = process;
239 } 241 }
240 242
241 var eventsDelimiter = ",\n"; 243 var eventsDelimiter = ",\n";
242 if (this._appendDelimiter) 244 if (this._appendDelimiter)
243 this._backingStorage.appendString(eventsDelimiter); 245 this._backingStorage.appendString(eventsDelimiter);
244 this._appendDelimiter = true; 246 this._appendDelimiter = true;
245 var stringPayload = JSON.stringify(payload); 247 var stringPayload = JSON.stringify(payload);
246 var isAccessible = payload.ph === WebInspector.TracingModel.Phase.Snapsh otObject; 248 var isAccessible = payload.ph === WebInspector.TracingModel.Phase.Snapsh otObject;
247 var backingStorage = null; 249 var backingStorage = null;
(...skipping 14 matching lines...) Expand all
262 var event = process._addEvent(payload); 264 var event = process._addEvent(payload);
263 if (!event) 265 if (!event)
264 return; 266 return;
265 // Build async event when we've got events from all threads & proces ses, so we can sort them and process in the 267 // Build async event when we've got events from all threads & proces ses, so we can sort them and process in the
266 // chronological order. However, also add individual async events to the thread flow (above), so we can easily 268 // chronological order. However, also add individual async events to the thread flow (above), so we can easily
267 // display them on the same chart as other events, should we choose so. 269 // display them on the same chart as other events, should we choose so.
268 if (WebInspector.TracingModel.isAsyncPhase(payload.ph)) 270 if (WebInspector.TracingModel.isAsyncPhase(payload.ph))
269 this._asyncEvents.push(event); 271 this._asyncEvents.push(event);
270 event._setBackingStorage(backingStorage); 272 event._setBackingStorage(backingStorage);
271 if (event.name === WebInspector.TracingModel.DevToolsMetadataEvent.T racingStartedInPage && 273 if (event.name === WebInspector.TracingModel.DevToolsMetadataEvent.T racingStartedInPage &&
272 event.category === WebInspector.TracingModel.DevToolsMetadataEve ntCategory) { 274 event.hasCategory(WebInspector.TracingModel.DevToolsMetadataEven tCategory)) {
273 this._devtoolsPageMetadataEvents.push(event); 275 this._devtoolsPageMetadataEvents.push(event);
274 } 276 }
275 if (event.name === WebInspector.TracingModel.DevToolsMetadataEvent.T racingSessionIdForWorker && 277 if (event.name === WebInspector.TracingModel.DevToolsMetadataEvent.T racingSessionIdForWorker &&
276 event.category === WebInspector.TracingModel.DevToolsMetadataEve ntCategory) { 278 event.hasCategory(WebInspector.TracingModel.DevToolsMetadataEven tCategory)) {
277 this._devtoolsWorkerMetadataEvents.push(event); 279 this._devtoolsWorkerMetadataEvents.push(event);
278 } 280 }
279 return; 281 return;
280 } 282 }
281 switch (payload.name) { 283 switch (payload.name) {
282 case WebInspector.TracingModel.MetadataEvent.ProcessSortIndex: 284 case WebInspector.TracingModel.MetadataEvent.ProcessSortIndex:
283 process._setSortIndex(payload.args["sort_index"]); 285 process._setSortIndex(payload.args["sort_index"]);
284 break; 286 break;
285 case WebInspector.TracingModel.MetadataEvent.ProcessName: 287 case WebInspector.TracingModel.MetadataEvent.ProcessName:
286 var processName = payload.args["name"]; 288 var processName = payload.args["name"];
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 } 417 }
416 this._openNestableAsyncEvents.clear(); 418 this._openNestableAsyncEvents.clear();
417 }, 419 },
418 420
419 /** 421 /**
420 * @param {!WebInspector.TracingModel.Event} event 422 * @param {!WebInspector.TracingModel.Event} event
421 */ 423 */
422 _addNestableAsyncEvent: function(event) 424 _addNestableAsyncEvent: function(event)
423 { 425 {
424 var phase = WebInspector.TracingModel.Phase; 426 var phase = WebInspector.TracingModel.Phase;
425 var key = event.category + "." + event.id; 427 var key = event.categoriesString + "." + event.id;
426 var openEventsStack = this._openNestableAsyncEvents.get(key); 428 var openEventsStack = this._openNestableAsyncEvents.get(key);
427 429
428 switch (event.phase) { 430 switch (event.phase) {
429 case phase.NestableAsyncBegin: 431 case phase.NestableAsyncBegin:
430 if (!openEventsStack) { 432 if (!openEventsStack) {
431 openEventsStack = []; 433 openEventsStack = [];
432 this._openNestableAsyncEvents.set(key, openEventsStack); 434 this._openNestableAsyncEvents.set(key, openEventsStack);
433 } 435 }
434 var asyncEvent = new WebInspector.TracingModel.AsyncEvent(event); 436 var asyncEvent = new WebInspector.TracingModel.AsyncEvent(event);
435 openEventsStack.push(asyncEvent); 437 openEventsStack.push(asyncEvent);
(...skipping 16 matching lines...) Expand all
452 top._addStep(event); 454 top._addStep(event);
453 } 455 }
454 }, 456 },
455 457
456 /** 458 /**
457 * @param {!WebInspector.TracingModel.Event} event 459 * @param {!WebInspector.TracingModel.Event} event
458 */ 460 */
459 _addAsyncEvent: function(event) 461 _addAsyncEvent: function(event)
460 { 462 {
461 var phase = WebInspector.TracingModel.Phase; 463 var phase = WebInspector.TracingModel.Phase;
462 var key = event.category + "." + event.name + "." + event.id; 464 var key = event.categoriesString + "." + event.name + "." + event.id;
463 var asyncEvent = this._openAsyncEvents.get(key); 465 var asyncEvent = this._openAsyncEvents.get(key);
464 466
465 if (event.phase === phase.AsyncBegin) { 467 if (event.phase === phase.AsyncBegin) {
466 if (asyncEvent) { 468 if (asyncEvent) {
467 console.error("Event " + event.name + " has already been started "); 469 console.error("Event " + event.name + " has already been started ");
468 return; 470 return;
469 } 471 }
470 asyncEvent = new WebInspector.TracingModel.AsyncEvent(event); 472 asyncEvent = new WebInspector.TracingModel.AsyncEvent(event);
471 this._openAsyncEvents.set(key, asyncEvent); 473 this._openAsyncEvents.set(key, asyncEvent);
472 event.thread._addAsyncEvent(asyncEvent); 474 event.thread._addAsyncEvent(asyncEvent);
(...skipping 12 matching lines...) Expand all
485 var lastStep = asyncEvent.steps.peekLast(); 487 var lastStep = asyncEvent.steps.peekLast();
486 if (lastStep.phase !== phase.AsyncBegin && lastStep.phase !== event. phase) { 488 if (lastStep.phase !== phase.AsyncBegin && lastStep.phase !== event. phase) {
487 console.assert(false, "Async event step phase mismatch: " + last Step.phase + " at " + lastStep.startTime + " vs. " + event.phase + " at " + even t.startTime); 489 console.assert(false, "Async event step phase mismatch: " + last Step.phase + " at " + lastStep.startTime + " vs. " + event.phase + " at " + even t.startTime);
488 return; 490 return;
489 } 491 }
490 asyncEvent._addStep(event); 492 asyncEvent._addStep(event);
491 return; 493 return;
492 } 494 }
493 console.assert(false, "Invalid async event phase"); 495 console.assert(false, "Invalid async event phase");
494 }, 496 },
497
498 /**
499 * @param {string} str
500 * @return {!Set<string>}
501 */
502 _parsedCategoriesForString: function(str)
503 {
504 var parsedCategories = this._parsedCategories.get(str);
505 if (!parsedCategories) {
506 parsedCategories = new Set(str.split(","));
507 this._parsedCategories.set(str, parsedCategories);
508 }
509 return parsedCategories;
510 }
495 } 511 }
496 512
497 /** 513 /**
498 * @constructor 514 * @constructor
499 * @param {!WebInspector.TracingModel} tracingModel 515 * @param {!WebInspector.TracingModel} tracingModel
500 */ 516 */
501 WebInspector.TracingModel.Loader = function(tracingModel) 517 WebInspector.TracingModel.Loader = function(tracingModel)
502 { 518 {
503 this._tracingModel = tracingModel; 519 this._tracingModel = tracingModel;
504 this._firstChunkReceived = false; 520 this._firstChunkReceived = false;
(...skipping 15 matching lines...) Expand all
520 finish: function() 536 finish: function()
521 { 537 {
522 this._tracingModel._loadedFromFile = true; 538 this._tracingModel._loadedFromFile = true;
523 this._tracingModel.tracingComplete(); 539 this._tracingModel.tracingComplete();
524 } 540 }
525 } 541 }
526 542
527 543
528 /** 544 /**
529 * @constructor 545 * @constructor
530 * @param {string} category 546 * @param {string} categories
531 * @param {string} name 547 * @param {string} name
532 * @param {!WebInspector.TracingModel.Phase} phase 548 * @param {!WebInspector.TracingModel.Phase} phase
533 * @param {number} startTime 549 * @param {number} startTime
534 * @param {!WebInspector.TracingModel.Thread} thread 550 * @param {!WebInspector.TracingModel.Thread} thread
535 */ 551 */
536 WebInspector.TracingModel.Event = function(category, name, phase, startTime, thr ead) 552 WebInspector.TracingModel.Event = function(categories, name, phase, startTime, t hread)
537 { 553 {
538 /** @type {string} */ 554 /** @type {string} */
539 this.category = category; 555 this.categoriesString = categories;
556 /** @type {!Set<string>} */
557 this._parsedCategories = thread._model._parsedCategoriesForString(categories );
540 /** @type {string} */ 558 /** @type {string} */
541 this.name = name; 559 this.name = name;
542 /** @type {!WebInspector.TracingModel.Phase} */ 560 /** @type {!WebInspector.TracingModel.Phase} */
543 this.phase = phase; 561 this.phase = phase;
544 /** @type {number} */ 562 /** @type {number} */
545 this.startTime = startTime; 563 this.startTime = startTime;
546 /** @type {!WebInspector.TracingModel.Thread} */ 564 /** @type {!WebInspector.TracingModel.Thread} */
547 this.thread = thread; 565 this.thread = thread;
548 /** @type {!Object} */ 566 /** @type {!Object} */
549 this.args = {}; 567 this.args = {};
(...skipping 29 matching lines...) Expand all
579 console.error("Missing mandatory event argument 'args' at " + payload.ts / 1000); 597 console.error("Missing mandatory event argument 'args' at " + payload.ts / 1000);
580 if (typeof payload.dur === "number") 598 if (typeof payload.dur === "number")
581 event.setEndTime((payload.ts + payload.dur) / 1000); 599 event.setEndTime((payload.ts + payload.dur) / 1000);
582 if (payload.id) 600 if (payload.id)
583 event.id = payload.id; 601 event.id = payload.id;
584 return event; 602 return event;
585 } 603 }
586 604
587 WebInspector.TracingModel.Event.prototype = { 605 WebInspector.TracingModel.Event.prototype = {
588 /** 606 /**
607 * @param {string} categoryName
608 * @return {boolean}
609 */
610 hasCategory: function(categoryName)
611 {
612 return this._parsedCategories.has(categoryName);
613 },
614
615 /**
589 * @param {number} endTime 616 * @param {number} endTime
590 */ 617 */
591 setEndTime: function(endTime) 618 setEndTime: function(endTime)
592 { 619 {
593 if (endTime < this.startTime) { 620 if (endTime < this.startTime) {
594 console.assert(false, "Event out of order: " + this.name); 621 console.assert(false, "Event out of order: " + this.name);
595 return; 622 return;
596 } 623 }
597 this.endTime = endTime; 624 this.endTime = endTime;
598 this.duration = endTime - this.startTime; 625 this.duration = endTime - this.startTime;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 __proto__: WebInspector.TracingModel.Event.prototype 769 __proto__: WebInspector.TracingModel.Event.prototype
743 } 770 }
744 771
745 /** 772 /**
746 * @constructor 773 * @constructor
747 * @param {!WebInspector.TracingModel.Event} startEvent 774 * @param {!WebInspector.TracingModel.Event} startEvent
748 * @extends {WebInspector.TracingModel.Event} 775 * @extends {WebInspector.TracingModel.Event}
749 */ 776 */
750 WebInspector.TracingModel.AsyncEvent = function(startEvent) 777 WebInspector.TracingModel.AsyncEvent = function(startEvent)
751 { 778 {
752 WebInspector.TracingModel.Event.call(this, startEvent.category, startEvent.n ame, startEvent.phase, startEvent.startTime, startEvent.thread) 779 WebInspector.TracingModel.Event.call(this, startEvent.categoriesString, star tEvent.name, startEvent.phase, startEvent.startTime, startEvent.thread)
753 this.addArgs(startEvent.args); 780 this.addArgs(startEvent.args);
754 this.steps = [startEvent]; 781 this.steps = [startEvent];
755 } 782 }
756 783
757 WebInspector.TracingModel.AsyncEvent.prototype = { 784 WebInspector.TracingModel.AsyncEvent.prototype = {
758 /** 785 /**
759 * @param {!WebInspector.TracingModel.Event} event 786 * @param {!WebInspector.TracingModel.Event} event
760 */ 787 */
761 _addStep: function(event) 788 _addStep: function(event)
762 { 789 {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 function comparator(a, b) 845 function comparator(a, b)
819 { 846 {
820 return a._sortIndex !== b._sortIndex ? a._sortIndex - b._sortIndex : a.n ame().localeCompare(b.name()); 847 return a._sortIndex !== b._sortIndex ? a._sortIndex - b._sortIndex : a.n ame().localeCompare(b.name());
821 } 848 }
822 return array.sort(comparator); 849 return array.sort(comparator);
823 } 850 }
824 851
825 /** 852 /**
826 * @constructor 853 * @constructor
827 * @extends {WebInspector.TracingModel.NamedObject} 854 * @extends {WebInspector.TracingModel.NamedObject}
855 * @param {!WebInspector.TracingModel} model
828 * @param {number} id 856 * @param {number} id
829 */ 857 */
830 WebInspector.TracingModel.Process = function(id) 858 WebInspector.TracingModel.Process = function(model, id)
831 { 859 {
832 WebInspector.TracingModel.NamedObject.call(this); 860 WebInspector.TracingModel.NamedObject.call(this);
833 this._setName("Process " + id); 861 this._setName("Process " + id);
834 this._id = id; 862 this._id = id;
835 /** @type {!Object.<number, !WebInspector.TracingModel.Thread>} */ 863 /** @type {!Object.<number, !WebInspector.TracingModel.Thread>} */
836 this._threads = {}; 864 this._threads = {};
837 this._threadByName = new Map(); 865 this._threadByName = new Map();
866 this._model = model;
838 } 867 }
839 868
840 WebInspector.TracingModel.Process.prototype = { 869 WebInspector.TracingModel.Process.prototype = {
841 /** 870 /**
842 * @return {number} 871 * @return {number}
843 */ 872 */
844 id: function() 873 id: function()
845 { 874 {
846 return this._id; 875 return this._id;
847 }, 876 },
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 * @param {number} id 934 * @param {number} id
906 */ 935 */
907 WebInspector.TracingModel.Thread = function(process, id) 936 WebInspector.TracingModel.Thread = function(process, id)
908 { 937 {
909 WebInspector.TracingModel.NamedObject.call(this); 938 WebInspector.TracingModel.NamedObject.call(this);
910 this._process = process; 939 this._process = process;
911 this._setName("Thread " + id); 940 this._setName("Thread " + id);
912 this._events = []; 941 this._events = [];
913 this._asyncEvents = []; 942 this._asyncEvents = [];
914 this._id = id; 943 this._id = id;
944 this._model = process._model;
915 } 945 }
916 946
917 WebInspector.TracingModel.Thread.prototype = { 947 WebInspector.TracingModel.Thread.prototype = {
918 /** 948 /**
919 * @return {?WebInspector.Target} 949 * @return {?WebInspector.Target}
920 */ 950 */
921 target: function() 951 target: function()
922 { 952 {
923 //FIXME: correctly specify target 953 //FIXME: correctly specify target
924 if (this.name() === WebInspector.TracingModel._rendererMainThreadName) 954 if (this.name() === WebInspector.TracingModel._rendererMainThreadName)
(...skipping 11 matching lines...) Expand all
936 for (var i = 0; i < this._events.length; ++i) { 966 for (var i = 0; i < this._events.length; ++i) {
937 var e = this._events[i]; 967 var e = this._events[i];
938 e.ordinal = i; 968 e.ordinal = i;
939 switch (e.phase) { 969 switch (e.phase) {
940 case phases.End: 970 case phases.End:
941 this._events[i] = null; // Mark for removal. 971 this._events[i] = null; // Mark for removal.
942 // Quietly ignore unbalanced close events, they're legit (we cou ld have missed start one). 972 // Quietly ignore unbalanced close events, they're legit (we cou ld have missed start one).
943 if (!stack.length) 973 if (!stack.length)
944 continue; 974 continue;
945 var top = stack.pop(); 975 var top = stack.pop();
946 if (top.name !== e.name || top.category !== e.category) 976 if (top.name !== e.name || top.categoriesString !== e.categories String)
947 console.error("B/E events mismatch at " + top.startTime + " (" + top.name + ") vs. " + e.startTime + " (" + e.name + ")"); 977 console.error("B/E events mismatch at " + top.startTime + " (" + top.name + ") vs. " + e.startTime + " (" + e.name + ")");
948 else 978 else
949 top._complete(e); 979 top._complete(e);
950 break; 980 break;
951 case phases.Begin: 981 case phases.Begin:
952 stack.push(e); 982 stack.push(e);
953 break; 983 break;
954 } 984 }
955 } 985 }
956 this._events.remove(null, false); 986 this._events.remove(null, false);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 /** 1050 /**
1021 * @return {!Array.<!WebInspector.TracingModel.AsyncEvent>} 1051 * @return {!Array.<!WebInspector.TracingModel.AsyncEvent>}
1022 */ 1052 */
1023 asyncEvents: function() 1053 asyncEvents: function()
1024 { 1054 {
1025 return this._asyncEvents; 1055 return this._asyncEvents;
1026 }, 1056 },
1027 1057
1028 __proto__: WebInspector.TracingModel.NamedObject.prototype 1058 __proto__: WebInspector.TracingModel.NamedObject.prototype
1029 } 1059 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/components_lazy/FilmStripModel.js ('k') | Source/devtools/front_end/timeline/TimelineFlameChart.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698