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, path 17 18import synth_common 19 20APP_PID = 3 21APP_TID = APP_PID 22SECOND_APP_TID = 3 23JIT_TID = 4 24GC_TID = 5 25GC2_TID = 6 26BINDER_TID = 7 27FONTS_TID = 8 28SYSTEM_SERVER_PID = 2 29SYSTEM_SERVER_TID = 2 30LAUNCH_START_TS = 100 31LAUNCH_END_TS = 10**9 32 33trace = synth_common.create_trace() 34trace.add_packet() 35trace.add_process(1, 0, 'init') 36trace.add_process(SYSTEM_SERVER_PID, 1, 'system_server') 37trace.add_process(APP_PID, 1, 'com.some.app') 38trace.add_thread(tid=SECOND_APP_TID, tgid=APP_PID, cmdline='second_thread') 39trace.add_thread( 40 tid=JIT_TID, 41 tgid=APP_PID, 42 cmdline='Jit thread pool', 43 name='Jit thread pool') 44trace.add_thread( 45 tid=GC_TID, tgid=APP_PID, cmdline='HeapTaskDaemon', name='HeapTaskDaemon') 46trace.add_thread( 47 tid=GC2_TID, tgid=APP_PID, cmdline='HeapTaskDaemon', name='HeapTaskDaemon') 48trace.add_thread(tid=BINDER_TID, tgid=APP_PID, cmdline='Binder', name='Binder') 49trace.add_thread(tid=FONTS_TID, tgid=APP_PID, cmdline='fonts', name='fonts') 50 51trace.add_ftrace_packet(cpu=0) 52# Start intent. 53trace.add_atrace_begin( 54 ts=LAUNCH_START_TS, 55 pid=SYSTEM_SERVER_PID, 56 tid=SYSTEM_SERVER_TID, 57 buf='MetricsLogger:launchObserverNotifyIntentStarted') 58trace.add_atrace_end( 59 ts=LAUNCH_START_TS + 1, tid=SYSTEM_SERVER_TID, pid=SYSTEM_SERVER_PID) 60 61# System server launching the app. 62trace.add_atrace_async_begin( 63 ts=LAUNCH_START_TS + 2, 64 pid=SYSTEM_SERVER_PID, 65 tid=SYSTEM_SERVER_TID, 66 buf='launching: com.some.app') 67 68# Emulate a hot start (and therefore that we only see activityResume). 69trace.add_atrace_begin(ts=125, tid=APP_TID, pid=APP_PID, buf='activityResume') 70trace.add_atrace_end(ts=130, tid=APP_TID, pid=APP_PID) 71 72# OpenDex slices within the startup. 73trace.add_atrace_begin( 74 ts=150, pid=APP_PID, tid=APP_TID, buf='OpenDexFilesFromOat(something)') 75trace.add_atrace_end(ts=165, pid=APP_PID, tid=APP_TID) 76 77trace.add_atrace_begin( 78 ts=170, pid=APP_PID, tid=APP_TID, buf='OpenDexFilesFromOat(something else)') 79trace.add_atrace_end(ts=175, pid=APP_PID, tid=APP_TID) 80 81# OpenDex slice outside the startup. 82trace.add_atrace_begin( 83 ts=5, pid=APP_PID, tid=APP_TID, buf='OpenDexFilesFromOat(nothing)') 84trace.add_atrace_end(ts=35, pid=APP_PID, tid=APP_TID) 85 86trace.add_atrace_async_end( 87 ts=LAUNCH_END_TS, 88 tid=SYSTEM_SERVER_TID, 89 pid=SYSTEM_SERVER_PID, 90 buf='launching: com.some.app') 91 92# VerifyClass slices within the startup. 93trace.add_atrace_begin(ts=250, pid=APP_PID, tid=APP_TID, buf='VerifyClass vr') 94trace.add_atrace_end(ts=265, pid=APP_PID, tid=APP_TID) 95 96trace.add_atrace_begin(ts=270, pid=APP_PID, tid=APP_TID, buf='VerifyClass dl') 97trace.add_atrace_end(ts=275, pid=APP_PID, tid=APP_TID) 98 99# VerifyClass slice outside the startup. 100trace.add_atrace_begin(ts=55, pid=APP_PID, tid=APP_TID, buf='VerifyClass xf') 101trace.add_atrace_end(ts=65, pid=APP_PID, tid=APP_TID) 102 103# VerifyClass slice on a different thread, overlapping with the other slices. 104trace.add_atrace_begin( 105 ts=260, pid=APP_PID, tid=SECOND_APP_TID, buf='VerifyClass vp') 106trace.add_atrace_end(ts=280, pid=APP_PID, tid=SECOND_APP_TID) 107 108# JIT compilation slices 109trace.add_atrace_begin( 110 ts=150, pid=APP_PID, tid=JIT_TID, buf='JIT compiling someting') 111trace.add_atrace_end(ts=160, pid=APP_PID, tid=JIT_TID) 112 113trace.add_sched(ts=155, prev_pid=0, next_pid=JIT_TID) 114trace.add_sched(ts=165, prev_pid=JIT_TID, next_pid=0) 115 116trace.add_atrace_begin( 117 ts=170, pid=APP_PID, tid=JIT_TID, buf='JIT compiling something else') 118trace.add_atrace_end(ts=190, pid=APP_PID, tid=JIT_TID) 119 120trace.add_sched(ts=170, prev_pid=0, next_pid=JIT_TID) 121trace.add_sched(ts=175, prev_pid=JIT_TID, next_pid=0, prev_state='R') 122trace.add_sched(ts=185, prev_pid=0, next_pid=JIT_TID) 123trace.add_sched(ts=190, prev_pid=JIT_TID, next_pid=0) 124 125# JIT slice, but not on JIT thread. 126trace.add_atrace_begin( 127 ts=200, pid=APP_PID, tid=SECOND_APP_TID, buf='JIT compiling nothing') 128trace.add_atrace_end(ts=210, pid=APP_PID, tid=SECOND_APP_TID) 129 130# Slice on JIT thread, but name doesn't match 131trace.add_atrace_begin( 132 ts=200, pid=APP_PID, tid=JIT_TID, buf='JIT compiled something') 133trace.add_atrace_end(ts=210, pid=APP_PID, tid=JIT_TID) 134 135# GC slices. 136trace.add_atrace_begin( 137 ts=300, pid=APP_PID, tid=GC_TID, buf='Background concurrent copying GC') 138trace.add_atrace_end(ts=330, pid=APP_PID, tid=GC_TID) 139 140trace.add_atrace_begin( 141 ts=340, pid=APP_PID, tid=GC_TID, buf='CollectorTransition mark sweep GC') 142trace.add_atrace_end(ts=390, pid=APP_PID, tid=GC_TID) 143 144trace.add_atrace_begin(ts=320, pid=APP_PID, tid=GC2_TID, buf='semispace GC') 145trace.add_atrace_end(ts=370, pid=APP_PID, tid=GC2_TID) 146 147# Start running copying slice on the first thread 148trace.add_sched(ts=310, prev_pid=0, next_pid=GC_TID) 149# Switch to the second thread to run semispace slice 150trace.add_sched(ts=325, prev_pid=GC_TID, next_pid=GC2_TID) 151# Switch back to the first thread to run mark sweep slice 152trace.add_sched(ts=350, prev_pid=GC2_TID, next_pid=GC_TID) 153# Finish running for GC. 154trace.add_sched(ts=360, prev_pid=GC_TID, next_pid=0) 155 156# Long binder transactions. 157trace.add_binder_transaction(1, 10**8, 2 * (10**8), BINDER_TID, APP_PID, 2, 158 10**8 + 1, 2 * (10**8) - 1, SYSTEM_SERVER_TID, 159 SYSTEM_SERVER_PID) 160 161trace.add_binder_transaction(3, 3 * (10**8), 5 * (10**8), FONTS_TID, APP_PID, 4, 162 3 * (10**8) + 1, 5 * (10**8) - 1, BINDER_TID, 163 APP_PID) 164 165# A short binder transaction. 166trace.add_binder_transaction(5, 10**7, 5 * (10**7), BINDER_TID, APP_TID, 6, 167 10**7 + 1, 5 * (10**7) - 1, SYSTEM_SERVER_TID, 168 SYSTEM_SERVER_PID) 169 170# Intent successful. 171trace.add_atrace_begin( 172 ts=LAUNCH_END_TS + 1, 173 pid=SYSTEM_SERVER_PID, 174 tid=SYSTEM_SERVER_TID, 175 buf='MetricsLogger:launchObserverNotifyActivityLaunchFinished') 176trace.add_atrace_end( 177 ts=LAUNCH_END_TS + 2, tid=SYSTEM_SERVER_TID, pid=SYSTEM_SERVER_PID) 178 179sys.stdout.buffer.write(trace.trace.SerializeToString()) 180