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 "clk_event_filter_table.h"
17
18 #include <cmath>
19
20 namespace SysTuning {
21 namespace TraceStreamer {
22 enum class Index : int32_t { ID = 0, TYPE, NAME, CPU };
ClkEventFilterTable(const TraceDataCache * dataCache)23 ClkEventFilterTable::ClkEventFilterTable(const TraceDataCache *dataCache) : TableBase(dataCache)
24 {
25 tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
26 tableColumn_.push_back(TableBase::ColumnInfo("type", "TEXT"));
27 tableColumn_.push_back(TableBase::ColumnInfo("name", "TEXT"));
28 tableColumn_.push_back(TableBase::ColumnInfo("cpu", "INTEGER"));
29 tablePriKey_.push_back("id");
30 }
31
~ClkEventFilterTable()32 ClkEventFilterTable::~ClkEventFilterTable() {}
33
CreateCursor()34 std::unique_ptr<TableBase::Cursor> ClkEventFilterTable::CreateCursor()
35 {
36 return std::make_unique<Cursor>(dataCache_, this);
37 }
38
Cursor(const TraceDataCache * dataCache,TableBase * table)39 ClkEventFilterTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
40 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstClkEventFilterData().Size()))
41 {
42 }
43
~Cursor()44 ClkEventFilterTable::Cursor::~Cursor() {}
45
Column(int32_t col) const46 int32_t ClkEventFilterTable::Cursor::Column(int32_t col) const
47 {
48 switch (static_cast<Index>(col)) {
49 case Index::ID:
50 sqlite3_result_int64(
51 context_, static_cast<sqlite3_int64>(dataCache_->GetConstClkEventFilterData().IdsData()[CurrentRow()]));
52 break;
53 case Index::TYPE: {
54 size_t typeId = static_cast<size_t>(dataCache_->GetConstClkEventFilterData().RatesData()[CurrentRow()]);
55 sqlite3_result_text(context_, dataCache_->GetDataFromDict(typeId).c_str(), STR_DEFAULT_LEN, nullptr);
56 break;
57 }
58 case Index::NAME: {
59 size_t strId = static_cast<size_t>(dataCache_->GetConstClkEventFilterData().NamesData()[CurrentRow()]);
60 sqlite3_result_text(context_, dataCache_->GetDataFromDict(strId).c_str(), STR_DEFAULT_LEN, nullptr);
61 break;
62 }
63 case Index::CPU:
64 sqlite3_result_int64(context_, static_cast<sqlite3_int64>(
65 dataCache_->GetConstClkEventFilterData().CpusData()[CurrentRow()]));
66 break;
67 default:
68 TS_LOGF("Unregistered column : %d", col);
69 break;
70 }
71 return SQLITE_OK;
72 }
73 } // namespace TraceStreamer
74 } // namespace SysTuning
75