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