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 "paged_memory_sample_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t { ID = 0, CALLCHAIN_ID, TYPE, IPID, START_TS, END_TS, DUR, SIZE, ADDR, ITID };
PagedMemorySampleTable(const TraceDataCache * dataCache)21 PagedMemorySampleTable::PagedMemorySampleTable(const TraceDataCache *dataCache) : TableBase(dataCache)
22 {
23 tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
24 tableColumn_.push_back(TableBase::ColumnInfo("callchain_id", "INTEGER"));
25 tableColumn_.push_back(TableBase::ColumnInfo("type", "INTEGER"));
26 tableColumn_.push_back(TableBase::ColumnInfo("ipid", "INTEGER"));
27 tableColumn_.push_back(TableBase::ColumnInfo("start_ts", "INTEGER"));
28 tableColumn_.push_back(TableBase::ColumnInfo("end_ts", "INTEGER"));
29 tableColumn_.push_back(TableBase::ColumnInfo("dur", "INTEGER"));
30 tableColumn_.push_back(TableBase::ColumnInfo("size", "INTEGER"));
31 tableColumn_.push_back(TableBase::ColumnInfo("addr", "TEXT"));
32 tableColumn_.push_back(TableBase::ColumnInfo("itid", "INTEGER"));
33 tablePriKey_.push_back("id");
34 }
35
~PagedMemorySampleTable()36 PagedMemorySampleTable::~PagedMemorySampleTable() {}
37
CreateCursor()38 std::unique_ptr<TableBase::Cursor> PagedMemorySampleTable::CreateCursor()
39 {
40 return std::make_unique<Cursor>(dataCache_, this);
41 }
42
Cursor(const TraceDataCache * dataCache,TableBase * table)43 PagedMemorySampleTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
44 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstPagedMemorySampleData().Size())),
45 PagedMemorySampleDataObj_(dataCache->GetConstPagedMemorySampleData())
46 {
47 }
48
~Cursor()49 PagedMemorySampleTable::Cursor::~Cursor() {}
Column(int32_t pagedMemorySampleColumn) const50 int32_t PagedMemorySampleTable::Cursor::Column(int32_t pagedMemorySampleColumn) const
51 {
52 switch (static_cast<Index>(pagedMemorySampleColumn)) {
53 case Index::ID:
54 sqlite3_result_int64(context_, static_cast<int32_t>(PagedMemorySampleDataObj_.IdsData()[CurrentRow()]));
55 break;
56 case Index::CALLCHAIN_ID:
57 SetTypeColumn(PagedMemorySampleDataObj_.CallChainIds()[CurrentRow()], INVALID_UINT32,
58 INVALID_CALL_CHAIN_ID);
59 break;
60 case Index::TYPE:
61 sqlite3_result_int64(context_, static_cast<int64_t>(PagedMemorySampleDataObj_.Types()[CurrentRow()]));
62 break;
63 case Index::IPID:
64 sqlite3_result_int64(context_, static_cast<int64_t>(PagedMemorySampleDataObj_.Ipids()[CurrentRow()]));
65 break;
66 case Index::ITID:
67 sqlite3_result_int64(context_, static_cast<int64_t>(PagedMemorySampleDataObj_.Itids()[CurrentRow()]));
68 break;
69 case Index::START_TS:
70 sqlite3_result_int64(context_, static_cast<int64_t>(PagedMemorySampleDataObj_.StartTs()[CurrentRow()]));
71 break;
72 case Index::END_TS:
73 sqlite3_result_int64(context_, static_cast<int64_t>(PagedMemorySampleDataObj_.EndTs()[CurrentRow()]));
74 break;
75 case Index::DUR:
76 sqlite3_result_int64(context_, static_cast<int64_t>(PagedMemorySampleDataObj_.Durs()[CurrentRow()]));
77 break;
78 case Index::SIZE: {
79 SetTypeColumnInt64(PagedMemorySampleDataObj_.Sizes()[CurrentRow()], MAX_SIZE_T);
80 break;
81 }
82 case Index::ADDR: {
83 SetTypeColumnText(PagedMemorySampleDataObj_.Addr()[CurrentRow()], INVALID_UINT64);
84 break;
85 }
86 default:
87 TS_LOGF("Unregistered pagedMemorySampleColumn : %d", pagedMemorySampleColumn);
88 break;
89 }
90 return SQLITE_OK;
91 }
92 } // namespace TraceStreamer
93 } // namespace SysTuning
94