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 class Index : int32_t { TS = 0, COUNTER_ID = 1, VALUE = 2 };
GpuCounterTable(const TraceDataCache * dataCache)22 GpuCounterTable::GpuCounterTable(const TraceDataCache* dataCache) : DemoTableBase(dataCache)
23 {
24 demoTableColumn_.push_back(DemoTableBase::ColumnInfo("ts", "INTEGER"));
25 demoTableColumn_.push_back(DemoTableBase::ColumnInfo("counter_id", "INTEGER"));
26 demoTableColumn_.push_back(DemoTableBase::ColumnInfo("value", "REAL"));
27 demoTablePriKey_.push_back("ts");
28 demoTablePriKey_.push_back("counter_id");
29 }
30
~GpuCounterTable()31 GpuCounterTable::~GpuCounterTable() {}
32
CreateCursor()33 std::unique_ptr<DemoTableBase::Cursor> GpuCounterTable::CreateCursor()
34 {
35 return std::make_unique<Cursor>(demoTraceDataCache_, this);
36 }
37
Cursor(const TraceDataCache * dataCache,DemoTableBase * table)38 GpuCounterTable::Cursor::Cursor(const TraceDataCache* dataCache, DemoTableBase* table)
39 : DemoTableBase::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 GpuCntColumn) const46 int32_t GpuCounterTable::Cursor::Column(int32_t GpuCntColumn) const
47 {
48 switch (static_cast<Index>(GpuCntColumn)) {
49 case Index::TS: {
50 sqlite3_result_int64(demoContext_, static_cast<int64_t>(gpuCounterDataObj_.TimeStamp()[CurrentRow()]));
51 break;
52 }
53 case Index::COUNTER_ID: {
54 sqlite3_result_int64(demoContext_, static_cast<int64_t>(gpuCounterDataObj_.CounterId()[CurrentRow()]));
55 break;
56 }
57 case Index::VALUE: {
58 sqlite3_result_int64(demoContext_, static_cast<int64_t>(gpuCounterDataObj_.Value()[CurrentRow()]));
59 break;
60 }
61 default:
62 TS_LOGF("Unregistered GpuCntColumn : %d", GpuCntColumn);
63 break;
64 }
65 return SQLITE_OK;
66 }
67 } // namespace TraceStreamer
68 } // namespace SysTuning
69