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 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') 30 31trace.add_ftrace_packet(cpu=0) 32 33# Start intent for a successful launch of calendar 34trace.add_atrace_begin( 35 ts=to_s(102), 36 tid=2, 37 pid=2, 38 buf='MetricsLogger:launchObserverNotifyIntentStarted') 39trace.add_atrace_end(ts=to_s(103), tid=2, pid=2) 40 41trace.add_atrace_async_begin( 42 ts=to_s(110), tid=2, pid=2, buf='launching: com.google.android.calendar') 43 44trace.add_atrace_begin( 45 ts=to_s(120), tid=2, pid=2, buf='Start proc: com.google.android.calendar') 46trace.add_atrace_end(ts=to_s(155), tid=2, pid=2) 47 48# Unrelated process binding, ignored 49trace.add_atrace_begin(ts=to_s(125), tid=1, pid=1, buf='bindApplication') 50trace.add_atrace_end(ts=to_s(195), tid=1, pid=1) 51 52trace.add_atrace_begin(ts=to_s(185), tid=3, pid=3, buf='bindApplication') 53trace.add_atrace_begin( 54 ts=to_s(188), 55 tid=3, 56 pid=3, 57 buf='performCreate:com.google.android.calendar.MainActivity') 58trace.add_atrace_begin(ts=to_s(188), tid=3, pid=3, buf='inflate') 59trace.add_atrace_end(ts=to_s(189), tid=3, pid=3) 60trace.add_atrace_begin( 61 ts=to_s(188), tid=3, pid=3, buf='ResourcesManager#getResources') 62trace.add_atrace_end(ts=to_s(189), tid=3, pid=3) 63trace.add_atrace_begin(ts=to_s(190), tid=3, pid=3, buf='inflate') 64trace.add_atrace_end(ts=to_s(192), tid=3, pid=3) 65trace.add_atrace_end(ts=to_s(192), tid=3, pid=3) 66trace.add_atrace_begin( 67 ts=193, 68 tid=3, 69 pid=3, 70 buf='performResume:com.google.android.calendar.MainActivity') 71trace.add_atrace_end(ts=to_s(194), tid=3, pid=3) 72trace.add_atrace_end(ts=to_s(195), tid=3, pid=3) 73 74trace.add_atrace_begin( 75 ts=to_s(200), 76 tid=3, 77 pid=3, 78 buf='location=error status=io-error-no-oat ' \ 79 'filter=run-from-apk reason=unknown') 80trace.add_atrace_end(ts=to_s(202), tid=3, pid=3) 81trace.add_atrace_begin( 82 ts=to_s(204), 83 tid=3, 84 pid=3, 85 buf='location=/system/framework/oat/arm/com.android.location.provider' \ 86 '.odex status=up-to-date filter=speed reason=prebuilt') 87trace.add_atrace_end(ts=to_s(205), tid=3, pid=3) 88 89trace.add_atrace_async_end( 90 ts=to_s(210), tid=2, pid=2, buf='launching: com.google.android.calendar') 91trace.add_atrace_begin( 92 ts=to_s(211), 93 tid=2, 94 pid=2, 95 buf='MetricsLogger:launchObserverNotifyActivityLaunchFinished') 96trace.add_atrace_end(ts=to_s(212), tid=2, pid=2) 97 98# Add the scheduling data to match the timestamps of events above but with 99# some idle time inbetween to make the computation more realisitic. 100trace.add_cpufreq(ts=to_s(50), freq=1000, cpu=0) 101trace.add_sched(ts=to_s(100), prev_pid=0, next_pid=2) 102trace.add_sched(ts=to_s(115), prev_pid=2, next_pid=0) 103trace.add_sched(ts=to_s(120), prev_pid=0, next_pid=2) 104trace.add_sched(ts=to_s(125), prev_pid=2, next_pid=1) 105trace.add_sched(ts=to_s(150), prev_pid=1, next_pid=2) 106trace.add_sched(ts=to_s(160), prev_pid=2, next_pid=1) 107trace.add_sched(ts=to_s(180), prev_pid=1, next_pid=3) 108trace.add_sched(ts=to_s(205), prev_pid=3, next_pid=2) 109trace.add_sched(ts=to_s(220), prev_pid=2, next_pid=0) 110 111sys.stdout.buffer.write(trace.trace.SerializeToString()) 112