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 {
21 ID = 0,
22 TIME_STAMP,
23 START_ADDRESS,
24 END_ADDRESS,
25 DIRTY,
26 SWAPPER,
27 RSS,
28 PSS,
29 SIZE,
30 RESIDE,
31 PROTECTION,
32 PATH,
33 SHARED_CLEAN,
34 SHARED_DIRTY,
35 PRIVATE_CLEAN,
36 PRIVATE_DIRTY,
37 SWAP,
38 SWAP_PSS,
39 TYPE
40 };
SmapsTable(const TraceDataCache * dataCache)41 SmapsTable::SmapsTable(const TraceDataCache* dataCache) : TableBase(dataCache)
42 {
43 tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
44 tableColumn_.push_back(TableBase::ColumnInfo("timeStamp", "INTEGER"));
45 tableColumn_.push_back(TableBase::ColumnInfo("start_addr", "TEXT"));
46 tableColumn_.push_back(TableBase::ColumnInfo("end_addr", "TEXT"));
47 tableColumn_.push_back(TableBase::ColumnInfo("dirty", "INTEGER"));
48 tableColumn_.push_back(TableBase::ColumnInfo("swapper", "INTEGER"));
49 tableColumn_.push_back(TableBase::ColumnInfo("resident_size", "INTEGER"));
50 tableColumn_.push_back(TableBase::ColumnInfo("pss", "INTEGER"));
51 tableColumn_.push_back(TableBase::ColumnInfo("virtaul_size", "INTEGER"));
52 tableColumn_.push_back(TableBase::ColumnInfo("reside", "REAL"));
53 tableColumn_.push_back(TableBase::ColumnInfo("protection_id", "INTEGER"));
54 tableColumn_.push_back(TableBase::ColumnInfo("path_id", "INTEGER"));
55 tableColumn_.push_back(TableBase::ColumnInfo("shared_clean", "INTEGER"));
56 tableColumn_.push_back(TableBase::ColumnInfo("shared_dirty", "INTEGER"));
57 tableColumn_.push_back(TableBase::ColumnInfo("private_clean", "INTEGER"));
58 tableColumn_.push_back(TableBase::ColumnInfo("private_dirty", "INTEGER"));
59 tableColumn_.push_back(TableBase::ColumnInfo("swap", "INTEGER"));
60 tableColumn_.push_back(TableBase::ColumnInfo("swap_pss", "INTEGER"));
61 tableColumn_.push_back(TableBase::ColumnInfo("type", "INTEGER"));
62 tablePriKey_.push_back("id");
63 }
64
~SmapsTable()65 SmapsTable::~SmapsTable() {}
66
CreateCursor()67 std::unique_ptr<TableBase::Cursor> SmapsTable::CreateCursor()
68 {
69 return std::make_unique<Cursor>(dataCache_, this);
70 }
71
Cursor(const TraceDataCache * dataCache,TableBase * table)72 SmapsTable::Cursor::Cursor(const TraceDataCache* dataCache, TableBase* table)
73 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstSmapsData().Size())),
74 smapsObj_(dataCache->GetConstSmapsData())
75 {
76 }
77
~Cursor()78 SmapsTable::Cursor::~Cursor() {}
79
Column(int32_t col) const80 int32_t SmapsTable::Cursor::Column(int32_t col) const
81 {
82 switch (col) {
83 case ID:
84 sqlite3_result_int64(context_, smapsObj_.IdsData()[CurrentRow()]);
85 break;
86 case TIME_STAMP:
87 sqlite3_result_int64(context_, smapsObj_.TimeStamps()[CurrentRow()]);
88 break;
89 case START_ADDRESS:
90 sqlite3_result_text(context_, smapsObj_.StartAddrs()[CurrentRow()].c_str(), STR_DEFAULT_LEN, nullptr);
91 break;
92 case END_ADDRESS:
93 sqlite3_result_text(context_, smapsObj_.EndAddrs()[CurrentRow()].c_str(), STR_DEFAULT_LEN, nullptr);
94 break;
95 case DIRTY:
96 sqlite3_result_int64(context_, smapsObj_.Dirtys()[CurrentRow()]);
97 break;
98 case SWAPPER:
99 sqlite3_result_int64(context_, smapsObj_.Swappers()[CurrentRow()]);
100 break;
101 case RSS:
102 sqlite3_result_int64(context_, smapsObj_.Rss()[CurrentRow()]);
103 break;
104 case PSS:
105 sqlite3_result_int64(context_, smapsObj_.Pss()[CurrentRow()]);
106 break;
107 case SIZE:
108 sqlite3_result_int64(context_, smapsObj_.Sizes()[CurrentRow()]);
109 break;
110 case RESIDE:
111 sqlite3_result_double(context_, smapsObj_.Resides()[CurrentRow()]);
112 break;
113 case PROTECTION:
114 sqlite3_result_int64(context_, smapsObj_.ProtectionIds()[CurrentRow()]);
115 break;
116 case PATH:
117 sqlite3_result_int64(context_, smapsObj_.PathIds()[CurrentRow()]);
118 break;
119 case SHARED_CLEAN:
120 sqlite3_result_int64(context_, smapsObj_.SharedClean()[CurrentRow()]);
121 break;
122 case SHARED_DIRTY:
123 sqlite3_result_int64(context_, smapsObj_.SharedDirty()[CurrentRow()]);
124 break;
125 case PRIVATE_CLEAN:
126 sqlite3_result_int64(context_, smapsObj_.PrivateClean()[CurrentRow()]);
127 break;
128 case PRIVATE_DIRTY:
129 sqlite3_result_int64(context_, smapsObj_.PrivateDirty()[CurrentRow()]);
130 break;
131 case SWAP:
132 sqlite3_result_int64(context_, smapsObj_.Swap()[CurrentRow()]);
133 break;
134 case SWAP_PSS:
135 sqlite3_result_int64(context_, smapsObj_.SwapPss()[CurrentRow()]);
136 break;
137 case TYPE:
138 sqlite3_result_int64(context_, smapsObj_.Type()[CurrentRow()]);
139 break;
140 default:
141 TS_LOGF("Unregistered column : %d", col);
142 break;
143 }
144 return SQLITE_OK;
145 }
146
147 } // namespace TraceStreamer
148 } // namespace SysTuning
149