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