1#!/usr/bin/env python3 2# Copyright (C) 2021 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16# Discarded events that do not get to GPU are invisible for UMA metric and 17# therefore should be excluded in trace-based metric. This tests ensures that's 18# the case. 19 20from os import sys 21 22import synth_common 23 24from synth_common import ms_to_ns 25trace = synth_common.create_trace() 26 27 28class Helper: 29 30 def __init__(self, trace, start_id, start_gesture_id): 31 self.trace = trace 32 self.id = start_id 33 self.gesture_id = start_gesture_id 34 35 def begin(self, from_ms, dur_ms): 36 self.trace.add_input_latency_event_slice( 37 "GestureScrollBegin", 38 ts=ms_to_ns(from_ms), 39 dur=ms_to_ns(dur_ms), 40 track=self.id, 41 trace_id=self.id, 42 gesture_scroll_id=self.gesture_id, 43 ) 44 self.id += 1 45 46 def update(self, from_ms, dur_ms, gets_to_gpu=True): 47 self.trace.add_input_latency_event_slice( 48 "GestureScrollUpdate", 49 ts=ms_to_ns(from_ms), 50 dur=ms_to_ns(dur_ms), 51 track=self.id, 52 trace_id=self.id, 53 gesture_scroll_id=self.gesture_id, 54 gets_to_gpu=gets_to_gpu, 55 is_coalesced=False, 56 ) 57 self.id += 1 58 59 def end(self, from_ms, dur_ms): 60 self.trace.add_input_latency_event_slice( 61 "GestureScrollEnd", 62 ts=ms_to_ns(from_ms), 63 dur=ms_to_ns(dur_ms), 64 track=self.id, 65 trace_id=self.id, 66 gesture_scroll_id=self.gesture_id) 67 self.id += 1 68 self.gesture_id += 1 69 70 71helper = Helper(trace, start_id=1234, start_gesture_id=5678) 72 73helper.begin(from_ms=0, dur_ms=10) 74helper.update(from_ms=15, dur_ms=10) 75# The next update should be recognized as janky 76helper.update(from_ms=30, dur_ms=30) 77helper.end(from_ms=70, dur_ms=10) 78 79helper.begin(from_ms=100, dur_ms=10) 80helper.update(from_ms=115, dur_ms=10) 81# The next update doesn't get to GPU, therefore would not be a part of jank 82# calculation 83helper.update(from_ms=130, dur_ms=30, gets_to_gpu=False) 84helper.end(from_ms=170, dur_ms=10) 85 86sys.stdout.buffer.write(trace.trace.SerializeToString()) 87