• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SELECTOR_OVERLAY_H_
18 #define SRC_TRACE_PROCESSOR_DB_COLUMN_SELECTOR_OVERLAY_H_
19 
20 #include <cstdint>
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 // Storage which "selects" specific rows from an underlying storage using a
33 // BitVector. See ArrangementOverlay for a more generic class which allows
34 // duplication and rearragement but is less performant.
35 class SelectorOverlay final : public DataLayer {
36  public:
37   explicit SelectorOverlay(const BitVector*);
38   ~SelectorOverlay() override;
39 
40   std::unique_ptr<DataLayerChain> MakeChain(
41       std::unique_ptr<DataLayerChain>,
42       ChainCreationArgs = ChainCreationArgs());
43 
44  private:
45   class ChainImpl : public DataLayerChain {
46    public:
47     ChainImpl(std::unique_ptr<DataLayerChain>, const BitVector*);
48 
49     SingleSearchResult SingleSearch(FilterOp,
50                                     SqlValue,
51                                     uint32_t) const override;
52 
53     SearchValidationResult ValidateSearchConstraints(FilterOp,
54                                                      SqlValue) const override;
55 
56     RangeOrBitVector SearchValidated(FilterOp, SqlValue, Range) const override;
57 
58     void IndexSearchValidated(FilterOp p, SqlValue, Indices&) const override;
59 
60     void StableSort(SortToken* start,
61                     SortToken* end,
62                     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 
72     void Serialize(StorageProto*) const override;
73 
size()74     uint32_t size() const override { return selector_->size(); }
75 
DebugString()76     std::string DebugString() const override { return "SelectorOverlay"; }
77 
78    private:
79     void TranslateToInnerIndices(Indices& indices) const;
80     std::unique_ptr<DataLayerChain> inner_ = nullptr;
81     const BitVector* selector_ = nullptr;
82   };
83 
84   const BitVector* selector_ = nullptr;
85 };
86 
87 }  // namespace perfetto::trace_processor::column
88 
89 #endif  // SRC_TRACE_PROCESSOR_DB_COLUMN_SELECTOR_OVERLAY_H_
90