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 "smaps_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum Index { ID = 0, TIME_STAMP, START_ADDRESS, END_ADDRESS, DIRTY, SWAPPER, RSS, PSS, SIZE, RESIDE, PROTECTION, PATH };
SmapsTable(const TraceDataCache * dataCache)21 SmapsTable::SmapsTable(const TraceDataCache* dataCache) : TableBase(dataCache)
22 {
23 tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
24 tableColumn_.push_back(TableBase::ColumnInfo("timeStamp", "INTEGER"));
25 tableColumn_.push_back(TableBase::ColumnInfo("start_addr", "TEXT"));
26 tableColumn_.push_back(TableBase::ColumnInfo("end_addr", "TEXT"));
27 tableColumn_.push_back(TableBase::ColumnInfo("dirty", "INTEGER"));
28 tableColumn_.push_back(TableBase::ColumnInfo("swapper", "INTEGER"));
29 tableColumn_.push_back(TableBase::ColumnInfo("resident_size", "INTEGER"));
30 tableColumn_.push_back(TableBase::ColumnInfo("pss", "INTEGER"));
31 tableColumn_.push_back(TableBase::ColumnInfo("virtaul_size", "INTEGER"));
32 tableColumn_.push_back(TableBase::ColumnInfo("reside", "REAL"));
33 tableColumn_.push_back(TableBase::ColumnInfo("protection_id", "INTEGER"));
34 tableColumn_.push_back(TableBase::ColumnInfo("path_id", "INTEGER"));
35 tablePriKey_.push_back("id");
36 }
37
~SmapsTable()38 SmapsTable::~SmapsTable() {}
39
CreateCursor()40 std::unique_ptr<TableBase::Cursor> SmapsTable::CreateCursor()
41 {
42 return std::make_unique<Cursor>(dataCache_, this);
43 }
44
Cursor(const TraceDataCache * dataCache,TableBase * table)45 SmapsTable::Cursor::Cursor(const TraceDataCache* dataCache, TableBase* table)
46 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstSmapsData().Size())),
47 smapsObj_(dataCache->GetConstSmapsData())
48 {
49 }
50
~Cursor()51 SmapsTable::Cursor::~Cursor() {}
52
Column(int32_t col) const53 int32_t SmapsTable::Cursor::Column(int32_t col) const
54 {
55 switch (col) {
56 case ID:
57 sqlite3_result_int64(context_, smapsObj_.IdsData()[CurrentRow()]);
58 break;
59 case TIME_STAMP:
60 sqlite3_result_int64(context_, smapsObj_.TimeStamps()[CurrentRow()]);
61 break;
62 case START_ADDRESS:
63 sqlite3_result_text(context_, smapsObj_.StartAddrs()[CurrentRow()].c_str(), STR_DEFAULT_LEN, nullptr);
64 break;
65 case END_ADDRESS:
66 sqlite3_result_text(context_, smapsObj_.EndAddrs()[CurrentRow()].c_str(), STR_DEFAULT_LEN, nullptr);
67 break;
68 case DIRTY:
69 sqlite3_result_int64(context_, smapsObj_.Dirtys()[CurrentRow()]);
70 break;
71 case SWAPPER:
72 sqlite3_result_int64(context_, smapsObj_.Swappers()[CurrentRow()]);
73 break;
74 case RSS:
75 sqlite3_result_int64(context_, smapsObj_.Rss()[CurrentRow()]);
76 break;
77 case PSS:
78 sqlite3_result_int64(context_, smapsObj_.Pss()[CurrentRow()]);
79 break;
80 case SIZE:
81 sqlite3_result_int64(context_, smapsObj_.Sizes()[CurrentRow()]);
82 break;
83 case RESIDE:
84 sqlite3_result_double(context_, smapsObj_.Resides()[CurrentRow()]);
85 break;
86 case PROTECTION:
87 sqlite3_result_int64(context_, smapsObj_.ProtectionIds()[CurrentRow()]);
88 break;
89 case PATH:
90 sqlite3_result_int64(context_, smapsObj_.PathIds()[CurrentRow()]);
91 break;
92 default:
93 TS_LOGF("Unregistered column : %d", col);
94 break;
95 }
96 return SQLITE_OK;
97 }
98
99 } // namespace TraceStreamer
100 } // namespace SysTuning
101