1#!/usr/bin/env python3 2# Copyright (C) 2018 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 17 18import synth_common 19 20 21def to_s(ts): 22 return ts * 1000 * 1000 * 1000 23 24 25trace = synth_common.create_trace() 26trace.add_packet() 27trace.add_process(1, 0, 'init') 28trace.add_process(2, 1, 'system_server') 29trace.add_process(3, 1, 'com.google.android.calendar', 10003) 30trace.add_process(4, 1, 'com.google.android.calculator', 10004) 31trace.add_process(5, 1, 'com.google.android.deskclock', 10005) 32trace.add_process(6, 1, 'com.google.android.gm', 10006) 33trace.add_process(10, 1, 'dex2oat64') 34trace.add_process(11, 1, 'installd') 35 36trace.add_package_list( 37 ts=to_s(1), name='com.google.android.calendar', uid=10003, version_code=123) 38trace.add_package_list( 39 ts=to_s(2), 40 name='com.google.android.calculator', 41 uid=10004, 42 version_code=123) 43trace.add_package_list( 44 ts=to_s(3), 45 name='com.google.android.deskclock', 46 uid=10005, 47 version_code=123) 48trace.add_package_list( 49 ts=to_s(4), name='com.google.android.gm', uid=10006, version_code=123) 50 51trace.add_ftrace_packet(cpu=0) 52 53# First launch: don't have either dex2oat or installd 54trace.add_atrace_async_begin( 55 ts=to_s(100), tid=2, pid=2, buf='launchingActivity#1') 56trace.add_atrace_async_end( 57 ts=to_s(200), tid=2, pid=2, buf='launchingActivity#1') 58trace.add_atrace_instant( 59 ts=to_s(201), 60 tid=2, 61 pid=2, 62 buf='launchingActivity#1:completed:com.google.android.calendar') 63 64# Second launch: just dex2oat 65trace.add_atrace_async_begin( 66 ts=to_s(300), tid=2, pid=2, buf='launchingActivity#2') 67trace.add_sched(ts=to_s(305), prev_pid=0, next_pid=10) 68trace.add_sched(ts=to_s(310), prev_pid=10, next_pid=0) 69trace.add_atrace_async_end( 70 ts=to_s(400), tid=2, pid=2, buf='launchingActivity#2') 71trace.add_atrace_instant( 72 ts=to_s(401), 73 tid=2, 74 pid=2, 75 buf='launchingActivity#2:completed:com.google.android.calculator') 76 77# Third launch: just installd 78trace.add_atrace_async_begin( 79 ts=to_s(500), tid=2, pid=2, buf='launchingActivity#3') 80trace.add_sched(ts=to_s(505), prev_pid=0, next_pid=11) 81trace.add_sched(ts=to_s(510), prev_pid=11, next_pid=0) 82trace.add_atrace_async_end( 83 ts=to_s(750), tid=2, pid=2, buf='launchingActivity#3') 84trace.add_atrace_instant( 85 ts=to_s(751), 86 tid=2, 87 pid=2, 88 buf='launchingActivity#3:completed:com.google.android.deskclock') 89 90# Third launch: just installd 91trace.add_atrace_async_begin( 92 ts=to_s(700), tid=2, pid=2, buf='launchingActivity#4') 93trace.add_sched(ts=to_s(705), prev_pid=0, next_pid=10) 94trace.add_sched(ts=to_s(710), prev_pid=10, next_pid=0) 95trace.add_sched(ts=to_s(715), prev_pid=0, next_pid=11) 96trace.add_sched(ts=to_s(720), prev_pid=11, next_pid=0) 97trace.add_atrace_async_end( 98 ts=to_s(800), tid=2, pid=2, buf='launchingActivity#4') 99trace.add_atrace_instant( 100 ts=to_s(801), 101 tid=2, 102 pid=2, 103 buf='launchingActivity#4:completed:com.google.android.gm') 104 105sys.stdout.buffer.write(trace.trace.SerializeToString()) 106