1/* 2 * Copyright (C) 2022 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 */ 16 17import {TRACE_INFO} from 'trace/trace_info'; 18import {TraceType} from 'trace/trace_type'; 19 20export interface TraceConfiguration { 21 name: string; 22 enabled: boolean; 23 config: ConfigurationOptions | undefined; 24 available: boolean; 25 types: TraceType[]; 26} 27 28export interface TraceConfigurationMap { 29 [key: string]: TraceConfiguration; 30} 31 32export interface ConfigurationOptions { 33 enableConfigs: EnableConfiguration[]; 34 selectionConfigs: SelectionConfiguration[]; 35} 36 37export interface EnableConfiguration { 38 name: string; 39 key: string; 40 enabled: boolean; 41} 42 43export interface SelectionConfiguration { 44 key: string; 45 name: string; 46 options: string[]; 47 value: string | string[]; 48 desc?: string; 49 optional?: boolean; 50 wideField?: boolean; 51} 52 53export interface ConfigMap { 54 [key: string]: string[] | string; 55} 56 57const wmTraceSelectionConfigs: SelectionConfiguration[] = [ 58 { 59 key: 'wmbuffersize', 60 name: 'buffer size (KB)', 61 options: ['4000', '8000', '16000', '32000'], 62 value: '32000', 63 }, 64 { 65 key: 'tracingtype', 66 name: 'tracing type', 67 options: ['frame', 'transaction'], 68 value: 'frame', 69 }, 70 { 71 key: 'tracinglevel', 72 name: 'tracing level', 73 options: ['verbose', 'debug', 'critical'], 74 value: 'verbose', 75 }, 76]; 77 78const sfTraceEnableConfigs: EnableConfiguration[] = [ 79 { 80 name: 'input', 81 key: 'input', 82 enabled: true, 83 }, 84 { 85 name: 'composition', 86 key: 'composition', 87 enabled: true, 88 }, 89 { 90 name: 'metadata', 91 key: 'metadata', 92 enabled: false, 93 }, 94 { 95 name: 'hwc', 96 key: 'hwc', 97 enabled: false, 98 }, 99 { 100 name: 'trace buffers', 101 key: 'tracebuffers', 102 enabled: false, 103 }, 104 { 105 name: 'virtual displays', 106 key: 'virtualdisplays', 107 enabled: false, 108 }, 109]; 110 111const sfTraceSelectionConfigs: SelectionConfiguration[] = [ 112 { 113 key: 'sfbuffersize', 114 name: 'buffer size (KB)', 115 options: ['4000', '8000', '16000', '32000'], 116 value: '32000', 117 }, 118]; 119const screenshotConfigs: SelectionConfiguration[] = [ 120 { 121 key: 'displays', 122 name: 'displays', 123 options: [], 124 value: [], 125 desc: 'Leave empty to capture active display', 126 wideField: true, 127 }, 128]; 129 130export function makeScreenRecordingConfigs( 131 options: string[], 132 initialValue: string | string[], 133): SelectionConfiguration[] { 134 return [ 135 { 136 key: 'displays', 137 name: 'displays', 138 options, 139 value: initialValue, 140 optional: true, 141 desc: 'Leave empty to capture active display', 142 wideField: true, 143 }, 144 ]; 145} 146 147const traceDefaultConfig: TraceConfigurationMap = { 148 layers_trace: { 149 name: TRACE_INFO[TraceType.SURFACE_FLINGER].name, 150 enabled: true, 151 config: { 152 enableConfigs: sfTraceEnableConfigs, 153 selectionConfigs: sfTraceSelectionConfigs, 154 }, 155 available: true, 156 types: [TraceType.SURFACE_FLINGER], 157 }, 158 window_trace: { 159 name: TRACE_INFO[TraceType.WINDOW_MANAGER].name, 160 enabled: true, 161 config: { 162 enableConfigs: [], 163 selectionConfigs: wmTraceSelectionConfigs, 164 }, 165 available: true, 166 types: [TraceType.WINDOW_MANAGER], 167 }, 168 screen_recording: { 169 name: TRACE_INFO[TraceType.SCREEN_RECORDING].name, 170 enabled: true, 171 config: { 172 enableConfigs: [], 173 selectionConfigs: makeScreenRecordingConfigs([], ''), 174 }, 175 available: true, 176 types: [TraceType.SCREEN_RECORDING], 177 }, 178 ime: { 179 name: 'IME', 180 enabled: true, 181 config: undefined, 182 available: true, 183 types: [ 184 TraceType.INPUT_METHOD_CLIENTS, 185 TraceType.INPUT_METHOD_SERVICE, 186 TraceType.INPUT_METHOD_MANAGER_SERVICE, 187 ], 188 }, 189 transactions: { 190 name: TRACE_INFO[TraceType.TRANSACTIONS].name, 191 enabled: true, 192 config: undefined, 193 available: true, 194 types: [TraceType.TRANSACTIONS, TraceType.TRANSACTIONS_LEGACY], 195 }, 196 proto_log: { 197 name: TRACE_INFO[TraceType.PROTO_LOG].name, 198 enabled: false, 199 config: undefined, 200 available: true, 201 types: [TraceType.PROTO_LOG], 202 }, 203 wayland_trace: { 204 name: TRACE_INFO[TraceType.WAYLAND].name, 205 enabled: false, 206 config: undefined, 207 available: false, 208 types: [TraceType.WAYLAND, TraceType.WAYLAND_DUMP], 209 }, 210 eventlog: { 211 name: TRACE_INFO[TraceType.EVENT_LOG].name, 212 enabled: false, 213 config: undefined, 214 available: true, 215 types: [TraceType.EVENT_LOG, TraceType.CUJS], 216 }, 217 transition_traces: { 218 name: TRACE_INFO[TraceType.SHELL_TRANSITION].name, 219 enabled: false, 220 config: undefined, 221 available: true, 222 types: [ 223 TraceType.SHELL_TRANSITION, 224 TraceType.WM_TRANSITION, 225 TraceType.TRANSITION, 226 ], 227 }, 228 view_capture_traces: { 229 name: TRACE_INFO[TraceType.VIEW_CAPTURE].name, 230 enabled: false, 231 config: undefined, 232 available: true, 233 types: [TraceType.VIEW_CAPTURE], 234 }, 235 input: { 236 name: 'Input', 237 enabled: false, 238 config: undefined, 239 available: true, 240 types: [ 241 TraceType.INPUT_KEY_EVENT, 242 TraceType.INPUT_MOTION_EVENT, 243 TraceType.INPUT_EVENT_MERGED, 244 ], 245 }, 246}; 247 248export function makeDefaultTraceConfigMap(): TraceConfigurationMap { 249 return structuredClone({ 250 window_trace: traceDefaultConfig['window_trace'], 251 layers_trace: traceDefaultConfig['layers_trace'], 252 transactions: traceDefaultConfig['transactions'], 253 proto_log: traceDefaultConfig['proto_log'], 254 screen_recording: traceDefaultConfig['screen_recording'], 255 ime: traceDefaultConfig['ime'], 256 eventlog: traceDefaultConfig['eventlog'], 257 transition_traces: traceDefaultConfig['transition_traces'], 258 view_capture_trace: traceDefaultConfig['view_capture_traces'], 259 input: traceDefaultConfig['input'], 260 wayland_trace: traceDefaultConfig['wayland_trace'], 261 }); 262} 263 264export function makeDefaultDumpConfigMap(): TraceConfigurationMap { 265 return structuredClone({ 266 window_dump: { 267 name: 'Window Manager', 268 enabled: true, 269 config: undefined, 270 available: true, 271 types: [TraceType.WINDOW_MANAGER], 272 }, 273 layers_dump: { 274 name: 'Surface Flinger', 275 enabled: true, 276 config: undefined, 277 available: true, 278 types: [TraceType.SURFACE_FLINGER], 279 }, 280 screenshot: { 281 name: 'Screenshot', 282 enabled: true, 283 config: { 284 enableConfigs: [], 285 selectionConfigs: screenshotConfigs, 286 }, 287 available: true, 288 types: [TraceType.SCREENSHOT], 289 }, 290 }); 291} 292