• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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_PRELUDE_OPERATORS_WINDOW_OPERATOR_H_
18 #define SRC_TRACE_PROCESSOR_PRELUDE_OPERATORS_WINDOW_OPERATOR_H_
19 
20 #include <limits>
21 #include <memory>
22 
23 #include "perfetto/base/status.h"
24 #include "src/trace_processor/sqlite/sqlite_table.h"
25 
26 namespace perfetto {
27 namespace trace_processor {
28 
29 class TraceStorage;
30 
31 class WindowOperatorTable final
32     : public TypedSqliteTable<WindowOperatorTable, const TraceStorage*> {
33  public:
34   enum Column {
35     kRowId = 0,
36     kQuantum = 1,
37     kWindowStart = 2,
38     kWindowDur = 3,
39     kTs = 4,
40     kDuration = 5,
41     kQuantumTs = 6
42   };
43   class Cursor final : public SqliteTable::BaseCursor {
44    public:
45     explicit Cursor(WindowOperatorTable*);
46     ~Cursor() final;
47 
48     Cursor(Cursor&&) = default;
49     Cursor& operator=(Cursor&&) = default;
50 
51     // Implementation of SqliteTable::Cursor.
52     base::Status Filter(const QueryConstraints& qc,
53                         sqlite3_value**,
54                         FilterHistory);
55     base::Status Next();
56     bool Eof();
57     base::Status Column(sqlite3_context*, int N);
58 
59    private:
60     // Defines the data to be generated by the table.
61     enum FilterType {
62       // Returns all the spans.
63       kReturnAll = 0,
64       // Only returns the first span of the table. Useful for UPDATE operations.
65       kReturnFirst = 1,
66     };
67 
68     int64_t window_start_ = 0;
69     int64_t window_end_ = 0;
70     int64_t step_size_ = 0;
71 
72     int64_t current_ts_ = 0;
73     int64_t quantum_ts_ = 0;
74     int64_t row_id_ = 0;
75 
76     FilterType filter_type_ = FilterType::kReturnAll;
77 
78     WindowOperatorTable* table_ = nullptr;
79   };
80 
81   WindowOperatorTable(sqlite3*, const TraceStorage*);
82   ~WindowOperatorTable() final;
83 
84   // Table implementation.
85   base::Status Init(int, const char* const*, Schema* schema) final;
86   std::unique_ptr<SqliteTable::BaseCursor> CreateCursor() final;
87   int BestIndex(const QueryConstraints&, BestIndexInfo*) final;
88   base::Status ModifyConstraints(QueryConstraints* qc) final;
89   base::Status Update(int, sqlite3_value**, sqlite3_int64*) final;
90 
91  private:
92   int64_t quantum_ = 0;
93   int64_t window_start_ = 0;
94 
95   // max of int64_t because SQLite technically only supports int64s and not
96   // uint64s.
97   int64_t window_dur_ = std::numeric_limits<int64_t>::max();
98 };
99 
100 }  // namespace trace_processor
101 }  // namespace perfetto
102 
103 #endif  // SRC_TRACE_PROCESSOR_PRELUDE_OPERATORS_WINDOW_OPERATOR_H_
104