1 /* 2 * Copyright (C) 2023 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_DB_COLUMN_ARRANGEMENT_OVERLAY_H_ 18 #define SRC_TRACE_PROCESSOR_DB_COLUMN_ARRANGEMENT_OVERLAY_H_ 19 20 #include <cstdint> 21 #include <memory> 22 #include <optional> 23 #include <string> 24 #include <vector> 25 26 #include "perfetto/trace_processor/basic_types.h" 27 #include "src/trace_processor/db/column/data_layer.h" 28 #include "src/trace_processor/db/column/overlay_layer.h" 29 #include "src/trace_processor/db/column/types.h" 30 31 namespace perfetto::trace_processor::column { 32 33 // Storage responsible for rearranging the elements of another Storage. It deals 34 // with duplicates, permutations and selection; for selection only, it's more 35 // efficient to use `SelectorOverlay`. 36 class ArrangementOverlay final : public OverlayLayer { 37 public: 38 ArrangementOverlay(const std::vector<uint32_t>* arrangement, 39 DataLayerChain::Indices::State arrangement_state); 40 ~ArrangementOverlay() override; 41 42 void Flatten(uint32_t* start, const uint32_t* end, uint32_t stride) override; 43 44 std::unique_ptr<DataLayerChain> MakeChain( 45 std::unique_ptr<DataLayerChain>, 46 ChainCreationArgs = ChainCreationArgs()); 47 48 private: 49 class ChainImpl : public DataLayerChain { 50 public: 51 ChainImpl(std::unique_ptr<DataLayerChain> inner, 52 const std::vector<uint32_t>* arrangement, 53 Indices::State arrangement_state, 54 bool does_arrangement_order_storage); 55 56 SingleSearchResult SingleSearch(FilterOp, 57 SqlValue, 58 uint32_t) const override; 59 60 SearchValidationResult ValidateSearchConstraints(FilterOp, 61 SqlValue) const override; 62 63 RangeOrBitVector SearchValidated(FilterOp, SqlValue, Range) const override; 64 65 void IndexSearchValidated(FilterOp, SqlValue, Indices&) const override; 66 67 void StableSort(Token* start, Token* end, SortDirection) const override; 68 69 void Distinct(Indices&) const override; 70 71 std::optional<Token> MaxElement(Indices&) const override; 72 73 std::optional<Token> MinElement(Indices&) const override; 74 75 SqlValue Get_AvoidUsingBecauseSlow(uint32_t index) const override; 76 size()77 uint32_t size() const override { 78 return static_cast<uint32_t>(arrangement_->size()); 79 } 80 DebugString()81 std::string DebugString() const override { return "ArrangementOverlay"; } 82 83 private: 84 std::unique_ptr<DataLayerChain> inner_; 85 const std::vector<uint32_t>* arrangement_; 86 const Indices::State arrangement_state_; 87 const bool does_arrangement_order_storage_; 88 }; 89 90 std::unique_ptr<DataLayerChain> inner_; 91 const std::vector<uint32_t>* arrangement_; 92 const DataLayerChain::Indices::State arrangement_state_; 93 }; 94 95 } // namespace perfetto::trace_processor::column 96 97 #endif // SRC_TRACE_PROCESSOR_DB_COLUMN_ARRANGEMENT_OVERLAY_H_ 98