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 17 #ifndef SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_TABLE_FUNCTIONS_STATIC_TABLE_FUNCTION_H_ 18 #define SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_TABLE_FUNCTIONS_STATIC_TABLE_FUNCTION_H_ 19 20 #include <cstdint> 21 #include <memory> 22 #include <string> 23 #include <vector> 24 25 #include "perfetto/ext/base/status_or.h" 26 #include "perfetto/trace_processor/basic_types.h" 27 #include "src/trace_processor/db/table.h" 28 29 namespace perfetto::trace_processor { 30 31 // Interface which can be subclassed to allow generation of tables dynamically 32 // at filter time. 33 // This class is used to implement table-valued functions and other similar 34 // tables. 35 class StaticTableFunction { 36 public: 37 virtual ~StaticTableFunction(); 38 39 // Returns the schema of the table that will be returned by ComputeTable. 40 virtual Table::Schema CreateSchema() = 0; 41 42 // Returns the name of the dynamic table. 43 // This will be used to register the table with SQLite. 44 virtual std::string TableName() = 0; 45 46 // Returns the estimated number of rows the table would generate. 47 virtual uint32_t EstimateRowCount() = 0; 48 49 // Dynamically computes the table given the provided arguments. 50 virtual base::StatusOr<std::unique_ptr<Table>> ComputeTable( 51 const std::vector<SqlValue>& arguments) = 0; 52 }; 53 54 } // namespace perfetto::trace_processor 55 56 #endif // SRC_TRACE_PROCESSOR_PERFETTO_SQL_INTRINSICS_TABLE_FUNCTIONS_STATIC_TABLE_FUNCTION_H_ 57