| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 /** | 4 /** |
| 5 * @unrestricted | 5 * @unrestricted |
| 6 */ | 6 */ |
| 7 WebInspector.TimelineIRModel = class { | 7 TimelineModel.TimelineIRModel = class { |
| 8 constructor() { | 8 constructor() { |
| 9 this.reset(); | 9 this.reset(); |
| 10 } | 10 } |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * @param {!WebInspector.TracingModel.Event} event | 13 * @param {!SDK.TracingModel.Event} event |
| 14 * @return {!WebInspector.TimelineIRModel.Phases} | 14 * @return {!TimelineModel.TimelineIRModel.Phases} |
| 15 */ | 15 */ |
| 16 static phaseForEvent(event) { | 16 static phaseForEvent(event) { |
| 17 return event[WebInspector.TimelineIRModel._eventIRPhase]; | 17 return event[TimelineModel.TimelineIRModel._eventIRPhase]; |
| 18 } | 18 } |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * @param {?Array<!WebInspector.TracingModel.AsyncEvent>} inputLatencies | 21 * @param {?Array<!SDK.TracingModel.AsyncEvent>} inputLatencies |
| 22 * @param {?Array<!WebInspector.TracingModel.AsyncEvent>} animations | 22 * @param {?Array<!SDK.TracingModel.AsyncEvent>} animations |
| 23 */ | 23 */ |
| 24 populate(inputLatencies, animations) { | 24 populate(inputLatencies, animations) { |
| 25 var eventTypes = WebInspector.TimelineIRModel.InputEvents; | 25 var eventTypes = TimelineModel.TimelineIRModel.InputEvents; |
| 26 var phases = WebInspector.TimelineIRModel.Phases; | 26 var phases = TimelineModel.TimelineIRModel.Phases; |
| 27 | 27 |
| 28 this.reset(); | 28 this.reset(); |
| 29 if (!inputLatencies) | 29 if (!inputLatencies) |
| 30 return; | 30 return; |
| 31 this._processInputLatencies(inputLatencies); | 31 this._processInputLatencies(inputLatencies); |
| 32 if (animations) | 32 if (animations) |
| 33 this._processAnimations(animations); | 33 this._processAnimations(animations); |
| 34 var range = new WebInspector.SegmentedRange(); | 34 var range = new Common.SegmentedRange(); |
| 35 range.appendRange(this._drags); // Drags take lower precedence than animati
on, as we can't detect them reliably. | 35 range.appendRange(this._drags); // Drags take lower precedence than animati
on, as we can't detect them reliably. |
| 36 range.appendRange(this._cssAnimations); | 36 range.appendRange(this._cssAnimations); |
| 37 range.appendRange(this._scrolls); | 37 range.appendRange(this._scrolls); |
| 38 range.appendRange(this._responses); | 38 range.appendRange(this._responses); |
| 39 this._segments = range.segments(); | 39 this._segments = range.segments(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * @param {!Array<!WebInspector.TracingModel.AsyncEvent>} events | 43 * @param {!Array<!SDK.TracingModel.AsyncEvent>} events |
| 44 */ | 44 */ |
| 45 _processInputLatencies(events) { | 45 _processInputLatencies(events) { |
| 46 var eventTypes = WebInspector.TimelineIRModel.InputEvents; | 46 var eventTypes = TimelineModel.TimelineIRModel.InputEvents; |
| 47 var phases = WebInspector.TimelineIRModel.Phases; | 47 var phases = TimelineModel.TimelineIRModel.Phases; |
| 48 var thresholdsMs = WebInspector.TimelineIRModel._mergeThresholdsMs; | 48 var thresholdsMs = TimelineModel.TimelineIRModel._mergeThresholdsMs; |
| 49 | 49 |
| 50 var scrollStart; | 50 var scrollStart; |
| 51 var flingStart; | 51 var flingStart; |
| 52 var touchStart; | 52 var touchStart; |
| 53 var firstTouchMove; | 53 var firstTouchMove; |
| 54 var mouseWheel; | 54 var mouseWheel; |
| 55 var mouseDown; | 55 var mouseDown; |
| 56 var mouseMove; | 56 var mouseMove; |
| 57 | 57 |
| 58 for (var i = 0; i < events.length; ++i) { | 58 for (var i = 0; i < events.length; ++i) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 74 scrollStart = null; | 74 scrollStart = null; |
| 75 break; | 75 break; |
| 76 | 76 |
| 77 case eventTypes.ScrollUpdate: | 77 case eventTypes.ScrollUpdate: |
| 78 touchStart = null; // Since we're scrolling now, disregard other touc
h gestures. | 78 touchStart = null; // Since we're scrolling now, disregard other touc
h gestures. |
| 79 this._scrolls.append(this._segmentForEvent(event, phases.Scroll)); | 79 this._scrolls.append(this._segmentForEvent(event, phases.Scroll)); |
| 80 break; | 80 break; |
| 81 | 81 |
| 82 case eventTypes.FlingStart: | 82 case eventTypes.FlingStart: |
| 83 if (flingStart) { | 83 if (flingStart) { |
| 84 WebInspector.console.error( | 84 Common.console.error( |
| 85 WebInspector.UIString('Two flings at the same time? %s vs %s', f
lingStart.startTime, event.startTime)); | 85 Common.UIString('Two flings at the same time? %s vs %s', flingSt
art.startTime, event.startTime)); |
| 86 break; | 86 break; |
| 87 } | 87 } |
| 88 flingStart = event; | 88 flingStart = event; |
| 89 break; | 89 break; |
| 90 | 90 |
| 91 case eventTypes.FlingCancel: | 91 case eventTypes.FlingCancel: |
| 92 // FIXME: also process renderer fling events. | 92 // FIXME: also process renderer fling events. |
| 93 if (!flingStart) | 93 if (!flingStart) |
| 94 break; | 94 break; |
| 95 this._scrolls.append(this._segmentForEventRange(flingStart, event, pha
ses.Fling)); | 95 this._scrolls.append(this._segmentForEventRange(flingStart, event, pha
ses.Fling)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 108 case eventTypes.Char: | 108 case eventTypes.Char: |
| 109 case eventTypes.Click: | 109 case eventTypes.Click: |
| 110 case eventTypes.ContextMenu: | 110 case eventTypes.ContextMenu: |
| 111 this._responses.append(this._segmentForEvent(event, phases.Response)); | 111 this._responses.append(this._segmentForEvent(event, phases.Response)); |
| 112 break; | 112 break; |
| 113 | 113 |
| 114 case eventTypes.TouchStart: | 114 case eventTypes.TouchStart: |
| 115 // We do not produce any response segment for TouchStart -- there's ei
ther going to be one upon | 115 // We do not produce any response segment for TouchStart -- there's ei
ther going to be one upon |
| 116 // TouchMove for drag, or one for GestureTap. | 116 // TouchMove for drag, or one for GestureTap. |
| 117 if (touchStart) { | 117 if (touchStart) { |
| 118 WebInspector.console.error( | 118 Common.console.error( |
| 119 WebInspector.UIString('Two touches at the same time? %s vs %s',
touchStart.startTime, event.startTime)); | 119 Common.UIString('Two touches at the same time? %s vs %s', touchS
tart.startTime, event.startTime)); |
| 120 break; | 120 break; |
| 121 } | 121 } |
| 122 touchStart = event; | 122 touchStart = event; |
| 123 event.steps[0][WebInspector.TimelineIRModel._eventIRPhase] = phases.Re
sponse; | 123 event.steps[0][TimelineModel.TimelineIRModel._eventIRPhase] = phases.R
esponse; |
| 124 firstTouchMove = null; | 124 firstTouchMove = null; |
| 125 break; | 125 break; |
| 126 | 126 |
| 127 case eventTypes.TouchCancel: | 127 case eventTypes.TouchCancel: |
| 128 touchStart = null; | 128 touchStart = null; |
| 129 break; | 129 break; |
| 130 | 130 |
| 131 case eventTypes.TouchMove: | 131 case eventTypes.TouchMove: |
| 132 if (firstTouchMove) { | 132 if (firstTouchMove) { |
| 133 this._drags.append(this._segmentForEvent(event, phases.Drag)); | 133 this._drags.append(this._segmentForEvent(event, phases.Drag)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 this._scrolls.append(this._segmentForEventRange(mouseWheel, event, p
hases.Scroll)); | 167 this._scrolls.append(this._segmentForEventRange(mouseWheel, event, p
hases.Scroll)); |
| 168 else | 168 else |
| 169 this._scrolls.append(this._segmentForEvent(event, phases.Scroll)); | 169 this._scrolls.append(this._segmentForEvent(event, phases.Scroll)); |
| 170 mouseWheel = event; | 170 mouseWheel = event; |
| 171 break; | 171 break; |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 | 174 |
| 175 /** | 175 /** |
| 176 * @param {number} threshold | 176 * @param {number} threshold |
| 177 * @param {!WebInspector.TracingModel.AsyncEvent} first | 177 * @param {!SDK.TracingModel.AsyncEvent} first |
| 178 * @param {!WebInspector.TracingModel.AsyncEvent} second | 178 * @param {!SDK.TracingModel.AsyncEvent} second |
| 179 * @return {boolean} | 179 * @return {boolean} |
| 180 */ | 180 */ |
| 181 function canMerge(threshold, first, second) { | 181 function canMerge(threshold, first, second) { |
| 182 return first.endTime < second.startTime && second.startTime < first.endTim
e + threshold; | 182 return first.endTime < second.startTime && second.startTime < first.endTim
e + threshold; |
| 183 } | 183 } |
| 184 } | 184 } |
| 185 | 185 |
| 186 /** | 186 /** |
| 187 * @param {!Array<!WebInspector.TracingModel.AsyncEvent>} events | 187 * @param {!Array<!SDK.TracingModel.AsyncEvent>} events |
| 188 */ | 188 */ |
| 189 _processAnimations(events) { | 189 _processAnimations(events) { |
| 190 for (var i = 0; i < events.length; ++i) | 190 for (var i = 0; i < events.length; ++i) |
| 191 this._cssAnimations.append(this._segmentForEvent(events[i], WebInspector.T
imelineIRModel.Phases.Animation)); | 191 this._cssAnimations.append(this._segmentForEvent(events[i], TimelineModel.
TimelineIRModel.Phases.Animation)); |
| 192 } | 192 } |
| 193 | 193 |
| 194 /** | 194 /** |
| 195 * @param {!WebInspector.TracingModel.AsyncEvent} event | 195 * @param {!SDK.TracingModel.AsyncEvent} event |
| 196 * @param {!WebInspector.TimelineIRModel.Phases} phase | 196 * @param {!TimelineModel.TimelineIRModel.Phases} phase |
| 197 * @return {!WebInspector.Segment} | 197 * @return {!Common.Segment} |
| 198 */ | 198 */ |
| 199 _segmentForEvent(event, phase) { | 199 _segmentForEvent(event, phase) { |
| 200 this._setPhaseForEvent(event, phase); | 200 this._setPhaseForEvent(event, phase); |
| 201 return new WebInspector.Segment(event.startTime, event.endTime, phase); | 201 return new Common.Segment(event.startTime, event.endTime, phase); |
| 202 } | 202 } |
| 203 | 203 |
| 204 /** | 204 /** |
| 205 * @param {!WebInspector.TracingModel.AsyncEvent} startEvent | 205 * @param {!SDK.TracingModel.AsyncEvent} startEvent |
| 206 * @param {!WebInspector.TracingModel.AsyncEvent} endEvent | 206 * @param {!SDK.TracingModel.AsyncEvent} endEvent |
| 207 * @param {!WebInspector.TimelineIRModel.Phases} phase | 207 * @param {!TimelineModel.TimelineIRModel.Phases} phase |
| 208 * @return {!WebInspector.Segment} | 208 * @return {!Common.Segment} |
| 209 */ | 209 */ |
| 210 _segmentForEventRange(startEvent, endEvent, phase) { | 210 _segmentForEventRange(startEvent, endEvent, phase) { |
| 211 this._setPhaseForEvent(startEvent, phase); | 211 this._setPhaseForEvent(startEvent, phase); |
| 212 this._setPhaseForEvent(endEvent, phase); | 212 this._setPhaseForEvent(endEvent, phase); |
| 213 return new WebInspector.Segment(startEvent.startTime, endEvent.endTime, phas
e); | 213 return new Common.Segment(startEvent.startTime, endEvent.endTime, phase); |
| 214 } | 214 } |
| 215 | 215 |
| 216 /** | 216 /** |
| 217 * @param {!WebInspector.TracingModel.AsyncEvent} asyncEvent | 217 * @param {!SDK.TracingModel.AsyncEvent} asyncEvent |
| 218 * @param {!WebInspector.TimelineIRModel.Phases} phase | 218 * @param {!TimelineModel.TimelineIRModel.Phases} phase |
| 219 */ | 219 */ |
| 220 _setPhaseForEvent(asyncEvent, phase) { | 220 _setPhaseForEvent(asyncEvent, phase) { |
| 221 asyncEvent.steps[0][WebInspector.TimelineIRModel._eventIRPhase] = phase; | 221 asyncEvent.steps[0][TimelineModel.TimelineIRModel._eventIRPhase] = phase; |
| 222 } | 222 } |
| 223 | 223 |
| 224 /** | 224 /** |
| 225 * @return {!Array<!WebInspector.Segment>} | 225 * @return {!Array<!Common.Segment>} |
| 226 */ | 226 */ |
| 227 interactionRecords() { | 227 interactionRecords() { |
| 228 return this._segments; | 228 return this._segments; |
| 229 } | 229 } |
| 230 | 230 |
| 231 reset() { | 231 reset() { |
| 232 var thresholdsMs = WebInspector.TimelineIRModel._mergeThresholdsMs; | 232 var thresholdsMs = TimelineModel.TimelineIRModel._mergeThresholdsMs; |
| 233 | 233 |
| 234 this._segments = []; | 234 this._segments = []; |
| 235 this._drags = new WebInspector.SegmentedRange(merge.bind(null, thresholdsMs.
mouse)); | 235 this._drags = new Common.SegmentedRange(merge.bind(null, thresholdsMs.mouse)
); |
| 236 this._cssAnimations = new WebInspector.SegmentedRange(merge.bind(null, thres
holdsMs.animation)); | 236 this._cssAnimations = new Common.SegmentedRange(merge.bind(null, thresholdsM
s.animation)); |
| 237 this._responses = new WebInspector.SegmentedRange(merge.bind(null, 0)); | 237 this._responses = new Common.SegmentedRange(merge.bind(null, 0)); |
| 238 this._scrolls = new WebInspector.SegmentedRange(merge.bind(null, thresholdsM
s.animation)); | 238 this._scrolls = new Common.SegmentedRange(merge.bind(null, thresholdsMs.anim
ation)); |
| 239 | 239 |
| 240 /** | 240 /** |
| 241 * @param {number} threshold | 241 * @param {number} threshold |
| 242 * @param {!WebInspector.Segment} first | 242 * @param {!Common.Segment} first |
| 243 * @param {!WebInspector.Segment} second | 243 * @param {!Common.Segment} second |
| 244 */ | 244 */ |
| 245 function merge(threshold, first, second) { | 245 function merge(threshold, first, second) { |
| 246 return first.end + threshold >= second.begin && first.data === second.data
? first : null; | 246 return first.end + threshold >= second.begin && first.data === second.data
? first : null; |
| 247 } | 247 } |
| 248 } | 248 } |
| 249 | 249 |
| 250 /** | 250 /** |
| 251 * @param {string} eventName | 251 * @param {string} eventName |
| 252 * @return {?WebInspector.TimelineIRModel.InputEvents} | 252 * @return {?TimelineModel.TimelineIRModel.InputEvents} |
| 253 */ | 253 */ |
| 254 _inputEventType(eventName) { | 254 _inputEventType(eventName) { |
| 255 var prefix = 'InputLatency::'; | 255 var prefix = 'InputLatency::'; |
| 256 if (!eventName.startsWith(prefix)) { | 256 if (!eventName.startsWith(prefix)) { |
| 257 if (eventName === WebInspector.TimelineIRModel.InputEvents.ImplSideFling) | 257 if (eventName === TimelineModel.TimelineIRModel.InputEvents.ImplSideFling) |
| 258 return /** @type {!WebInspector.TimelineIRModel.InputEvents} */ (eventNa
me); | 258 return /** @type {!TimelineModel.TimelineIRModel.InputEvents} */ (eventN
ame); |
| 259 console.error('Unrecognized input latency event: ' + eventName); | 259 console.error('Unrecognized input latency event: ' + eventName); |
| 260 return null; | 260 return null; |
| 261 } | 261 } |
| 262 return /** @type {!WebInspector.TimelineIRModel.InputEvents} */ (eventName.s
ubstr(prefix.length)); | 262 return /** @type {!TimelineModel.TimelineIRModel.InputEvents} */ (eventName.
substr(prefix.length)); |
| 263 } | 263 } |
| 264 }; | 264 }; |
| 265 | 265 |
| 266 /** | 266 /** |
| 267 * @enum {string} | 267 * @enum {string} |
| 268 */ | 268 */ |
| 269 WebInspector.TimelineIRModel.Phases = { | 269 TimelineModel.TimelineIRModel.Phases = { |
| 270 Idle: 'Idle', | 270 Idle: 'Idle', |
| 271 Response: 'Response', | 271 Response: 'Response', |
| 272 Scroll: 'Scroll', | 272 Scroll: 'Scroll', |
| 273 Fling: 'Fling', | 273 Fling: 'Fling', |
| 274 Drag: 'Drag', | 274 Drag: 'Drag', |
| 275 Animation: 'Animation', | 275 Animation: 'Animation', |
| 276 Uncategorized: 'Uncategorized' | 276 Uncategorized: 'Uncategorized' |
| 277 }; | 277 }; |
| 278 | 278 |
| 279 /** | 279 /** |
| 280 * @enum {string} | 280 * @enum {string} |
| 281 */ | 281 */ |
| 282 WebInspector.TimelineIRModel.InputEvents = { | 282 TimelineModel.TimelineIRModel.InputEvents = { |
| 283 Char: 'Char', | 283 Char: 'Char', |
| 284 Click: 'GestureClick', | 284 Click: 'GestureClick', |
| 285 ContextMenu: 'ContextMenu', | 285 ContextMenu: 'ContextMenu', |
| 286 FlingCancel: 'GestureFlingCancel', | 286 FlingCancel: 'GestureFlingCancel', |
| 287 FlingStart: 'GestureFlingStart', | 287 FlingStart: 'GestureFlingStart', |
| 288 ImplSideFling: WebInspector.TimelineModel.RecordType.ImplSideFling, | 288 ImplSideFling: TimelineModel.TimelineModel.RecordType.ImplSideFling, |
| 289 KeyDown: 'KeyDown', | 289 KeyDown: 'KeyDown', |
| 290 KeyDownRaw: 'RawKeyDown', | 290 KeyDownRaw: 'RawKeyDown', |
| 291 KeyUp: 'KeyUp', | 291 KeyUp: 'KeyUp', |
| 292 LatencyScrollUpdate: 'ScrollUpdate', | 292 LatencyScrollUpdate: 'ScrollUpdate', |
| 293 MouseDown: 'MouseDown', | 293 MouseDown: 'MouseDown', |
| 294 MouseMove: 'MouseMove', | 294 MouseMove: 'MouseMove', |
| 295 MouseUp: 'MouseUp', | 295 MouseUp: 'MouseUp', |
| 296 MouseWheel: 'MouseWheel', | 296 MouseWheel: 'MouseWheel', |
| 297 PinchBegin: 'GesturePinchBegin', | 297 PinchBegin: 'GesturePinchBegin', |
| 298 PinchEnd: 'GesturePinchEnd', | 298 PinchEnd: 'GesturePinchEnd', |
| 299 PinchUpdate: 'GesturePinchUpdate', | 299 PinchUpdate: 'GesturePinchUpdate', |
| 300 ScrollBegin: 'GestureScrollBegin', | 300 ScrollBegin: 'GestureScrollBegin', |
| 301 ScrollEnd: 'GestureScrollEnd', | 301 ScrollEnd: 'GestureScrollEnd', |
| 302 ScrollUpdate: 'GestureScrollUpdate', | 302 ScrollUpdate: 'GestureScrollUpdate', |
| 303 ScrollUpdateRenderer: 'ScrollUpdate', | 303 ScrollUpdateRenderer: 'ScrollUpdate', |
| 304 ShowPress: 'GestureShowPress', | 304 ShowPress: 'GestureShowPress', |
| 305 Tap: 'GestureTap', | 305 Tap: 'GestureTap', |
| 306 TapCancel: 'GestureTapCancel', | 306 TapCancel: 'GestureTapCancel', |
| 307 TapDown: 'GestureTapDown', | 307 TapDown: 'GestureTapDown', |
| 308 TouchCancel: 'TouchCancel', | 308 TouchCancel: 'TouchCancel', |
| 309 TouchEnd: 'TouchEnd', | 309 TouchEnd: 'TouchEnd', |
| 310 TouchMove: 'TouchMove', | 310 TouchMove: 'TouchMove', |
| 311 TouchStart: 'TouchStart' | 311 TouchStart: 'TouchStart' |
| 312 }; | 312 }; |
| 313 | 313 |
| 314 WebInspector.TimelineIRModel._mergeThresholdsMs = { | 314 TimelineModel.TimelineIRModel._mergeThresholdsMs = { |
| 315 animation: 1, | 315 animation: 1, |
| 316 mouse: 40, | 316 mouse: 40, |
| 317 }; | 317 }; |
| 318 | 318 |
| 319 WebInspector.TimelineIRModel._eventIRPhase = Symbol('eventIRPhase'); | 319 TimelineModel.TimelineIRModel._eventIRPhase = Symbol('eventIRPhase'); |
| OLD | NEW |