• 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_SCHED_SLICE_TABLE_H_
18 #define SRC_TRACE_PROCESSOR_SCHED_SLICE_TABLE_H_
19 
20 #include "src/trace_processor/ftrace_utils.h"
21 #include "src/trace_processor/storage_table.h"
22 
23 namespace perfetto {
24 namespace trace_processor {
25 
26 // The implementation of the SQLite table containing slices of CPU time with the
27 // metadata for those slices.
28 class SchedSliceTable : public StorageTable {
29  public:
30   SchedSliceTable(sqlite3*, const TraceStorage* storage);
31 
32   static void RegisterTable(sqlite3* db, const TraceStorage* storage);
33 
34   // StorageTable implementation.
35   StorageSchema CreateStorageSchema() override;
36   uint32_t RowCount() override;
37   int BestIndex(const QueryConstraints&, BestIndexInfo*) override;
38 
39  private:
40   uint32_t EstimateQueryCost(const QueryConstraints& cs);
41 
42   class EndStateColumn : public StorageColumn {
43    public:
44     EndStateColumn(std::string col_name,
45                    const std::deque<ftrace_utils::TaskState>* deque);
46     ~EndStateColumn() override;
47 
48     void ReportResult(sqlite3_context*, uint32_t row) const override;
49 
50     void Filter(int op, sqlite3_value*, FilteredRowIndex*) const override;
51 
52     Comparator Sort(const QueryConstraints::OrderBy&) const override;
53 
54     Table::ColumnType GetType() const override;
55 
56    private:
57     static constexpr uint16_t kNumStateStrings =
58         ftrace_utils::TaskState::kMaxState + 1;
59     std::array<ftrace_utils::TaskState::TaskStateStr, kNumStateStrings>
60         state_strings_;
61 
62     void FilterOnState(int op,
63                        sqlite3_value* value,
64                        FilteredRowIndex* index) const;
65 
66     const std::deque<ftrace_utils::TaskState>* deque_ = nullptr;
67   };
68 
69   const TraceStorage* const storage_;
70 };
71 
72 }  // namespace trace_processor
73 }  // namespace perfetto
74 
75 #endif  // SRC_TRACE_PROCESSOR_SCHED_SLICE_TABLE_H_
76