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 "network_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum Index {
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 (column) {
67 case TS: {
68 sqlite3_result_int64(context_, static_cast<int64_t>(networkDataObj_.TimeStampData()[CurrentRow()]));
69 break;
70 }
71 case TX: {
72 sqlite3_result_int64(context_, static_cast<int64_t>(networkDataObj_.TxDatas()[CurrentRow()]));
73 break;
74 }
75 case RX: {
76 sqlite3_result_int64(context_, static_cast<int64_t>(networkDataObj_.RxDatas()[CurrentRow()]));
77 break;
78 }
79 case DUR: {
80 sqlite3_result_int64(context_, static_cast<int64_t>(networkDataObj_.Durs()[CurrentRow()]));
81 break;
82 }
83 case TX_SPEED: {
84 sqlite3_result_double(context_, static_cast<double>(networkDataObj_.TxSpeed()[CurrentRow()]));
85 break;
86 }
87 case RX_SPEED: {
88 sqlite3_result_double(context_,
89 static_cast<double>(dataCache_->GetConstNetworkData().RxSpeed()[CurrentRow()]));
90 break;
91 }
92 case PACKET_IN: {
93 sqlite3_result_int64(context_,
94 static_cast<int64_t>(dataCache_->GetConstNetworkData().PacketIn()[CurrentRow()]));
95 break;
96 }
97 case PACKET_IN_SEC: {
98 sqlite3_result_double(context_,
99 static_cast<double>(dataCache_->GetConstNetworkData().PacketInSec()[CurrentRow()]));
100 break;
101 }
102 case PACKET_OUT: {
103 sqlite3_result_int64(context_,
104 static_cast<double>(dataCache_->GetConstNetworkData().PacketOut()[CurrentRow()]));
105 break;
106 }
107 case PACKET_OUT_SEC: {
108 sqlite3_result_double(context_,
109 static_cast<double>(dataCache_->GetConstNetworkData().PacketOutSec()[CurrentRow()]));
110 break;
111 }
112 case NET_TYPE: {
113 sqlite3_result_text(context_, dataCache_->GetConstNetworkData().NetTypes()[CurrentRow()].c_str(),
114 STR_DEFAULT_LEN, nullptr);
115 break;
116 }
117 default:
118 TS_LOGF("Unregistered column : %d", column);
119 break;
120 }
121 return SQLITE_OK;
122 }
123 } // namespace TraceStreamer
124 } // namespace SysTuning
125