• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "sysevent_measure_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t { ID = 0, SERIAL, TS, NAME_ID, KEY_ID, TYPE, INT_VALUE, STRING_VALUE };
SysEventMeasureTable(const TraceDataCache * dataCache)21 SysEventMeasureTable::SysEventMeasureTable(const TraceDataCache *dataCache) : TableBase(dataCache)
22 {
23     tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
24     tableColumn_.push_back(TableBase::ColumnInfo("serial", "INTEGER"));
25     tableColumn_.push_back(TableBase::ColumnInfo("ts", "INTEGER"));
26     tableColumn_.push_back(TableBase::ColumnInfo("name_id", "INTEGER"));
27     tableColumn_.push_back(TableBase::ColumnInfo("key_id", "INTEGER"));
28     tableColumn_.push_back(TableBase::ColumnInfo("type", "INTEGER"));
29     tableColumn_.push_back(TableBase::ColumnInfo("int_value", "REAL"));
30     tableColumn_.push_back(TableBase::ColumnInfo("string_value", "TEXT"));
31     tablePriKey_.push_back("id");
32 }
33 
~SysEventMeasureTable()34 SysEventMeasureTable::~SysEventMeasureTable() {}
35 
CreateCursor()36 std::unique_ptr<TableBase::Cursor> SysEventMeasureTable::CreateCursor()
37 {
38     return std::make_unique<Cursor>(dataCache_, this);
39 }
40 
Cursor(const TraceDataCache * dataCache,TableBase * table)41 SysEventMeasureTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
42     : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstHiSyseventMeasureData().Size())),
43       sysEventMeasure_(dataCache->GetConstHiSyseventMeasureData())
44 {
45 }
46 
~Cursor()47 SysEventMeasureTable::Cursor::~Cursor() {}
48 
Column(int32_t sysEntMeasureCol) const49 int32_t SysEventMeasureTable::Cursor::Column(int32_t sysEntMeasureCol) const
50 {
51     switch (static_cast<Index>(sysEntMeasureCol)) {
52         case Index::ID:
53             sqlite3_result_int64(context_, dataCache_->GetConstHiSyseventMeasureData().IdsData()[CurrentRow()]);
54             break;
55         case Index::SERIAL:
56             sqlite3_result_int64(context_, dataCache_->GetConstHiSyseventMeasureData().Serial()[CurrentRow()]);
57             break;
58         case Index::TS:
59             sqlite3_result_int64(context_, dataCache_->GetConstHiSyseventMeasureData().Ts()[CurrentRow()]);
60             break;
61         case Index::NAME_ID:
62             sqlite3_result_int(context_, dataCache_->GetConstHiSyseventMeasureData().NameFilterId()[CurrentRow()]);
63             break;
64         case Index::KEY_ID:
65             sqlite3_result_int(context_, dataCache_->GetConstHiSyseventMeasureData().AppKeyFilterId()[CurrentRow()]);
66             break;
67         case Index::TYPE:
68             sqlite3_result_int(context_, dataCache_->GetConstHiSyseventMeasureData().Type()[CurrentRow()]);
69             break;
70         case Index::INT_VALUE:
71             sqlite3_result_double(context_, dataCache_->GetConstHiSyseventMeasureData().NumValue()[CurrentRow()]);
72             break;
73         case Index::STRING_VALUE:
74             sqlite3_result_text(context_,
75                                 dataCache_->GetDataFromDict(sysEventMeasure_.StringValue()[CurrentRow()]).c_str(),
76                                 STR_DEFAULT_LEN, nullptr);
77             break;
78         default:
79             TS_LOGF("Unregistered sysEntMeasureCol : %d", sysEntMeasureCol);
80             break;
81     }
82     return SQLITE_OK;
83 }
84 } // namespace TraceStreamer
85 } // namespace SysTuning
86