• 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_STATS_TABLE_H_
18 #define SRC_TRACE_PROCESSOR_SQLITE_STATS_TABLE_H_
19 
20 #include <limits>
21 #include <memory>
22 
23 #include "src/trace_processor/sqlite/sqlite_table.h"
24 #include "src/trace_processor/storage/stats.h"
25 #include "src/trace_processor/storage/trace_storage.h"
26 
27 namespace perfetto {
28 namespace trace_processor {
29 
30 // The stats table contains diagnostic info and errors that are either:
31 // - Collected at trace time (e.g., ftrace buffer overruns).
32 // - Generated at parsing time (e.g., clock events out-of-order).
33 class StatsTable final
34     : public TypedSqliteTable<StatsTable, const TraceStorage*> {
35  public:
36   enum Column { kName = 0, kIndex, kSeverity, kSource, kValue, kDescription };
37   class Cursor final : public SqliteTable::BaseCursor {
38    public:
39     explicit Cursor(StatsTable*);
40     ~Cursor() final;
41 
42     // Implementation of SqliteTable::Cursor.
43     base::Status Filter(const QueryConstraints&,
44                         sqlite3_value**,
45                         FilterHistory);
46     base::Status Next();
47     bool Eof();
48     base::Status Column(sqlite3_context*, int N);
49 
50    private:
51     Cursor(Cursor&) = delete;
52     Cursor& operator=(const Cursor&) = delete;
53 
54     Cursor(Cursor&&) noexcept = default;
55     Cursor& operator=(Cursor&&) = default;
56 
57     StatsTable* table_ = nullptr;
58     const TraceStorage* storage_ = nullptr;
59     size_t key_ = 0;
60     TraceStorage::Stats::IndexMap::const_iterator index_{};
61   };
62 
63   StatsTable(sqlite3*, const TraceStorage*);
64   ~StatsTable() final;
65 
66   // Table implementation.
67   util::Status Init(int, const char* const*, SqliteTable::Schema*) final;
68   std::unique_ptr<SqliteTable::BaseCursor> CreateCursor() final;
69   int BestIndex(const QueryConstraints&, BestIndexInfo*) final;
70 
71  private:
72   const TraceStorage* const storage_;
73 };
74 }  // namespace trace_processor
75 }  // namespace perfetto
76 
77 #endif  // SRC_TRACE_PROCESSOR_SQLITE_STATS_TABLE_H_
78