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