• 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 "network_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t {
21     TS = 0,
22     DUR,
23     TX,
24     RX,
25     TX_SPEED,
26     RX_SPEED,
27     PACKET_IN,
28     PACKET_IN_SEC,
29     PACKET_OUT,
30     PACKET_OUT_SEC,
31     NET_TYPE,
32 };
NetworkTable(const TraceDataCache * dataCache)33 NetworkTable::NetworkTable(const TraceDataCache *dataCache) : TableBase(dataCache)
34 {
35     tableColumn_.push_back(TableBase::ColumnInfo("ts", "INTEGER"));
36     tableColumn_.push_back(TableBase::ColumnInfo("dur", "INTEGER"));
37     tableColumn_.push_back(TableBase::ColumnInfo("tx", "INTEGER"));
38     tableColumn_.push_back(TableBase::ColumnInfo("rx", "INTEGER"));
39     tableColumn_.push_back(TableBase::ColumnInfo("tx_speed", "REAL"));
40     tableColumn_.push_back(TableBase::ColumnInfo("rx_speed", "REAL"));
41     tableColumn_.push_back(TableBase::ColumnInfo("packet_in", "INTEGER"));
42     tableColumn_.push_back(TableBase::ColumnInfo("packet_in_sec", "REAL"));
43     tableColumn_.push_back(TableBase::ColumnInfo("packet_out", "INTEGER"));
44     tableColumn_.push_back(TableBase::ColumnInfo("packet_out_sec", "REAL"));
45     tableColumn_.push_back(TableBase::ColumnInfo("net_type", "TEXT"));
46     tablePriKey_.push_back("ts");
47 }
48 
~NetworkTable()49 NetworkTable::~NetworkTable() {}
50 
CreateCursor()51 std::unique_ptr<TableBase::Cursor> NetworkTable::CreateCursor()
52 {
53     return std::make_unique<Cursor>(dataCache_, this);
54 }
55 
Cursor(const TraceDataCache * dataCache,TableBase * table)56 NetworkTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
57     : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstNetworkData().Size())),
58       networkDataObj_(dataCache->GetConstNetworkData())
59 {
60 }
61 
~Cursor()62 NetworkTable::Cursor::~Cursor() {}
63 
Column(int32_t column) const64 int32_t NetworkTable::Cursor::Column(int32_t column) const
65 {
66     switch (static_cast<Index>(column)) {
67         case Index::TS: {
68             sqlite3_result_int64(context_, static_cast<int64_t>(networkDataObj_.TimeStampData()[CurrentRow()]));
69             break;
70         }
71         case Index::TX: {
72             sqlite3_result_int64(context_, static_cast<int64_t>(networkDataObj_.TxDatas()[CurrentRow()]));
73             break;
74         }
75         case Index::RX: {
76             sqlite3_result_int64(context_, static_cast<int64_t>(networkDataObj_.RxDatas()[CurrentRow()]));
77             break;
78         }
79         case Index::DUR: {
80             sqlite3_result_int64(context_, static_cast<int64_t>(networkDataObj_.Durs()[CurrentRow()]));
81             break;
82         }
83         case Index::TX_SPEED: {
84             sqlite3_result_double(context_, static_cast<double>(networkDataObj_.TxSpeed()[CurrentRow()]));
85             break;
86             default:
87                 HandleTypeColumns(column);
88         }
89     }
90     return SQLITE_OK;
91 }
HandleTypeColumns(int32_t networkColumn) const92 void NetworkTable::Cursor::HandleTypeColumns(int32_t networkColumn) const
93 {
94     switch (static_cast<Index>(networkColumn)) {
95         case Index::RX_SPEED: {
96             sqlite3_result_double(context_,
97                                   static_cast<double>(dataCache_->GetConstNetworkData().RxSpeed()[CurrentRow()]));
98             break;
99         }
100         case Index::PACKET_IN: {
101             sqlite3_result_int64(context_,
102                                  static_cast<int64_t>(dataCache_->GetConstNetworkData().PacketIn()[CurrentRow()]));
103             break;
104         }
105         case Index::PACKET_IN_SEC: {
106             sqlite3_result_double(context_,
107                                   static_cast<double>(dataCache_->GetConstNetworkData().PacketInSec()[CurrentRow()]));
108             break;
109         }
110         case Index::PACKET_OUT: {
111             sqlite3_result_int64(context_,
112                                  static_cast<double>(dataCache_->GetConstNetworkData().PacketOut()[CurrentRow()]));
113             break;
114         }
115         case Index::PACKET_OUT_SEC: {
116             sqlite3_result_double(context_,
117                                   static_cast<double>(dataCache_->GetConstNetworkData().PacketOutSec()[CurrentRow()]));
118             break;
119         }
120         case Index::NET_TYPE: {
121             sqlite3_result_text(context_, dataCache_->GetConstNetworkData().NetTypes()[CurrentRow()].c_str(),
122                                 STR_DEFAULT_LEN, nullptr);
123             break;
124         }
125         default:
126             TS_LOGF("Unregistered networkColumn : %d", networkColumn);
127             break;
128     }
129 }
130 } // namespace TraceStreamer
131 } // namespace SysTuning
132