• 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
20PID = 1000
21RTID = 1555
22JITID = 1777
23LAYER = "TX - NotificationShade#0"
24
25
26def add_main_thread_atrace(trace, ts, ts_end, buf):
27  trace.add_atrace_begin(ts=ts, tid=PID, pid=PID, buf=buf)
28  trace.add_atrace_end(ts=ts_end, tid=PID, pid=PID)
29
30
31def add_render_thread_atrace(trace, ts, ts_end, buf):
32  trace.add_atrace_begin(ts=ts, tid=RTID, pid=PID, buf=buf)
33  trace.add_atrace_end(ts=ts_end, tid=RTID, pid=PID)
34
35
36def add_gpu_thread_atrace(trace, ts, ts_end, buf):
37  trace.add_atrace_begin(ts=ts, tid=1666, pid=PID, buf=buf)
38  trace.add_atrace_end(ts=ts_end, tid=1666, pid=PID)
39
40
41def add_jit_thread_atrace(trace, ts, ts_end, buf):
42  trace.add_atrace_begin(ts=ts, tid=JITID, pid=PID, buf=buf)
43  trace.add_atrace_end(ts=ts_end, tid=JITID, pid=PID)
44
45
46def add_frame(trace, vsync, ts_do_frame, ts_end_do_frame, ts_draw_frame,
47              ts_end_draw_frame, ts_gpu, ts_end_gpu):
48  add_main_thread_atrace(trace, ts_do_frame, ts_end_do_frame,
49                         "Choreographer#doFrame %d" % vsync)
50  add_render_thread_atrace(trace, ts_draw_frame, ts_end_draw_frame,
51                           "DrawFrames %d" % vsync)
52  add_gpu_thread_atrace(trace, ts_gpu, ts_end_gpu,
53                        "waiting for GPU completion 123")
54
55
56def add_display_frame_events(ts,
57                             dur,
58                             token_start,
59                             jank=None,
60                             on_time_finish_override=None):
61  jank_type = jank if jank is not None else 1
62  present_type = 2 if jank is not None else 1
63  if on_time_finish_override is None:
64    on_time_finish = 1 if jank is None else 0
65  else:
66    on_time_finish = on_time_finish_override
67  trace.add_expected_display_frame_start_event(
68      ts=ts, cookie=token_start, token=token_start, pid=PID)
69  trace.add_frame_end_event(ts=ts + 20_500_000, cookie=token_start)
70  trace.add_actual_display_frame_start_event(
71      ts=ts,
72      cookie=token_start + 1,
73      token=token_start,
74      pid=PID,
75      present_type=present_type,
76      on_time_finish=on_time_finish,
77      gpu_composition=0,
78      jank_type=jank_type,
79      prediction_type=3)
80  trace.add_frame_end_event(ts=ts + dur, cookie=token_start + 1)
81  trace.add_expected_surface_frame_start_event(
82      ts=ts,
83      cookie=token_start + 2,
84      token=token_start,
85      display_frame_token=token_start,
86      pid=PID,
87      layer_name=LAYER)
88  trace.add_frame_end_event(ts=ts + 20_500_000, cookie=token_start + 2)
89  trace.add_actual_surface_frame_start_event(
90      ts=ts,
91      cookie=token_start + 3,
92      token=token_start,
93      display_frame_token=token_start,
94      pid=PID,
95      layer_name=LAYER,
96      present_type=present_type,
97      on_time_finish=on_time_finish,
98      gpu_composition=0,
99      jank_type=jank_type,
100      prediction_type=3)
101  trace.add_frame_end_event(ts=ts + dur, cookie=token_start + 3)
102
103
104trace = synth_common.create_trace()
105
106trace.add_packet()
107trace.add_package_list(
108    ts=0, name="com.android.systemui", uid=10001, version_code=1)
109
110trace.add_process(pid=PID, ppid=1, cmdline="com.android.systemui", uid=10001)
111trace.add_thread(
112    tid=RTID, tgid=PID, cmdline="RenderThread", name="RenderThread")
113trace.add_thread(
114    tid=1666, tgid=PID, cmdline="GPU completion", name="GPU completion")
115trace.add_thread(
116    tid=JITID, tgid=PID, cmdline="Jit thread pool", name="Jit thread pool")
117trace.add_ftrace_packet(cpu=0)
118trace.add_atrace_async_begin(ts=0, tid=PID, pid=PID, buf="J<SHADE_ROW_EXPAND>")
119trace.add_atrace_async_end(
120    ts=1_000_000_000, tid=PID, pid=PID, buf="J<SHADE_ROW_EXPAND>")
121
122add_frame(
123    trace,
124    vsync=10,
125    ts_do_frame=0,
126    ts_end_do_frame=5_000_000,
127    ts_draw_frame=4_000_000,
128    ts_end_draw_frame=5_000_000,
129    ts_gpu=10_000_000,
130    ts_end_gpu=15_000_000)
131add_main_thread_atrace(
132    trace, ts=1_500_000, ts_end=2_000_000, buf="binder transaction")
133add_render_thread_atrace(
134    trace, ts=4_500_000, ts_end=4_800_000, buf="flush layers")
135
136
137add_frame(
138    trace,
139    vsync=20,
140    ts_do_frame=8_000_000,
141    ts_end_do_frame=23_000_000,
142    ts_draw_frame=22_000_000,
143    ts_end_draw_frame=26_000_000,
144    ts_gpu=27_500_000,
145    ts_end_gpu=35_000_000)
146add_main_thread_atrace(
147    trace, ts=9_000_000, ts_end=20_000_000, buf="binder transaction")
148add_render_thread_atrace(
149    trace, ts=24_000_000, ts_end=25_000_000, buf="flush layers")
150
151add_frame(
152    trace,
153    vsync=30,
154    ts_do_frame=30_000_000,
155    ts_end_do_frame=33_000_000,
156    ts_draw_frame=31_000_000,
157    ts_end_draw_frame=50_000_000,
158    ts_gpu=51_500_000,
159    ts_end_gpu=52_000_000)
160add_main_thread_atrace(
161    trace, ts=31_000_000, ts_end=31_050_000, buf="binder transaction")
162add_main_thread_atrace(
163    trace, ts=31_100_000, ts_end=31_150_000, buf="binder transaction")
164add_main_thread_atrace(
165    trace, ts=31_200_000, ts_end=31_250_000, buf="binder transaction")
166add_main_thread_atrace(
167    trace, ts=31_300_000, ts_end=31_350_000, buf="binder transaction")
168add_main_thread_atrace(
169    trace, ts=31_400_000, ts_end=31_450_000, buf="binder transaction")
170add_main_thread_atrace(
171    trace, ts=31_500_000, ts_end=31_550_000, buf="binder transaction")
172add_main_thread_atrace(
173    trace, ts=31_600_000, ts_end=31_650_000, buf="binder transaction")
174add_main_thread_atrace(
175    trace, ts=31_700_000, ts_end=31_750_000, buf="binder transaction")
176add_main_thread_atrace(
177    trace, ts=31_800_000, ts_end=31_850_000, buf="binder transaction")
178add_render_thread_atrace(
179    trace, ts=38_000_000, ts_end=50_000_000, buf="flush layers")
180
181add_frame(
182    trace,
183    vsync=40,
184    ts_do_frame=40_000_000,
185    ts_end_do_frame=53_000_000,
186    ts_draw_frame=52_000_000,
187    ts_end_draw_frame=59_000_000,
188    ts_gpu=66_500_000,
189    ts_end_gpu=78_000_000)
190
191add_jit_thread_atrace(
192    trace,
193    ts=39_000_000,
194    ts_end=45_000_000,
195    buf="JIT compiling void aa.aa(java.lang.Object, bb) (kind=Baseline)")
196add_jit_thread_atrace(
197    trace,
198    ts=46_000_000,
199    ts_end=47_000_000,
200    buf="Lock contention on Jit code cache (owner tid: 12345)")
201add_jit_thread_atrace(
202    trace,
203    ts=52_500_000,
204    ts_end=54_000_000,
205    buf="JIT compiling void cc.bb(java.lang.Object, bb) (kind=Osr)")
206add_jit_thread_atrace(
207    trace,
208    ts=56_500_000,
209    ts_end=60_000_000,
210    buf="JIT compiling void ff.zz(java.lang.Object, bb) (kind=Baseline)")
211
212# Main thread Running for 14 millis
213trace.add_sched(ts=39_000_000, prev_pid=0, next_pid=PID)
214trace.add_sched(ts=53_000_000, prev_pid=PID, next_pid=0, prev_state='R')
215
216# RenderThread Running for 5 millis
217trace.add_sched(ts=54_000_000, prev_pid=0, next_pid=RTID)
218trace.add_sched(ts=59_000_000, prev_pid=RTID, next_pid=0, prev_state='R')
219
220add_frame(
221    trace,
222    vsync=60,
223    ts_do_frame=70_000_000,
224    ts_end_do_frame=80_000_000,
225    ts_draw_frame=78_000_000,
226    ts_end_draw_frame=87_000_000,
227    ts_gpu=86_500_000,
228    ts_end_gpu=88_000_000)
229
230# Main thread Running for 1 millis
231trace.add_sched(ts=70_000_000, prev_pid=0, next_pid=PID)
232trace.add_sched(ts=71_000_000, prev_pid=PID, next_pid=0, prev_state='R')
233
234# RenderThread Running for 1 millis and R for 9.5 millis
235trace.add_sched(ts=78_000_000, prev_pid=0, next_pid=RTID)
236trace.add_sched(ts=78_500_000, prev_pid=RTID, next_pid=0, prev_state='R')
237trace.add_sched(ts=78_500_000, prev_pid=0, next_pid=0)
238trace.add_sched(ts=88_000_000, prev_pid=0, next_pid=RTID)
239trace.add_sched(ts=88_500_000, prev_pid=RTID, next_pid=0, prev_state='R')
240
241add_frame(
242    trace,
243    vsync=90,
244    ts_do_frame=100_000_000,
245    ts_end_do_frame=115_000_000,
246    ts_draw_frame=102_000_000,
247    ts_end_draw_frame=104_000_000,
248    ts_gpu=108_000_000,
249    ts_end_gpu=115_600_000)
250
251add_render_thread_atrace(
252    trace, ts=108_000_000, ts_end=114_000_000, buf="DrawFrames 90")
253add_gpu_thread_atrace(
254    trace,
255    ts=121_500_000,
256    ts_end=122_000_000,
257    buf="waiting for GPU completion 123")
258
259add_frame(
260    trace,
261    vsync=100,
262    ts_do_frame=200_000_000,
263    ts_end_do_frame=215_000_000,
264    ts_draw_frame=202_000_000,
265    ts_end_draw_frame=204_000_000,
266    ts_gpu=208_000_000,
267    ts_end_gpu=210_000_000)
268
269add_render_thread_atrace(
270    trace, ts=208_000_000, ts_end=214_000_000, buf="DrawFrames 100")
271
272add_frame(
273    trace,
274    vsync=110,
275    ts_do_frame=300_000_000,
276    ts_end_do_frame=315_000_000,
277    ts_draw_frame=302_000_000,
278    ts_end_draw_frame=304_000_000,
279    ts_gpu=308_000_000,
280    ts_end_gpu=310_000_000)
281
282add_render_thread_atrace(
283    trace, ts=305_000_000, ts_end=308_000_000, buf="dispatchFrameCallbacks")
284
285add_frame(
286    trace,
287    vsync=120,
288    ts_do_frame=400_000_000,
289    ts_end_do_frame=415_000_000,
290    ts_draw_frame=402_000_000,
291    ts_end_draw_frame=404_000_000,
292    ts_gpu=408_000_000,
293    ts_end_gpu=410_000_000)
294
295add_render_thread_atrace(
296    trace, ts=415_000_000, ts_end=418_000_000, buf="dispatchFrameCallbacks")
297
298# One more frame after the CUJ is finished
299add_frame(
300    trace,
301    vsync=130,
302    ts_do_frame=1_100_000_000,
303    ts_end_do_frame=1_200_000_000,
304    ts_draw_frame=1_150_000_000,
305    ts_end_draw_frame=1_300_000_000,
306    ts_gpu=1_400_000_000,
307    ts_end_gpu=1_500_000_000)
308
309add_display_frame_events(ts=1, dur=16_000_000, token_start=10)
310add_display_frame_events(ts=8_000_000, dur=28_000_000, token_start=20, jank=66)
311add_display_frame_events(ts=30_000_000, dur=25_000_000, token_start=30, jank=64)
312add_display_frame_events(ts=40_000_000, dur=40_000_000, token_start=40, jank=64)
313add_display_frame_events(ts=70_000_000, dur=20_000_000, token_start=60, jank=64)
314add_display_frame_events(
315    ts=100_000_000, dur=23_000_000, token_start=90, jank=64)
316add_display_frame_events(
317    ts=200_000_000, dur=22_000_000, token_start=100, jank=34)
318add_display_frame_events(ts=300_000_000, dur=61_000_000, token_start=110)
319add_display_frame_events(
320    ts=400_000_000,
321    dur=61_000_000,
322    token_start=120,
323    jank=128,
324    on_time_finish_override=1)
325add_display_frame_events(
326    ts=1_100_000_000, dur=500_000_000, token_start=130, jank=64)
327
328sys.stdout.buffer.write(trace.trace.SerializeToString())
329