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