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