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 "hidump_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t { ID = 0, TS, FPS };
HidumpTable(const TraceDataCache * dataCache)21 HidumpTable::HidumpTable(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("fps", "INTEGER"));
26 tablePriKey_.push_back("ts");
27 }
28
~HidumpTable()29 HidumpTable::~HidumpTable() {}
CreateCursor()30 std::unique_ptr<TableBase::Cursor> HidumpTable::CreateCursor()
31 {
32 return std::make_unique<Cursor>(dataCache_, this);
33 }
34
Cursor(const TraceDataCache * dataCache,TableBase * table)35 HidumpTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
36 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstHidumpData().Size())),
37 hidumpObj_(dataCache->GetConstHidumpData())
38 {
39 }
40
~Cursor()41 HidumpTable::Cursor::~Cursor() {}
42
Column(int32_t hidumpColumn) const43 int32_t HidumpTable::Cursor::Column(int32_t hidumpColumn) const
44 {
45 switch (static_cast<Index>(hidumpColumn)) {
46 case Index::ID:
47 sqlite3_result_int64(context_, static_cast<int32_t>(CurrentRow()));
48 break;
49 case Index::TS:
50 sqlite3_result_int64(context_, static_cast<int64_t>(hidumpObj_.TimeStampData()[CurrentRow()]));
51 break;
52 case Index::FPS: {
53 sqlite3_result_int64(context_, static_cast<int64_t>(hidumpObj_.Fpss()[CurrentRow()]));
54 break;
55 }
56 default:
57 TS_LOGF("Unregistered hidumpColumn : %d", hidumpColumn);
58 break;
59 }
60 return SQLITE_OK;
61 }
62 } // namespace TraceStreamer
63 } // namespace SysTuning
64