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