1#!/usr/bin/env python3 2# Copyright (C) 2020 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 17 18import synth_common 19 20trace = synth_common.create_trace() 21 22process_track1 = 1234 23process_track2 = 4567 24 25process_pid1 = 2345 26process_pid2 = 5678 27 28thread_track1 = 1235 29thread_track2 = 4568 30 31rail_track1 = 1236 32rail_track2 = 4569 33 34# Main threads have the same ID as the process 35thread_tid1 = process_pid1 36thread_tid2 = process_pid2 37 38seq1 = 9876 39seq2 = 9877 40 41thread1_counter = 60 42thread2_counter = 61 43 44trace.add_chrome_process_track_descriptor(process_track1, process_pid1) 45trace.add_chrome_process_track_descriptor(process_track2, process_pid2) 46 47trace.add_chrome_thread_with_cpu_counter( 48 process_track1, 49 thread_track1, 50 trusted_packet_sequence_id=seq1, 51 counter_track=thread1_counter, 52 pid=process_pid1, 53 tid=thread_tid1, 54 thread_type=trace.prototypes.ThreadDescriptor.ChromeThreadType 55 .CHROME_THREAD_MAIN) 56 57trace.add_chrome_thread_with_cpu_counter( 58 process_track2, 59 thread_track2, 60 trusted_packet_sequence_id=seq2, 61 counter_track=thread2_counter, 62 pid=process_pid2, 63 tid=thread_tid2, 64 thread_type=trace.prototypes.ThreadDescriptor.ChromeThreadType 65 .CHROME_THREAD_MAIN) 66 67trace.add_track_descriptor(rail_track1, parent=process_track1) 68trace.add_track_descriptor(rail_track2, parent=process_track2) 69 70trace.add_track_event_slice( 71 "task", 0, 5000, trusted_sequence_id=seq1, cpu_start=0, cpu_delta=10000) 72trace.add_track_event_slice( 73 "task", 74 5000, 75 5000, 76 trusted_sequence_id=seq1, 77 cpu_start=12000, 78 cpu_delta=4000) 79 80trace.add_track_event_slice( 81 "task", 82 10000, 83 6000, 84 trusted_sequence_id=seq1, 85 cpu_start=18000, 86 cpu_delta=2000) 87trace.add_track_event_slice( 88 "task", 89 16000, 90 4000, 91 trusted_sequence_id=seq1, 92 cpu_start=20000, 93 cpu_delta=7000) 94 95trace.add_track_event_slice( 96 "task", 97 30000, 98 10000, 99 trusted_sequence_id=seq1, 100 cpu_start=30000, 101 cpu_delta=1000) 102 103trace.add_rail_mode_slice( 104 ts=0, 105 dur=10000, 106 track=rail_track1, 107 mode=trace.prototypes.ChromeRAILMode.RAIL_MODE_RESPONSE) 108trace.add_rail_mode_slice( 109 ts=10000, 110 dur=20000, 111 track=rail_track1, 112 mode=trace.prototypes.ChromeRAILMode.RAIL_MODE_LOAD) 113trace.add_rail_mode_slice( 114 ts=30000, 115 dur=-1, 116 track=rail_track1, 117 mode=trace.prototypes.ChromeRAILMode.RAIL_MODE_IDLE) 118 119trace.add_track_event_slice( 120 "task", 0, 10000, trusted_sequence_id=seq2, cpu_start=0, cpu_delta=10000) 121 122trace.add_track_event_slice( 123 "task", 124 10000, 125 15000, 126 trusted_sequence_id=seq2, 127 cpu_start=12000, 128 cpu_delta=1000) 129 130trace.add_track_event_slice( 131 "task", 132 35000, 133 10000, 134 trusted_sequence_id=seq2, 135 cpu_start=20000, 136 cpu_delta=20000) 137 138trace.add_track_event_slice( 139 "task", 140 45000, 141 10000, 142 trusted_sequence_id=seq2, 143 cpu_start=40000, 144 cpu_delta=1000) 145 146trace.add_rail_mode_slice( 147 ts=0, 148 dur=10000, 149 track=rail_track2, 150 mode=trace.prototypes.ChromeRAILMode.RAIL_MODE_ANIMATION) 151trace.add_rail_mode_slice( 152 ts=10000, 153 dur=25000, 154 track=rail_track2, 155 mode=trace.prototypes.ChromeRAILMode.RAIL_MODE_IDLE) 156trace.add_rail_mode_slice( 157 ts=35000, 158 dur=10000, 159 track=rail_track2, 160 mode=trace.prototypes.ChromeRAILMode.RAIL_MODE_ANIMATION) 161trace.add_rail_mode_slice( 162 ts=45000, 163 dur=10000, 164 track=rail_track2, 165 mode=trace.prototypes.ChromeRAILMode.RAIL_MODE_IDLE) 166 167sys.stdout.buffer.write(trace.trace.SerializeToString()) 168