Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame^] | 1 | <!DOCTYPE html> |
| 2 | <!-- |
| 3 | Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 4 | Use of this source code is governed by a BSD-style license that can be |
| 5 | found in the LICENSE file. |
| 6 | --> |
| 7 | <link rel="import" href="/core/trace_model/async_slice.html"> |
| 8 | |
| 9 | <script> |
| 10 | 'use strict'; |
| 11 | |
| 12 | tv.exportTo('tv.e.cc', function() { |
| 13 | var AsyncSlice = tv.c.trace_model.AsyncSlice; |
| 14 | |
| 15 | |
| 16 | var UI_COMP_NAME = 'INPUT_EVENT_LATENCY_UI_COMPONENT'; |
| 17 | var ORIGINAL_COMP_NAME = 'INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT'; |
| 18 | var BEGIN_COMP_NAME = 'INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT'; |
| 19 | var END_COMP_NAME = 'INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT'; |
| 20 | |
| 21 | |
| 22 | function InputLatencyAsyncSlice() { |
| 23 | AsyncSlice.apply(this, arguments); |
| 24 | } |
| 25 | |
| 26 | InputLatencyAsyncSlice.prototype = { |
| 27 | __proto__: AsyncSlice.prototype, |
| 28 | |
| 29 | |
| 30 | get inputLatency() { |
| 31 | if (!('data' in this.args)) |
| 32 | return undefined; |
| 33 | |
| 34 | var data = this.args.data; |
| 35 | if (!(END_COMP_NAME in data)) |
| 36 | return undefined; |
| 37 | |
| 38 | var latency = 0; |
| 39 | var endTime = data[END_COMP_NAME].time; |
| 40 | if (ORIGINAL_COMP_NAME in data) { |
| 41 | latency = endTime - data[ORIGINAL_COMP_NAME].time; |
| 42 | } else if (UI_COMP_NAME in data) { |
| 43 | latency = endTime - data[UI_COMP_NAME].time; |
| 44 | } else if (BEGIN_COMP_NAME in data) { |
| 45 | latency = endTime - data[BEGIN_COMP_NAME].time; |
| 46 | } else { |
| 47 | throw new Error('No valid begin latency component'); |
| 48 | } |
| 49 | return latency; |
| 50 | } |
| 51 | }; |
| 52 | |
| 53 | var eventTypeNames = [ |
| 54 | 'Char', |
| 55 | 'GestureFlingCancel', |
| 56 | 'GestureFlingStart', |
| 57 | 'GestureScrollBegin', |
| 58 | 'GestureScrollEnd', |
| 59 | 'GestureScrollUpdate', |
| 60 | 'GestureShowPress', |
| 61 | 'GestureTap', |
| 62 | 'GestureTapCancel', |
| 63 | 'GestureTapDown', |
| 64 | 'KeyUp', |
| 65 | 'MouseDown', |
| 66 | 'MouseMove', |
| 67 | 'MouseUp', |
| 68 | 'MouseWheel', |
| 69 | 'RawKeyDown', |
| 70 | 'ScrollUpdate', |
| 71 | 'TouchEnd', |
| 72 | 'TouchMove', |
| 73 | 'TouchStart' |
| 74 | ]; |
| 75 | var allTypeNames = ['InputLatency']; |
| 76 | eventTypeNames.forEach(function(eventTypeName) { |
| 77 | // Old style. |
| 78 | allTypeNames.push('InputLatency:' + eventTypeName); |
| 79 | |
| 80 | // New style. |
| 81 | allTypeNames.push('InputLatency::' + eventTypeName); |
| 82 | }); |
| 83 | |
| 84 | AsyncSlice.register( |
| 85 | InputLatencyAsyncSlice, |
| 86 | { |
| 87 | typeNames: allTypeNames |
| 88 | }); |
| 89 | |
| 90 | return { |
| 91 | InputLatencyAsyncSlice: InputLatencyAsyncSlice |
| 92 | }; |
| 93 | }); |
| 94 | </script> |