• 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_SQL_STATS_TABLE_H_
18 #define SRC_TRACE_PROCESSOR_SQLITE_SQL_STATS_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 QueryConstraints;
29 class TraceStorage;
30 
31 // A virtual table that allows to introspect performances of the SQL engine
32 // for the kMaxLogEntries queries.
33 class SqlStatsTable : public SqliteTable {
34  public:
35   enum Column {
36     kQuery = 0,
37     kTimeStarted = 1,
38     kTimeFirstNext = 2,
39     kTimeEnded = 3,
40   };
41 
42   // Implementation of the SQLite cursor interface.
43   class Cursor : public SqliteTable::Cursor {
44    public:
45     Cursor(SqlStatsTable* storage);
46     ~Cursor() override;
47 
48     // Implementation of SqliteTable::Cursor.
49     int Filter(const QueryConstraints&,
50                sqlite3_value**,
51                FilterHistory) override;
52     int Next() override;
53     int Eof() override;
54     int Column(sqlite3_context*, int N) override;
55 
56    private:
57     Cursor(Cursor&) = delete;
58     Cursor& operator=(const Cursor&) = delete;
59 
60     Cursor(Cursor&&) noexcept = default;
61     Cursor& operator=(Cursor&&) = default;
62 
63     size_t row_ = 0;
64     size_t num_rows_ = 0;
65     const TraceStorage* storage_ = nullptr;
66     SqlStatsTable* table_ = nullptr;
67   };
68 
69   SqlStatsTable(sqlite3*, const TraceStorage* storage);
70 
71   static void RegisterTable(sqlite3* db, const TraceStorage* storage);
72 
73   // Table implementation.
74   util::Status Init(int, const char* const*, Schema*) override;
75   std::unique_ptr<SqliteTable::Cursor> CreateCursor() override;
76   int BestIndex(const QueryConstraints&, BestIndexInfo*) override;
77 
78  private:
79   const TraceStorage* const storage_;
80 };
81 
82 }  // namespace trace_processor
83 }  // namespace perfetto
84 
85 #endif  // SRC_TRACE_PROCESSOR_SQLITE_SQL_STATS_TABLE_H_
86