xref: /aosp_15_r20/development/tools/winscope/src/app/trace_search/abstract_search_view_factory.ts (revision 90c8c64db3049935a07c6143d7fd006e26f8ecca)
1/*
2 * Copyright (C) 2024 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 {TraceType} from 'trace/trace_type';
18import {WasmEngineProxy} from 'trace_processor/wasm_engine_proxy';
19
20export abstract class AbstractSearchViewFactory {
21  abstract readonly traceType: TraceType;
22
23  constructor(protected traceProcessor: WasmEngineProxy) {}
24
25  protected async createSqlTableWithDefaults(
26    tableName: string,
27  ): Promise<string> {
28    const newTableName = `${tableName}_with_defaults`;
29    const sql = `
30      CREATE PERFETTO TABLE ${newTableName}(
31        id INT,
32        base64_proto_id INT,
33        flat_key STRING,
34        key STRING,
35        int_value LONG,
36        string_value STRING,
37        real_value DOUBLE,
38        display_value STRING
39      ) AS
40      SELECT
41      id,
42      base64_proto_id,
43      flat_key,
44      key,
45      int_value,
46      string_value,
47      real_value,
48      CASE
49        WHEN int_value IS NOT NULL THEN cast_string!(int_value)
50        WHEN string_value IS NOT NULL THEN string_value
51        WHEN real_value IS NOT NULL THEN cast_string!(real_value)
52        ELSE NULL END
53      AS display_value
54      FROM __intrinsic_winscope_proto_to_args_with_defaults('${tableName}');
55    `;
56    await this.traceProcessor.query(sql);
57    return newTableName;
58  }
59
60  abstract createSearchViews(): Promise<string[]>;
61}
62