• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright (C) 2021 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
16# This is intended to test the handling of simple_watcher style mojo events,
17# which are often missing trace events below them and so are all aggregated
18# together despite them coming into different mojo interfaces.
19
20from os import sys
21
22import synth_common
23
24from synth_common import ms_to_ns
25trace = synth_common.create_trace()
26
27process_track1 = 1234
28
29trace.add_process_track_descriptor(process_track1, pid=0)
30
31process_pid1 = 2345
32
33thread_track1 = 1235
34
35# Main threads have the same ID as the process
36thread_tid1 = process_pid1
37
38seq1 = 9876
39
40thread1_counter = 60
41
42touch_move_trace_id = 34576
43trace_id1 = touch_move_trace_id + 1
44trace_id2 = trace_id1 + 1
45trace_id3 = trace_id2 + 1
46touch_end_trace_id = trace_id3 + 1
47
48touch_gesture_id = 87654
49
50flow_id1 = 45678
51flow_id2 = 45679
52flow_id3 = 45680
53
54trace.add_input_latency_event_slice(
55    "TouchStart",
56    ts=ms_to_ns(0),
57    dur=ms_to_ns(1),
58    track=touch_move_trace_id,
59    trace_id=touch_move_trace_id,
60    touch_id=touch_gesture_id)
61
62trace.add_chrome_process_track_descriptor(process_track1, process_pid1)
63
64trace.add_chrome_thread_with_cpu_counter(
65    process_track1,
66    thread_track1,
67    trusted_packet_sequence_id=seq1,
68    counter_track=thread1_counter,
69    pid=process_pid1,
70    tid=thread_tid1,
71    thread_type=trace.prototypes.ThreadDescriptor.ChromeThreadType
72    .CHROME_THREAD_MAIN)
73
74# Touch move 1 - not janky
75trace.add_input_latency_event_slice(
76    "TouchMove",
77    ts=ms_to_ns(0),
78    dur=ms_to_ns(10),
79    track=trace_id1,
80    trace_id=trace_id1,
81    touch_id=touch_gesture_id,
82    is_coalesced=0)
83
84trace.add_latency_info_flow(
85    ts=ms_to_ns(0),
86    dur=ms_to_ns(1),
87    trusted_sequence_id=seq1,
88    trace_id=trace_id1,
89    flow_ids=[flow_id1])
90
91# The slices below will block this "not janky" touch move 1.
92trace.add_track_event_slice(
93    "task", ts=ms_to_ns(2), dur=ms_to_ns(6), trusted_sequence_id=seq1)
94
95trace.add_track_event_slice(
96    "subtask", ts=ms_to_ns(3), dur=ms_to_ns(4), trusted_sequence_id=seq1)
97# This ends the blocking slices of "not janky" touch move 1.
98
99trace.add_latency_info_flow(
100    ts=ms_to_ns(11),
101    dur=ms_to_ns(1),
102    trusted_sequence_id=seq1,
103    trace_id=trace_id1,
104    terminating_flow_ids=[flow_id1])
105
106# Touch move 2 - janky
107trace.add_input_latency_event_slice(
108    "TouchMove",
109    ts=ms_to_ns(16),
110    dur=ms_to_ns(33),
111    track=trace_id2,
112    trace_id=trace_id2,
113    touch_id=touch_gesture_id,
114    is_coalesced=0)
115
116trace.add_latency_info_flow(
117    ts=ms_to_ns(16),
118    dur=ms_to_ns(1),
119    trusted_sequence_id=seq1,
120    trace_id=trace_id2,
121    flow_ids=[flow_id2])
122
123# The slices below will block this "janky" touch move 2.
124trace.add_track_event_slice(
125    "task", ts=ms_to_ns(18), dur=ms_to_ns(29), trusted_sequence_id=seq1)
126
127trace.add_track_event_slice(
128    "subtask", ts=ms_to_ns(19), dur=ms_to_ns(27), trusted_sequence_id=seq1)
129# This ends the blocking slices of "janky" touch move 2.
130
131trace.add_latency_info_flow(
132    ts=ms_to_ns(50),
133    dur=ms_to_ns(1),
134    trusted_sequence_id=seq1,
135    trace_id=trace_id2,
136    terminating_flow_ids=[flow_id2])
137
138# Touch move 3 - janky
139trace.add_input_latency_event_slice(
140    "TouchMove",
141    ts=ms_to_ns(55),
142    dur=ms_to_ns(33),
143    track=trace_id3,
144    trace_id=trace_id3,
145    touch_id=touch_gesture_id,
146    is_coalesced=0)
147
148trace.add_latency_info_flow(
149    ts=ms_to_ns(55),
150    dur=ms_to_ns(1),
151    trusted_sequence_id=seq1,
152    trace_id=trace_id3,
153    flow_ids=[flow_id3])
154
155# The slices below will block this "janky" touch move 3.
156trace.add_track_event_slice(
157    "task", ts=ms_to_ns(57), dur=ms_to_ns(29), trusted_sequence_id=seq1)
158
159packet = trace.add_track_event_slice(
160    "subtask", ts=ms_to_ns(58), dur=ms_to_ns(27), trusted_sequence_id=seq1)
161# This ends the blocking slices of "janky" touch move 3.
162
163trace.add_latency_info_flow(
164    ts=ms_to_ns(87),
165    dur=ms_to_ns(1),
166    trusted_sequence_id=seq1,
167    trace_id=trace_id3,
168    step=trace.prototypes.ChromeLatencyInfo.Step.STEP_SEND_INPUT_EVENT_UI,
169    terminating_flow_ids=[flow_id3])
170
171trace.add_latency_info_flow(
172    ts=ms_to_ns(89),
173    dur=ms_to_ns(1),
174    trusted_sequence_id=seq1,
175    trace_id=trace_id3,
176    terminating_flow_ids=[flow_id3])
177
178trace.add_input_latency_event_slice(
179    "TouchEnd",
180    ts=ms_to_ns(90),
181    dur=ms_to_ns(2),
182    track=touch_end_trace_id,
183    trace_id=touch_end_trace_id,
184    touch_id=touch_gesture_id)
185
186sys.stdout.buffer.write(trace.trace.SerializeToString())
187