1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
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 "system_call_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 namespace {
21 enum Index { SYSCALL_NUM = 0, TYPE, IPID, TS, RET };
22 }
SystemCallTable(const TraceDataCache * dataCache)23 SystemCallTable::SystemCallTable(const TraceDataCache* dataCache) : TableBase(dataCache)
24 {
25 tableColumn_.push_back(TableBase::ColumnInfo("syscall_num", "INTEGER"));
26 tableColumn_.push_back(TableBase::ColumnInfo("type", "TEXT"));
27 tableColumn_.push_back(TableBase::ColumnInfo("ipid", "INTEGER"));
28 tableColumn_.push_back(TableBase::ColumnInfo("ts", "INTEGER"));
29 tableColumn_.push_back(TableBase::ColumnInfo("ret", "INTEGER"));
30 tablePriKey_.push_back("syscall_num");
31 }
32
~SystemCallTable()33 SystemCallTable::~SystemCallTable() {}
34
CreateCursor()35 std::unique_ptr<TableBase::Cursor> SystemCallTable::CreateCursor()
36 {
37 return std::make_unique<Cursor>(dataCache_, this);
38 }
39
Cursor(const TraceDataCache * dataCache,TableBase * table)40 SystemCallTable::Cursor::Cursor(const TraceDataCache* dataCache, TableBase* table)
41 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstSysCallData().Size())),
42 sysCallObj_(dataCache->GetConstSysCallData())
43 {
44 }
45
~Cursor()46 SystemCallTable::Cursor::~Cursor() {}
47
Column(int column) const48 int SystemCallTable::Cursor::Column(int column) const
49 {
50 switch (column) {
51 case SYSCALL_NUM:
52 sqlite3_result_int64(context_, dataCache_->GetConstSysCallData().SysCallsData()[CurrentRow()]);
53 break;
54 case TYPE:
55 sqlite3_result_text(context_, dataCache_->GetDataFromDict(sysCallObj_.TypesData()[CurrentRow()]).c_str(),
56 STR_DEFAULT_LEN, nullptr);
57 break;
58 case IPID:
59 sqlite3_result_int64(context_, dataCache_->GetConstSysCallData().IpidsData()[CurrentRow()]);
60 break;
61 case TS:
62 sqlite3_result_int64(context_, dataCache_->GetConstSysCallData().TimeStamData()[CurrentRow()]);
63 break;
64 case RET:
65 sqlite3_result_int64(context_, dataCache_->GetConstSysCallData().RetsData()[CurrentRow()]);
66 break;
67 default:
68 TS_LOGF("Unregistered column : %d", column);
69 break;
70 }
71 return SQLITE_OK;
72 }
73 } // namespace TraceStreamer
74 } // namespace SysTuning
75