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