| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <!-- | |
| 3 Copyright 2015 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 | |
| 8 <link rel="import" href="/perf_insights/mre/function_handle.html"> | |
| 9 | |
| 10 <script> | |
| 11 'use strict'; | |
| 12 | |
| 13 tr.exportTo('pie', function() { | |
| 14 // Reports the delay and length of scroll gestures relative to first paint. | |
| 15 // See https://goo.gl/l7V5xg. | |
| 16 function mapGestureTiming(result, model) { | |
| 17 var loadIRs = model.userModel.expectations.filter(function(ir) { | |
| 18 return ir instanceof tr.model.um.LoadExpectation; | |
| 19 }); | |
| 20 var responseIRs = model.userModel.expectations.filter(function(ir) { | |
| 21 return ir.stageTitle === 'Response' && | |
| 22 ir.initiatorTitle.indexOf('Scroll') >= 0; | |
| 23 }); | |
| 24 var animationIRs = model.userModel.expectations.filter(function(ir) { | |
| 25 return ir.stageTitle === 'Animation' && | |
| 26 ir.initiatorTitle.indexOf('Scroll') >= 0; | |
| 27 }); | |
| 28 | |
| 29 var firstGestureAfterLoadTimes = []; | |
| 30 var gestureDurations = new Array(responseIRs.length); | |
| 31 var intervalBetweenGestures = []; | |
| 32 | |
| 33 // This loop is quadratic, but typically we only expect a low number (~tens | |
| 34 // per minute of tracing) of both load and response IRs. | |
| 35 loadIRs.forEach(function(loadIR) { | |
| 36 var loadEnd = loadIR.start + loadIR.duration; | |
| 37 for (var i = 0; i < responseIRs.length; i++) { | |
| 38 var responseIR = responseIRs[i]; | |
| 39 if (responseIR.start < loadEnd) | |
| 40 continue; | |
| 41 firstGestureAfterLoadTimes.push(responseIR.start - loadEnd); | |
| 42 break; | |
| 43 } | |
| 44 }); | |
| 45 | |
| 46 // Compute the interval between responses and the duration of each gesture | |
| 47 // and any gesture animation that follows. This loop is also quadratic, but | |
| 48 // again the expected number of IRs is small (~tens per minute). | |
| 49 var prevGestureStart = undefined; | |
| 50 responseIRs.forEach(function(responseIR, index) { | |
| 51 if (prevGestureStart !== undefined) | |
| 52 intervalBetweenGestures.push(responseIR.start - prevGestureStart); | |
| 53 prevGestureStart = responseIR.start; | |
| 54 var gestureDuration = responseIR.duration; | |
| 55 for (var i = 0; i < animationIRs.length; i++) { | |
| 56 if (animationIRs[i].start !== responseIR.start + responseIR.duration) | |
| 57 continue; | |
| 58 gestureDuration += animationIRs[i].duration; | |
| 59 break; | |
| 60 } | |
| 61 gestureDurations[index] = gestureDuration; | |
| 62 }); | |
| 63 | |
| 64 result.addPair( | |
| 65 'gestureTiming', { | |
| 66 firstGestureAfterLoadTime: firstGestureAfterLoadTimes, | |
| 67 gestureDuration: gestureDurations, | |
| 68 intervalBetweenGestures: intervalBetweenGestures | |
| 69 }); | |
| 70 } | |
| 71 | |
| 72 pi.FunctionRegistry.register(mapGestureTiming); | |
| 73 | |
| 74 return { | |
| 75 mapGestureTimingForTest: mapGestureTiming | |
| 76 }; | |
| 77 }); | |
| 78 </script> | |
| OLD | NEW |