• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "memory_dma_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t {
21     ID = 0,
22     TS,
23     IPID,
24     FD,
25     SIZE,
26     INO,
27     EXP_PID,
28     EXP_TASK_COMM,
29     BUF_NAME_ID,
30     EXP_NAME_ID,
31     FLAG,
32 };
MemoryDmaTable(const TraceDataCache * dataCache)33 MemoryDmaTable::MemoryDmaTable(const TraceDataCache *dataCache) : TableBase(dataCache)
34 {
35     tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
36     tableColumn_.push_back(TableBase::ColumnInfo("ts", "INTEGER"));
37     tableColumn_.push_back(TableBase::ColumnInfo("ipid", "INTEGER"));
38     tableColumn_.push_back(TableBase::ColumnInfo("fd", "INTEGER"));
39     tableColumn_.push_back(TableBase::ColumnInfo("size", "INTEGER"));
40     tableColumn_.push_back(TableBase::ColumnInfo("ino", "INTEGER"));
41     tableColumn_.push_back(TableBase::ColumnInfo("exp_pid", "INTEGER"));
42     tableColumn_.push_back(TableBase::ColumnInfo("exp_task_comm_id", "INTEGER"));
43     tableColumn_.push_back(TableBase::ColumnInfo("buf_name_id", "INTEGER"));
44     tableColumn_.push_back(TableBase::ColumnInfo("exp_name_id", "INTEGER"));
45     tableColumn_.push_back(TableBase::ColumnInfo("flag", "INTEGER"));
46     tablePriKey_.push_back("id");
47 }
48 
~MemoryDmaTable()49 MemoryDmaTable::~MemoryDmaTable() {}
50 
CreateCursor()51 std::unique_ptr<TableBase::Cursor> MemoryDmaTable::CreateCursor()
52 {
53     return std::make_unique<Cursor>(dataCache_, this);
54 }
55 
Cursor(const TraceDataCache * dataCache,TableBase * table)56 MemoryDmaTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
57     : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstDmaMemData().Size())),
58       DmaMemDataObj_(dataCache->GetConstDmaMemData())
59 {
60 }
61 
~Cursor()62 MemoryDmaTable::Cursor::~Cursor() {}
63 
Column(int32_t column) const64 int32_t MemoryDmaTable::Cursor::Column(int32_t column) const
65 {
66     switch (static_cast<Index>(column)) {
67         case Index::ID:
68             sqlite3_result_int64(context_, DmaMemDataObj_.IdsData()[CurrentRow()]);
69             break;
70         case Index::TS:
71             sqlite3_result_int64(context_, DmaMemDataObj_.TimeStampData()[CurrentRow()]);
72             break;
73         case Index::IPID:
74             sqlite3_result_int64(context_, DmaMemDataObj_.Ipids()[CurrentRow()]);
75             break;
76         case Index::FD:
77             sqlite3_result_int(context_, DmaMemDataObj_.Fds()[CurrentRow()]);
78             break;
79         case Index::SIZE:
80             sqlite3_result_int64(context_, DmaMemDataObj_.Sizes()[CurrentRow()]);
81             break;
82         case Index::INO:
83             sqlite3_result_int(context_, DmaMemDataObj_.Inos()[CurrentRow()]);
84             break;
85         case Index::EXP_PID:
86             sqlite3_result_int(context_, DmaMemDataObj_.ExpPids()[CurrentRow()]);
87             break;
88         case Index::EXP_TASK_COMM:
89             sqlite3_result_int64(context_, DmaMemDataObj_.ExpTaskCommIds()[CurrentRow()]);
90             break;
91         case Index::BUF_NAME_ID:
92             sqlite3_result_int64(context_, DmaMemDataObj_.BufNameIds()[CurrentRow()]);
93             break;
94         case Index::EXP_NAME_ID:
95             sqlite3_result_int64(context_, DmaMemDataObj_.ExpNameIds()[CurrentRow()]);
96             break;
97         case Index::FLAG:
98             sqlite3_result_int(context_, DmaMemDataObj_.Flags()[CurrentRow()]);
99             break;
100         default:
101             TS_LOGF("Unregistered column : %d", column);
102             break;
103     }
104     return SQLITE_OK;
105 }
106 } // namespace TraceStreamer
107 } // namespace SysTuning
108