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