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_ID_STORAGE_H_ 17 #define SRC_TRACE_PROCESSOR_DB_COLUMN_ID_STORAGE_H_ 18 19 #include <cstdint> 20 #include <limits> 21 #include <memory> 22 #include <optional> 23 #include <string> 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/types.h" 29 30 namespace perfetto::trace_processor::column { 31 32 // Base level storage for id columns. 33 // 34 // Note: This storage does not have any size instead spanning the entire 35 // uint32_t space (any such integer is a valid id). Overlays (e.g. 36 // RangeOverlay/SelectorOverlay) can be used to limit which ids are 37 // included in the column. 38 class IdStorage final : public DataLayer { 39 public: 40 IdStorage(); 41 ~IdStorage() override; 42 43 std::unique_ptr<DataLayerChain> MakeChain(); 44 45 private: 46 class ChainImpl : public DataLayerChain { 47 public: 48 SingleSearchResult SingleSearch(FilterOp, 49 SqlValue, 50 uint32_t) const override; 51 52 SearchValidationResult ValidateSearchConstraints(FilterOp, 53 SqlValue) const override; 54 55 RangeOrBitVector SearchValidated(FilterOp, SqlValue, Range) const override; 56 57 void IndexSearchValidated(FilterOp, SqlValue, Indices&) const override; 58 59 void StableSort(SortToken* start, 60 SortToken* end, 61 SortDirection) const override; 62 63 void Distinct(Indices&) const override; 64 65 std::optional<Token> MaxElement(Indices&) const override; 66 67 std::optional<Token> MinElement(Indices&) const override; 68 69 SqlValue Get_AvoidUsingBecauseSlow(uint32_t index) const override; 70 71 void Serialize(StorageProto*) const override; 72 size()73 uint32_t size() const override { 74 return std::numeric_limits<uint32_t>::max(); 75 } 76 DebugString()77 std::string DebugString() const override { return "IdStorage"; } 78 79 private: 80 using Id = uint32_t; 81 82 BitVector IndexSearch(FilterOp, Id, uint32_t*, uint32_t) const; 83 static Range BinarySearchIntrinsic(FilterOp, Id, Range); 84 }; 85 }; 86 87 } // namespace perfetto::trace_processor::column 88 89 #endif // SRC_TRACE_PROCESSOR_DB_COLUMN_ID_STORAGE_H_ 90