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 21def add_main_thread_atrace(trace, ts, ts_end, buf): 22 trace.add_atrace_begin(ts=ts, tid=PID, pid=PID, buf=buf) 23 trace.add_atrace_end(ts=ts_end, tid=PID, pid=PID) 24 25 26def add_render_thread_atrace(trace, ts, ts_end, buf): 27 trace.add_atrace_begin(ts=ts, tid=RTID, pid=PID, buf=buf) 28 trace.add_atrace_end(ts=ts_end, tid=RTID, pid=PID) 29 30 31trace = synth_common.create_trace() 32 33trace.add_packet() 34trace.add_package_list( 35 ts=0, name="com.android.systemui", uid=10001, version_code=1) 36trace.add_package_list( 37 ts=0, 38 name="com.google.android.inputmethod.latin", 39 uid=10002, 40 version_code=1) 41 42trace.add_process(pid=1000, ppid=1, cmdline="com.android.systemui", uid=10001) 43trace.add_thread( 44 tid=1001, tgid=1000, cmdline="RenderThread", name="RenderThread") 45trace.add_process( 46 pid=2000, ppid=1, cmdline="com.google.android.inputmethod.latin", uid=10002) 47trace.add_thread( 48 tid=2001, tgid=2000, cmdline="RenderThread", name="RenderThread") 49 50trace.add_ftrace_packet(cpu=0) 51 52# com.android.systemui 53 54trace.add_atrace_begin( 55 ts=1_000_000, tid=1000, pid=1000, buf='Choreographer#doFrame') 56trace.add_atrace_begin(ts=1_000_100, tid=1000, pid=1000, buf='traversal') 57trace.add_atrace_begin(ts=1_000_500, tid=1000, pid=1000, buf='measure') 58trace.add_atrace_end(ts=4_000_000, tid=1000, pid=1000) 59trace.add_atrace_begin(ts=4_000_500, tid=1000, pid=1000, buf='layout') 60trace.add_atrace_begin(ts=4_001_000, tid=1000, pid=1000, buf='setupListItem') 61trace.add_atrace_begin(ts=4_500_000, tid=1000, pid=1000, buf='inflate') 62trace.add_atrace_end(ts=5_500_000, tid=1000, pid=1000) 63trace.add_atrace_begin(ts=6_500_000, tid=1000, pid=1000, buf='inflate') 64trace.add_atrace_end(ts=7_500_000, tid=1000, pid=1000) 65trace.add_atrace_end(ts=7_500_500, tid=1000, pid=1000) 66trace.add_atrace_begin(ts=8_000_000, tid=1000, pid=1000, buf='obtainView') 67trace.add_atrace_begin(ts=8_000_100, tid=1000, pid=1000, buf='inflate') 68trace.add_atrace_end(ts=8_500_000, tid=1000, pid=1000) 69trace.add_atrace_end(ts=8_900_000, tid=1000, pid=1000) 70trace.add_atrace_end(ts=9_000_000, tid=1000, pid=1000) 71trace.add_atrace_end(ts=9_000_000, tid=1000, pid=1000) 72trace.add_atrace_end(ts=20_000_000, tid=1000, pid=1000) 73 74trace.add_sched(ts=1_000_000, prev_pid=0, next_pid=1000) 75trace.add_sched(ts=10_000_000, prev_pid=1000, next_pid=0, prev_state='R') 76trace.add_sched(ts=10_500_000, prev_pid=0, next_pid=0) 77trace.add_sched(ts=19_500_000, prev_pid=0, next_pid=1000) 78trace.add_sched(ts=20_500_000, prev_pid=1000, next_pid=0, prev_state='R') 79 80# com.google.android.inputmethod.latin 81 82trace.add_atrace_begin( 83 ts=101_000_000, tid=2000, pid=2000, buf='Choreographer#doFrame') 84trace.add_atrace_begin(ts=101_000_100, tid=2000, pid=2000, buf='traversal') 85trace.add_atrace_begin(ts=101_000_500, tid=2000, pid=2000, buf='measure') 86trace.add_atrace_end(ts=104_000_000, tid=2000, pid=2000) 87trace.add_atrace_begin(ts=104_000_500, tid=2000, pid=2000, buf='layout') 88trace.add_atrace_end(ts=105_000_000, tid=2000, pid=2000) 89trace.add_atrace_end(ts=105_000_000, tid=2000, pid=2000) 90trace.add_atrace_begin(ts=105_000_000, tid=2000, pid=2000, buf='draw') 91trace.add_atrace_end(ts=119_000_000, tid=2000, pid=2000) 92trace.add_atrace_end(ts=120_000_000, tid=2000, pid=2000) 93 94trace.add_atrace_begin(ts=105_000_000, tid=2001, pid=2000, buf='DrawFrames 3') 95trace.add_atrace_begin( 96 ts=108_000_000, tid=2001, pid=2000, buf='Upload 300x300 Texture') 97trace.add_atrace_end(ts=112_000_000, tid=2001, pid=2000) 98trace.add_atrace_begin( 99 ts=116_000_000, 100 tid=2001, 101 pid=2000, 102 buf='alpha caused unclipped saveLayer 201x319') 103trace.add_atrace_end(ts=117_300_000, tid=2001, pid=2000) 104trace.add_atrace_end(ts=118_000_000, tid=2001, pid=2000) 105 106trace.add_sched(ts=101_000_000, prev_pid=0, next_pid=2000) 107trace.add_sched(ts=120_000_000, prev_pid=2000, next_pid=0, prev_state='R') 108trace.add_sched(ts=120_500_000, prev_pid=0, next_pid=0) 109 110sys.stdout.buffer.write(trace.trace.SerializeToString()) 111