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 <limits> 21 #include <memory> 22 23 #include "perfetto/base/status.h" 24 #include "src/trace_processor/sqlite/sqlite_table.h" 25 26 namespace perfetto { 27 namespace trace_processor { 28 29 class QueryConstraints; 30 class TraceStorage; 31 32 // A virtual table that allows to introspect performances of the SQL engine 33 // for the kMaxLogEntries queries. 34 class SqlStatsTable final 35 : public TypedSqliteTable<SqlStatsTable, const TraceStorage*> { 36 public: 37 enum Column { 38 kQuery = 0, 39 kTimeStarted = 1, 40 kTimeFirstNext = 2, 41 kTimeEnded = 3, 42 }; 43 44 // Implementation of the SQLite cursor interface. 45 class Cursor final : public SqliteTable::BaseCursor { 46 public: 47 explicit Cursor(SqlStatsTable* storage); 48 ~Cursor() final; 49 50 // Implementation of SqliteTable::Cursor. 51 base::Status Filter(const QueryConstraints&, 52 sqlite3_value**, 53 FilterHistory); 54 base::Status Next(); 55 bool Eof(); 56 base::Status Column(sqlite3_context*, int N); 57 58 private: 59 Cursor(Cursor&) = delete; 60 Cursor& operator=(const Cursor&) = delete; 61 62 Cursor(Cursor&&) noexcept = default; 63 Cursor& operator=(Cursor&&) = default; 64 65 size_t row_ = 0; 66 size_t num_rows_ = 0; 67 const TraceStorage* storage_ = nullptr; 68 SqlStatsTable* table_ = nullptr; 69 }; 70 71 SqlStatsTable(sqlite3*, const TraceStorage* storage); 72 ~SqlStatsTable() final; 73 74 // Table implementation. 75 base::Status Init(int, const char* const*, Schema*) final; 76 std::unique_ptr<SqliteTable::BaseCursor> CreateCursor() final; 77 int BestIndex(const QueryConstraints&, BestIndexInfo*) final; 78 79 private: 80 const TraceStorage* const storage_; 81 }; 82 83 } // namespace trace_processor 84 } // namespace perfetto 85 86 #endif // SRC_TRACE_PROCESSOR_SQLITE_SQL_STATS_TABLE_H_ 87