1// Copyright (C) 2024 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15import {test, Page} from '@playwright/test'; 16import {PerfettoTestHelper} from './perfetto_ui_test_helper'; 17import {assertExists} from '../base/logging'; 18 19test.describe.configure({mode: 'serial'}); 20 21let pth: PerfettoTestHelper; 22let page: Page; 23 24test.beforeAll(async ({browser}, _testInfo) => { 25 page = await browser.newPage(); 26 pth = new PerfettoTestHelper(page); 27 await pth.openTraceFile('api34_startup_cold.perfetto-trace'); 28}); 29 30test('sched', async () => { 31 await page.mouse.move(600, 250); 32 await page.mouse.down(); 33 await page.mouse.move(800, 350); 34 await page.mouse.up(); 35 await pth.waitForPerfettoIdle(); 36 await pth.waitForIdleAndScreenshot('cpu-by-thread.png'); 37 38 await page.click('button[label="CPU by process"]'); 39 await pth.waitForIdleAndScreenshot('cpu-by-process.png'); 40 41 // Now test sorting. 42 43 const hdr = page.getByRole('cell', {name: 'Avg Wall duration (ms)'}); 44 await hdr.click(); 45 await pth.waitForIdleAndScreenshot('sort-by-wall-duration.png'); 46 47 await hdr.click(); 48 await pth.waitForIdleAndScreenshot('sort-by-wall-duration-desc.png'); 49 50 await page.getByRole('cell', {name: 'Occurrences'}).click(); 51 await pth.waitForIdleAndScreenshot('sort-by-occurrences.png'); 52}); 53 54test('gpu counter', async () => { 55 await page.keyboard.press('Escape'); 56 const gpuTrack = pth.locateTrack('Gpu 0 Frequency'); 57 const coords = assertExists(await gpuTrack.boundingBox()); 58 await page.mouse.move(600, coords.y + 10); 59 await page.mouse.down(); 60 await page.mouse.move(800, coords.y + 60); 61 await page.mouse.up(); 62 await pth.waitForIdleAndScreenshot('gpu-counter-aggregation.png'); 63}); 64 65test('frametimeline', async () => { 66 await page.keyboard.press('Escape'); 67 const sysui = pth.locateTrackGroup('com.android.systemui 25348'); 68 await sysui.scrollIntoViewIfNeeded(); 69 await pth.toggleTrackGroup(sysui); 70 const actualTimeline = pth.locateTrack( 71 'com.android.systemui 25348/Actual Timeline', 72 sysui, 73 ); 74 const coords = assertExists(await actualTimeline.boundingBox()); 75 await page.mouse.move(600, coords.y + 10); 76 await page.mouse.down(); 77 await page.mouse.move(1000, coords.y + 20); 78 await page.mouse.up(); 79 await pth.waitForIdleAndScreenshot('frame-timeline-aggregation.png'); 80}); 81 82test('slices', async () => { 83 await page.keyboard.press('Escape'); 84 const syssrv = pth.locateTrackGroup('system_server 1719'); 85 await syssrv.scrollIntoViewIfNeeded(); 86 await pth.toggleTrackGroup(syssrv); 87 const animThread = pth 88 .locateTrack('system_server 1719/android.anim 1754', syssrv) 89 .nth(1); 90 await animThread.scrollIntoViewIfNeeded(); 91 await pth.waitForPerfettoIdle(); 92 const coords = assertExists(await animThread.boundingBox()); 93 await page.mouse.move(600, coords.y + 10); 94 await page.mouse.down(); 95 await page.mouse.move(1000, coords.y + 20); 96 await page.mouse.up(); 97 await pth.waitForIdleAndScreenshot('slice-aggregation.png'); 98}); 99