• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
20
21class JankType:
22  JANK_UNSPECIFIED = 0
23  JANK_NONE = 1
24  JANK_SF_SCHEDULING = 2
25  JANK_PREDICTION_ERROR = 4
26  JANK_DISPLAY_HAL = 8
27  JANK_SF_CPU_DEADLINE_MISSED = 16
28  JANK_SF_GPU_DEADLINE_MISSED = 32
29  JANK_APP_DEADLINE_MISSED = 64
30  JANK_BUFFER_STUFFING = 128
31  JANK_UNKNOWN = 256
32  JANK_SF_STUFFING = 512
33  JANK_DROPPED = 1024
34
35
36class JankSeverityType:
37  UNKNOWN = 0
38  NONE = 1
39  PARTIAL = 2
40  FULL = 3
41
42
43class PresentType:
44  PRESENT_UNSPECIFIED = 0
45  PRESENT_ON_TIME = 1
46  PRESENT_LATE = 2
47  PRESENT_EARLY = 3
48  PRESENT_DROPPED = 4
49  PRESENT_UNKNOWN = 5
50
51
52class PredictionType:
53  PREDICTION_UNSPECIFIED = 0
54  PREDICTION_VALID = 1
55  PREDICTION_EXPIRED = 2
56  PREDICTION_UNKNOWN = 3
57
58
59trace = synth_common.create_trace()
60
61# DisplayFrame without a SurfaceFrame
62trace.add_expected_display_frame_start_event(ts=20, cookie=1, token=2, pid=666)
63trace.add_frame_end_event(ts=26, cookie=1)
64trace.add_actual_display_frame_start_event(
65    ts=20,
66    cookie=2,
67    token=2,
68    pid=666,
69    present_type=PresentType.PRESENT_ON_TIME,
70    on_time_finish=1,
71    gpu_composition=0,
72    jank_type=JankType.JANK_NONE,
73    prediction_type=PredictionType.PREDICTION_VALID)
74trace.add_frame_end_event(ts=26, cookie=2)
75
76# DisplayFrame with a SurfaceFrame
77trace.add_expected_display_frame_start_event(ts=40, cookie=3, token=4, pid=666)
78trace.add_frame_end_event(ts=46, cookie=3)
79trace.add_actual_display_frame_start_event(
80    ts=42,
81    cookie=4,
82    token=4,
83    pid=666,
84    present_type=PresentType.PRESENT_ON_TIME,
85    on_time_finish=1,
86    gpu_composition=0,
87    jank_type=JankType.JANK_NONE,
88    prediction_type=PredictionType.PREDICTION_VALID)
89trace.add_frame_end_event(ts=47, cookie=4)
90trace.add_expected_surface_frame_start_event(
91    ts=21,
92    cookie=5,
93    token=1,
94    display_frame_token=4,
95    pid=1000,
96    layer_name="Layer1")
97trace.add_frame_end_event(ts=36, cookie=5)
98trace.add_actual_surface_frame_start_event(
99    ts=21,
100    cookie=6,
101    token=1,
102    display_frame_token=4,
103    pid=1000,
104    layer_name="Layer1",
105    present_type=PresentType.PRESENT_ON_TIME,
106    on_time_finish=1,
107    gpu_composition=0,
108    jank_type=JankType.JANK_NONE,
109    prediction_type=PredictionType.PREDICTION_VALID)
110trace.add_frame_end_event(ts=37, cookie=6)
111
112# DisplayFrame with a janky SurfaceFrame
113trace.add_expected_display_frame_start_event(ts=80, cookie=7, token=6, pid=666)
114trace.add_frame_end_event(ts=86, cookie=7)
115trace.add_actual_display_frame_start_event(
116    ts=81,
117    cookie=8,
118    token=6,
119    pid=666,
120    present_type=PresentType.PRESENT_ON_TIME,
121    on_time_finish=1,
122    gpu_composition=0,
123    jank_type=JankType.JANK_NONE,
124    prediction_type=PredictionType.PREDICTION_VALID)
125trace.add_frame_end_event(ts=88, cookie=8)
126trace.add_expected_surface_frame_start_event(
127    ts=41,
128    cookie=9,
129    token=5,
130    display_frame_token=6,
131    pid=1000,
132    layer_name="Layer1")
133trace.add_frame_end_event(ts=56, cookie=9)
134trace.add_actual_surface_frame_start_event(
135    ts=41,
136    cookie=10,
137    token=5,
138    display_frame_token=6,
139    pid=1000,
140    layer_name="Layer1",
141    present_type=PresentType.PRESENT_LATE,
142    on_time_finish=0,
143    gpu_composition=0,
144    jank_type=JankType.JANK_APP_DEADLINE_MISSED,
145    jank_severity_type=JankSeverityType.FULL,
146    prediction_type=PredictionType.PREDICTION_VALID)
147trace.add_frame_end_event(ts=74, cookie=10)
148
149# Janky DisplayFrame with a SurfaceFrame
150trace.add_expected_display_frame_start_event(
151    ts=120, cookie=11, token=8, pid=666)
152trace.add_frame_end_event(ts=126, cookie=11)
153trace.add_actual_display_frame_start_event(
154    ts=108,
155    cookie=12,
156    token=8,
157    pid=666,
158    present_type=PresentType.PRESENT_EARLY,
159    on_time_finish=1,
160    gpu_composition=0,
161    jank_type=JankType.JANK_SF_SCHEDULING,
162    prediction_type=PredictionType.PREDICTION_VALID)
163trace.add_frame_end_event(ts=112, cookie=12)
164trace.add_expected_surface_frame_start_event(
165    ts=90,
166    cookie=13,
167    token=7,
168    display_frame_token=8,
169    pid=1000,
170    layer_name="Layer1")
171trace.add_frame_end_event(ts=106, cookie=13)
172trace.add_actual_surface_frame_start_event(
173    ts=90,
174    cookie=14,
175    token=7,
176    display_frame_token=8,
177    pid=1000,
178    layer_name="Layer1",
179    present_type=PresentType.PRESENT_EARLY,
180    on_time_finish=1,
181    gpu_composition=0,
182    jank_type=JankType.JANK_SF_SCHEDULING,
183    prediction_type=PredictionType.PREDICTION_VALID)
184trace.add_frame_end_event(ts=106, cookie=14)
185
186# DisplayFrame with multiple jank reasons
187trace.add_expected_display_frame_start_event(
188    ts=140, cookie=15, token=12, pid=666)
189trace.add_frame_end_event(ts=146, cookie=15)
190trace.add_actual_display_frame_start_event(
191    ts=148,
192    cookie=16,
193    token=12,
194    pid=666,
195    present_type=PresentType.PRESENT_LATE,
196    on_time_finish=0,
197    gpu_composition=0,
198    jank_type=JankType.JANK_SF_CPU_DEADLINE_MISSED
199    | JankType.JANK_SF_SCHEDULING,
200    prediction_type=PredictionType.PREDICTION_VALID)
201trace.add_frame_end_event(ts=156, cookie=16)
202
203# Two SurfaceFrames with same token
204trace.add_expected_display_frame_start_event(
205    ts=170, cookie=17, token=15, pid=666)
206trace.add_frame_end_event(ts=176, cookie=17)
207trace.add_actual_display_frame_start_event(
208    ts=170,
209    cookie=18,
210    token=15,
211    pid=666,
212    present_type=PresentType.PRESENT_ON_TIME,
213    on_time_finish=1,
214    gpu_composition=0,
215    jank_type=JankType.JANK_NONE,
216    prediction_type=PredictionType.PREDICTION_VALID)
217trace.add_frame_end_event(ts=176, cookie=18)
218trace.add_expected_surface_frame_start_event(
219    ts=150,
220    cookie=19,
221    token=14,
222    display_frame_token=15,
223    pid=1000,
224    layer_name="Layer1")
225trace.add_frame_end_event(ts=170, cookie=19)
226trace.add_actual_surface_frame_start_event(
227    ts=150,
228    cookie=20,
229    token=14,
230    display_frame_token=15,
231    pid=1000,
232    layer_name="Layer1",
233    present_type=PresentType.PRESENT_ON_TIME,
234    on_time_finish=1,
235    gpu_composition=0,
236    jank_type=JankType.JANK_NONE,
237    prediction_type=PredictionType.PREDICTION_VALID)
238trace.add_frame_end_event(ts=167, cookie=20)
239trace.add_expected_surface_frame_start_event(
240    ts=150,
241    cookie=21,
242    token=14,
243    display_frame_token=15,
244    pid=1000,
245    layer_name="Layer2")
246trace.add_frame_end_event(ts=170, cookie=21)
247trace.add_actual_surface_frame_start_event(
248    ts=150,
249    cookie=22,
250    token=14,
251    display_frame_token=15,
252    pid=1000,
253    layer_name="Layer2",
254    present_type=PresentType.PRESENT_ON_TIME,
255    on_time_finish=1,
256    gpu_composition=0,
257    jank_type=JankType.JANK_NONE,
258    prediction_type=PredictionType.PREDICTION_VALID)
259trace.add_frame_end_event(ts=167, cookie=22)
260
261# SurfaceFrame with prediction expired (no expected timeline packet)
262trace.add_expected_display_frame_start_event(
263    ts=200, cookie=23, token=17, pid=666)
264trace.add_frame_end_event(ts=206, cookie=23)
265trace.add_actual_display_frame_start_event(
266    ts=200,
267    cookie=24,
268    token=17,
269    pid=666,
270    present_type=PresentType.PRESENT_ON_TIME,
271    on_time_finish=1,
272    gpu_composition=0,
273    jank_type=JankType.JANK_NONE,
274    prediction_type=PredictionType.PREDICTION_VALID)
275trace.add_frame_end_event(ts=206, cookie=24)
276trace.add_actual_surface_frame_start_event(
277    ts=80,
278    cookie=25,
279    token=16,
280    display_frame_token=17,
281    pid=1000,
282    layer_name="Layer1",
283    present_type=PresentType.PRESENT_UNKNOWN,
284    on_time_finish=0,
285    gpu_composition=0,
286    jank_type=JankType.JANK_UNKNOWN,
287    jank_severity_type=JankSeverityType.PARTIAL,
288    prediction_type=PredictionType.PREDICTION_EXPIRED)
289trace.add_frame_end_event(ts=190, cookie=25)
290
291# DisplayFrame with SF Stuffing jank
292trace.add_expected_display_frame_start_event(
293    ts=220, cookie=26, token=18, pid=666)
294trace.add_frame_end_event(ts=230, cookie=26)
295trace.add_actual_display_frame_start_event(
296    ts=245,
297    cookie=27,
298    token=18,
299    pid=666,
300    present_type=PresentType.PRESENT_LATE,
301    on_time_finish=0,
302    gpu_composition=0,
303    jank_type=JankType.JANK_SF_STUFFING,
304    prediction_type=PredictionType.PREDICTION_VALID)
305trace.add_frame_end_event(ts=260, cookie=27)
306
307# DisplayFrame with dropped frame jank
308trace.add_expected_display_frame_start_event(
309    ts=220, cookie=26, token=18, pid=666)
310trace.add_frame_end_event(ts=230, cookie=26)
311trace.add_actual_display_frame_start_event(
312    ts=245,
313    cookie=27,
314    token=18,
315    pid=666,
316    present_type=PresentType.PRESENT_DROPPED,
317    on_time_finish=0,
318    gpu_composition=0,
319    jank_type=JankType.JANK_DROPPED,
320    prediction_type=PredictionType.PREDICTION_UNSPECIFIED)
321trace.add_frame_end_event(ts=260, cookie=27)
322
323sys.stdout.buffer.write(trace.trace.SerializeToString())
324