• 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 add_startup(trace, ts, pid):
22  trace.add_ftrace_packet(cpu=0)
23  trace.add_atrace_begin(
24      ts=ts,
25      tid=2,
26      pid=2,
27      buf='MetricsLogger:launchObserverNotifyIntentStarted')
28  trace.add_atrace_end(ts=ts + 1, tid=2, pid=2)
29  trace.add_atrace_async_begin(
30      ts=ts + 2, tid=2, pid=2, buf='launching: com.google.android.calendar')
31  trace.add_newtask(
32      ts=ts + 3,
33      tid=1,
34      new_tid=pid,
35      new_comm='com.google.android.calendar',
36      flags=0)
37  trace.add_atrace_begin(ts=ts + 3, tid=pid, pid=pid, buf='bindApplication')
38  trace.add_atrace_end(ts=ts + 4, tid=pid, pid=pid)
39  trace.add_atrace_begin(ts=ts + 4, tid=pid, pid=pid, buf='activityStart')
40  trace.add_atrace_end(ts=ts + 5, tid=pid, pid=pid)
41  trace.add_atrace_begin(ts=ts + 5, tid=pid, pid=pid, buf='activityResume')
42  trace.add_atrace_end(ts=ts + 6, tid=pid, pid=pid)
43  trace.add_atrace_async_end(
44      ts=ts + 7, tid=2, pid=2, buf='launching: com.google.android.calendar')
45  trace.add_atrace_begin(
46      ts=ts + 7,
47      tid=2,
48      pid=2,
49      buf='MetricsLogger:launchObserverNotifyActivityLaunchFinished')
50  trace.add_atrace_end(ts=ts + 8, tid=2, pid=2)
51
52
53# Build a trace where calendar starts, exits and restarts.
54# Verify that each startup is only associated with a single process
55# (i.e. process exit is taken into account).
56trace = synth_common.create_trace()
57trace.add_packet()
58trace.add_process(1, 0, 'init', uid=10001)
59trace.add_process(2, 1, 'system_server', uid=1000)
60
61trace.add_package_list(
62    ts=99, name='com.google.android.calendar', uid=10001, version_code=123)
63
64add_startup(trace, ts=100, pid=3)
65trace.add_packet(ts=140)
66trace.add_process(3, 1, 'com.google.android.calendar:debug', uid=10001)
67
68trace.add_packet()
69trace.add_process_free(ts=150, tid=3, comm='', prio=0)
70
71add_startup(trace, ts=200, pid=4)
72trace.add_packet(ts=250)
73trace.add_process(4, 1, 'com.google.android.calendar', uid=10001)
74
75sys.stdout.buffer.write(trace.trace.SerializeToString())
76