xref: /aosp_15_r20/external/perfetto/src/trace_processor/db/column/range_overlay.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1 /*
2  * Copyright (C) 2024 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_RANGE_OVERLAY_H_
18 #define SRC_TRACE_PROCESSOR_DB_COLUMN_RANGE_OVERLAY_H_
19 
20 #include <cstdint>
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/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 class RangeOverlay final : public OverlayLayer {
34  public:
35   explicit RangeOverlay(const Range*);
36   ~RangeOverlay() override;
37 
38   void Flatten(uint32_t* start, const uint32_t* end, uint32_t stride) 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 Range*);
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(Token* start, Token* end, SortDirection) const override;
61 
62     void Distinct(Indices&) const override;
63 
64     std::optional<Token> MaxElement(Indices&) const override;
65 
66     std::optional<Token> MinElement(Indices&) const override;
67 
68     SqlValue Get_AvoidUsingBecauseSlow(uint32_t index) const override;
69 
size()70     uint32_t size() const override { return range_->size(); }
71 
DebugString()72     std::string DebugString() const override { return "RangeOverlay"; }
73 
74    private:
75     std::unique_ptr<DataLayerChain> inner_;
76     const Range* range_;
77   };
78 
79   const Range* range_;
80 };
81 
82 }  // namespace perfetto::trace_processor::column
83 
84 #endif  // SRC_TRACE_PROCESSOR_DB_COLUMN_RANGE_OVERLAY_H_
85