• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright 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 */
16import {globalConfig} from 'common/global_config';
17import {PersistentStoreProxy} from 'common/persistent_store_proxy';
18import {MockStorage} from 'test/unit/mock_storage';
19import {TraceConfigurationMap, TRACES} from './trace_collection_utils';
20
21export class TracingConfig {
22  requestedTraces: string[] = [];
23  requestedDumps: string[] = [];
24
25  private storage: Storage;
26  private traceConfig: TraceConfigurationMap;
27  private dumpConfig: TraceConfigurationMap;
28
29  private static instance: TracingConfig | undefined;
30
31  static getInstance(): TracingConfig {
32    if (!TracingConfig.instance) {
33      TracingConfig.instance = new TracingConfig();
34    }
35    return TracingConfig.instance;
36  }
37
38  setTraceConfigForAvailableTraces(isWaylandAvailable = false) {
39    const availableTracesConfig = TRACES['default'];
40    if (isWaylandAvailable) {
41      Object.assign(availableTracesConfig, TRACES['arc']);
42    }
43    this.setTraceConfig(availableTracesConfig);
44  }
45
46  setTraceConfig(traceConfig: TraceConfigurationMap) {
47    this.traceConfig = PersistentStoreProxy.new<TraceConfigurationMap>(
48      'TraceConfiguration',
49      traceConfig,
50      this.storage
51    );
52  }
53
54  getTraceConfig(): TraceConfigurationMap {
55    return this.traceConfig;
56  }
57
58  getDumpConfig(): TraceConfigurationMap {
59    if (this.dumpConfig === undefined) {
60      throw Error('Dump config not initialized yet');
61    }
62    return this.dumpConfig;
63  }
64
65  private constructor() {
66    this.storage = globalConfig.MODE === 'PROD' ? localStorage : new MockStorage();
67
68    this.traceConfig = PersistentStoreProxy.new<TraceConfigurationMap>(
69      'TracingSettings',
70      TRACES['default'],
71      this.storage
72    );
73
74    this.dumpConfig = PersistentStoreProxy.new<TraceConfigurationMap>(
75      'DumpSettings',
76      {
77        window_dump: {
78          name: 'Window Manager',
79          isTraceCollection: undefined,
80          run: true,
81          config: undefined,
82        },
83        layers_dump: {
84          name: 'Surface Flinger',
85          isTraceCollection: undefined,
86          run: true,
87          config: undefined,
88        },
89      },
90      this.storage
91    );
92  }
93}
94