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