• 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
20APP_PID = 3
21APP_TID = 1
22SECOND_APP_TID = 3
23JIT_TID = 4
24GC_TID = 5
25GC2_TID = 6
26BINDER_TID = 7
27FONTS_TID = 8
28SYSTEM_SERVER_PID = 2
29SYSTEM_SERVER_TID = 2
30LAUNCH_START_TS = 100
31LAUNCH_END_TS = 10**9
32
33trace = synth_common.create_trace()
34trace.add_packet()
35trace.add_process(1, 0, 'init')
36trace.add_process(SYSTEM_SERVER_PID, 1, 'system_server')
37trace.add_process(APP_PID, 1, 'com.some.app')
38trace.add_thread(tid=SECOND_APP_TID, tgid=APP_PID, cmdline='second_thread')
39trace.add_thread(
40    tid=JIT_TID,
41    tgid=APP_PID,
42    cmdline='Jit thread pool',
43    name='Jit thread pool')
44trace.add_thread(
45    tid=GC_TID, tgid=APP_PID, cmdline='HeapTaskDaemon', name='HeapTaskDaemon')
46trace.add_thread(
47    tid=GC2_TID, tgid=APP_PID, cmdline='HeapTaskDaemon', name='HeapTaskDaemon')
48trace.add_thread(tid=BINDER_TID, tgid=APP_PID, cmdline='Binder', name='Binder')
49trace.add_thread(tid=FONTS_TID, tgid=APP_PID, cmdline='fonts', name='fonts')
50
51trace.add_ftrace_packet(cpu=0)
52# Start intent.
53trace.add_atrace_begin(
54    ts=LAUNCH_START_TS,
55    pid=SYSTEM_SERVER_PID,
56    tid=SYSTEM_SERVER_TID,
57    buf='MetricsLogger:launchObserverNotifyIntentStarted')
58trace.add_atrace_end(
59    ts=LAUNCH_START_TS + 1, tid=SYSTEM_SERVER_TID, pid=SYSTEM_SERVER_PID)
60
61# System server launching the app.
62trace.add_atrace_async_begin(
63    ts=LAUNCH_START_TS + 2,
64    pid=SYSTEM_SERVER_PID,
65    tid=SYSTEM_SERVER_TID,
66    buf='launching: com.some.app')
67
68# OpenDex slices within the startup.
69trace.add_atrace_begin(
70    ts=150, pid=APP_PID, tid=APP_TID, buf='OpenDexFilesFromOat(something)')
71trace.add_atrace_end(ts=165, pid=APP_PID, tid=APP_TID)
72
73trace.add_atrace_begin(
74    ts=170, pid=APP_PID, tid=APP_TID, buf='OpenDexFilesFromOat(something else)')
75trace.add_atrace_end(ts=175, pid=APP_PID, tid=APP_TID)
76
77# OpenDex slice outside the startup.
78trace.add_atrace_begin(
79    ts=5, pid=APP_PID, tid=APP_TID, buf='OpenDexFilesFromOat(nothing)')
80trace.add_atrace_end(ts=35, pid=APP_PID, tid=APP_TID)
81
82trace.add_atrace_async_end(
83    ts=LAUNCH_END_TS,
84    tid=SYSTEM_SERVER_TID,
85    pid=SYSTEM_SERVER_PID,
86    buf='launching: com.some.app')
87
88# VerifyClass slices within the startup.
89trace.add_atrace_begin(ts=250, pid=APP_PID, tid=APP_TID, buf='VerifyClass vr')
90trace.add_atrace_end(ts=265, pid=APP_PID, tid=APP_TID)
91
92trace.add_atrace_begin(ts=270, pid=APP_PID, tid=APP_TID, buf='VerifyClass dl')
93trace.add_atrace_end(ts=275, pid=APP_PID, tid=APP_TID)
94
95# VerifyClass slice outside the startup.
96trace.add_atrace_begin(ts=55, pid=APP_PID, tid=APP_TID, buf='VerifyClass xf')
97trace.add_atrace_end(ts=65, pid=APP_PID, tid=APP_TID)
98
99# VerifyClass slice on a different thread, overlapping with the other slices.
100trace.add_atrace_begin(
101    ts=260, pid=APP_PID, tid=SECOND_APP_TID, buf='VerifyClass vp')
102trace.add_atrace_end(ts=280, pid=APP_PID, tid=SECOND_APP_TID)
103
104# JIT compilation slices
105trace.add_atrace_begin(
106    ts=150, pid=APP_PID, tid=JIT_TID, buf='JIT compiling someting')
107trace.add_atrace_end(ts=160, pid=APP_PID, tid=JIT_TID)
108
109trace.add_sched(ts=155, prev_pid=0, next_pid=JIT_TID)
110trace.add_sched(ts=165, prev_pid=JIT_TID, next_pid=0)
111
112trace.add_atrace_begin(
113    ts=170, pid=APP_PID, tid=JIT_TID, buf='JIT compiling something else')
114trace.add_atrace_end(ts=190, pid=APP_PID, tid=JIT_TID)
115
116trace.add_sched(ts=170, prev_pid=0, next_pid=JIT_TID)
117trace.add_sched(ts=175, prev_pid=JIT_TID, next_pid=0, prev_state='R')
118trace.add_sched(ts=185, prev_pid=0, next_pid=JIT_TID)
119trace.add_sched(ts=190, prev_pid=JIT_TID, next_pid=0)
120
121# JIT slice, but not on JIT thread.
122trace.add_atrace_begin(
123    ts=200, pid=APP_PID, tid=SECOND_APP_TID, buf='JIT compiling nothing')
124trace.add_atrace_end(ts=210, pid=APP_PID, tid=SECOND_APP_TID)
125
126# Slice on JIT thread, but name doesn't match
127trace.add_atrace_begin(
128    ts=200, pid=APP_PID, tid=JIT_TID, buf='JIT compiled something')
129trace.add_atrace_end(ts=210, pid=APP_PID, tid=JIT_TID)
130
131# GC slices.
132trace.add_atrace_begin(
133    ts=300, pid=APP_PID, tid=GC_TID, buf='Background concurrent copying GC')
134trace.add_atrace_end(ts=330, pid=APP_PID, tid=GC_TID)
135
136trace.add_atrace_begin(
137    ts=340, pid=APP_PID, tid=GC_TID, buf='CollectorTransition mark sweep GC')
138trace.add_atrace_end(ts=390, pid=APP_PID, tid=GC_TID)
139
140trace.add_atrace_begin(ts=320, pid=APP_PID, tid=GC2_TID, buf='semispace GC')
141trace.add_atrace_end(ts=370, pid=APP_PID, tid=GC2_TID)
142
143# Start running copying slice on the first thread
144trace.add_sched(ts=310, prev_pid=0, next_pid=GC_TID)
145# Switch to the second thread to run semispace slice
146trace.add_sched(ts=325, prev_pid=GC_TID, next_pid=GC2_TID)
147# Switch back to the first thread to run mark sweep slice
148trace.add_sched(ts=350, prev_pid=GC2_TID, next_pid=GC_TID)
149# Finish running for GC.
150trace.add_sched(ts=360, prev_pid=GC_TID, next_pid=0)
151
152# Long binder transactions.
153trace.add_atrace_begin(
154    ts=10**8, pid=APP_PID, tid=BINDER_TID, buf='binder transaction')
155trace.add_atrace_end(ts=2 * (10**8), pid=APP_PID, tid=BINDER_TID)
156
157trace.add_atrace_begin(
158    ts=3 * (10**8), pid=APP_PID, tid=FONTS_TID, buf='binder transaction')
159trace.add_atrace_end(ts=5 * (10**8), pid=APP_PID, tid=FONTS_TID)
160
161# A short binder transaction.
162trace.add_atrace_begin(
163    ts=10**7, pid=APP_PID, tid=BINDER_TID, buf='binder transaction')
164trace.add_atrace_end(ts=6 * (10**7), pid=APP_PID, tid=BINDER_TID)
165
166# Intent successful.
167trace.add_atrace_begin(
168    ts=LAUNCH_END_TS + 1,
169    pid=SYSTEM_SERVER_PID,
170    tid=SYSTEM_SERVER_TID,
171    buf='MetricsLogger:launchObserverNotifyActivityLaunchFinished')
172trace.add_atrace_end(
173    ts=LAUNCH_END_TS + 2, tid=SYSTEM_SERVER_TID, pid=SYSTEM_SERVER_PID)
174
175sys.stdout.buffer.write(trace.trace.SerializeToString())
176