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 "gpu_counter_object_table.h"
17 #include <cmath>
18
19 namespace SysTuning {
20 namespace TraceStreamer {
21 enum class Index : int32_t { COUNTER_ID = 0, COUNTER_NAME = 1 };
GpuCounterObjectTable(const TraceDataCache * dataCache)22 GpuCounterObjectTable::GpuCounterObjectTable(const TraceDataCache *dataCache) : DemoTableBase(dataCache)
23 {
24 demoTableColumn_.push_back(DemoTableBase::ColumnInfo("counter_id", "INTEGER"));
25 demoTableColumn_.push_back(DemoTableBase::ColumnInfo("counter_name", "REAL"));
26 demoTablePriKey_.push_back("counter_id");
27 }
28
~GpuCounterObjectTable()29 GpuCounterObjectTable::~GpuCounterObjectTable() {}
30
CreateCursor()31 std::unique_ptr<DemoTableBase::Cursor> GpuCounterObjectTable::CreateCursor()
32 {
33 return std::make_unique<Cursor>(demoTraceDataCache_, this);
34 }
35
Cursor(const TraceDataCache * dataCache,DemoTableBase * table)36 GpuCounterObjectTable::Cursor::Cursor(const TraceDataCache *dataCache, DemoTableBase *table)
37 : DemoTableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstGpuCounterObjectData().Size())),
38 gpuCounterObjectDataObj_(dataCache->GetConstGpuCounterObjectData())
39 {
40 }
41
~Cursor()42 GpuCounterObjectTable::Cursor::~Cursor() {}
43
Column(int32_t gpuCntObjColumn) const44 int32_t GpuCounterObjectTable::Cursor::Column(int32_t gpuCntObjColumn) const
45 {
46 switch (static_cast<Index>(gpuCntObjColumn)) {
47 case Index::COUNTER_ID: {
48 sqlite3_result_int64(demoContext_,
49 static_cast<int64_t>(gpuCounterObjectDataObj_.CounterId()[CurrentRow()]));
50 break;
51 }
52 case Index::COUNTER_NAME: {
53 sqlite3_result_text(demoContext_, gpuCounterObjectDataObj_.CounterName()[CurrentRow()].c_str(),
54 STR_DEFAULT_LEN, nullptr);
55 break;
56 }
57 default:
58 TS_LOGF("Unregistered gpuCntObjColumn : %d", gpuCntObjColumn);
59 break;
60 }
61 return SQLITE_OK;
62 }
63 } // namespace TraceStreamer
64 } // namespace SysTuning
65