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. 14 15import { 16 TableColumn, 17 TableColumnSet, 18} from '../../components/widgets/sql/table/column'; 19import {SqlTableDescription} from '../../components/widgets/sql/table/table_description'; 20 21// Handles the access to all of the Perfetto SQL modules accessible to Trace 22// Processor. 23export interface SqlModules { 24 // Returns names of all tables/views between all loaded Perfetto SQL modules. 25 listTables(): string[]; 26 27 // Returns Perfetto SQL table/view if it was loaded in one of the Perfetto 28 // SQL module. 29 getModuleForTable(tableName: string): SqlModule | undefined; 30} 31 32// Handles the access to a specific Perfetto SQL Package. Package consists of 33// Perfetto SQL modules. 34export interface SqlPackage { 35 readonly name: string; 36 readonly modules: SqlModule[]; 37 38 // Returns names of all tables/views in this package. 39 listTables(): string[]; 40 41 // Returns sqlModule containing table with provided name. 42 getModuleForTable(tableName: string): SqlModule | undefined; 43 44 // Returns sqlTableDescription of the table with provided name. 45 getSqlTableDescription(tableName: string): SqlTableDescription | undefined; 46} 47 48// Handles the access to a specific Perfetto SQL module. 49export interface SqlModule { 50 readonly includeKey: string; 51 readonly dataObjects: SqlTable[]; 52 readonly functions: SqlFunction[]; 53 readonly tableFunctions: SqlTableFunction[]; 54 readonly macros: SqlMacro[]; 55 56 // Returns sqlTable with provided name. 57 getTable(tableName: string): SqlTable | undefined; 58 59 // Returns sqlTableDescription of the table with provided name. 60 getSqlTableDescription(tableName: string): SqlTableDescription | undefined; 61} 62 63// The definition of Perfetto SQL table/view. 64export interface SqlTable { 65 readonly name: string; 66 readonly description: string; 67 readonly type: string; 68 readonly columns: SqlColumn[]; 69 70 // Returns all columns as TableColumns. 71 getTableColumns(): (TableColumn | TableColumnSet)[]; 72} 73 74// The definition of Perfetto SQL function. 75export interface SqlFunction { 76 readonly name: string; 77 readonly description: string; 78 readonly args: SqlArgument[]; 79 readonly returnType: string; 80 readonly returnDesc: string; 81} 82 83// The definition of Perfetto SQL table function. 84export interface SqlTableFunction { 85 readonly name: string; 86 readonly description: string; 87 readonly args: SqlArgument[]; 88 readonly returnCols: SqlColumn[]; 89} 90 91// The definition of Perfetto SQL macro. 92export interface SqlMacro { 93 readonly name: string; 94 readonly description: string; 95 readonly args: SqlArgument[]; 96 readonly returnType: string; 97} 98 99// The definition of Perfetto SQL column. 100export interface SqlColumn { 101 readonly name: string; 102 readonly description: string; 103 readonly type: string; 104 105 // Translates this column to TableColumn. 106 asTableColumn(tableName: string): TableColumn | TableColumnSet; 107} 108 109// The definition of Perfetto SQL argument. Can be used for functions, table 110// functions or macros. 111export interface SqlArgument { 112 readonly name: string; 113 readonly description: string; 114 readonly type: string; 115} 116