1#!/usr/bin/env python3
2# Copyright (C) 2020 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
16from os import sys, path
17
18import synth_common
19
20class JankType:
21  JANK_UNSPECIFIED = 0;
22  JANK_NONE = 1;
23  JANK_SF_SCHEDULING = 2;
24  JANK_PREDICTION_ERROR = 4;
25  JANK_DISPLAY_HAL = 8;
26  JANK_SF_CPU_DEADLINE_MISSED = 16;
27  JANK_SF_GPU_DEADLINE_MISSED = 32;
28  JANK_APP_DEADLINE_MISSED = 64;
29  JANK_BUFFER_STUFFING = 128;
30  JANK_UNKNOWN = 256;
31  JANK_SF_STUFFING = 512;
32
33class PresentType:
34  PRESENT_UNSPECIFIED = 0;
35  PRESENT_ON_TIME = 1;
36  PRESENT_LATE = 2;
37  PRESENT_EARLY = 3;
38  PRESENT_DROPPED = 4;
39  PRESENT_UNKNOWN = 5;
40
41class PredictionType:
42  PREDICTION_UNSPECIFIED = 0;
43  PREDICTION_VALID = 1;
44  PREDICTION_EXPIRED = 2;
45  PREDICTION_UNKNOWN = 3;
46
47trace = synth_common.create_trace()
48
49# DisplayFrame without a SurfaceFrame
50trace.add_expected_display_frame_start_event(ts=20, cookie=1, token=2, pid=666)
51trace.add_frame_end_event(ts=26, cookie=1)
52trace.add_actual_display_frame_start_event(ts=20, cookie=2, token=2, pid=666, present_type=PresentType.PRESENT_ON_TIME, on_time_finish=1, gpu_composition=0, jank_type=JankType.JANK_NONE, prediction_type=PredictionType.PREDICTION_VALID)
53trace.add_frame_end_event(ts=26, cookie=2)
54
55# DisplayFrame with a SurfaceFrame
56trace.add_expected_display_frame_start_event(ts=40, cookie=3, token=4, pid=666)
57trace.add_frame_end_event(ts=46, cookie=3)
58trace.add_actual_display_frame_start_event(ts=42, cookie=4, token=4, pid=666, present_type=PresentType.PRESENT_ON_TIME, on_time_finish=1, gpu_composition=0, jank_type=JankType.JANK_NONE, prediction_type=PredictionType.PREDICTION_VALID)
59trace.add_frame_end_event(ts=47, cookie=4)
60trace.add_expected_surface_frame_start_event(ts=21, cookie=5, token=1, display_frame_token=4, pid=1000, layer_name="Layer1")
61trace.add_frame_end_event(ts=36, cookie=5)
62trace.add_actual_surface_frame_start_event(ts=21, cookie=6, token=1, display_frame_token=4, pid=1000, layer_name="Layer1", present_type=PresentType.PRESENT_ON_TIME, on_time_finish=1, gpu_composition=0, jank_type=JankType.JANK_NONE, prediction_type=PredictionType.PREDICTION_VALID)
63trace.add_frame_end_event(ts=37, cookie=6)
64
65
66# DisplayFrame with a janky SurfaceFrame
67trace.add_expected_display_frame_start_event(ts=80, cookie=7, token=6, pid=666)
68trace.add_frame_end_event(ts=86, cookie=7)
69trace.add_actual_display_frame_start_event(ts=81, cookie=8, token=6, pid=666, present_type=PresentType.PRESENT_ON_TIME, on_time_finish=1, gpu_composition=0, jank_type=JankType.JANK_NONE, prediction_type=PredictionType.PREDICTION_VALID)
70trace.add_frame_end_event(ts=88, cookie=8)
71trace.add_expected_surface_frame_start_event(ts=41, cookie=9, token=5, display_frame_token=6, pid=1000, layer_name="Layer1")
72trace.add_frame_end_event(ts=56, cookie=9)
73trace.add_actual_surface_frame_start_event(ts=41, cookie=10, token=5, display_frame_token=6, pid=1000, layer_name="Layer1", present_type=PresentType.PRESENT_LATE, on_time_finish=0, gpu_composition=0, jank_type=JankType.JANK_APP_DEADLINE_MISSED, prediction_type=PredictionType.PREDICTION_VALID)
74trace.add_frame_end_event(ts=74, cookie=10)
75
76
77# Janky DisplayFrame with a SurfaceFrame
78trace.add_expected_display_frame_start_event(ts=120, cookie=11, token=8, pid=666)
79trace.add_frame_end_event(ts=126, cookie=11)
80trace.add_actual_display_frame_start_event(ts=108, cookie=12, token=8, pid=666, present_type=PresentType.PRESENT_EARLY, on_time_finish=1, gpu_composition=0, jank_type=JankType.JANK_SF_SCHEDULING, prediction_type=PredictionType.PREDICTION_VALID)
81trace.add_frame_end_event(ts=112, cookie=12)
82trace.add_expected_surface_frame_start_event(ts=90, cookie=13, token=7, display_frame_token=8, pid=1000, layer_name="Layer1")
83trace.add_frame_end_event(ts=106, cookie=13)
84trace.add_actual_surface_frame_start_event(ts=90, cookie=14, token=7, display_frame_token=8, pid=1000, layer_name="Layer1", present_type=PresentType.PRESENT_EARLY, on_time_finish=1, gpu_composition=0, jank_type=JankType.JANK_SF_SCHEDULING, prediction_type=PredictionType.PREDICTION_VALID)
85trace.add_frame_end_event(ts=106, cookie=14)
86
87# DisplayFrame with multiple jank reasons
88trace.add_expected_display_frame_start_event(ts=140, cookie=15, token=12, pid=666)
89trace.add_frame_end_event(ts=146, cookie=15)
90trace.add_actual_display_frame_start_event(ts=148, cookie=16, token=12, pid=666, present_type=PresentType.PRESENT_LATE, on_time_finish=0, gpu_composition=0, jank_type=JankType.JANK_SF_CPU_DEADLINE_MISSED | JankType.JANK_SF_SCHEDULING, prediction_type=PredictionType.PREDICTION_VALID)
91trace.add_frame_end_event(ts=156, cookie=16)
92
93# Two SurfaceFrames with same token
94trace.add_expected_display_frame_start_event(ts=170, cookie=17, token=15, pid=666)
95trace.add_frame_end_event(ts=176, cookie=17)
96trace.add_actual_display_frame_start_event(ts=170, cookie=18, token=15, pid=666, present_type=PresentType.PRESENT_ON_TIME, on_time_finish=1, gpu_composition=0, jank_type=JankType.JANK_NONE, prediction_type=PredictionType.PREDICTION_VALID)
97trace.add_frame_end_event(ts=176, cookie=18)
98trace.add_expected_surface_frame_start_event(ts=150, cookie=19, token=14, display_frame_token=15, pid=1000, layer_name="Layer1")
99trace.add_frame_end_event(ts=170, cookie=19)
100trace.add_actual_surface_frame_start_event(ts=150, cookie=20, token=14, display_frame_token=15, pid=1000, layer_name="Layer1", present_type=PresentType.PRESENT_ON_TIME, on_time_finish=1, gpu_composition=0, jank_type=JankType.JANK_NONE, prediction_type=PredictionType.PREDICTION_VALID)
101trace.add_frame_end_event(ts=167, cookie=20)
102trace.add_expected_surface_frame_start_event(ts=150, cookie=21, token=14, display_frame_token=15, pid=1000, layer_name="Layer2")
103trace.add_frame_end_event(ts=170, cookie=21)
104trace.add_actual_surface_frame_start_event(ts=150, cookie=22, token=14, display_frame_token=15, pid=1000, layer_name="Layer2", present_type=PresentType.PRESENT_ON_TIME, on_time_finish=1, gpu_composition=0, jank_type=JankType.JANK_NONE, prediction_type=PredictionType.PREDICTION_VALID)
105trace.add_frame_end_event(ts=167, cookie=22)
106
107# SurfaceFrame with prediction expired (no expected timeline packet)
108trace.add_expected_display_frame_start_event(ts=200, cookie=23, token=17, pid=666)
109trace.add_frame_end_event(ts=206, cookie=23)
110trace.add_actual_display_frame_start_event(ts=200, cookie=24, token=17, pid=666, present_type=PresentType.PRESENT_ON_TIME, on_time_finish=1, gpu_composition=0, jank_type=JankType.JANK_NONE, prediction_type=PredictionType.PREDICTION_VALID)
111trace.add_frame_end_event(ts=206, cookie=24)
112trace.add_actual_surface_frame_start_event(ts=80, cookie=25, token=16, display_frame_token=17, pid=1000, layer_name="Layer1", present_type=PresentType.PRESENT_UNKNOWN, on_time_finish=0, gpu_composition=0, jank_type=JankType.JANK_UNKNOWN, prediction_type=PredictionType.PREDICTION_EXPIRED)
113trace.add_frame_end_event(ts=190, cookie=25)
114
115# DisplayFrame with SF Stuffing jank
116trace.add_expected_display_frame_start_event(ts=220, cookie=26, token=18, pid=666)
117trace.add_frame_end_event(ts=230, cookie=26)
118trace.add_actual_display_frame_start_event(ts=245, cookie=27, token=18, pid=666, present_type=PresentType.PRESENT_LATE, on_time_finish=0, gpu_composition=0, jank_type=JankType.JANK_SF_STUFFING, prediction_type=PredictionType.PREDICTION_VALID)
119trace.add_frame_end_event(ts=260, cookie=27)
120
121sys.stdout.buffer.write(trace.trace.SerializeToString())
122