• 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)
51trace.add_atrace_begin(ts=117, tid=3, pid=3, buf='activityResume')
52trace.add_atrace_end(ts=118, tid=3, pid=3)
53
54# P1: 10ns running
55trace.add_sched(ts=120, prev_pid=3, next_pid=0, prev_state='S')
56# P1: 10ns sleep
57trace.add_sched(ts=130, prev_pid=0, next_pid=3)
58
59trace.add_sched(ts=130, prev_pid=3, next_pid=4)
60
61# Create an unrelated task
62trace.add_newtask(ts=155, tid=1, new_tid=5, new_comm='', flags=0)
63
64# P2: 30ns running
65trace.add_sched(ts=160, prev_pid=4, next_pid=0, prev_state='R')
66# P2: 49ns runnable
67trace.add_sched(ts=209, prev_pid=0, next_pid=4)
68# P2: 1ns running
69trace.add_sched(ts=210, prev_pid=4, next_pid=0)
70
71trace.add_atrace_async_end(
72    ts=210, tid=2, pid=2, buf='launching: com.google.android.calendar')
73trace.add_atrace_begin(
74    ts=211,
75    tid=2,
76    pid=2,
77    buf='MetricsLogger:launchObserverNotifyActivityLaunchFinished')
78trace.add_atrace_end(ts=212, tid=2, pid=2)
79
80# Some time after, add a slice for fully drawn frame.
81trace.add_atrace_begin(
82    ts=300,
83    tid=3,
84    pid=3,
85    buf='reportFullyDrawn() for \{com.google.android.calendar\}')
86trace.add_atrace_end(ts=305, tid=2, pid=2)
87
88# Start intent for calendar, we failed to launch the activity.
89trace.add_atrace_begin(
90    ts=402, tid=2, pid=2, buf='MetricsLogger:launchObserverNotifyIntentStarted')
91trace.add_atrace_end(ts=403, tid=2, pid=2)
92
93trace.add_atrace_async_begin(
94    ts=410, tid=2, pid=2, buf='launching: com.google.android.calendar')
95
96trace.add_atrace_async_end(
97    ts=510,
98    tid=2,
99    pid=2,
100    buf='launching: com.google.android.apps.nexuslauncher')
101
102trace.add_ftrace_packet(cpu=1)
103trace.add_sched(ts=160, prev_pid=0, next_pid=1)
104trace.add_sched(ts=200, prev_pid=1, next_pid=0)
105
106sys.stdout.buffer.write(trace.trace.SerializeToString())
107