• 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_async_end(
40      ts=ts + 5, tid=2, pid=2, buf='launching: com.google.android.calendar')
41  trace.add_atrace_begin(
42      ts=ts + 6,
43      tid=2,
44      pid=2,
45      buf='MetricsLogger:launchObserverNotifyActivityLaunchFinished')
46  trace.add_atrace_end(ts=ts + 6, tid=2, pid=2)
47
48
49# Build a trace where calendar starts, exits and restarts.
50# Verify that each startup is only associated with a single process
51# (i.e. process exit is taken into account).
52trace = synth_common.create_trace()
53trace.add_packet()
54trace.add_process(1, 0, 'init')
55trace.add_process(2, 1, 'system_server')
56add_startup(trace, ts=100, pid=3)
57trace.add_process_free(ts=150, tid=3, comm='', prio=0)
58add_startup(trace, ts=200, pid=4)
59
60sys.stdout.buffer.write(trace.trace.SerializeToString())
61