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_STATS_TABLE_H_ 18 #define SRC_TRACE_PROCESSOR_STATS_TABLE_H_ 19 20 #include <limits> 21 #include <memory> 22 23 #include "src/trace_processor/stats.h" 24 #include "src/trace_processor/table.h" 25 #include "src/trace_processor/trace_storage.h" 26 27 namespace perfetto { 28 namespace trace_processor { 29 30 // The stats table contains diagnostic info and errors that are either: 31 // - Collected at trace time (e.g., ftrace buffer overruns). 32 // - Generated at parsing time (e.g., clock events out-of-order). 33 class StatsTable : public Table { 34 public: 35 enum Column { kName = 0, kIndex, kSeverity, kSource, kValue }; 36 class Cursor : public Table::Cursor { 37 public: 38 Cursor(StatsTable*); 39 40 // Implementation of Table::Cursor. 41 int Filter(const QueryConstraints&, sqlite3_value**) override; 42 int Next() override; 43 int Eof() override; 44 int Column(sqlite3_context*, int N) override; 45 46 private: 47 Cursor(Cursor&) = delete; 48 Cursor& operator=(const Cursor&) = delete; 49 50 Cursor(Cursor&&) noexcept = default; 51 Cursor& operator=(Cursor&&) = default; 52 53 StatsTable* table_ = nullptr; 54 const TraceStorage* storage_ = nullptr; 55 size_t key_ = 0; 56 TraceStorage::Stats::IndexMap::const_iterator index_{}; 57 }; 58 59 static void RegisterTable(sqlite3* db, const TraceStorage* storage); 60 61 StatsTable(sqlite3*, const TraceStorage*); 62 63 // Table implementation. 64 base::Optional<Table::Schema> Init(int, const char* const*) override; 65 std::unique_ptr<Table::Cursor> CreateCursor() override; 66 int BestIndex(const QueryConstraints&, BestIndexInfo*) override; 67 68 private: 69 const TraceStorage* const storage_; 70 }; 71 } // namespace trace_processor 72 } // namespace perfetto 73 74 #endif // SRC_TRACE_PROCESSOR_STATS_TABLE_H_ 75