| OLD | NEW |
| 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 WebInspector.TracingModel = class { | 10 SDK.TracingModel = class { |
| 11 /** | 11 /** |
| 12 * @param {!WebInspector.BackingStorage} backingStorage | 12 * @param {!SDK.BackingStorage} backingStorage |
| 13 */ | 13 */ |
| 14 constructor(backingStorage) { | 14 constructor(backingStorage) { |
| 15 this._backingStorage = backingStorage; | 15 this._backingStorage = backingStorage; |
| 16 // Avoid extra reset of the storage as it's expensive. | 16 // Avoid extra reset of the storage as it's expensive. |
| 17 this._firstWritePending = true; | 17 this._firstWritePending = true; |
| 18 this.reset(); | 18 this.reset(); |
| 19 } | 19 } |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * @param {string} phase | 22 * @param {string} phase |
| 23 * @return {boolean} | 23 * @return {boolean} |
| 24 */ | 24 */ |
| 25 static isNestableAsyncPhase(phase) { | 25 static isNestableAsyncPhase(phase) { |
| 26 return phase === 'b' || phase === 'e' || phase === 'n'; | 26 return phase === 'b' || phase === 'e' || phase === 'n'; |
| 27 } | 27 } |
| 28 | 28 |
| 29 /** | 29 /** |
| 30 * @param {string} phase | 30 * @param {string} phase |
| 31 * @return {boolean} | 31 * @return {boolean} |
| 32 */ | 32 */ |
| 33 static isAsyncBeginPhase(phase) { | 33 static isAsyncBeginPhase(phase) { |
| 34 return phase === 'S' || phase === 'b'; | 34 return phase === 'S' || phase === 'b'; |
| 35 } | 35 } |
| 36 | 36 |
| 37 /** | 37 /** |
| 38 * @param {string} phase | 38 * @param {string} phase |
| 39 * @return {boolean} | 39 * @return {boolean} |
| 40 */ | 40 */ |
| 41 static isAsyncPhase(phase) { | 41 static isAsyncPhase(phase) { |
| 42 return WebInspector.TracingModel.isNestableAsyncPhase(phase) || phase === 'S
' || phase === 'T' || phase === 'F' || | 42 return SDK.TracingModel.isNestableAsyncPhase(phase) || phase === 'S' || phas
e === 'T' || phase === 'F' || |
| 43 phase === 'p'; | 43 phase === 'p'; |
| 44 } | 44 } |
| 45 | 45 |
| 46 /** | 46 /** |
| 47 * @param {string} phase | 47 * @param {string} phase |
| 48 * @return {boolean} | 48 * @return {boolean} |
| 49 */ | 49 */ |
| 50 static isFlowPhase(phase) { | 50 static isFlowPhase(phase) { |
| 51 return phase === 's' || phase === 't' || phase === 'f'; | 51 return phase === 's' || phase === 't' || phase === 'f'; |
| 52 } | 52 } |
| 53 | 53 |
| 54 /** | 54 /** |
| 55 * @param {!WebInspector.TracingModel.Event} event | 55 * @param {!SDK.TracingModel.Event} event |
| 56 * @return {boolean} | 56 * @return {boolean} |
| 57 */ | 57 */ |
| 58 static isTopLevelEvent(event) { | 58 static isTopLevelEvent(event) { |
| 59 return event.hasCategory(WebInspector.TracingModel.TopLevelEventCategory) || | 59 return event.hasCategory(SDK.TracingModel.TopLevelEventCategory) || |
| 60 event.hasCategory(WebInspector.TracingModel.DevToolsMetadataEventCategor
y) && | 60 event.hasCategory(SDK.TracingModel.DevToolsMetadataEventCategory) && |
| 61 event.name === 'Program'; // Older timelines may have this instead of t
oplevel. | 61 event.name === 'Program'; // Older timelines may have this instead of t
oplevel. |
| 62 } | 62 } |
| 63 | 63 |
| 64 /** | 64 /** |
| 65 * @param {!WebInspector.TracingManager.EventPayload} payload | 65 * @param {!SDK.TracingManager.EventPayload} payload |
| 66 * @return {string|undefined} | 66 * @return {string|undefined} |
| 67 */ | 67 */ |
| 68 static _extractId(payload) { | 68 static _extractId(payload) { |
| 69 var scope = payload.scope || ''; | 69 var scope = payload.scope || ''; |
| 70 if (typeof payload.id2 === 'undefined') | 70 if (typeof payload.id2 === 'undefined') |
| 71 return scope && payload.id ? `${scope}@${payload.id}` : payload.id; | 71 return scope && payload.id ? `${scope}@${payload.id}` : payload.id; |
| 72 var id2 = payload.id2; | 72 var id2 = payload.id2; |
| 73 if (typeof id2 === 'object' && ('global' in id2) !== ('local' in id2)) | 73 if (typeof id2 === 'object' && ('global' in id2) !== ('local' in id2)) |
| 74 return typeof id2['global'] !== 'undefined' ? `:${scope}:${id2['global']}`
: | 74 return typeof id2['global'] !== 'undefined' ? `:${scope}:${id2['global']}`
: |
| 75 `:${scope}:${payload.pid}:${
id2['local']}`; | 75 `:${scope}:${payload.pid}:${
id2['local']}`; |
| 76 console.error( | 76 console.error( |
| 77 `Unexpected id2 field at ${payload.ts / 1000}, one and only one of 'loca
l' and 'global' should be present.`); | 77 `Unexpected id2 field at ${payload.ts / 1000}, one and only one of 'loca
l' and 'global' should be present.`); |
| 78 } | 78 } |
| 79 | 79 |
| 80 /** | 80 /** |
| 81 * @param {!WebInspector.TracingModel} tracingModel | 81 * @param {!SDK.TracingModel} tracingModel |
| 82 * @return {?WebInspector.TracingModel.Thread} | 82 * @return {?SDK.TracingModel.Thread} |
| 83 * | 83 * |
| 84 * TODO: Move this to a better place. This is here just for convenience o | 84 * TODO: Move this to a better place. This is here just for convenience o |
| 85 * re-use between modules. This really belongs to a higher level, since it | 85 * re-use between modules. This really belongs to a higher level, since it |
| 86 * is specific to chrome's usage of tracing. | 86 * is specific to chrome's usage of tracing. |
| 87 */ | 87 */ |
| 88 static browserMainThread(tracingModel) { | 88 static browserMainThread(tracingModel) { |
| 89 var processes = tracingModel.sortedProcesses(); | 89 var processes = tracingModel.sortedProcesses(); |
| 90 // Avoid warning for an empty model. | 90 // Avoid warning for an empty model. |
| 91 if (!processes.length) | 91 if (!processes.length) |
| 92 return null; | 92 return null; |
| 93 var browserProcesses = []; | 93 var browserProcesses = []; |
| 94 var crRendererMainThreads = []; | 94 var crRendererMainThreads = []; |
| 95 for (var process of processes) { | 95 for (var process of processes) { |
| 96 if (process.name().toLowerCase().endsWith('browser')) | 96 if (process.name().toLowerCase().endsWith('browser')) |
| 97 browserProcesses.push(process); | 97 browserProcesses.push(process); |
| 98 crRendererMainThreads.push(...process.sortedThreads().filter(t => t.name()
=== 'CrBrowserMain')); | 98 crRendererMainThreads.push(...process.sortedThreads().filter(t => t.name()
=== 'CrBrowserMain')); |
| 99 } | 99 } |
| 100 if (crRendererMainThreads.length === 1) | 100 if (crRendererMainThreads.length === 1) |
| 101 return crRendererMainThreads[0]; | 101 return crRendererMainThreads[0]; |
| 102 if (browserProcesses.length === 1) | 102 if (browserProcesses.length === 1) |
| 103 return browserProcesses[0].threadByName('CrBrowserMain'); | 103 return browserProcesses[0].threadByName('CrBrowserMain'); |
| 104 var tracingStartedInBrowser = | 104 var tracingStartedInBrowser = |
| 105 tracingModel.devToolsMetadataEvents().filter(e => e.name === 'TracingSta
rtedInBrowser'); | 105 tracingModel.devToolsMetadataEvents().filter(e => e.name === 'TracingSta
rtedInBrowser'); |
| 106 if (tracingStartedInBrowser.length === 1) | 106 if (tracingStartedInBrowser.length === 1) |
| 107 return tracingStartedInBrowser[0].thread; | 107 return tracingStartedInBrowser[0].thread; |
| 108 WebInspector.console.error( | 108 Common.console.error( |
| 109 'Failed to find browser main thread in trace, some timeline features may
be unavailable'); | 109 'Failed to find browser main thread in trace, some timeline features may
be unavailable'); |
| 110 return null; | 110 return null; |
| 111 } | 111 } |
| 112 | 112 |
| 113 /** | 113 /** |
| 114 * @return {!Array.<!WebInspector.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 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events | 121 * @param {!Array.<!SDK.TracingManager.EventPayload>} events |
| 122 */ | 122 */ |
| 123 setEventsForTest(events) { | 123 setEventsForTest(events) { |
| 124 this.reset(); | 124 this.reset(); |
| 125 this.addEvents(events); | 125 this.addEvents(events); |
| 126 this.tracingComplete(); | 126 this.tracingComplete(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 /** | 129 /** |
| 130 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events | 130 * @param {!Array.<!SDK.TracingManager.EventPayload>} events |
| 131 */ | 131 */ |
| 132 addEvents(events) { | 132 addEvents(events) { |
| 133 for (var i = 0; i < events.length; ++i) | 133 for (var i = 0; i < events.length; ++i) |
| 134 this._addEvent(events[i]); | 134 this._addEvent(events[i]); |
| 135 } | 135 } |
| 136 | 136 |
| 137 tracingComplete() { | 137 tracingComplete() { |
| 138 this._processPendingAsyncEvents(); | 138 this._processPendingAsyncEvents(); |
| 139 this._backingStorage.appendString(this._firstWritePending ? '[]' : ']'); | 139 this._backingStorage.appendString(this._firstWritePending ? '[]' : ']'); |
| 140 this._backingStorage.finishWriting(); | 140 this._backingStorage.finishWriting(); |
| 141 this._firstWritePending = false; | 141 this._firstWritePending = false; |
| 142 for (var process of this._processById.values()) { | 142 for (var process of this._processById.values()) { |
| 143 for (var thread of process._threads.values()) | 143 for (var thread of process._threads.values()) |
| 144 thread.tracingComplete(); | 144 thread.tracingComplete(); |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 | 147 |
| 148 reset() { | 148 reset() { |
| 149 /** @type {!Map<(number|string), !WebInspector.TracingModel.Process>} */ | 149 /** @type {!Map<(number|string), !SDK.TracingModel.Process>} */ |
| 150 this._processById = new Map(); | 150 this._processById = new Map(); |
| 151 this._processByName = new Map(); | 151 this._processByName = new Map(); |
| 152 this._minimumRecordTime = 0; | 152 this._minimumRecordTime = 0; |
| 153 this._maximumRecordTime = 0; | 153 this._maximumRecordTime = 0; |
| 154 this._devToolsMetadataEvents = []; | 154 this._devToolsMetadataEvents = []; |
| 155 if (!this._firstWritePending) | 155 if (!this._firstWritePending) |
| 156 this._backingStorage.reset(); | 156 this._backingStorage.reset(); |
| 157 | 157 |
| 158 this._firstWritePending = true; | 158 this._firstWritePending = true; |
| 159 /** @type {!Array<!WebInspector.TracingModel.Event>} */ | 159 /** @type {!Array<!SDK.TracingModel.Event>} */ |
| 160 this._asyncEvents = []; | 160 this._asyncEvents = []; |
| 161 /** @type {!Map<string, !WebInspector.TracingModel.AsyncEvent>} */ | 161 /** @type {!Map<string, !SDK.TracingModel.AsyncEvent>} */ |
| 162 this._openAsyncEvents = new Map(); | 162 this._openAsyncEvents = new Map(); |
| 163 /** @type {!Map<string, !Array<!WebInspector.TracingModel.AsyncEvent>>} */ | 163 /** @type {!Map<string, !Array<!SDK.TracingModel.AsyncEvent>>} */ |
| 164 this._openNestableAsyncEvents = new Map(); | 164 this._openNestableAsyncEvents = new Map(); |
| 165 /** @type {!Map<string, !WebInspector.TracingModel.ProfileEventsGroup>} */ | 165 /** @type {!Map<string, !SDK.TracingModel.ProfileEventsGroup>} */ |
| 166 this._profileGroups = new Map(); | 166 this._profileGroups = new Map(); |
| 167 /** @type {!Map<string, !Set<string>>} */ | 167 /** @type {!Map<string, !Set<string>>} */ |
| 168 this._parsedCategories = new Map(); | 168 this._parsedCategories = new Map(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 /** | 171 /** |
| 172 * @param {!WebInspector.TracingManager.EventPayload} payload | 172 * @param {!SDK.TracingManager.EventPayload} payload |
| 173 */ | 173 */ |
| 174 _addEvent(payload) { | 174 _addEvent(payload) { |
| 175 var process = this._processById.get(payload.pid); | 175 var process = this._processById.get(payload.pid); |
| 176 if (!process) { | 176 if (!process) { |
| 177 process = new WebInspector.TracingModel.Process(this, payload.pid); | 177 process = new SDK.TracingModel.Process(this, payload.pid); |
| 178 this._processById.set(payload.pid, process); | 178 this._processById.set(payload.pid, process); |
| 179 } | 179 } |
| 180 | 180 |
| 181 var eventsDelimiter = ',\n'; | 181 var eventsDelimiter = ',\n'; |
| 182 this._backingStorage.appendString(this._firstWritePending ? '[' : eventsDeli
miter); | 182 this._backingStorage.appendString(this._firstWritePending ? '[' : eventsDeli
miter); |
| 183 this._firstWritePending = false; | 183 this._firstWritePending = false; |
| 184 var stringPayload = JSON.stringify(payload); | 184 var stringPayload = JSON.stringify(payload); |
| 185 var isAccessible = payload.ph === WebInspector.TracingModel.Phase.SnapshotOb
ject; | 185 var isAccessible = payload.ph === SDK.TracingModel.Phase.SnapshotObject; |
| 186 var backingStorage = null; | 186 var backingStorage = null; |
| 187 var keepStringsLessThan = 10000; | 187 var keepStringsLessThan = 10000; |
| 188 if (isAccessible && stringPayload.length > keepStringsLessThan) | 188 if (isAccessible && stringPayload.length > keepStringsLessThan) |
| 189 backingStorage = this._backingStorage.appendAccessibleString(stringPayload
); | 189 backingStorage = this._backingStorage.appendAccessibleString(stringPayload
); |
| 190 else | 190 else |
| 191 this._backingStorage.appendString(stringPayload); | 191 this._backingStorage.appendString(stringPayload); |
| 192 | 192 |
| 193 var timestamp = payload.ts / 1000; | 193 var timestamp = payload.ts / 1000; |
| 194 // We do allow records for unrelated threads to arrive out-of-order, | 194 // We do allow records for unrelated threads to arrive out-of-order, |
| 195 // so there's a chance we're getting records from the past. | 195 // so there's a chance we're getting records from the past. |
| 196 if (timestamp && (!this._minimumRecordTime || timestamp < this._minimumRecor
dTime)) | 196 if (timestamp && (!this._minimumRecordTime || timestamp < this._minimumRecor
dTime)) |
| 197 this._minimumRecordTime = timestamp; | 197 this._minimumRecordTime = timestamp; |
| 198 var endTimeStamp = (payload.ts + (payload.dur || 0)) / 1000; | 198 var endTimeStamp = (payload.ts + (payload.dur || 0)) / 1000; |
| 199 this._maximumRecordTime = Math.max(this._maximumRecordTime, endTimeStamp); | 199 this._maximumRecordTime = Math.max(this._maximumRecordTime, endTimeStamp); |
| 200 var event = process._addEvent(payload); | 200 var event = process._addEvent(payload); |
| 201 if (!event) | 201 if (!event) |
| 202 return; | 202 return; |
| 203 if (payload.ph === WebInspector.TracingModel.Phase.Sample) { | 203 if (payload.ph === SDK.TracingModel.Phase.Sample) { |
| 204 this._addSampleEvent(event); | 204 this._addSampleEvent(event); |
| 205 return; | 205 return; |
| 206 } | 206 } |
| 207 // Build async event when we've got events from all threads & processes, so
we can sort them and process in the | 207 // Build async event when we've got events from all threads & processes, so
we can sort them and process in the |
| 208 // chronological order. However, also add individual async events to the thr
ead flow (above), so we can easily | 208 // chronological order. However, also add individual async events to the thr
ead flow (above), so we can easily |
| 209 // display them on the same chart as other events, should we choose so. | 209 // display them on the same chart as other events, should we choose so. |
| 210 if (WebInspector.TracingModel.isAsyncPhase(payload.ph)) | 210 if (SDK.TracingModel.isAsyncPhase(payload.ph)) |
| 211 this._asyncEvents.push(event); | 211 this._asyncEvents.push(event); |
| 212 event._setBackingStorage(backingStorage); | 212 event._setBackingStorage(backingStorage); |
| 213 if (event.hasCategory(WebInspector.TracingModel.DevToolsMetadataEventCategor
y)) | 213 if (event.hasCategory(SDK.TracingModel.DevToolsMetadataEventCategory)) |
| 214 this._devToolsMetadataEvents.push(event); | 214 this._devToolsMetadataEvents.push(event); |
| 215 | 215 |
| 216 if (payload.ph !== WebInspector.TracingModel.Phase.Metadata) | 216 if (payload.ph !== SDK.TracingModel.Phase.Metadata) |
| 217 return; | 217 return; |
| 218 | 218 |
| 219 switch (payload.name) { | 219 switch (payload.name) { |
| 220 case WebInspector.TracingModel.MetadataEvent.ProcessSortIndex: | 220 case SDK.TracingModel.MetadataEvent.ProcessSortIndex: |
| 221 process._setSortIndex(payload.args['sort_index']); | 221 process._setSortIndex(payload.args['sort_index']); |
| 222 break; | 222 break; |
| 223 case WebInspector.TracingModel.MetadataEvent.ProcessName: | 223 case SDK.TracingModel.MetadataEvent.ProcessName: |
| 224 var processName = payload.args['name']; | 224 var processName = payload.args['name']; |
| 225 process._setName(processName); | 225 process._setName(processName); |
| 226 this._processByName.set(processName, process); | 226 this._processByName.set(processName, process); |
| 227 break; | 227 break; |
| 228 case WebInspector.TracingModel.MetadataEvent.ThreadSortIndex: | 228 case SDK.TracingModel.MetadataEvent.ThreadSortIndex: |
| 229 process.threadById(payload.tid)._setSortIndex(payload.args['sort_index']
); | 229 process.threadById(payload.tid)._setSortIndex(payload.args['sort_index']
); |
| 230 break; | 230 break; |
| 231 case WebInspector.TracingModel.MetadataEvent.ThreadName: | 231 case SDK.TracingModel.MetadataEvent.ThreadName: |
| 232 process.threadById(payload.tid)._setName(payload.args['name']); | 232 process.threadById(payload.tid)._setName(payload.args['name']); |
| 233 break; | 233 break; |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 | 236 |
| 237 /** | 237 /** |
| 238 * @param {!WebInspector.TracingModel.Event} event | 238 * @param {!SDK.TracingModel.Event} event |
| 239 */ | 239 */ |
| 240 _addSampleEvent(event) { | 240 _addSampleEvent(event) { |
| 241 var group = this._profileGroups.get(event.id); | 241 var group = this._profileGroups.get(event.id); |
| 242 if (group) | 242 if (group) |
| 243 group._addChild(event); | 243 group._addChild(event); |
| 244 else | 244 else |
| 245 this._profileGroups.set(event.id, new WebInspector.TracingModel.ProfileEve
ntsGroup(event)); | 245 this._profileGroups.set(event.id, new SDK.TracingModel.ProfileEventsGroup(
event)); |
| 246 } | 246 } |
| 247 | 247 |
| 248 /** | 248 /** |
| 249 * @param {string} id | 249 * @param {string} id |
| 250 * @return {?WebInspector.TracingModel.ProfileEventsGroup} | 250 * @return {?SDK.TracingModel.ProfileEventsGroup} |
| 251 */ | 251 */ |
| 252 profileGroup(id) { | 252 profileGroup(id) { |
| 253 return this._profileGroups.get(id) || null; | 253 return this._profileGroups.get(id) || null; |
| 254 } | 254 } |
| 255 | 255 |
| 256 /** | 256 /** |
| 257 * @return {number} | 257 * @return {number} |
| 258 */ | 258 */ |
| 259 minimumRecordTime() { | 259 minimumRecordTime() { |
| 260 return this._minimumRecordTime; | 260 return this._minimumRecordTime; |
| 261 } | 261 } |
| 262 | 262 |
| 263 /** | 263 /** |
| 264 * @return {number} | 264 * @return {number} |
| 265 */ | 265 */ |
| 266 maximumRecordTime() { | 266 maximumRecordTime() { |
| 267 return this._maximumRecordTime; | 267 return this._maximumRecordTime; |
| 268 } | 268 } |
| 269 | 269 |
| 270 /** | 270 /** |
| 271 * @return {!Array.<!WebInspector.TracingModel.Process>} | 271 * @return {!Array.<!SDK.TracingModel.Process>} |
| 272 */ | 272 */ |
| 273 sortedProcesses() { | 273 sortedProcesses() { |
| 274 return WebInspector.TracingModel.NamedObject._sort(this._processById.valuesA
rray()); | 274 return SDK.TracingModel.NamedObject._sort(this._processById.valuesArray()); |
| 275 } | 275 } |
| 276 | 276 |
| 277 /** | 277 /** |
| 278 * @param {string} name | 278 * @param {string} name |
| 279 * @return {?WebInspector.TracingModel.Process} | 279 * @return {?SDK.TracingModel.Process} |
| 280 */ | 280 */ |
| 281 processByName(name) { | 281 processByName(name) { |
| 282 return this._processByName.get(name); | 282 return this._processByName.get(name); |
| 283 } | 283 } |
| 284 | 284 |
| 285 /** | 285 /** |
| 286 * @param {string} processName | 286 * @param {string} processName |
| 287 * @param {string} threadName | 287 * @param {string} threadName |
| 288 * @return {?WebInspector.TracingModel.Thread} | 288 * @return {?SDK.TracingModel.Thread} |
| 289 */ | 289 */ |
| 290 threadByName(processName, threadName) { | 290 threadByName(processName, threadName) { |
| 291 var process = this.processByName(processName); | 291 var process = this.processByName(processName); |
| 292 return process && process.threadByName(threadName); | 292 return process && process.threadByName(threadName); |
| 293 } | 293 } |
| 294 | 294 |
| 295 _processPendingAsyncEvents() { | 295 _processPendingAsyncEvents() { |
| 296 this._asyncEvents.stableSort(WebInspector.TracingModel.Event.compareStartTim
e); | 296 this._asyncEvents.stableSort(SDK.TracingModel.Event.compareStartTime); |
| 297 for (var i = 0; i < this._asyncEvents.length; ++i) { | 297 for (var i = 0; i < this._asyncEvents.length; ++i) { |
| 298 var event = this._asyncEvents[i]; | 298 var event = this._asyncEvents[i]; |
| 299 if (WebInspector.TracingModel.isNestableAsyncPhase(event.phase)) | 299 if (SDK.TracingModel.isNestableAsyncPhase(event.phase)) |
| 300 this._addNestableAsyncEvent(event); | 300 this._addNestableAsyncEvent(event); |
| 301 else | 301 else |
| 302 this._addAsyncEvent(event); | 302 this._addAsyncEvent(event); |
| 303 } | 303 } |
| 304 this._asyncEvents = []; | 304 this._asyncEvents = []; |
| 305 this._closeOpenAsyncEvents(); | 305 this._closeOpenAsyncEvents(); |
| 306 } | 306 } |
| 307 | 307 |
| 308 _closeOpenAsyncEvents() { | 308 _closeOpenAsyncEvents() { |
| 309 for (var event of this._openAsyncEvents.values()) { | 309 for (var event of this._openAsyncEvents.values()) { |
| 310 event.setEndTime(this._maximumRecordTime); | 310 event.setEndTime(this._maximumRecordTime); |
| 311 // FIXME: remove this once we figure a better way to convert async console | 311 // FIXME: remove this once we figure a better way to convert async console |
| 312 // events to sync [waterfall] timeline records. | 312 // events to sync [waterfall] timeline records. |
| 313 event.steps[0].setEndTime(this._maximumRecordTime); | 313 event.steps[0].setEndTime(this._maximumRecordTime); |
| 314 } | 314 } |
| 315 this._openAsyncEvents.clear(); | 315 this._openAsyncEvents.clear(); |
| 316 | 316 |
| 317 for (var eventStack of this._openNestableAsyncEvents.values()) { | 317 for (var eventStack of this._openNestableAsyncEvents.values()) { |
| 318 while (eventStack.length) | 318 while (eventStack.length) |
| 319 eventStack.pop().setEndTime(this._maximumRecordTime); | 319 eventStack.pop().setEndTime(this._maximumRecordTime); |
| 320 } | 320 } |
| 321 this._openNestableAsyncEvents.clear(); | 321 this._openNestableAsyncEvents.clear(); |
| 322 } | 322 } |
| 323 | 323 |
| 324 /** | 324 /** |
| 325 * @param {!WebInspector.TracingModel.Event} event | 325 * @param {!SDK.TracingModel.Event} event |
| 326 */ | 326 */ |
| 327 _addNestableAsyncEvent(event) { | 327 _addNestableAsyncEvent(event) { |
| 328 var phase = WebInspector.TracingModel.Phase; | 328 var phase = SDK.TracingModel.Phase; |
| 329 var key = event.categoriesString + '.' + event.id; | 329 var key = event.categoriesString + '.' + event.id; |
| 330 var openEventsStack = this._openNestableAsyncEvents.get(key); | 330 var openEventsStack = this._openNestableAsyncEvents.get(key); |
| 331 | 331 |
| 332 switch (event.phase) { | 332 switch (event.phase) { |
| 333 case phase.NestableAsyncBegin: | 333 case phase.NestableAsyncBegin: |
| 334 if (!openEventsStack) { | 334 if (!openEventsStack) { |
| 335 openEventsStack = []; | 335 openEventsStack = []; |
| 336 this._openNestableAsyncEvents.set(key, openEventsStack); | 336 this._openNestableAsyncEvents.set(key, openEventsStack); |
| 337 } | 337 } |
| 338 var asyncEvent = new WebInspector.TracingModel.AsyncEvent(event); | 338 var asyncEvent = new SDK.TracingModel.AsyncEvent(event); |
| 339 openEventsStack.push(asyncEvent); | 339 openEventsStack.push(asyncEvent); |
| 340 event.thread._addAsyncEvent(asyncEvent); | 340 event.thread._addAsyncEvent(asyncEvent); |
| 341 break; | 341 break; |
| 342 | 342 |
| 343 case phase.NestableAsyncInstant: | 343 case phase.NestableAsyncInstant: |
| 344 if (openEventsStack && openEventsStack.length) | 344 if (openEventsStack && openEventsStack.length) |
| 345 openEventsStack.peekLast()._addStep(event); | 345 openEventsStack.peekLast()._addStep(event); |
| 346 break; | 346 break; |
| 347 | 347 |
| 348 case phase.NestableAsyncEnd: | 348 case phase.NestableAsyncEnd: |
| 349 if (!openEventsStack || !openEventsStack.length) | 349 if (!openEventsStack || !openEventsStack.length) |
| 350 break; | 350 break; |
| 351 var top = openEventsStack.pop(); | 351 var top = openEventsStack.pop(); |
| 352 if (top.name !== event.name) { | 352 if (top.name !== event.name) { |
| 353 console.error( | 353 console.error( |
| 354 `Begin/end event mismatch for nestable async event, ${top.name} vs
. ${event.name}, key: ${key}`); | 354 `Begin/end event mismatch for nestable async event, ${top.name} vs
. ${event.name}, key: ${key}`); |
| 355 break; | 355 break; |
| 356 } | 356 } |
| 357 top._addStep(event); | 357 top._addStep(event); |
| 358 } | 358 } |
| 359 } | 359 } |
| 360 | 360 |
| 361 /** | 361 /** |
| 362 * @param {!WebInspector.TracingModel.Event} event | 362 * @param {!SDK.TracingModel.Event} event |
| 363 */ | 363 */ |
| 364 _addAsyncEvent(event) { | 364 _addAsyncEvent(event) { |
| 365 var phase = WebInspector.TracingModel.Phase; | 365 var phase = SDK.TracingModel.Phase; |
| 366 var key = event.categoriesString + '.' + event.name + '.' + event.id; | 366 var key = event.categoriesString + '.' + event.name + '.' + event.id; |
| 367 var asyncEvent = this._openAsyncEvents.get(key); | 367 var asyncEvent = this._openAsyncEvents.get(key); |
| 368 | 368 |
| 369 if (event.phase === phase.AsyncBegin) { | 369 if (event.phase === phase.AsyncBegin) { |
| 370 if (asyncEvent) { | 370 if (asyncEvent) { |
| 371 console.error(`Event ${event.name} has already been started`); | 371 console.error(`Event ${event.name} has already been started`); |
| 372 return; | 372 return; |
| 373 } | 373 } |
| 374 asyncEvent = new WebInspector.TracingModel.AsyncEvent(event); | 374 asyncEvent = new SDK.TracingModel.AsyncEvent(event); |
| 375 this._openAsyncEvents.set(key, asyncEvent); | 375 this._openAsyncEvents.set(key, asyncEvent); |
| 376 event.thread._addAsyncEvent(asyncEvent); | 376 event.thread._addAsyncEvent(asyncEvent); |
| 377 return; | 377 return; |
| 378 } | 378 } |
| 379 if (!asyncEvent) { | 379 if (!asyncEvent) { |
| 380 // Quietly ignore stray async events, we're probably too late for the star
t. | 380 // Quietly ignore stray async events, we're probably too late for the star
t. |
| 381 return; | 381 return; |
| 382 } | 382 } |
| 383 if (event.phase === phase.AsyncEnd) { | 383 if (event.phase === phase.AsyncEnd) { |
| 384 asyncEvent._addStep(event); | 384 asyncEvent._addStep(event); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 409 parsedCategories = new Set(str.split(',')); | 409 parsedCategories = new Set(str.split(',')); |
| 410 this._parsedCategories.set(str, parsedCategories); | 410 this._parsedCategories.set(str, parsedCategories); |
| 411 } | 411 } |
| 412 return parsedCategories; | 412 return parsedCategories; |
| 413 } | 413 } |
| 414 }; | 414 }; |
| 415 | 415 |
| 416 /** | 416 /** |
| 417 * @enum {string} | 417 * @enum {string} |
| 418 */ | 418 */ |
| 419 WebInspector.TracingModel.Phase = { | 419 SDK.TracingModel.Phase = { |
| 420 Begin: 'B', | 420 Begin: 'B', |
| 421 End: 'E', | 421 End: 'E', |
| 422 Complete: 'X', | 422 Complete: 'X', |
| 423 Instant: 'I', | 423 Instant: 'I', |
| 424 AsyncBegin: 'S', | 424 AsyncBegin: 'S', |
| 425 AsyncStepInto: 'T', | 425 AsyncStepInto: 'T', |
| 426 AsyncStepPast: 'p', | 426 AsyncStepPast: 'p', |
| 427 AsyncEnd: 'F', | 427 AsyncEnd: 'F', |
| 428 NestableAsyncBegin: 'b', | 428 NestableAsyncBegin: 'b', |
| 429 NestableAsyncEnd: 'e', | 429 NestableAsyncEnd: 'e', |
| 430 NestableAsyncInstant: 'n', | 430 NestableAsyncInstant: 'n', |
| 431 FlowBegin: 's', | 431 FlowBegin: 's', |
| 432 FlowStep: 't', | 432 FlowStep: 't', |
| 433 FlowEnd: 'f', | 433 FlowEnd: 'f', |
| 434 Metadata: 'M', | 434 Metadata: 'M', |
| 435 Counter: 'C', | 435 Counter: 'C', |
| 436 Sample: 'P', | 436 Sample: 'P', |
| 437 CreateObject: 'N', | 437 CreateObject: 'N', |
| 438 SnapshotObject: 'O', | 438 SnapshotObject: 'O', |
| 439 DeleteObject: 'D' | 439 DeleteObject: 'D' |
| 440 }; | 440 }; |
| 441 | 441 |
| 442 WebInspector.TracingModel.MetadataEvent = { | 442 SDK.TracingModel.MetadataEvent = { |
| 443 ProcessSortIndex: 'process_sort_index', | 443 ProcessSortIndex: 'process_sort_index', |
| 444 ProcessName: 'process_name', | 444 ProcessName: 'process_name', |
| 445 ThreadSortIndex: 'thread_sort_index', | 445 ThreadSortIndex: 'thread_sort_index', |
| 446 ThreadName: 'thread_name' | 446 ThreadName: 'thread_name' |
| 447 }; | 447 }; |
| 448 | 448 |
| 449 WebInspector.TracingModel.TopLevelEventCategory = 'toplevel'; | 449 SDK.TracingModel.TopLevelEventCategory = 'toplevel'; |
| 450 WebInspector.TracingModel.DevToolsMetadataEventCategory = 'disabled-by-default-d
evtools.timeline'; | 450 SDK.TracingModel.DevToolsMetadataEventCategory = 'disabled-by-default-devtools.t
imeline'; |
| 451 WebInspector.TracingModel.DevToolsTimelineEventCategory = 'disabled-by-default-d
evtools.timeline'; | 451 SDK.TracingModel.DevToolsTimelineEventCategory = 'disabled-by-default-devtools.t
imeline'; |
| 452 | 452 |
| 453 WebInspector.TracingModel.FrameLifecycleEventCategory = 'cc,devtools'; | 453 SDK.TracingModel.FrameLifecycleEventCategory = 'cc,devtools'; |
| 454 | 454 |
| 455 | 455 |
| 456 /** | 456 /** |
| 457 * @interface | 457 * @interface |
| 458 */ | 458 */ |
| 459 WebInspector.BackingStorage = function() {}; | 459 SDK.BackingStorage = function() {}; |
| 460 | 460 |
| 461 WebInspector.BackingStorage.prototype = { | 461 SDK.BackingStorage.prototype = { |
| 462 /** | 462 /** |
| 463 * @param {string} string | 463 * @param {string} string |
| 464 */ | 464 */ |
| 465 appendString: function(string) {}, | 465 appendString: function(string) {}, |
| 466 | 466 |
| 467 /** | 467 /** |
| 468 * @param {string} string | 468 * @param {string} string |
| 469 * @return {function():!Promise.<?string>} | 469 * @return {function():!Promise.<?string>} |
| 470 */ | 470 */ |
| 471 appendAccessibleString: function(string) {}, | 471 appendAccessibleString: function(string) {}, |
| 472 | 472 |
| 473 finishWriting: function() {}, | 473 finishWriting: function() {}, |
| 474 | 474 |
| 475 reset: function() {}, | 475 reset: function() {}, |
| 476 }; | 476 }; |
| 477 | 477 |
| 478 /** | 478 /** |
| 479 * @unrestricted | 479 * @unrestricted |
| 480 */ | 480 */ |
| 481 WebInspector.TracingModel.Event = class { | 481 SDK.TracingModel.Event = class { |
| 482 /** | 482 /** |
| 483 * @param {string} categories | 483 * @param {string} categories |
| 484 * @param {string} name | 484 * @param {string} name |
| 485 * @param {!WebInspector.TracingModel.Phase} phase | 485 * @param {!SDK.TracingModel.Phase} phase |
| 486 * @param {number} startTime | 486 * @param {number} startTime |
| 487 * @param {!WebInspector.TracingModel.Thread} thread | 487 * @param {!SDK.TracingModel.Thread} thread |
| 488 */ | 488 */ |
| 489 constructor(categories, name, phase, startTime, thread) { | 489 constructor(categories, name, phase, startTime, thread) { |
| 490 /** @type {string} */ | 490 /** @type {string} */ |
| 491 this.categoriesString = categories; | 491 this.categoriesString = categories; |
| 492 /** @type {!Set<string>} */ | 492 /** @type {!Set<string>} */ |
| 493 this._parsedCategories = thread._model._parsedCategoriesForString(categories
); | 493 this._parsedCategories = thread._model._parsedCategoriesForString(categories
); |
| 494 /** @type {string} */ | 494 /** @type {string} */ |
| 495 this.name = name; | 495 this.name = name; |
| 496 /** @type {!WebInspector.TracingModel.Phase} */ | 496 /** @type {!SDK.TracingModel.Phase} */ |
| 497 this.phase = phase; | 497 this.phase = phase; |
| 498 /** @type {number} */ | 498 /** @type {number} */ |
| 499 this.startTime = startTime; | 499 this.startTime = startTime; |
| 500 /** @type {!WebInspector.TracingModel.Thread} */ | 500 /** @type {!SDK.TracingModel.Thread} */ |
| 501 this.thread = thread; | 501 this.thread = thread; |
| 502 /** @type {!Object} */ | 502 /** @type {!Object} */ |
| 503 this.args = {}; | 503 this.args = {}; |
| 504 | 504 |
| 505 /** @type {number} */ | 505 /** @type {number} */ |
| 506 this.selfTime = 0; | 506 this.selfTime = 0; |
| 507 } | 507 } |
| 508 | 508 |
| 509 /** | 509 /** |
| 510 * @param {!WebInspector.TracingManager.EventPayload} payload | 510 * @param {!SDK.TracingManager.EventPayload} payload |
| 511 * @param {!WebInspector.TracingModel.Thread} thread | 511 * @param {!SDK.TracingModel.Thread} thread |
| 512 * @return {!WebInspector.TracingModel.Event} | 512 * @return {!SDK.TracingModel.Event} |
| 513 */ | 513 */ |
| 514 static fromPayload(payload, thread) { | 514 static fromPayload(payload, thread) { |
| 515 var event = new WebInspector.TracingModel.Event( | 515 var event = new SDK.TracingModel.Event( |
| 516 payload.cat, payload.name, /** @type {!WebInspector.TracingModel.Phase}
*/ (payload.ph), payload.ts / 1000, | 516 payload.cat, payload.name, /** @type {!SDK.TracingModel.Phase} */ (paylo
ad.ph), payload.ts / 1000, |
| 517 thread); | 517 thread); |
| 518 if (payload.args) | 518 if (payload.args) |
| 519 event.addArgs(payload.args); | 519 event.addArgs(payload.args); |
| 520 else | 520 else |
| 521 console.error('Missing mandatory event argument \'args\' at ' + payload.ts
/ 1000); | 521 console.error('Missing mandatory event argument \'args\' at ' + payload.ts
/ 1000); |
| 522 if (typeof payload.dur === 'number') | 522 if (typeof payload.dur === 'number') |
| 523 event.setEndTime((payload.ts + payload.dur) / 1000); | 523 event.setEndTime((payload.ts + payload.dur) / 1000); |
| 524 var id = WebInspector.TracingModel._extractId(payload); | 524 var id = SDK.TracingModel._extractId(payload); |
| 525 if (typeof id !== 'undefined') | 525 if (typeof id !== 'undefined') |
| 526 event.id = id; | 526 event.id = id; |
| 527 if (payload.bind_id) | 527 if (payload.bind_id) |
| 528 event.bind_id = payload.bind_id; | 528 event.bind_id = payload.bind_id; |
| 529 | 529 |
| 530 return event; | 530 return event; |
| 531 } | 531 } |
| 532 | 532 |
| 533 /** | 533 /** |
| 534 * @param {!WebInspector.TracingModel.Event} a | 534 * @param {!SDK.TracingModel.Event} a |
| 535 * @param {!WebInspector.TracingModel.Event} b | 535 * @param {!SDK.TracingModel.Event} b |
| 536 * @return {number} | 536 * @return {number} |
| 537 */ | 537 */ |
| 538 static compareStartTime(a, b) { | 538 static compareStartTime(a, b) { |
| 539 return a.startTime - b.startTime; | 539 return a.startTime - b.startTime; |
| 540 } | 540 } |
| 541 | 541 |
| 542 /** | 542 /** |
| 543 * @param {!WebInspector.TracingModel.Event} a | 543 * @param {!SDK.TracingModel.Event} a |
| 544 * @param {!WebInspector.TracingModel.Event} b | 544 * @param {!SDK.TracingModel.Event} b |
| 545 * @return {number} | 545 * @return {number} |
| 546 */ | 546 */ |
| 547 static compareStartAndEndTime(a, b) { | 547 static compareStartAndEndTime(a, b) { |
| 548 return a.startTime - b.startTime || (b.endTime !== undefined && a.endTime !=
= undefined && b.endTime - a.endTime) || | 548 return a.startTime - b.startTime || (b.endTime !== undefined && a.endTime !=
= undefined && b.endTime - a.endTime) || |
| 549 0; | 549 0; |
| 550 } | 550 } |
| 551 | 551 |
| 552 /** | 552 /** |
| 553 * @param {!WebInspector.TracingModel.Event} a | 553 * @param {!SDK.TracingModel.Event} a |
| 554 * @param {!WebInspector.TracingModel.Event} b | 554 * @param {!SDK.TracingModel.Event} b |
| 555 * @return {number} | 555 * @return {number} |
| 556 */ | 556 */ |
| 557 static orderedCompareStartTime(a, b) { | 557 static orderedCompareStartTime(a, b) { |
| 558 // Array.mergeOrdered coalesces objects if comparator returns 0. | 558 // Array.mergeOrdered coalesces objects if comparator returns 0. |
| 559 // To change this behavior this comparator return -1 in the case events | 559 // To change this behavior this comparator return -1 in the case events |
| 560 // startTime's are equal, so both events got placed into the result array. | 560 // startTime's are equal, so both events got placed into the result array. |
| 561 return a.startTime - b.startTime || a.ordinal - b.ordinal || -1; | 561 return a.startTime - b.startTime || a.ordinal - b.ordinal || -1; |
| 562 } | 562 } |
| 563 | 563 |
| 564 /** | 564 /** |
| (...skipping 22 matching lines...) Expand all Loading... |
| 587 addArgs(args) { | 587 addArgs(args) { |
| 588 // Shallow copy args to avoid modifying original payload which may be saved
to file. | 588 // Shallow copy args to avoid modifying original payload which may be saved
to file. |
| 589 for (var name in args) { | 589 for (var name in args) { |
| 590 if (name in this.args) | 590 if (name in this.args) |
| 591 console.error('Same argument name (' + name + ') is used for begin and e
nd phases of ' + this.name); | 591 console.error('Same argument name (' + name + ') is used for begin and e
nd phases of ' + this.name); |
| 592 this.args[name] = args[name]; | 592 this.args[name] = args[name]; |
| 593 } | 593 } |
| 594 } | 594 } |
| 595 | 595 |
| 596 /** | 596 /** |
| 597 * @param {!WebInspector.TracingModel.Event} endEvent | 597 * @param {!SDK.TracingModel.Event} endEvent |
| 598 */ | 598 */ |
| 599 _complete(endEvent) { | 599 _complete(endEvent) { |
| 600 if (endEvent.args) | 600 if (endEvent.args) |
| 601 this.addArgs(endEvent.args); | 601 this.addArgs(endEvent.args); |
| 602 else | 602 else |
| 603 console.error('Missing mandatory event argument \'args\' at ' + endEvent.s
tartTime); | 603 console.error('Missing mandatory event argument \'args\' at ' + endEvent.s
tartTime); |
| 604 this.setEndTime(endEvent.startTime); | 604 this.setEndTime(endEvent.startTime); |
| 605 } | 605 } |
| 606 | 606 |
| 607 /** | 607 /** |
| 608 * @param {?function():!Promise.<?string>} backingStorage | 608 * @param {?function():!Promise.<?string>} backingStorage |
| 609 */ | 609 */ |
| 610 _setBackingStorage(backingStorage) { | 610 _setBackingStorage(backingStorage) { |
| 611 } | 611 } |
| 612 }; | 612 }; |
| 613 | 613 |
| 614 | 614 |
| 615 /** | 615 /** |
| 616 * @unrestricted | 616 * @unrestricted |
| 617 */ | 617 */ |
| 618 WebInspector.TracingModel.ObjectSnapshot = class extends WebInspector.TracingMod
el.Event { | 618 SDK.TracingModel.ObjectSnapshot = class extends SDK.TracingModel.Event { |
| 619 /** | 619 /** |
| 620 * @param {string} category | 620 * @param {string} category |
| 621 * @param {string} name | 621 * @param {string} name |
| 622 * @param {number} startTime | 622 * @param {number} startTime |
| 623 * @param {!WebInspector.TracingModel.Thread} thread | 623 * @param {!SDK.TracingModel.Thread} thread |
| 624 */ | 624 */ |
| 625 constructor(category, name, startTime, thread) { | 625 constructor(category, name, startTime, thread) { |
| 626 super(category, name, WebInspector.TracingModel.Phase.SnapshotObject, startT
ime, thread); | 626 super(category, name, SDK.TracingModel.Phase.SnapshotObject, startTime, thre
ad); |
| 627 } | 627 } |
| 628 | 628 |
| 629 /** | 629 /** |
| 630 * @param {!WebInspector.TracingManager.EventPayload} payload | 630 * @param {!SDK.TracingManager.EventPayload} payload |
| 631 * @param {!WebInspector.TracingModel.Thread} thread | 631 * @param {!SDK.TracingModel.Thread} thread |
| 632 * @return {!WebInspector.TracingModel.ObjectSnapshot} | 632 * @return {!SDK.TracingModel.ObjectSnapshot} |
| 633 */ | 633 */ |
| 634 static fromPayload(payload, thread) { | 634 static fromPayload(payload, thread) { |
| 635 var snapshot = new WebInspector.TracingModel.ObjectSnapshot(payload.cat, pay
load.name, payload.ts / 1000, thread); | 635 var snapshot = new SDK.TracingModel.ObjectSnapshot(payload.cat, payload.name
, payload.ts / 1000, thread); |
| 636 var id = WebInspector.TracingModel._extractId(payload); | 636 var id = SDK.TracingModel._extractId(payload); |
| 637 if (typeof id !== 'undefined') | 637 if (typeof id !== 'undefined') |
| 638 snapshot.id = id; | 638 snapshot.id = id; |
| 639 if (!payload.args || !payload.args['snapshot']) { | 639 if (!payload.args || !payload.args['snapshot']) { |
| 640 console.error('Missing mandatory \'snapshot\' argument at ' + payload.ts /
1000); | 640 console.error('Missing mandatory \'snapshot\' argument at ' + payload.ts /
1000); |
| 641 return snapshot; | 641 return snapshot; |
| 642 } | 642 } |
| 643 if (payload.args) | 643 if (payload.args) |
| 644 snapshot.addArgs(payload.args); | 644 snapshot.addArgs(payload.args); |
| 645 return snapshot; | 645 return snapshot; |
| 646 } | 646 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 660 */ | 660 */ |
| 661 function onRead(result) { | 661 function onRead(result) { |
| 662 if (!result) { | 662 if (!result) { |
| 663 callback(null); | 663 callback(null); |
| 664 return; | 664 return; |
| 665 } | 665 } |
| 666 try { | 666 try { |
| 667 var payload = JSON.parse(result); | 667 var payload = JSON.parse(result); |
| 668 callback(payload['args']['snapshot']); | 668 callback(payload['args']['snapshot']); |
| 669 } catch (e) { | 669 } catch (e) { |
| 670 WebInspector.console.error('Malformed event data in backing storage'); | 670 Common.console.error('Malformed event data in backing storage'); |
| 671 callback(null); | 671 callback(null); |
| 672 } | 672 } |
| 673 } | 673 } |
| 674 } | 674 } |
| 675 | 675 |
| 676 /** | 676 /** |
| 677 * @return {!Promise<?>} | 677 * @return {!Promise<?>} |
| 678 */ | 678 */ |
| 679 objectPromise() { | 679 objectPromise() { |
| 680 if (!this._objectPromise) | 680 if (!this._objectPromise) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 691 return; | 691 return; |
| 692 this._backingStorage = backingStorage; | 692 this._backingStorage = backingStorage; |
| 693 this.args = {}; | 693 this.args = {}; |
| 694 } | 694 } |
| 695 }; | 695 }; |
| 696 | 696 |
| 697 | 697 |
| 698 /** | 698 /** |
| 699 * @unrestricted | 699 * @unrestricted |
| 700 */ | 700 */ |
| 701 WebInspector.TracingModel.AsyncEvent = class extends WebInspector.TracingModel.E
vent { | 701 SDK.TracingModel.AsyncEvent = class extends SDK.TracingModel.Event { |
| 702 /** | 702 /** |
| 703 * @param {!WebInspector.TracingModel.Event} startEvent | 703 * @param {!SDK.TracingModel.Event} startEvent |
| 704 */ | 704 */ |
| 705 constructor(startEvent) { | 705 constructor(startEvent) { |
| 706 super(startEvent.categoriesString, startEvent.name, startEvent.phase, startE
vent.startTime, startEvent.thread); | 706 super(startEvent.categoriesString, startEvent.name, startEvent.phase, startE
vent.startTime, startEvent.thread); |
| 707 this.addArgs(startEvent.args); | 707 this.addArgs(startEvent.args); |
| 708 this.steps = [startEvent]; | 708 this.steps = [startEvent]; |
| 709 } | 709 } |
| 710 | 710 |
| 711 /** | 711 /** |
| 712 * @param {!WebInspector.TracingModel.Event} event | 712 * @param {!SDK.TracingModel.Event} event |
| 713 */ | 713 */ |
| 714 _addStep(event) { | 714 _addStep(event) { |
| 715 this.steps.push(event); | 715 this.steps.push(event); |
| 716 if (event.phase === WebInspector.TracingModel.Phase.AsyncEnd || | 716 if (event.phase === SDK.TracingModel.Phase.AsyncEnd || |
| 717 event.phase === WebInspector.TracingModel.Phase.NestableAsyncEnd) { | 717 event.phase === SDK.TracingModel.Phase.NestableAsyncEnd) { |
| 718 this.setEndTime(event.startTime); | 718 this.setEndTime(event.startTime); |
| 719 // FIXME: ideally, we shouldn't do this, but this makes the logic of conve
rting | 719 // FIXME: ideally, we shouldn't do this, but this makes the logic of conve
rting |
| 720 // async console events to sync ones much simpler. | 720 // async console events to sync ones much simpler. |
| 721 this.steps[0].setEndTime(event.startTime); | 721 this.steps[0].setEndTime(event.startTime); |
| 722 } | 722 } |
| 723 } | 723 } |
| 724 }; | 724 }; |
| 725 | 725 |
| 726 /** | 726 /** |
| 727 * @unrestricted | 727 * @unrestricted |
| 728 */ | 728 */ |
| 729 WebInspector.TracingModel.ProfileEventsGroup = class { | 729 SDK.TracingModel.ProfileEventsGroup = class { |
| 730 /** | 730 /** |
| 731 * @param {!WebInspector.TracingModel.Event} event | 731 * @param {!SDK.TracingModel.Event} event |
| 732 */ | 732 */ |
| 733 constructor(event) { | 733 constructor(event) { |
| 734 /** @type {!Array<!WebInspector.TracingModel.Event>} */ | 734 /** @type {!Array<!SDK.TracingModel.Event>} */ |
| 735 this.children = [event]; | 735 this.children = [event]; |
| 736 } | 736 } |
| 737 | 737 |
| 738 /** | 738 /** |
| 739 * @param {!WebInspector.TracingModel.Event} event | 739 * @param {!SDK.TracingModel.Event} event |
| 740 */ | 740 */ |
| 741 _addChild(event) { | 741 _addChild(event) { |
| 742 this.children.push(event); | 742 this.children.push(event); |
| 743 } | 743 } |
| 744 }; | 744 }; |
| 745 | 745 |
| 746 /** | 746 /** |
| 747 * @unrestricted | 747 * @unrestricted |
| 748 */ | 748 */ |
| 749 WebInspector.TracingModel.NamedObject = class { | 749 SDK.TracingModel.NamedObject = class { |
| 750 /** | 750 /** |
| 751 * @param {!Array.<!WebInspector.TracingModel.NamedObject>} array | 751 * @param {!Array.<!SDK.TracingModel.NamedObject>} array |
| 752 */ | 752 */ |
| 753 static _sort(array) { | 753 static _sort(array) { |
| 754 /** | 754 /** |
| 755 * @param {!WebInspector.TracingModel.NamedObject} a | 755 * @param {!SDK.TracingModel.NamedObject} a |
| 756 * @param {!WebInspector.TracingModel.NamedObject} b | 756 * @param {!SDK.TracingModel.NamedObject} b |
| 757 */ | 757 */ |
| 758 function comparator(a, b) { | 758 function comparator(a, b) { |
| 759 return a._sortIndex !== b._sortIndex ? a._sortIndex - b._sortIndex : a.nam
e().localeCompare(b.name()); | 759 return a._sortIndex !== b._sortIndex ? a._sortIndex - b._sortIndex : a.nam
e().localeCompare(b.name()); |
| 760 } | 760 } |
| 761 return array.sort(comparator); | 761 return array.sort(comparator); |
| 762 } | 762 } |
| 763 | 763 |
| 764 /** | 764 /** |
| 765 * @param {string} name | 765 * @param {string} name |
| 766 */ | 766 */ |
| (...skipping 13 matching lines...) Expand all Loading... |
| 780 */ | 780 */ |
| 781 _setSortIndex(sortIndex) { | 781 _setSortIndex(sortIndex) { |
| 782 this._sortIndex = sortIndex; | 782 this._sortIndex = sortIndex; |
| 783 } | 783 } |
| 784 }; | 784 }; |
| 785 | 785 |
| 786 | 786 |
| 787 /** | 787 /** |
| 788 * @unrestricted | 788 * @unrestricted |
| 789 */ | 789 */ |
| 790 WebInspector.TracingModel.Process = class extends WebInspector.TracingModel.Name
dObject { | 790 SDK.TracingModel.Process = class extends SDK.TracingModel.NamedObject { |
| 791 /** | 791 /** |
| 792 * @param {!WebInspector.TracingModel} model | 792 * @param {!SDK.TracingModel} model |
| 793 * @param {number} id | 793 * @param {number} id |
| 794 */ | 794 */ |
| 795 constructor(model, id) { | 795 constructor(model, id) { |
| 796 super(); | 796 super(); |
| 797 this._setName('Process ' + id); | 797 this._setName('Process ' + id); |
| 798 this._id = id; | 798 this._id = id; |
| 799 /** @type {!Map<number, !WebInspector.TracingModel.Thread>} */ | 799 /** @type {!Map<number, !SDK.TracingModel.Thread>} */ |
| 800 this._threads = new Map(); | 800 this._threads = new Map(); |
| 801 this._threadByName = new Map(); | 801 this._threadByName = new Map(); |
| 802 this._model = model; | 802 this._model = model; |
| 803 } | 803 } |
| 804 | 804 |
| 805 /** | 805 /** |
| 806 * @return {number} | 806 * @return {number} |
| 807 */ | 807 */ |
| 808 id() { | 808 id() { |
| 809 return this._id; | 809 return this._id; |
| 810 } | 810 } |
| 811 | 811 |
| 812 /** | 812 /** |
| 813 * @param {number} id | 813 * @param {number} id |
| 814 * @return {!WebInspector.TracingModel.Thread} | 814 * @return {!SDK.TracingModel.Thread} |
| 815 */ | 815 */ |
| 816 threadById(id) { | 816 threadById(id) { |
| 817 var thread = this._threads.get(id); | 817 var thread = this._threads.get(id); |
| 818 if (!thread) { | 818 if (!thread) { |
| 819 thread = new WebInspector.TracingModel.Thread(this, id); | 819 thread = new SDK.TracingModel.Thread(this, id); |
| 820 this._threads.set(id, thread); | 820 this._threads.set(id, thread); |
| 821 } | 821 } |
| 822 return thread; | 822 return thread; |
| 823 } | 823 } |
| 824 | 824 |
| 825 /** | 825 /** |
| 826 * @param {string} name | 826 * @param {string} name |
| 827 * @return {?WebInspector.TracingModel.Thread} | 827 * @return {?SDK.TracingModel.Thread} |
| 828 */ | 828 */ |
| 829 threadByName(name) { | 829 threadByName(name) { |
| 830 return this._threadByName.get(name) || null; | 830 return this._threadByName.get(name) || null; |
| 831 } | 831 } |
| 832 | 832 |
| 833 /** | 833 /** |
| 834 * @param {string} name | 834 * @param {string} name |
| 835 * @param {!WebInspector.TracingModel.Thread} thread | 835 * @param {!SDK.TracingModel.Thread} thread |
| 836 */ | 836 */ |
| 837 _setThreadByName(name, thread) { | 837 _setThreadByName(name, thread) { |
| 838 this._threadByName.set(name, thread); | 838 this._threadByName.set(name, thread); |
| 839 } | 839 } |
| 840 | 840 |
| 841 /** | 841 /** |
| 842 * @param {!WebInspector.TracingManager.EventPayload} payload | 842 * @param {!SDK.TracingManager.EventPayload} payload |
| 843 * @return {?WebInspector.TracingModel.Event} event | 843 * @return {?SDK.TracingModel.Event} event |
| 844 */ | 844 */ |
| 845 _addEvent(payload) { | 845 _addEvent(payload) { |
| 846 return this.threadById(payload.tid)._addEvent(payload); | 846 return this.threadById(payload.tid)._addEvent(payload); |
| 847 } | 847 } |
| 848 | 848 |
| 849 /** | 849 /** |
| 850 * @return {!Array.<!WebInspector.TracingModel.Thread>} | 850 * @return {!Array.<!SDK.TracingModel.Thread>} |
| 851 */ | 851 */ |
| 852 sortedThreads() { | 852 sortedThreads() { |
| 853 return WebInspector.TracingModel.NamedObject._sort(this._threads.valuesArray
()); | 853 return SDK.TracingModel.NamedObject._sort(this._threads.valuesArray()); |
| 854 } | 854 } |
| 855 }; | 855 }; |
| 856 | 856 |
| 857 /** | 857 /** |
| 858 * @unrestricted | 858 * @unrestricted |
| 859 */ | 859 */ |
| 860 WebInspector.TracingModel.Thread = class extends WebInspector.TracingModel.Named
Object { | 860 SDK.TracingModel.Thread = class extends SDK.TracingModel.NamedObject { |
| 861 /** | 861 /** |
| 862 * @param {!WebInspector.TracingModel.Process} process | 862 * @param {!SDK.TracingModel.Process} process |
| 863 * @param {number} id | 863 * @param {number} id |
| 864 */ | 864 */ |
| 865 constructor(process, id) { | 865 constructor(process, id) { |
| 866 super(); | 866 super(); |
| 867 this._process = process; | 867 this._process = process; |
| 868 this._setName('Thread ' + id); | 868 this._setName('Thread ' + id); |
| 869 this._events = []; | 869 this._events = []; |
| 870 this._asyncEvents = []; | 870 this._asyncEvents = []; |
| 871 this._id = id; | 871 this._id = id; |
| 872 this._model = process._model; | 872 this._model = process._model; |
| 873 } | 873 } |
| 874 | 874 |
| 875 tracingComplete() { | 875 tracingComplete() { |
| 876 this._asyncEvents.stableSort(WebInspector.TracingModel.Event.compareStartAnd
EndTime); | 876 this._asyncEvents.stableSort(SDK.TracingModel.Event.compareStartAndEndTime); |
| 877 this._events.stableSort(WebInspector.TracingModel.Event.compareStartTime); | 877 this._events.stableSort(SDK.TracingModel.Event.compareStartTime); |
| 878 var phases = WebInspector.TracingModel.Phase; | 878 var phases = SDK.TracingModel.Phase; |
| 879 var stack = []; | 879 var stack = []; |
| 880 for (var i = 0; i < this._events.length; ++i) { | 880 for (var i = 0; i < this._events.length; ++i) { |
| 881 var e = this._events[i]; | 881 var e = this._events[i]; |
| 882 e.ordinal = i; | 882 e.ordinal = i; |
| 883 switch (e.phase) { | 883 switch (e.phase) { |
| 884 case phases.End: | 884 case phases.End: |
| 885 this._events[i] = null; // Mark for removal. | 885 this._events[i] = null; // Mark for removal. |
| 886 // Quietly ignore unbalanced close events, they're legit (we could hav
e missed start one). | 886 // Quietly ignore unbalanced close events, they're legit (we could hav
e missed start one). |
| 887 if (!stack.length) | 887 if (!stack.length) |
| 888 continue; | 888 continue; |
| 889 var top = stack.pop(); | 889 var top = stack.pop(); |
| 890 if (top.name !== e.name || top.categoriesString !== e.categoriesString
) | 890 if (top.name !== e.name || top.categoriesString !== e.categoriesString
) |
| 891 console.error( | 891 console.error( |
| 892 'B/E events mismatch at ' + top.startTime + ' (' + top.name + ')
vs. ' + e.startTime + ' (' + e.name + | 892 'B/E events mismatch at ' + top.startTime + ' (' + top.name + ')
vs. ' + e.startTime + ' (' + e.name + |
| 893 ')'); | 893 ')'); |
| 894 else | 894 else |
| 895 top._complete(e); | 895 top._complete(e); |
| 896 break; | 896 break; |
| 897 case phases.Begin: | 897 case phases.Begin: |
| 898 stack.push(e); | 898 stack.push(e); |
| 899 break; | 899 break; |
| 900 } | 900 } |
| 901 } | 901 } |
| 902 while (stack.length) | 902 while (stack.length) |
| 903 stack.pop().setEndTime(this._model.maximumRecordTime()); | 903 stack.pop().setEndTime(this._model.maximumRecordTime()); |
| 904 this._events.remove(null, false); | 904 this._events.remove(null, false); |
| 905 } | 905 } |
| 906 | 906 |
| 907 /** | 907 /** |
| 908 * @param {!WebInspector.TracingManager.EventPayload} payload | 908 * @param {!SDK.TracingManager.EventPayload} payload |
| 909 * @return {?WebInspector.TracingModel.Event} event | 909 * @return {?SDK.TracingModel.Event} event |
| 910 */ | 910 */ |
| 911 _addEvent(payload) { | 911 _addEvent(payload) { |
| 912 var event = payload.ph === WebInspector.TracingModel.Phase.SnapshotObject ? | 912 var event = payload.ph === SDK.TracingModel.Phase.SnapshotObject ? |
| 913 WebInspector.TracingModel.ObjectSnapshot.fromPayload(payload, this) : | 913 SDK.TracingModel.ObjectSnapshot.fromPayload(payload, this) : |
| 914 WebInspector.TracingModel.Event.fromPayload(payload, this); | 914 SDK.TracingModel.Event.fromPayload(payload, this); |
| 915 if (WebInspector.TracingModel.isTopLevelEvent(event)) { | 915 if (SDK.TracingModel.isTopLevelEvent(event)) { |
| 916 // Discard nested "top-level" events. | 916 // Discard nested "top-level" events. |
| 917 if (this._lastTopLevelEvent && this._lastTopLevelEvent.endTime > event.sta
rtTime) | 917 if (this._lastTopLevelEvent && this._lastTopLevelEvent.endTime > event.sta
rtTime) |
| 918 return null; | 918 return null; |
| 919 this._lastTopLevelEvent = event; | 919 this._lastTopLevelEvent = event; |
| 920 } | 920 } |
| 921 this._events.push(event); | 921 this._events.push(event); |
| 922 return event; | 922 return event; |
| 923 } | 923 } |
| 924 | 924 |
| 925 /** | 925 /** |
| 926 * @param {!WebInspector.TracingModel.AsyncEvent} asyncEvent | 926 * @param {!SDK.TracingModel.AsyncEvent} asyncEvent |
| 927 */ | 927 */ |
| 928 _addAsyncEvent(asyncEvent) { | 928 _addAsyncEvent(asyncEvent) { |
| 929 this._asyncEvents.push(asyncEvent); | 929 this._asyncEvents.push(asyncEvent); |
| 930 } | 930 } |
| 931 | 931 |
| 932 /** | 932 /** |
| 933 * @override | 933 * @override |
| 934 * @param {string} name | 934 * @param {string} name |
| 935 */ | 935 */ |
| 936 _setName(name) { | 936 _setName(name) { |
| 937 super._setName(name); | 937 super._setName(name); |
| 938 this._process._setThreadByName(name, this); | 938 this._process._setThreadByName(name, this); |
| 939 } | 939 } |
| 940 | 940 |
| 941 /** | 941 /** |
| 942 * @return {number} | 942 * @return {number} |
| 943 */ | 943 */ |
| 944 id() { | 944 id() { |
| 945 return this._id; | 945 return this._id; |
| 946 } | 946 } |
| 947 | 947 |
| 948 /** | 948 /** |
| 949 * @return {!WebInspector.TracingModel.Process} | 949 * @return {!SDK.TracingModel.Process} |
| 950 */ | 950 */ |
| 951 process() { | 951 process() { |
| 952 return this._process; | 952 return this._process; |
| 953 } | 953 } |
| 954 | 954 |
| 955 /** | 955 /** |
| 956 * @return {!Array.<!WebInspector.TracingModel.Event>} | 956 * @return {!Array.<!SDK.TracingModel.Event>} |
| 957 */ | 957 */ |
| 958 events() { | 958 events() { |
| 959 return this._events; | 959 return this._events; |
| 960 } | 960 } |
| 961 | 961 |
| 962 /** | 962 /** |
| 963 * @return {!Array.<!WebInspector.TracingModel.AsyncEvent>} | 963 * @return {!Array.<!SDK.TracingModel.AsyncEvent>} |
| 964 */ | 964 */ |
| 965 asyncEvents() { | 965 asyncEvents() { |
| 966 return this._asyncEvents; | 966 return this._asyncEvents; |
| 967 } | 967 } |
| 968 }; | 968 }; |
| OLD | NEW |