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 19from synth_common import ms_to_ns 20 21trace = synth_common.create_trace() 22 23process_track1 = 1234 24process_track2 = 4567 25 26process_pid1 = 2345 27process_pid2 = 5678 28 29thread_track1 = 1235 30thread_track2 = 4568 31 32rail_track1 = 1236 33rail_track2 = 4569 34 35# Main threads have the same ID as the process 36thread_tid1 = process_pid1 37thread_tid2 = process_pid2 38 39seq1 = 9876 40seq2 = 9877 41 42thread1_counter = 60 43thread2_counter = 61 44 45packet = trace.add_packet() 46packet.system_info.android_build_fingerprint = "google/sargo/foo" 47 48trace.add_chrome_process_track_descriptor(process_track1, process_pid1) 49trace.add_chrome_process_track_descriptor(process_track2, process_pid2) 50 51trace.add_chrome_thread_with_cpu_counter( 52 process_track1, 53 thread_track1, 54 trusted_packet_sequence_id=seq1, 55 counter_track=thread1_counter, 56 pid=process_pid1, 57 tid=thread_tid1, 58 thread_type=trace.prototypes.ThreadDescriptor.ChromeThreadType 59 .CHROME_THREAD_MAIN) 60 61trace.add_chrome_thread_with_cpu_counter( 62 process_track2, 63 thread_track2, 64 trusted_packet_sequence_id=seq2, 65 counter_track=thread2_counter, 66 pid=process_pid2, 67 tid=thread_tid2, 68 thread_type=trace.prototypes.ThreadDescriptor.ChromeThreadType 69 .CHROME_THREAD_MAIN) 70 71trace.add_track_descriptor(rail_track1, parent=process_track1) 72trace.add_track_descriptor(rail_track2, parent=process_track2) 73 74trace.add_rail_mode_slice( 75 ts=0, 76 dur=ms_to_ns(10), 77 track=rail_track1, 78 mode=trace.prototypes.ChromeRAILMode.RAIL_MODE_RESPONSE) 79trace.add_rail_mode_slice( 80 ts=ms_to_ns(10), 81 dur=ms_to_ns(20), 82 track=rail_track1, 83 mode=trace.prototypes.ChromeRAILMode.RAIL_MODE_LOAD) 84trace.add_rail_mode_slice( 85 ts=ms_to_ns(30), 86 dur=-1, 87 track=rail_track1, 88 mode=trace.prototypes.ChromeRAILMode.RAIL_MODE_IDLE) 89 90trace.add_rail_mode_slice( 91 ts=0, 92 dur=ms_to_ns(10), 93 track=rail_track2, 94 mode=trace.prototypes.ChromeRAILMode.RAIL_MODE_ANIMATION) 95trace.add_rail_mode_slice( 96 ts=ms_to_ns(10), 97 dur=ms_to_ns(25), 98 track=rail_track2, 99 mode=trace.prototypes.ChromeRAILMode.RAIL_MODE_IDLE) 100trace.add_rail_mode_slice( 101 ts=ms_to_ns(35), 102 dur=ms_to_ns(10), 103 track=rail_track2, 104 mode=trace.prototypes.ChromeRAILMode.RAIL_MODE_ANIMATION) 105trace.add_rail_mode_slice( 106 ts=ms_to_ns(45), 107 dur=ms_to_ns(10), 108 track=rail_track2, 109 mode=trace.prototypes.ChromeRAILMode.RAIL_MODE_IDLE) 110 111# Create process tree 112trace.add_packet() 113trace.add_process(1, 0, "init") 114trace.add_process(thread_tid1, 1, "Renderer") 115trace.add_process(thread_tid2, 1, "Renderer") 116 117packet = trace.add_packet() 118 119# Add scheduling and cpu frequency data 120trace.add_ftrace_packet(cpu=0) 121trace.add_sched(ts=0, prev_pid=0, next_pid=thread_tid1) 122trace.add_cpufreq(ts=ms_to_ns(0), freq=1708800, cpu=0) 123trace.add_cpufreq(ts=ms_to_ns(5), freq=1324800, cpu=0) 124trace.add_sched(ts=ms_to_ns(20), prev_pid=thread_tid1, next_pid=0) 125trace.add_sched(ts=ms_to_ns(30), prev_pid=0, next_pid=thread_tid1) 126trace.add_cpufreq(ts=ms_to_ns(30), freq=300000, cpu=0) 127trace.add_cpufreq(ts=ms_to_ns(35), freq=1708800, cpu=0) 128trace.add_sched(ts=ms_to_ns(40), prev_pid=thread_tid1, next_pid=0) 129 130trace.add_ftrace_packet(cpu=1) 131trace.add_sched(ts=0, prev_pid=0, next_pid=thread_tid2) 132trace.add_cpufreq(ts=ms_to_ns(0), freq=998400, cpu=1) 133trace.add_sched(ts=ms_to_ns(10), prev_pid=thread_tid2, next_pid=0) 134trace.add_sched(ts=ms_to_ns(35), prev_pid=0, next_pid=thread_tid2) 135trace.add_cpufreq(ts=ms_to_ns(35), freq=1708800, cpu=1) 136trace.add_sched(ts=ms_to_ns(47), prev_pid=thread_tid2, next_pid=0) 137 138sys.stdout.buffer.write(trace.trace.SerializeToString()) 139