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

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

Issue 2750133003: Revert of DevTools: move flow events tracking to TracingModel, support cross-threads case (Closed)
Patch Set: Created 3 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
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 * @unrestricted 8 * @unrestricted
9 */ 9 */
10 SDK.TracingModel = class { 10 SDK.TracingModel = class {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 111 }
112 112
113 /** 113 /**
114 * @return {!Array.<!SDK.TracingModel.Event>} 114 * @return {!Array.<!SDK.TracingModel.Event>}
115 */ 115 */
116 devToolsMetadataEvents() { 116 devToolsMetadataEvents() {
117 return this._devToolsMetadataEvents; 117 return this._devToolsMetadataEvents;
118 } 118 }
119 119
120 /** 120 /**
121 * @return {!Array.<!SDK.TracingModel.Event>}
122 */
123 flowHeads() {
124 return this._flowHeads;
125 }
126
127 /**
128 * @param {!Array.<!SDK.TracingManager.EventPayload>} events 121 * @param {!Array.<!SDK.TracingManager.EventPayload>} events
129 */ 122 */
130 setEventsForTest(events) { 123 setEventsForTest(events) {
131 this.reset(); 124 this.reset();
132 this.addEvents(events); 125 this.addEvents(events);
133 this.tracingComplete(); 126 this.tracingComplete();
134 } 127 }
135 128
136 /** 129 /**
137 * @param {!Array.<!SDK.TracingManager.EventPayload>} events 130 * @param {!Array.<!SDK.TracingManager.EventPayload>} events
138 */ 131 */
139 addEvents(events) { 132 addEvents(events) {
140 for (var i = 0; i < events.length; ++i) 133 for (var i = 0; i < events.length; ++i)
141 this._addEvent(events[i]); 134 this._addEvent(events[i]);
142 } 135 }
143 136
144 tracingComplete() { 137 tracingComplete() {
145 this._processPendingAsyncEvents(); 138 this._processPendingAsyncEvents();
146 this._processFlowEvents();
147 this._backingStorage.appendString(this._firstWritePending ? '[]' : ']'); 139 this._backingStorage.appendString(this._firstWritePending ? '[]' : ']');
148 this._backingStorage.finishWriting(); 140 this._backingStorage.finishWriting();
149 this._firstWritePending = false; 141 this._firstWritePending = false;
150 for (var process of this._processById.values()) { 142 for (var process of this._processById.values()) {
151 for (var thread of process._threads.values()) 143 for (var thread of process._threads.values())
152 thread.tracingComplete(); 144 thread.tracingComplete();
153 } 145 }
154 } 146 }
155 147
156 reset() { 148 reset() {
157 /** @type {!Map<(number|string), !SDK.TracingModel.Process>} */ 149 /** @type {!Map<(number|string), !SDK.TracingModel.Process>} */
158 this._processById = new Map(); 150 this._processById = new Map();
159 this._processByName = new Map(); 151 this._processByName = new Map();
160 this._minimumRecordTime = 0; 152 this._minimumRecordTime = 0;
161 this._maximumRecordTime = 0; 153 this._maximumRecordTime = 0;
162 this._devToolsMetadataEvents = []; 154 this._devToolsMetadataEvents = [];
163 if (!this._firstWritePending) 155 if (!this._firstWritePending)
164 this._backingStorage.reset(); 156 this._backingStorage.reset();
165 157
166 this._firstWritePending = true; 158 this._firstWritePending = true;
167 /** @type {!Array<!SDK.TracingModel.Event>} */ 159 /** @type {!Array<!SDK.TracingModel.Event>} */
168 this._asyncEvents = []; 160 this._asyncEvents = [];
169 /** @type {!Map<string, !SDK.TracingModel.AsyncEvent>} */ 161 /** @type {!Map<string, !SDK.TracingModel.AsyncEvent>} */
170 this._openAsyncEvents = new Map(); 162 this._openAsyncEvents = new Map();
171 /** @type {!Map<string, !Array<!SDK.TracingModel.AsyncEvent>>} */ 163 /** @type {!Map<string, !Array<!SDK.TracingModel.AsyncEvent>>} */
172 this._openNestableAsyncEvents = new Map(); 164 this._openNestableAsyncEvents = new Map();
173 /** @type {!Map<string, !Array<!SDK.TracingModel.Event>>} */
174 this._flowEventsById = new Map();
175 /** @type {!Map<string, !SDK.TracingModel.ProfileEventsGroup>} */ 165 /** @type {!Map<string, !SDK.TracingModel.ProfileEventsGroup>} */
176 this._profileGroups = new Map(); 166 this._profileGroups = new Map();
177 /** @type {!Map<string, !Set<string>>} */ 167 /** @type {!Map<string, !Set<string>>} */
178 this._parsedCategories = new Map(); 168 this._parsedCategories = new Map();
179 /** @type {!Array<!SDK.TracingModel.Event>} */
180 this._flowHeads = [];
181 } 169 }
182 170
183 /** 171 /**
184 * @param {number} offset 172 * @param {number} offset
185 */ 173 */
186 adjustTime(offset) { 174 adjustTime(offset) {
187 this._minimumRecordTime += offset; 175 this._minimumRecordTime += offset;
188 this._maximumRecordTime += offset; 176 this._maximumRecordTime += offset;
189 for (const process of this._processById.values()) { 177 for (const process of this._processById.values()) {
190 for (const thread of process._threads.values()) { 178 for (const thread of process._threads.values()) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 const event = process._addEvent(payload); 224 const event = process._addEvent(payload);
237 if (!event) 225 if (!event)
238 return; 226 return;
239 if (payload.ph === phase.Sample) { 227 if (payload.ph === phase.Sample) {
240 this._addSampleEvent(event); 228 this._addSampleEvent(event);
241 return; 229 return;
242 } 230 }
243 // Build async event when we've got events from all threads & processes, so we can sort them and process in the 231 // Build async event when we've got events from all threads & processes, so we can sort them and process in the
244 // chronological order. However, also add individual async events to the thr ead flow (above), so we can easily 232 // chronological order. However, also add individual async events to the thr ead flow (above), so we can easily
245 // display them on the same chart as other events, should we choose so. 233 // display them on the same chart as other events, should we choose so.
246 if (SDK.TracingModel.isAsyncPhase(payload.ph)) { 234 if (SDK.TracingModel.isAsyncPhase(payload.ph))
247 this._asyncEvents.push(event); 235 this._asyncEvents.push(event);
248 } else if (SDK.TracingModel.isFlowPhase(payload.ph)) {
249 var key = `${event.categoriesString}-${event.name}-${event.id}`;
250 var flowEvents = this._flowEventsById.get(key);
251 if (!flowEvents) {
252 flowEvents = [];
253 this._flowEventsById.set(key, flowEvents);
254 }
255 flowEvents.push(event);
256 }
257
258 event._setBackingStorage(backingStorage); 236 event._setBackingStorage(backingStorage);
259 if (event.hasCategory(SDK.TracingModel.DevToolsMetadataEventCategory)) 237 if (event.hasCategory(SDK.TracingModel.DevToolsMetadataEventCategory))
260 this._devToolsMetadataEvents.push(event); 238 this._devToolsMetadataEvents.push(event);
261 239
262 if (payload.ph !== phase.Metadata) 240 if (payload.ph !== phase.Metadata)
263 return; 241 return;
264 242
265 switch (payload.name) { 243 switch (payload.name) {
266 case SDK.TracingModel.MetadataEvent.ProcessSortIndex: 244 case SDK.TracingModel.MetadataEvent.ProcessSortIndex:
267 process._setSortIndex(payload.args['sort_index']); 245 process._setSortIndex(payload.args['sort_index']);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 var event = this._asyncEvents[i]; 322 var event = this._asyncEvents[i];
345 if (SDK.TracingModel.isNestableAsyncPhase(event.phase)) 323 if (SDK.TracingModel.isNestableAsyncPhase(event.phase))
346 this._addNestableAsyncEvent(event); 324 this._addNestableAsyncEvent(event);
347 else 325 else
348 this._addAsyncEvent(event); 326 this._addAsyncEvent(event);
349 } 327 }
350 this._asyncEvents = []; 328 this._asyncEvents = [];
351 this._closeOpenAsyncEvents(); 329 this._closeOpenAsyncEvents();
352 } 330 }
353 331
354 _processFlowEvents() {
355 var phases = SDK.TracingModel.Phase;
356 for (var events of this._flowEventsById.values()) {
357 events.stableSort(SDK.TracingModel.Event.compareStartTime);
358 var lastInChain = null;
359 for (var e of events) {
360 if (lastInChain && e.phase !== phases.FlowBegin)
361 lastInChain._appendFlowEvent(e);
362 if (!lastInChain && e.phase !== phases.FlowEnd)
363 this._flowHeads.push(e);
364 lastInChain = e.phase !== phases.FlowEnd ? e : null;
365 }
366 }
367 this._flowEventsById.clear();
368 }
369
370 _closeOpenAsyncEvents() { 332 _closeOpenAsyncEvents() {
371 for (var event of this._openAsyncEvents.values()) { 333 for (var event of this._openAsyncEvents.values()) {
372 event.setEndTime(this._maximumRecordTime); 334 event.setEndTime(this._maximumRecordTime);
373 // FIXME: remove this once we figure a better way to convert async console 335 // FIXME: remove this once we figure a better way to convert async console
374 // events to sync [waterfall] timeline records. 336 // events to sync [waterfall] timeline records.
375 event.steps[0].setEndTime(this._maximumRecordTime); 337 event.steps[0].setEndTime(this._maximumRecordTime);
376 } 338 }
377 this._openAsyncEvents.clear(); 339 this._openAsyncEvents.clear();
378 340
379 for (var eventStack of this._openNestableAsyncEvents.values()) { 341 for (var eventStack of this._openNestableAsyncEvents.values()) {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 /** @type {string} */ 518 /** @type {string} */
557 this.name = name; 519 this.name = name;
558 /** @type {!SDK.TracingModel.Phase} */ 520 /** @type {!SDK.TracingModel.Phase} */
559 this.phase = phase; 521 this.phase = phase;
560 /** @type {number} */ 522 /** @type {number} */
561 this.startTime = startTime; 523 this.startTime = startTime;
562 /** @type {!SDK.TracingModel.Thread} */ 524 /** @type {!SDK.TracingModel.Thread} */
563 this.thread = thread; 525 this.thread = thread;
564 /** @type {!Object} */ 526 /** @type {!Object} */
565 this.args = {}; 527 this.args = {};
566 /** @type {!SDK.TracingModel.Event|undefined} */
567 this.nextFlow;
568 /** @type {!SDK.TracingModel.Event|undefined} */
569 this.previousFlow;
570 528
571 /** @type {number} */ 529 /** @type {number} */
572 this.selfTime = 0; 530 this.selfTime = 0;
573 } 531 }
574 532
575 /** 533 /**
576 * @param {!SDK.TracingManager.EventPayload} payload 534 * @param {!SDK.TracingManager.EventPayload} payload
577 * @param {!SDK.TracingModel.Thread} thread 535 * @param {!SDK.TracingModel.Thread} thread
578 * @return {!SDK.TracingModel.Event} 536 * @return {!SDK.TracingModel.Event}
579 */ 537 */
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 */ 621 */
664 _complete(endEvent) { 622 _complete(endEvent) {
665 if (endEvent.args) 623 if (endEvent.args)
666 this.addArgs(endEvent.args); 624 this.addArgs(endEvent.args);
667 else 625 else
668 console.error('Missing mandatory event argument \'args\' at ' + endEvent.s tartTime); 626 console.error('Missing mandatory event argument \'args\' at ' + endEvent.s tartTime);
669 this.setEndTime(endEvent.startTime); 627 this.setEndTime(endEvent.startTime);
670 } 628 }
671 629
672 /** 630 /**
673 * @param {!SDK.TracingModel.Event} nextFlow
674 */
675 _appendFlowEvent(nextFlow) {
676 this.nextFlow = nextFlow;
677 nextFlow.previousFlow = this;
678 }
679
680 /**
681 * @param {?function():!Promise.<?string>} backingStorage 631 * @param {?function():!Promise.<?string>} backingStorage
682 */ 632 */
683 _setBackingStorage(backingStorage) { 633 _setBackingStorage(backingStorage) {
684 } 634 }
685 }; 635 };
686 636
687 SDK.TracingModel.ObjectSnapshot = class extends SDK.TracingModel.Event { 637 SDK.TracingModel.ObjectSnapshot = class extends SDK.TracingModel.Event {
688 /** 638 /**
689 * @param {string} category 639 * @param {string} category
690 * @param {string} name 640 * @param {string} name
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 return this._events; 980 return this._events;
1031 } 981 }
1032 982
1033 /** 983 /**
1034 * @return {!Array.<!SDK.TracingModel.AsyncEvent>} 984 * @return {!Array.<!SDK.TracingModel.AsyncEvent>}
1035 */ 985 */
1036 asyncEvents() { 986 asyncEvents() {
1037 return this._asyncEvents; 987 return this._asyncEvents;
1038 } 988 }
1039 }; 989 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698