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. 14import {Trace} from '../../../public/trace'; 15 16/** 17 * Represents data for a Full trace metric 18 * Eg.- perfetto_ft_launcher-missed_sf_frames-mean 19 * ft here stands for full trace 20 */ 21export interface FullTraceMetricData { 22 /** Process name (e.g., com.google.android.apps.nexuslauncher) */ 23 process: string; 24 25 /** Jank type (e.g., app or sf missed frame) */ 26 jankType: JankType; 27} 28 29/** 30 * Represents data for a CUJ scoped metric 31 * Eg.- perfetto_cuj_launcher-RECENTS_SCROLLING-counter_metrics-missed_sf_frames-mean 32 */ 33export interface CujScopedMetricData { 34 /** Process name (e.g., com.google.android.apps.nexuslauncher) */ 35 process: string; 36 37 /** Cuj interaction name (e.g., RECENTS_SCROLLING) */ 38 cujName: string; 39 40 /** Jank type (e.g., app or sf missed frame) */ 41 jankType: JankType; 42} 43 44/** 45 * Represents data for a Blocking Call metric 46 * Eg.- perfetto_android_blocking_call-cuj-name-com.google.android.apps.nexuslauncher-name-TASKBAR_EXPAND-blocking_calls-name-animation-total_dur_ms-mean 47 * Eg.- perfetto_android_blocking_call_per_frame-cuj-name-com.android.systemui-name-NOTIFICATION_SHADE_EXPAND_COLLAPSE::Collapse-blocking_calls-name-input-mean_dur_per_frame_ns-max 48 */ 49export interface BlockingCallMetricData { 50 /** Process name (e.g., com.google.android.apps.nexuslauncher) */ 51 process: string; 52 53 /** Cuj interaction name (e.g., TASKBAR_EXPAND) */ 54 cujName: string; 55 56 /** Blocking Call name (e.g., animation) */ 57 blockingCallName: string; 58 59 /** aggregation type (e.g., total_dur_ms-mean) */ 60 aggregation: string; 61} 62 63/** Represents a cuj to be pinned. */ 64export interface CujMetricData { 65 cujName: string; 66} 67 68// Common MetricData for all handler. If new needed then add here. 69export type MetricData = 70 | FullTraceMetricData 71 | CujScopedMetricData 72 | BlockingCallMetricData 73 | CujMetricData; 74 75// Common JankType for cujScoped and fullTrace metrics 76export type JankType = 'sf_frames' | 'app_frames' | 'frames'; 77 78/** 79 * Common interface for debug track handlers 80 */ 81export interface MetricHandler { 82 /** 83 * Match metric key & return parsed data if successful. 84 * 85 * @param {string} metricKey The metric key to match. 86 * @returns {MetricData | undefined} Parsed data or undefined if no match. 87 */ 88 match(metricKey: string): MetricData | undefined; 89 90 /** 91 * Add debug track for parsed metric data. 92 * 93 * @param {MetricData} metricData The parsed metric data. 94 * @param {Trace} ctx context for trace methods and properties 95 * @returns {void} 96 */ 97 addMetricTrack(metricData: MetricData, ctx: Trace): void; 98} 99 100// Pair for matching metric and its handler 101export type MetricHandlerMatch = { 102 metricData: MetricData; 103 metricHandler: MetricHandler; 104}; 105 106/** 107 * Expand process name for specific system processes 108 * 109 * @param {string} metricProcessName Name of the processes 110 * @returns {string} Either the same or expanded name for abbreviated process names 111 */ 112export function expandProcessName(metricProcessName: string): string { 113 if (metricProcessName.includes('systemui')) { 114 return 'com.android.systemui'; 115 } else if (metricProcessName.includes('launcher')) { 116 return 'com.google.android.apps.nexuslauncher'; 117 } else if (metricProcessName.includes('surfaceflinger')) { 118 return '/system/bin/surfaceflinger'; 119 } else { 120 return metricProcessName; 121 } 122} 123