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_window_gpu_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t {
21 ID = 0,
22 TS,
23 WINDOW_NAME_ID,
24 WINDOW_ID,
25 MODULE_NAME_ID,
26 CATEGORY_NAME_ID,
27 SIZE,
28 COUNT,
29 PURGEABLE_SIZE,
30 IPID
31 };
MemoryWindowGpuTable(const TraceDataCache * dataCache)32 MemoryWindowGpuTable::MemoryWindowGpuTable(const TraceDataCache *dataCache) : TableBase(dataCache)
33 {
34 tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
35 tableColumn_.push_back(TableBase::ColumnInfo("ts", "INTEGER"));
36 tableColumn_.push_back(TableBase::ColumnInfo("window_name_id", "INTEGER"));
37 tableColumn_.push_back(TableBase::ColumnInfo("window_id", "INTEGER"));
38 tableColumn_.push_back(TableBase::ColumnInfo("module_name_id", "INTEGER"));
39 tableColumn_.push_back(TableBase::ColumnInfo("category_name_id", "INTEGER"));
40 tableColumn_.push_back(TableBase::ColumnInfo("size", "INTEGER"));
41 tableColumn_.push_back(TableBase::ColumnInfo("count", "INTEGER"));
42 tableColumn_.push_back(TableBase::ColumnInfo("purgeable_size", "INTEGER"));
43 tableColumn_.push_back(TableBase::ColumnInfo("ipid", "INTEGER"));
44 tablePriKey_.push_back("id");
45 }
46
~MemoryWindowGpuTable()47 MemoryWindowGpuTable::~MemoryWindowGpuTable() {}
48
CreateCursor()49 std::unique_ptr<TableBase::Cursor> MemoryWindowGpuTable::CreateCursor()
50 {
51 return std::make_unique<Cursor>(dataCache_, this);
52 }
53
Cursor(const TraceDataCache * dataCache,TableBase * table)54 MemoryWindowGpuTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
55 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstGpuWindowMemData().Size())),
56 GpuWindowMemDataObj_(dataCache->GetConstGpuWindowMemData())
57 {
58 }
59
~Cursor()60 MemoryWindowGpuTable::Cursor::~Cursor() {}
61
Column(int32_t memWinGpuColumn) const62 int32_t MemoryWindowGpuTable::Cursor::Column(int32_t memWinGpuColumn) const
63 {
64 switch (static_cast<Index>(memWinGpuColumn)) {
65 case Index::ID:
66 sqlite3_result_int64(context_, GpuWindowMemDataObj_.IdsData()[CurrentRow()]);
67 break;
68 case Index::TS:
69 sqlite3_result_int64(context_, GpuWindowMemDataObj_.TimeStampData()[CurrentRow()]);
70 break;
71 case Index::WINDOW_NAME_ID:
72 sqlite3_result_int64(context_, GpuWindowMemDataObj_.WindowNameIds()[CurrentRow()]);
73 break;
74 case Index::WINDOW_ID:
75 sqlite3_result_int64(context_, GpuWindowMemDataObj_.WindowIds()[CurrentRow()]);
76 break;
77 case Index::MODULE_NAME_ID:
78 sqlite3_result_int64(context_, GpuWindowMemDataObj_.ModuleNameIds()[CurrentRow()]);
79 break;
80 case Index::CATEGORY_NAME_ID:
81 sqlite3_result_int64(context_, GpuWindowMemDataObj_.CategoryNameIds()[CurrentRow()]);
82 break;
83 case Index::SIZE:
84 sqlite3_result_int64(context_, GpuWindowMemDataObj_.Sizes()[CurrentRow()]);
85 break;
86 case Index::COUNT:
87 sqlite3_result_int(context_, GpuWindowMemDataObj_.Counts()[CurrentRow()]);
88 break;
89 case Index::PURGEABLE_SIZE:
90 sqlite3_result_int64(context_, GpuWindowMemDataObj_.PurgeableSizes()[CurrentRow()]);
91 break;
92 case Index::IPID:
93 if (GpuWindowMemDataObj_.Ipids()[CurrentRow()] != INVALID_IPID) {
94 sqlite3_result_int64(context_, GpuWindowMemDataObj_.Ipids()[CurrentRow()]);
95 }
96 break;
97 default:
98 TS_LOGF("Unregistered memWinGpuColumn : %d", memWinGpuColumn);
99 break;
100 }
101 return SQLITE_OK;
102 }
103 } // namespace TraceStreamer
104 } // namespace SysTuning
105