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 "memory_ashmem_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t {
21 ID = 0,
22 TS,
23 IPID,
24 ADJ,
25 FD,
26 ASHMEM_NAME_ID,
27 SIZE,
28 PSS,
29 ASHMEM_ID,
30 TIME,
31 REF_COUNT,
32 PURGED,
33 FLAG,
34 };
MemoryAshMemTable(const TraceDataCache * dataCache)35 MemoryAshMemTable::MemoryAshMemTable(const TraceDataCache *dataCache) : TableBase(dataCache)
36 {
37 tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
38 tableColumn_.push_back(TableBase::ColumnInfo("ts", "INTEGER"));
39 tableColumn_.push_back(TableBase::ColumnInfo("ipid", "INTEGER"));
40 tableColumn_.push_back(TableBase::ColumnInfo("adj", "INTEGER"));
41 tableColumn_.push_back(TableBase::ColumnInfo("fd", "INTEGER"));
42 tableColumn_.push_back(TableBase::ColumnInfo("ashmem_name_id", "INTEGER"));
43 tableColumn_.push_back(TableBase::ColumnInfo("size", "INTEGER"));
44 tableColumn_.push_back(TableBase::ColumnInfo("pss", "INTEGER"));
45 tableColumn_.push_back(TableBase::ColumnInfo("ashmem_id", "INTEGER"));
46 tableColumn_.push_back(TableBase::ColumnInfo("time", "INTEGER"));
47 tableColumn_.push_back(TableBase::ColumnInfo("ref_count", "INTEGER"));
48 tableColumn_.push_back(TableBase::ColumnInfo("purged", "INTEGER"));
49 tableColumn_.push_back(TableBase::ColumnInfo("flag", "INTEGER"));
50 tablePriKey_.push_back("id");
51 }
52
~MemoryAshMemTable()53 MemoryAshMemTable::~MemoryAshMemTable() {}
54
CreateCursor()55 std::unique_ptr<TableBase::Cursor> MemoryAshMemTable::CreateCursor()
56 {
57 return std::make_unique<Cursor>(dataCache_, this);
58 }
59
Cursor(const TraceDataCache * dataCache,TableBase * table)60 MemoryAshMemTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
61 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstAshMemData().Size())),
62 AshMemDataObj_(dataCache->GetConstAshMemData())
63 {
64 }
65
~Cursor()66 MemoryAshMemTable::Cursor::~Cursor() {}
67
Column(int32_t column) const68 int32_t MemoryAshMemTable::Cursor::Column(int32_t column) const
69 {
70 switch (static_cast<Index>(column)) {
71 case Index::ID:
72 sqlite3_result_int64(context_, AshMemDataObj_.IdsData()[CurrentRow()]);
73 break;
74 case Index::TS:
75 sqlite3_result_int64(context_, AshMemDataObj_.TimeStampData()[CurrentRow()]);
76 break;
77 case Index::IPID:
78 sqlite3_result_int64(context_, AshMemDataObj_.Ipids()[CurrentRow()]);
79 break;
80 case Index::ADJ:
81 sqlite3_result_int(context_, AshMemDataObj_.Adjs()[CurrentRow()]);
82 break;
83 case Index::FD:
84 sqlite3_result_int(context_, AshMemDataObj_.Fds()[CurrentRow()]);
85 break;
86 case Index::ASHMEM_NAME_ID:
87 sqlite3_result_int(context_, AshMemDataObj_.AshmemNameIds()[CurrentRow()]);
88 break;
89 case Index::SIZE:
90 sqlite3_result_int64(context_, AshMemDataObj_.Sizes()[CurrentRow()]);
91 break;
92 case Index::PSS:
93 sqlite3_result_int64(context_, AshMemDataObj_.Psss()[CurrentRow()]);
94 break;
95 case Index::ASHMEM_ID:
96 sqlite3_result_int64(context_, AshMemDataObj_.AshmemIds()[CurrentRow()]);
97 break;
98 case Index::TIME:
99 sqlite3_result_int64(context_, AshMemDataObj_.Times()[CurrentRow()]);
100 break;
101 case Index::REF_COUNT:
102 sqlite3_result_int64(context_, AshMemDataObj_.RefCounts()[CurrentRow()]);
103 break;
104 case Index::PURGED:
105 sqlite3_result_int64(context_, AshMemDataObj_.Purgeds()[CurrentRow()]);
106 break;
107 case Index::FLAG:
108 sqlite3_result_int(context_, AshMemDataObj_.Flags()[CurrentRow()]);
109 break;
110 default:
111 TS_LOGF("Unregistered column : %d", column);
112 break;
113 }
114 return SQLITE_OK;
115 }
116 } // namespace TraceStreamer
117 } // namespace SysTuning
118