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 s_to_ns 20 21trace = synth_common.create_trace() 22 23trace.add_chrome_metadata(os_name="Android") 24 25track1 = 1234 26track2 = 4567 27gpu_track = 7890 28 29trace.add_process_track_descriptor(track1, pid=0) 30trace.add_process_track_descriptor(track2, pid=2) 31trace.add_process_track_descriptor(gpu_track, pid=4) 32 33frame_period = s_to_ns(1.0 / 60) 34 35trace.add_track_event_slice("VSync", ts=s_to_ns(3), dur=10, track=gpu_track) 36trace.add_track_event_slice( 37 "VSync", ts=s_to_ns(3) + frame_period, dur=10, track=gpu_track) 38# Frame skipped, but modified rail mode won't go back to foreground_idle 39trace.add_track_event_slice( 40 "VSync", ts=s_to_ns(3) + frame_period * 3, dur=10, track=gpu_track) 41# Larger gap now when mode will go to foreground_idle 42trace.add_track_event_slice( 43 "VSync", ts=s_to_ns(3) + frame_period * 12, dur=10, track=gpu_track) 44trace.add_track_event_slice( 45 "VSync", ts=s_to_ns(3) + frame_period * 13, dur=10, track=gpu_track) 46trace.add_track_event_slice( 47 "VSync", ts=s_to_ns(3) + frame_period * 14, dur=10, track=gpu_track) 48 49trace.add_rail_mode_slice( 50 ts=0, 51 dur=s_to_ns(1), 52 track=track1, 53 mode=trace.prototypes.ChromeRAILMode.RAIL_MODE_RESPONSE) 54trace.add_rail_mode_slice( 55 ts=s_to_ns(1), 56 dur=s_to_ns(2), 57 track=track1, 58 mode=trace.prototypes.ChromeRAILMode.RAIL_MODE_LOAD) 59trace.add_rail_mode_slice( 60 ts=s_to_ns(3), 61 dur=-1, 62 track=track1, 63 mode=trace.prototypes.ChromeRAILMode.RAIL_MODE_IDLE) 64 65trace.add_rail_mode_slice( 66 ts=0, 67 dur=s_to_ns(1), 68 track=track2, 69 mode=trace.prototypes.ChromeRAILMode.RAIL_MODE_ANIMATION) 70trace.add_rail_mode_slice( 71 ts=s_to_ns(1), 72 dur=s_to_ns(2.5), 73 track=track2, 74 mode=trace.prototypes.ChromeRAILMode.RAIL_MODE_IDLE) 75trace.add_rail_mode_slice( 76 ts=s_to_ns(2.5), 77 dur=s_to_ns(1), 78 track=track2, 79 mode=trace.prototypes.ChromeRAILMode.RAIL_MODE_ANIMATION) 80trace.add_rail_mode_slice( 81 ts=s_to_ns(3.5), 82 dur=s_to_ns(1), 83 track=track2, 84 mode=trace.prototypes.ChromeRAILMode.RAIL_MODE_IDLE) 85 86sys.stdout.buffer.write(trace.trace.SerializeToString()) 87