• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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# List of blocking calls
25blocking_call_names = [
26    'NotificationStackScrollLayout#onMeasure',
27    'ExpNotRow#onMeasure(MessagingStyle)', 'ExpNotRow#onMeasure(BigTextStyle)',
28    'NotificationShadeWindowView#onMeasure', 'ImageFloatingTextView#onMeasure',
29    'Should not be in the metric'
30]
31
32
33def add_main_thread_atrace(trace, ts, ts_end, buf, pid):
34  trace.add_atrace_begin(ts=ts, tid=pid, pid=pid, buf=buf)
35  trace.add_atrace_end(ts=ts_end, tid=pid, pid=pid)
36
37
38def add_async_trace(trace, ts, ts_end, buf, pid):
39  trace.add_atrace_async_begin(ts=ts, tid=pid, pid=pid, buf=buf)
40  trace.add_atrace_async_end(ts=ts_end, tid=pid, pid=pid, buf=buf)
41
42
43# Creates a trace that contains one of each blocking call.
44def add_all_sysui_notifications_blocking_calls(trace, pid):
45  blocking_call_dur = 10_000_000
46  blocking_call_ts = 2_000_000
47
48  cuj_dur = len(blocking_call_names) * blocking_call_dur
49  add_async_trace(
50      trace,
51      ts=blocking_call_ts,
52      ts_end=blocking_call_ts + cuj_dur,
53      buf="L<TEST_WITH_MANY_BLOCKING_CALLS>",
54      pid=pid)
55
56  for blocking_call in blocking_call_names:
57    add_main_thread_atrace(
58        trace,
59        ts=blocking_call_ts,
60        ts_end=blocking_call_ts + blocking_call_dur,
61        buf=blocking_call,
62        pid=pid)
63    blocking_call_ts += blocking_call_dur
64
65
66def add_process(trace, package_name, uid, pid):
67  trace.add_package_list(ts=0, name=package_name, uid=uid, version_code=1)
68  trace.add_process(pid=pid, ppid=0, cmdline=package_name, uid=uid)
69  trace.add_thread(tid=pid, tgid=pid, cmdline="MainThread", name="MainThread")
70
71
72def setup_trace():
73  trace = synth_common.create_trace()
74  trace.add_packet()
75  add_process(
76      trace, package_name="com.android.systemui", uid=10001, pid=SYSUI_PID)
77  trace.add_ftrace_packet(cpu=0)
78  return trace
79
80
81trace = setup_trace()
82
83add_all_sysui_notifications_blocking_calls(trace, pid=SYSUI_PID)
84
85# See test_android_sysui_notifications_blocking_calls.
86sys.stdout.buffer.write(trace.trace.SerializeToString())
87