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