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 #ifndef SRC_TRACE_PROCESSOR_DB_COLUMN_SET_ID_STORAGE_H_ 17 #define SRC_TRACE_PROCESSOR_DB_COLUMN_SET_ID_STORAGE_H_ 18 19 #include <cstdint> 20 #include <memory> 21 #include <optional> 22 #include <string> 23 #include <vector> 24 25 #include "perfetto/trace_processor/basic_types.h" 26 #include "src/trace_processor/containers/bit_vector.h" 27 #include "src/trace_processor/db/column/data_layer.h" 28 #include "src/trace_processor/db/column/storage_layer.h" 29 #include "src/trace_processor/db/column/types.h" 30 31 namespace perfetto::trace_processor::column { 32 33 // Storage for SetId columns. 34 class SetIdStorage final : public StorageLayer { 35 public: 36 using SetId = uint32_t; 37 38 explicit SetIdStorage(const std::vector<uint32_t>*); 39 ~SetIdStorage() override; 40 41 StoragePtr GetStoragePtr() override; 42 43 std::unique_ptr<DataLayerChain> MakeChain(); 44 45 private: 46 class ChainImpl : public DataLayerChain { 47 public: 48 explicit ChainImpl(const std::vector<uint32_t>*); 49 50 SingleSearchResult SingleSearch(FilterOp, 51 SqlValue, 52 uint32_t) const override; 53 54 SearchValidationResult ValidateSearchConstraints(FilterOp, 55 SqlValue) const override; 56 57 RangeOrBitVector SearchValidated(FilterOp, SqlValue, Range) const override; 58 59 void IndexSearchValidated(FilterOp, SqlValue, Indices&) const override; 60 61 void StableSort(Token* start, 62 Token* end, 63 SortDirection direction) const override; 64 65 void Distinct(Indices&) const override; 66 67 std::optional<Token> MaxElement(Indices&) const override; 68 69 std::optional<Token> MinElement(Indices&) const override; 70 71 SqlValue Get_AvoidUsingBecauseSlow(uint32_t index) const override; 72 size()73 uint32_t size() const override { 74 return static_cast<uint32_t>(values_->size()); 75 } 76 DebugString()77 std::string DebugString() const override { return "SetIdStorage"; } 78 79 private: 80 BitVector IndexSearch(FilterOp, SetId, uint32_t*, uint32_t) const; 81 Range BinarySearchIntrinsic(FilterOp, SetId, Range search_range) const; 82 83 const std::vector<SetId>* values_ = nullptr; 84 }; 85 86 const std::vector<SetId>* values_ = nullptr; 87 }; 88 89 } // namespace perfetto::trace_processor::column 90 91 #endif // SRC_TRACE_PROCESSOR_DB_COLUMN_SET_ID_STORAGE_H_ 92