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 "so_static_initalization_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t { ID = 0, IPID, TID, CALL_ID, START_TIME, END_TIME, SO_NAME, DEPTH };
SoStaticInitalizationTable(const TraceDataCache * dataCache)21 SoStaticInitalizationTable::SoStaticInitalizationTable(const TraceDataCache *dataCache) : TableBase(dataCache)
22 {
23 tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
24 tableColumn_.push_back(TableBase::ColumnInfo("ipid", "INTEGER"));
25 tableColumn_.push_back(TableBase::ColumnInfo("tid", "INTEGER"));
26 tableColumn_.push_back(TableBase::ColumnInfo("call_id", "INTEGER"));
27 tableColumn_.push_back(TableBase::ColumnInfo("start_time", "INTEGER"));
28 tableColumn_.push_back(TableBase::ColumnInfo("end_time", "INTEGER"));
29 tableColumn_.push_back(TableBase::ColumnInfo("so_name", "TEXT"));
30 tableColumn_.push_back(TableBase::ColumnInfo("depth", "INTEGER"));
31 tablePriKey_.push_back("id");
32 }
33
~SoStaticInitalizationTable()34 SoStaticInitalizationTable::~SoStaticInitalizationTable() {}
35
CreateCursor()36 std::unique_ptr<TableBase::Cursor> SoStaticInitalizationTable::CreateCursor()
37 {
38 return std::make_unique<Cursor>(dataCache_, this);
39 }
40
Cursor(const TraceDataCache * dataCache,TableBase * table)41 SoStaticInitalizationTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
42 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstSoStaticInitalizationData().Size())),
43 staticInitalizationObj_(dataCache->GetConstSoStaticInitalizationData())
44 {
45 }
46
~Cursor()47 SoStaticInitalizationTable::Cursor::~Cursor() {}
48
Column(int32_t column) const49 int32_t SoStaticInitalizationTable::Cursor::Column(int32_t column) const
50 {
51 switch (static_cast<Index>(column)) {
52 case Index::ID:
53 sqlite3_result_int64(context_, static_cast<int32_t>(CurrentRow()));
54 break;
55 case Index::IPID:
56 sqlite3_result_int64(context_, static_cast<int64_t>(staticInitalizationObj_.Pids()[CurrentRow()]));
57 break;
58 case Index::TID:
59 sqlite3_result_int64(context_, static_cast<int64_t>(staticInitalizationObj_.Tids()[CurrentRow()]));
60 break;
61 case Index::CALL_ID:
62 sqlite3_result_int64(context_, static_cast<int64_t>(staticInitalizationObj_.CallIds()[CurrentRow()]));
63 break;
64 case Index::START_TIME:
65 sqlite3_result_int64(context_, static_cast<int64_t>(staticInitalizationObj_.StartTimes()[CurrentRow()]));
66 break;
67 case Index::END_TIME:
68 sqlite3_result_int64(context_, static_cast<int64_t>(staticInitalizationObj_.EndTimes()[CurrentRow()]));
69 break;
70 case Index::SO_NAME:
71 sqlite3_result_text(context_,
72 dataCache_->GetDataFromDict(staticInitalizationObj_.SoNames()[CurrentRow()]).c_str(),
73 STR_DEFAULT_LEN, nullptr);
74 break;
75 case Index::DEPTH:
76 sqlite3_result_int64(context_, static_cast<int64_t>(staticInitalizationObj_.Depths()[CurrentRow()]));
77 break;
78 default:
79 TS_LOGF("Unregistered column : %d", column);
80 break;
81 }
82 return SQLITE_OK;
83 }
84 } // namespace TraceStreamer
85 } // namespace SysTuning
86