xref: /aosp_15_r20/external/walt/docs/DragLatency.md (revision bf47c6829f95be9dd55f4c5bbc44a71c90aad403)
1*bf47c682SAndroid Build Coastguard Worker## Drag / scroll latency
2*bf47c682SAndroid Build Coastguard Worker
3*bf47c682SAndroid Build Coastguard WorkerSee also:
4*bf47c682SAndroid Build Coastguard Worker * Instructions on how to perform the measurement in the [usage doc](usage/WALT_usage.md#dragscroll-latency)
5*bf47c682SAndroid Build Coastguard Worker * [Video demonstration](https://www.youtube.com/watch?v=pVy5AYVzf7Q&list=PLd6Fi7WgXfcB4Ma6A-5rPlr1jptNR3RxQ&index=4)
6*bf47c682SAndroid Build Coastguard Worker * A [video](https://plus.google.com/+FrancoisBeaufort/posts/XctAif2nv4U) showing the measurement
7*bf47c682SAndroid Build Coastguard Workerperformed using a robotic stylus
8*bf47c682SAndroid Build Coastguard Worker
9*bf47c682SAndroid Build Coastguard Worker
10*bf47c682SAndroid Build Coastguard WorkerFor drag (or scroll) latency WALT uses a laser that shines across the touch device and hits a detector on the
11*bf47c682SAndroid Build Coastguard Workerother side. The microcontroller monitors the state of the laser detector and reports (over usb) when
12*bf47c682SAndroid Build Coastguard Workerthe laser beam is broken. A finger dragged back and forth on a touchpad or touch screen
13*bf47c682SAndroid Build Coastguard Workerand interrupts a laser beam. Touch events from the pad and laser events are then processed together
14*bf47c682SAndroid Build Coastguard Workerto deduce the delay.
15*bf47c682SAndroid Build Coastguard Worker
16*bf47c682SAndroid Build Coastguard Worker![Drag/scroll latency measurement](usage/images/drag.png)
17*bf47c682SAndroid Build Coastguard Worker
18*bf47c682SAndroid Build Coastguard WorkerSample measurements
19*bf47c682SAndroid Build Coastguard Worker
20*bf47c682SAndroid Build Coastguard Worker| Device       | OS version     | Drag latency [ms]|
21*bf47c682SAndroid Build Coastguard Worker| :---         | :---           |             ---: |
22*bf47c682SAndroid Build Coastguard Worker| Nexus 5      | M4B30Z (6.0.1) |             18.4 |
23*bf47c682SAndroid Build Coastguard Worker| Nexus 5X     | NRD91P (7.0)   |             18.9 |
24*bf47c682SAndroid Build Coastguard Worker| Nexus 7      | LMY47Q (5.1)   |             35.8 |
25*bf47c682SAndroid Build Coastguard Worker| Nexus 9      | MMB29K (6.0.1) |             10.2 |
26*bf47c682SAndroid Build Coastguard Worker
27*bf47c682SAndroid Build Coastguard Worker
28*bf47c682SAndroid Build Coastguard Worker## Drag latency calculation
29*bf47c682SAndroid Build Coastguard Worker
30*bf47c682SAndroid Build Coastguard WorkerThe app collects all the motion events reported by Android with their coordinates and timestamps. The plot on the screenshot below show the vertical coordinate as a function of time as seen by the app _y_(_t_).
31*bf47c682SAndroid Build Coastguard Worker
32*bf47c682SAndroid Build Coastguard WorkerThe red 'x' marks are points where the finger was at times _t<sub>i</sub>_ when the finger went into or out of the laser beam. The y distance between the two lines of x marks is roughly the thickness of the finger. For now consider only one of the lines, e.g. the upper one.
33*bf47c682SAndroid Build Coastguard Worker
34*bf47c682SAndroid Build Coastguard WorkerNow imagine that the clocks timestamping the touch and the laser events diverge a little (this divergence is the latency we want to measure). The red 'x' marks would move along the graph. But half of them would move up and half down (corresponding to direction of the finger movement in that point) and therefore they would diverge in opposite directions from the relatively straight horizontal line you see on the screenshot.
35*bf47c682SAndroid Build Coastguard Worker
36*bf47c682SAndroid Build Coastguard WorkerThe WALT app finds a shift _S_ such that the standard deviation of _y_( _t<sub>i</sub>_ + _S_) is minimal - that is the 'x' marks are as close as possible to a horizontal straight line on the graph below. The reported number is the average of the two time shifts calculated separately for the upper and the lower lines (corresponding to two sides of the finger).
37*bf47c682SAndroid Build Coastguard Worker
38*bf47c682SAndroid Build Coastguard WorkerThis calculation that only looks at the _y_ coordinate assumes the laser beam is parallel to the _x_ axis and prefers no motion of the finger in the _x_ direction.
39*bf47c682SAndroid Build Coastguard Worker
40*bf47c682SAndroid Build Coastguard WorkerThe Python script used for ChromeOS employs a 2D extension of this method (implemented in [minimization.py](/pywalt/minimization.py)). This has the opposite requirement of some considerable spread of the collected _x_ coordinates.
41*bf47c682SAndroid Build Coastguard Worker
42*bf47c682SAndroid Build Coastguard Worker![Drag/scroll latency measurement results](Drag_screen_N5X.png)
43