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_PROCESS_TABLE_H_ 18 #define SRC_TRACE_PROCESSOR_PROCESS_TABLE_H_ 19 20 #include <limits> 21 #include <memory> 22 23 #include "src/trace_processor/table.h" 24 #include "src/trace_processor/trace_storage.h" 25 26 namespace perfetto { 27 namespace trace_processor { 28 29 // The implementation of the SQLite table containing each unique process with 30 // their details (only name at the moment). 31 class ProcessTable : public Table { 32 public: 33 enum Column { kUpid = 0, kName = 1, kPid = 2, kStartTs = 3 }; 34 class Cursor : public Table::Cursor { 35 public: 36 Cursor(ProcessTable*); 37 38 // Implementation of Table::Cursor. 39 int Filter(const QueryConstraints&, sqlite3_value**) override; 40 int Next() override; 41 int Eof() override; 42 int Column(sqlite3_context*, int N) override; 43 44 private: 45 const TraceStorage* const storage_; 46 UniquePid min; 47 UniquePid max; 48 UniquePid current; 49 bool desc; 50 }; 51 52 static void RegisterTable(sqlite3* db, const TraceStorage* storage); 53 54 ProcessTable(sqlite3*, const TraceStorage*); 55 56 // Table implementation. 57 base::Optional<Table::Schema> Init(int, const char* const*) override; 58 std::unique_ptr<Table::Cursor> CreateCursor() override; 59 int BestIndex(const QueryConstraints&, BestIndexInfo*) override; 60 61 private: 62 const TraceStorage* const storage_; 63 }; 64 } // namespace trace_processor 65 } // namespace perfetto 66 67 #endif // SRC_TRACE_PROCESSOR_PROCESS_TABLE_H_ 68