• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 to_s(ts):
22  return ts * 1000 * 1000 * 1000
23
24
25trace = synth_common.create_trace()
26trace.add_packet()
27trace.add_process(1, 0, 'init')
28trace.add_process(2, 1, 'system_server')
29trace.add_process(3, 1, 'com.google.android.calendar', 10001)
30trace.add_process(4, 3, 'com.google.android.calendar', 10001)
31
32trace.add_package_list(
33    ts=to_s(1), name='com.google.android.calendar', uid=10001, version_code=123)
34
35trace.add_ftrace_packet(cpu=0)
36# Intent without any corresponding end state, will be ignored
37trace.add_atrace_begin(
38    ts=to_s(100),
39    tid=2,
40    pid=2,
41    buf='MetricsLogger:launchObserverNotifyIntentStarted')
42trace.add_atrace_end(ts=to_s(101), tid=2, pid=2)
43
44# Start intent for a successful launch of calendar
45trace.add_atrace_begin(
46    ts=to_s(102),
47    tid=2,
48    pid=2,
49    buf='MetricsLogger:launchObserverNotifyIntentStarted')
50trace.add_atrace_end(ts=to_s(103), tid=2, pid=2)
51
52trace.add_atrace_async_begin(
53    ts=to_s(110), tid=2, pid=2, buf='launching: com.google.android.calendar')
54
55trace.add_sched(ts=to_s(110), prev_pid=0, next_pid=3)
56
57# As the process already existed before intent started, this is a
58# warm/hot start (we choose warm). Therefore, emit an activityStart
59# slice.
60trace.add_atrace_begin(ts=to_s(115), tid=3, pid=3, buf='activityStart')
61trace.add_atrace_end(ts=to_s(117), tid=3, pid=3)
62trace.add_atrace_begin(ts=to_s(117), tid=3, pid=3, buf='activityResume')
63trace.add_atrace_end(ts=to_s(118), tid=3, pid=3)
64
65# P1: 5s interruptable sleep
66trace.add_sched(ts=to_s(120), prev_pid=3, next_pid=0, prev_state='S')
67trace.add_sched(ts=to_s(125), prev_pid=0, next_pid=3)
68# P1: 5s blocking I/O state
69trace.add_sched(ts=to_s(125), prev_pid=3, next_pid=0, prev_state='D')
70trace.add_sched_blocked_reason(ts=to_s(127), pid=3, io_wait=1, unblock_pid=4)
71trace.add_sched(ts=to_s(130), prev_pid=0, next_pid=3)
72
73trace.add_sched(ts=to_s(130), prev_pid=3, next_pid=4)
74
75# Create an unrelated task
76trace.add_newtask(ts=to_s(155), tid=1, new_tid=5, new_comm='', flags=0)
77
78# P2: 30ns running
79trace.add_sched(ts=to_s(160), prev_pid=4, next_pid=0, prev_state='R')
80# P2: 49ns runnable
81trace.add_sched(ts=to_s(209), prev_pid=0, next_pid=4)
82# P2: 1ns running
83trace.add_sched(ts=to_s(210), prev_pid=4, next_pid=0)
84
85trace.add_atrace_async_end(
86    ts=to_s(210), tid=2, pid=2, buf='launching: com.google.android.calendar')
87trace.add_atrace_begin(
88    ts=to_s(211),
89    tid=2,
90    pid=2,
91    buf='MetricsLogger:launchObserverNotifyActivityLaunchFinished')
92trace.add_atrace_end(ts=to_s(212), tid=2, pid=2)
93
94# Some time after, add a slice for fully drawn frame.
95trace.add_atrace_begin(
96    ts=to_s(300),
97    tid=3,
98    pid=3,
99    buf='reportFullyDrawn() for \{com.google.android.calendar\}')
100trace.add_atrace_end(ts=to_s(305), tid=2, pid=2)
101
102# Start intent for calendar, we failed to launch the activity.
103trace.add_atrace_begin(
104    ts=to_s(402),
105    tid=2,
106    pid=2,
107    buf='MetricsLogger:launchObserverNotifyIntentStarted')
108trace.add_atrace_end(ts=to_s(403), tid=2, pid=2)
109
110trace.add_atrace_async_begin(
111    ts=to_s(410), tid=2, pid=2, buf='launching: com.google.android.calendar')
112
113trace.add_atrace_async_end(
114    ts=to_s(510),
115    tid=2,
116    pid=2,
117    buf='launching: com.google.android.apps.nexuslauncher')
118
119trace.add_ftrace_packet(cpu=1)
120trace.add_sched(ts=to_s(160), prev_pid=0, next_pid=1)
121trace.add_sched(ts=to_s(200), prev_pid=1, next_pid=0)
122
123sys.stdout.buffer.write(trace.trace.SerializeToString())
124