1 /* 2 * Copyright (C) 2018 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_SQLITE_SQL_STATS_TABLE_H_ 18 #define SRC_TRACE_PROCESSOR_SQLITE_SQL_STATS_TABLE_H_ 19 20 #include <cstddef> 21 22 #include "src/trace_processor/sqlite/bindings/sqlite_module.h" 23 24 namespace perfetto::trace_processor { 25 26 class QueryConstraints; 27 class TraceStorage; 28 29 // A virtual table that allows to introspect performances of the SQL engine 30 // for the kMaxLogEntries queries. 31 struct SqlStatsModule : sqlite::Module<SqlStatsModule> { 32 using Context = TraceStorage; 33 struct Vtab : sqlite::Module<SqlStatsModule>::Vtab { 34 TraceStorage* storage = nullptr; 35 }; 36 struct Cursor : sqlite::Module<SqlStatsModule>::Cursor { 37 const TraceStorage* storage = nullptr; 38 size_t row = 0; 39 size_t num_rows = 0; 40 }; 41 enum Column { 42 kQuery = 0, 43 kTimeStarted = 1, 44 kTimeFirstNext = 2, 45 kTimeEnded = 3, 46 }; 47 48 static constexpr auto kType = kEponymousOnly; 49 static constexpr bool kSupportsWrites = false; 50 static constexpr bool kDoesOverloadFunctions = false; 51 52 static int Connect(sqlite3*, 53 void*, 54 int, 55 const char* const*, 56 sqlite3_vtab**, 57 char**); 58 static int Disconnect(sqlite3_vtab*); 59 60 static int BestIndex(sqlite3_vtab*, sqlite3_index_info*); 61 62 static int Open(sqlite3_vtab*, sqlite3_vtab_cursor**); 63 static int Close(sqlite3_vtab_cursor*); 64 65 static int Filter(sqlite3_vtab_cursor*, 66 int, 67 const char*, 68 int, 69 sqlite3_value**); 70 static int Next(sqlite3_vtab_cursor*); 71 static int Eof(sqlite3_vtab_cursor*); 72 static int Column(sqlite3_vtab_cursor*, sqlite3_context*, int); 73 static int Rowid(sqlite3_vtab_cursor*, sqlite_int64*); 74 75 // This needs to happen at the end as it depends on the functions 76 // defined above. 77 static constexpr sqlite3_module kModule = CreateModule(); 78 }; 79 80 } // namespace perfetto::trace_processor 81 82 #endif // SRC_TRACE_PROCESSOR_SQLITE_SQL_STATS_TABLE_H_ 83