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_ROW_ITERATORS_H_ 18 #define SRC_TRACE_PROCESSOR_ROW_ITERATORS_H_ 19 20 #include <stdint.h> 21 #include <vector> 22 23 namespace perfetto { 24 namespace trace_processor { 25 26 // Implements a strategy of yielding indices into a storage system to fulfil 27 // a query. 28 class RowIterator { 29 public: 30 virtual ~RowIterator(); 31 32 virtual void NextRow() = 0; 33 virtual uint32_t Row() = 0; 34 virtual bool IsEnd() = 0; 35 }; 36 37 // A row iterator which iterates through a range of indicies in either ascending 38 // or descending order and optionally skips rows depending on a bitvector. 39 class RangeRowIterator : public RowIterator { 40 public: 41 RangeRowIterator(uint32_t start_row, uint32_t end_row, bool desc); 42 RangeRowIterator(uint32_t start_row, bool desc, std::vector<bool> row_filter); 43 44 void NextRow() override; 45 bool IsEnd() override; 46 uint32_t Row() override; 47 48 uint32_t RowCount() const; 49 50 private: 51 uint32_t start_row_ = 0; 52 uint32_t end_row_ = 0; 53 bool desc_ = false; 54 std::vector<bool> row_filter_; 55 56 // In non-desc mode, this is an offset from start_row_ while in desc mode, 57 // this is an offset from end_row_. 58 uint32_t offset_ = 0; 59 }; 60 61 // A row iterator which yields row indices from a provided vector. 62 class VectorRowIterator : public RowIterator { 63 public: 64 explicit VectorRowIterator(std::vector<uint32_t> row_indices); 65 ~VectorRowIterator() override; 66 67 void NextRow() override; 68 bool IsEnd() override; 69 uint32_t Row() override; 70 71 private: 72 std::vector<uint32_t> row_indices_; 73 uint32_t offset_ = 0; 74 }; 75 76 } // namespace trace_processor 77 } // namespace perfetto 78 79 #endif // SRC_TRACE_PROCESSOR_ROW_ITERATORS_H_ 80