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