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 add_startup(trace, ts, pid): 22 trace.add_ftrace_packet(cpu=0) 23 trace.add_atrace_begin( 24 ts=ts, 25 tid=2, 26 pid=2, 27 buf='MetricsLogger:launchObserverNotifyIntentStarted') 28 trace.add_atrace_end(ts=ts + 1, tid=2, pid=2) 29 trace.add_atrace_async_begin( 30 ts=ts + 2, tid=2, pid=2, buf='launching: com.google.android.calendar') 31 trace.add_newtask( 32 ts=ts + 3, 33 tid=1, 34 new_tid=pid, 35 new_comm='com.google.android.calendar', 36 flags=0) 37 trace.add_atrace_async_end( 38 ts=ts + 4, tid=2, pid=2, buf='launching: com.google.android.calendar') 39 trace.add_atrace_begin( 40 ts=ts + 5, 41 tid=2, 42 pid=2, 43 buf='MetricsLogger:launchObserverNotifyActivityLaunchFinished') 44 trace.add_atrace_end(ts=ts + 6, tid=2, pid=2) 45 46 47# Build a trace where calendar starts, exits and restarts. 48# Verify that each startup is only associated with a single process 49# (i.e. process exit is taken into account). 50trace = synth_common.create_trace() 51trace.add_packet() 52trace.add_process(1, 0, 'init') 53trace.add_process(2, 1, 'system_server') 54add_startup(trace, ts=100, pid=3) 55trace.add_process_free(ts=150, tid=3, comm='', prio=0) 56add_startup(trace, ts=200, pid=4) 57 58sys.stdout.buffer.write(trace.trace.SerializeToString()) 59