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 "gpu_counter_table.h"
17 #include <cmath>
18
19 namespace SysTuning {
20 namespace TraceStreamer {
21 namespace {
22 enum Index { TS = 0, COUNTER_ID = 1, VALUE = 2 };
23 }
GpuCounterTable(const TraceDataCache * dataCache)24 GpuCounterTable::GpuCounterTable(const TraceDataCache* dataCache) : TableBase(dataCache)
25 {
26 tableColumn_.push_back(TableBase::ColumnInfo("ts", "INTEGER"));
27 tableColumn_.push_back(TableBase::ColumnInfo("counter_id", "INTEGER"));
28 tableColumn_.push_back(TableBase::ColumnInfo("value", "REAL"));
29 tablePriKey_.push_back("ts");
30 tablePriKey_.push_back("counter_id");
31 }
32
~GpuCounterTable()33 GpuCounterTable::~GpuCounterTable() {}
34
CreateCursor()35 std::unique_ptr<TableBase::Cursor> GpuCounterTable::CreateCursor()
36 {
37 return std::make_unique<Cursor>(dataCache_, this);
38 }
39
Cursor(const TraceDataCache * dataCache,TableBase * table)40 GpuCounterTable::Cursor::Cursor(const TraceDataCache* dataCache, TableBase* table)
41 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstGpuCounterData().Size())),
42 gpuCounterDataObj_(dataCache->GetConstGpuCounterData())
43 {
44 }
45
~Cursor()46 GpuCounterTable::Cursor::~Cursor() {}
47
Column(int32_t column) const48 int32_t GpuCounterTable::Cursor::Column(int32_t column) const
49 {
50 switch (column) {
51 case TS: {
52 sqlite3_result_int64(context_, static_cast<int64_t>(gpuCounterDataObj_.TimeStamp()[CurrentRow()]));
53 break;
54 }
55 case COUNTER_ID: {
56 sqlite3_result_int64(context_, static_cast<int64_t>(gpuCounterDataObj_.CounterId()[CurrentRow()]));
57 break;
58 }
59 case VALUE: {
60 sqlite3_result_int64(context_, static_cast<int64_t>(gpuCounterDataObj_.Value()[CurrentRow()]));
61 break;
62 }
63 default:
64 TS_LOGF("Unregistered column : %d", column);
65 break;
66 }
67 return SQLITE_OK;
68 }
69 } // namespace TraceStreamer
70 } // namespace SysTuning
71