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 | undefined;
22  run: boolean | undefined;
23  config: ConfigurationOptions | undefined;
24}
25
26export interface TraceConfigurationMap {
27  [key: string]: TraceConfiguration;
28}
29
30interface ConfigurationOptions {
31  enableConfigs: EnableConfiguration[];
32  selectionConfigs: SelectionConfiguration[];
33}
34
35export interface EnableConfiguration {
36  name: string;
37  key: string;
38  enabled: boolean;
39}
40
41export interface SelectionConfiguration {
42  key: string;
43  name: string;
44  options: string[];
45  value: string;
46}
47
48export interface ConfigMap {
49  [key: string]: string[] | string;
50}
51
52const wmTraceSelectionConfigs: SelectionConfiguration[] = [
53  {
54    key: 'wmbuffersize',
55    name: 'buffer size (KB)',
56    options: ['4000', '8000', '16000', '32000'],
57    value: '32000',
58  },
59  {
60    key: 'tracingtype',
61    name: 'tracing type',
62    options: ['frame', 'transaction'],
63    value: 'frame',
64  },
65  {
66    key: 'tracinglevel',
67    name: 'tracing level',
68    options: ['verbose', 'debug', 'critical'],
69    value: 'verbose',
70  },
71];
72
73const sfTraceEnableConfigs: EnableConfiguration[] = [
74  {
75    name: 'input',
76    key: 'input',
77    enabled: true,
78  },
79  {
80    name: 'composition',
81    key: 'composition',
82    enabled: true,
83  },
84  {
85    name: 'metadata',
86    key: 'metadata',
87    enabled: false,
88  },
89  {
90    name: 'hwc',
91    key: 'hwc',
92    enabled: true,
93  },
94  {
95    name: 'trace buffers',
96    key: 'tracebuffers',
97    enabled: true,
98  },
99  {
100    name: 'virtual displays',
101    key: 'virtualdisplays',
102    enabled: false,
103  },
104];
105
106const sfTraceSelectionConfigs: SelectionConfiguration[] = [
107  {
108    key: 'sfbuffersize',
109    name: 'buffer size (KB)',
110    options: ['4000', '8000', '16000', '32000'],
111    value: '32000',
112  },
113];
114
115const traceConfigurations: TraceConfigurationMap = {
116  layers_trace: {
117    name: TRACE_INFO[TraceType.SURFACE_FLINGER].name,
118    run: true,
119    config: {
120      enableConfigs: sfTraceEnableConfigs,
121      selectionConfigs: sfTraceSelectionConfigs,
122    },
123  },
124  window_trace: {
125    name: TRACE_INFO[TraceType.WINDOW_MANAGER].name,
126    run: true,
127    config: {
128      enableConfigs: [],
129      selectionConfigs: wmTraceSelectionConfigs,
130    },
131  },
132  screen_recording: {
133    name: TRACE_INFO[TraceType.SCREEN_RECORDING].name,
134    run: true,
135    config: undefined,
136  },
137  ime: {
138    name: 'IME',
139    run: true,
140    config: undefined,
141  },
142  transactions: {
143    name: TRACE_INFO[TraceType.TRANSACTIONS].name,
144    run: false,
145    config: undefined,
146  },
147  proto_log: {
148    name: TRACE_INFO[TraceType.PROTO_LOG].name,
149    run: false,
150    config: undefined,
151  },
152  wayland_trace: {
153    name: TRACE_INFO[TraceType.WAYLAND].name,
154    run: false,
155    config: undefined,
156  },
157  eventlog: {
158    name: TRACE_INFO[TraceType.EVENT_LOG].name,
159    run: false,
160    config: undefined,
161  },
162  transition_traces: {
163    name: TRACE_INFO[TraceType.SHELL_TRANSITION].name,
164    run: false,
165    config: undefined,
166  },
167  view_capture_traces: {
168    name: 'View Capture',
169    run: false,
170    config: undefined,
171  },
172};
173
174export const TRACES: {[key: string]: TraceConfigurationMap} = {
175  default: {
176    window_trace: traceConfigurations['window_trace'],
177    layers_trace: traceConfigurations['layers_trace'],
178    transactions: traceConfigurations['transactions'],
179    proto_log: traceConfigurations['proto_log'],
180    screen_recording: traceConfigurations['screen_recording'],
181    ime: traceConfigurations['ime'],
182    eventlog: traceConfigurations['eventlog'],
183    transition_traces: traceConfigurations['transition_traces'],
184    view_capture_trace: traceConfigurations['view_capture_traces'],
185  },
186  arc: {
187    wayland_trace: traceConfigurations['wayland_trace'],
188  },
189};
190