• 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 "args_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 namespace {
21 enum Index { ID = 0, KEY, DATATYPE, VALUE, ARGSETID };
22 }
ArgsTable(const TraceDataCache * dataCache)23 ArgsTable::ArgsTable(const TraceDataCache* dataCache) : TableBase(dataCache)
24 {
25     tableColumn_.push_back(TableBase::ColumnInfo("id", "UNSIGNED INT"));
26     tableColumn_.push_back(TableBase::ColumnInfo("key", "UNSIGNED INT"));
27     tableColumn_.push_back(TableBase::ColumnInfo("datatype", "UNSIGNED SHORT"));
28     tableColumn_.push_back(TableBase::ColumnInfo("value", "BIG INT"));
29     tableColumn_.push_back(TableBase::ColumnInfo("argset", "UNSIGNED INT"));
30     tablePriKey_.push_back("id");
31 }
32 
~ArgsTable()33 ArgsTable::~ArgsTable() {}
34 
CreateCursor()35 void ArgsTable::CreateCursor()
36 {
37     cursor_ = std::make_unique<Cursor>(dataCache_);
38 }
39 
Cursor(const TraceDataCache * dataCache)40 ArgsTable::Cursor::Cursor(const TraceDataCache* dataCache)
41     : TableBase::Cursor(dataCache, 0, static_cast<uint32_t>(dataCache->GetConstArgSetData().Size())),
42       argSet_(dataCache->GetConstArgSetData())
43 {
44 }
45 
~Cursor()46 ArgsTable::Cursor::~Cursor() {}
47 
Column(int column) const48 int ArgsTable::Cursor::Column(int column) const
49 {
50     switch (column) {
51         case ID:
52             sqlite3_result_int64(context_, static_cast<int64_t>(argSet_.IdsData()[CurrentRow()]));
53             break;
54         case KEY:
55             sqlite3_result_int64(context_, static_cast<int64_t>(argSet_.NamesData()[CurrentRow()]));
56             break;
57         case DATATYPE:
58             sqlite3_result_int64(context_, static_cast<int64_t>(argSet_.DataTypes()[CurrentRow()]));
59             break;
60         case VALUE:
61             sqlite3_result_int64(context_, static_cast<int64_t>(argSet_.ValuesData()[CurrentRow()]));
62             break;
63         case ARGSETID:
64             sqlite3_result_int64(context_, static_cast<int64_t>(argSet_.ArgsData()[CurrentRow()]));
65             break;
66         default:
67             TS_LOGF("Unregistered column : %d", column);
68             break;
69     }
70     return SQLITE_OK;
71 }
72 } // namespace TraceStreamer
73 } // namespace SysTuning
74