1#!/usr/bin/env python3 2# Copyright (C) 2023 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 17import synth_common 18 19from google.protobuf import text_format 20 21SS_PID = 1234 22 23trace = synth_common.create_trace() 24 25trace.add_packet() 26trace.add_process(pid=SS_PID, ppid=1, cmdline="system_server", uid=10001) 27 28# Add first ANR. 29trace.add_ftrace_packet(cpu=0) 30trace.add_atrace_counter( 31 ts=1000, 32 pid=SS_PID, 33 tid=SS_PID, 34 buf="ErrorId:com.google.android.app1 11167#da24554c-452a-4ae1-b74a-fb898f6e0982", 35 cnt=1) 36 37trace.add_ftrace_packet(cpu=0) 38trace.add_atrace_counter( 39 ts=1001, 40 tid=SS_PID, 41 pid=SS_PID, 42 buf="Subject(for ErrorId da24554c-452a-4ae1-b74a-fb898f6e0982):Test ANR subject 1", 43 cnt=1) 44 45# Add second ANR. 46# Does not include PID 47trace.add_ftrace_packet(cpu=0) 48trace.add_atrace_counter( 49 ts=2000, 50 pid=SS_PID, 51 tid=SS_PID, 52 buf="ErrorId:com.google.android.app2#8612fece-c2f1-4aeb-9d45-8e6d9d0201cf", 53 cnt=1) 54 55trace.add_ftrace_packet(cpu=0) 56trace.add_atrace_counter( 57 ts=2001, 58 tid=SS_PID, 59 pid=SS_PID, 60 buf="Subject(for ErrorId 8612fece-c2f1-4aeb-9d45-8e6d9d0201cf):Test ANR subject 2", 61 cnt=1) 62 63# Add third ANR. 64# Does not include PID or subject 65trace.add_ftrace_packet(cpu=0) 66trace.add_atrace_counter( 67 ts=3000, 68 pid=SS_PID, 69 tid=SS_PID, 70 buf="ErrorId:com.google.android.app3#c25916a0-a8f0-41f3-87df-319e06471a0f", 71 cnt=1) 72 73sys.stdout.buffer.write(trace.trace.SerializeToString()) 74