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, path 17import synth_common 18 19# com.android.systemui 20SYSUI_PID = 1000 21 22THIRD_PROCESS_PID = 3000 23 24# duration for each child slice 25child_slice_dur = 10_000_000 26 27# parent slice idle duration 28parent_slice_idle_dur = 10_000_000 29 30# List of inflation-related descendant slices of interesting slices 31inflation_child_slice_names = [ 32 'HybridGroupManager#inflateHybridView', 33 'NotifChildCont#recreateHeader', 34] 35 36# List of Shade-node-modification-related descendant slices of interesting slices 37modification_child_slice_names = [ 38 'ShadeNode#addChildAt', 39 'ShadeNode#removeChildAt', 40 'ShadeNode#moveChildTo', 41] 42 43 44def add_main_thread_atrace(trace, ts, ts_end, buf, pid): 45 trace.add_atrace_begin(ts=ts, tid=pid, pid=pid, buf=buf) 46 trace.add_atrace_end(ts=ts_end, tid=pid, pid=pid) 47 48 49# Creates a trace that has the interesting slices that we are querying for 50# A ShadeListBuilder.buildList slice that has one of each of the inflation_child_slice_names 51# A ShadeListBuilder.buildList slice that has one of each of the modification_child_slice_names 52def add_slices(trace, pid): 53 slice_ts = 2_000_000 54 slice_ts = add_slice_with_children(trace, pid, slice_ts, 'updateNotifOnUiModeChanged', inflation_child_slice_names) 55 add_slice_with_children(trace, pid, slice_ts, 'updateNotifOnUiModeChanged', modification_child_slice_names) 56 57# Add a slice with a set of children slices, return the parent slice's end ts 58def add_slice_with_children(trace, pid, current_ts, parent_name, children_list): 59 ts_end = current_ts + parent_slice_idle_dur + len(children_list) * (child_slice_dur + 1) 60 # add the parent slice 61 add_main_thread_atrace( 62 trace, 63 ts=current_ts, 64 ts_end=ts_end, 65 buf=parent_name, 66 pid=pid) 67 current_ts += parent_slice_idle_dur 68 # Add the children 69 for child_name in children_list: 70 ts_child_end = current_ts + child_slice_dur + 1 71 add_main_thread_atrace( 72 trace, 73 ts=current_ts, 74 ts_end=ts_child_end, 75 buf=child_name, 76 pid=pid) 77 current_ts = ts_child_end 78 return ts_end 79 80def add_process(trace, package_name, uid, pid): 81 trace.add_package_list(ts=0, name=package_name, uid=uid, version_code=1) 82 trace.add_process( 83 pid=pid, ppid=0, cmdline=package_name, uid=uid) 84 trace.add_thread(tid=pid, tgid=pid, cmdline="MainThread", name="MainThread") 85 86 87def setup_trace(): 88 trace = synth_common.create_trace() 89 trace.add_packet() 90 add_process(trace, package_name="com.android.systemui", uid=10001, 91 pid=SYSUI_PID) 92 trace.add_ftrace_packet(cpu=0) 93 return trace 94 95 96trace = setup_trace() 97 98 99add_slices(trace, pid=SYSUI_PID) 100 101# See test_sysui_update_notif_on_ui_mode_changed. 102sys.stdout.buffer.write(trace.trace.SerializeToString())