xref: /aosp_15_r20/external/perfetto/src/trace_processor/db/column/selector_overlay.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
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/overlay_layer.h"
29 #include "src/trace_processor/db/column/types.h"
30 
31 namespace perfetto::trace_processor::column {
32 
33 // Storage which "selects" specific rows from an underlying storage using a
34 // BitVector. See ArrangementOverlay for a more generic class which allows
35 // duplication and rearragement but is less performant.
36 class SelectorOverlay final : public OverlayLayer {
37  public:
38   explicit SelectorOverlay(const BitVector*);
39   ~SelectorOverlay() override;
40 
41   void Flatten(uint32_t* start, const uint32_t* end, uint32_t stride) override;
42 
43   std::unique_ptr<DataLayerChain> MakeChain(
44       std::unique_ptr<DataLayerChain>,
45       ChainCreationArgs = ChainCreationArgs());
46 
47  private:
48   class ChainImpl : public DataLayerChain {
49    public:
50     ChainImpl(std::unique_ptr<DataLayerChain>, const BitVector*);
51 
52     SingleSearchResult SingleSearch(FilterOp,
53                                     SqlValue,
54                                     uint32_t) const override;
55 
56     SearchValidationResult ValidateSearchConstraints(FilterOp,
57                                                      SqlValue) const override;
58 
59     RangeOrBitVector SearchValidated(FilterOp, SqlValue, Range) const override;
60 
61     void IndexSearchValidated(FilterOp p, SqlValue, Indices&) const override;
62 
63     void StableSort(Token* start, Token* end, SortDirection) 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 { return selector_->size(); }
74 
DebugString()75     std::string DebugString() const override { return "SelectorOverlay"; }
76 
77    private:
78     std::unique_ptr<DataLayerChain> inner_ = nullptr;
79     const BitVector* selector_ = nullptr;
80   };
81 
82   const BitVector* selector_ = nullptr;
83 };
84 
85 }  // namespace perfetto::trace_processor::column
86 
87 #endif  // SRC_TRACE_PROCESSOR_DB_COLUMN_SELECTOR_OVERLAY_H_
88