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_STATS_TABLE_H_ 18 #define SRC_TRACE_PROCESSOR_SQLITE_STATS_TABLE_H_ 19 20 #include <cstddef> 21 22 #include "src/trace_processor/sqlite/bindings/sqlite_module.h" 23 #include "src/trace_processor/storage/trace_storage.h" 24 25 namespace perfetto::trace_processor { 26 27 // The stats table contains diagnostic info and errors that are either: 28 // - Collected at trace time (e.g., ftrace buffer overruns). 29 // - Generated at parsing time (e.g., clock events out-of-order). 30 struct StatsModule : sqlite::Module<StatsModule> { 31 using Context = TraceStorage; 32 struct Vtab : sqlite::Module<StatsModule>::Vtab { 33 TraceStorage* storage = nullptr; 34 }; 35 struct Cursor : sqlite::Module<StatsModule>::Cursor { 36 const TraceStorage* storage = nullptr; 37 size_t key = 0; 38 TraceStorage::Stats::IndexMap::const_iterator it{}; 39 }; 40 enum Column { kName = 0, kIndex, kSeverity, kSource, kValue, kDescription }; 41 42 static constexpr auto kType = kEponymousOnly; 43 static constexpr bool kSupportsWrites = false; 44 static constexpr bool kDoesOverloadFunctions = false; 45 46 static int Connect(sqlite3*, 47 void*, 48 int, 49 const char* const*, 50 sqlite3_vtab**, 51 char**); 52 static int Disconnect(sqlite3_vtab*); 53 54 static int BestIndex(sqlite3_vtab*, sqlite3_index_info*); 55 56 static int Open(sqlite3_vtab*, sqlite3_vtab_cursor**); 57 static int Close(sqlite3_vtab_cursor*); 58 59 static int Filter(sqlite3_vtab_cursor*, 60 int, 61 const char*, 62 int, 63 sqlite3_value**); 64 static int Next(sqlite3_vtab_cursor*); 65 static int Eof(sqlite3_vtab_cursor*); 66 static int Column(sqlite3_vtab_cursor*, sqlite3_context*, int); 67 static int Rowid(sqlite3_vtab_cursor*, sqlite_int64*); 68 69 // This needs to happen at the end as it depends on the functions 70 // defined above. 71 static constexpr sqlite3_module kModule = CreateModule(); 72 }; 73 74 } // namespace perfetto::trace_processor 75 76 #endif // SRC_TRACE_PROCESSOR_SQLITE_STATS_TABLE_H_ 77