• 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 "disk_io_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t {
21     TS = 0,
22     DUR,
23     RD,
24     WR,
25     RD_SPEED,
26     WR_SPEED,
27     RD_COUNT,
28     WR_COUNT,
29     RD_COUNT_SPEED,
30     WR_COUNT_SPEED,
31 };
DiskIOTable(const TraceDataCache * dataCache)32 DiskIOTable::DiskIOTable(const TraceDataCache *dataCache) : TableBase(dataCache)
33 {
34     tableColumn_.push_back(TableBase::ColumnInfo("ts", "INTEGER"));
35     tableColumn_.push_back(TableBase::ColumnInfo("dur", "INTEGER"));
36     tableColumn_.push_back(TableBase::ColumnInfo("rd", "INTEGER"));
37     tableColumn_.push_back(TableBase::ColumnInfo("wr", "INTEGER"));
38     tableColumn_.push_back(TableBase::ColumnInfo("rd_speed", "REAL"));
39     tableColumn_.push_back(TableBase::ColumnInfo("wr_speed", "REAL"));
40     tableColumn_.push_back(TableBase::ColumnInfo("rd_count", "INTEGER"));
41     tableColumn_.push_back(TableBase::ColumnInfo("wr_count", "INTEGER"));
42     tableColumn_.push_back(TableBase::ColumnInfo("rd_count_speed", "REAL"));
43     tableColumn_.push_back(TableBase::ColumnInfo("wr_count_speed", "REAL"));
44     tablePriKey_.push_back("ts");
45 }
46 
~DiskIOTable()47 DiskIOTable::~DiskIOTable() {}
48 
CreateCursor()49 std::unique_ptr<TableBase::Cursor> DiskIOTable::CreateCursor()
50 {
51     return std::make_unique<Cursor>(dataCache_, this);
52 }
53 
Cursor(const TraceDataCache * dataCache,TableBase * table)54 DiskIOTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
55     : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstDiskIOData().Size())),
56       diskIODataObj_(dataCache->GetConstDiskIOData())
57 {
58 }
59 
~Cursor()60 DiskIOTable::Cursor::~Cursor() {}
61 
Column(int32_t diskIoColumn) const62 int32_t DiskIOTable::Cursor::Column(int32_t diskIoColumn) const
63 {
64     switch (static_cast<Index>(diskIoColumn)) {
65         case Index::TS: {
66             sqlite3_result_int64(context_, static_cast<int64_t>(diskIODataObj_.TimeStampData()[CurrentRow()]));
67             break;
68         }
69         case Index::DUR: {
70             sqlite3_result_int64(context_, static_cast<int64_t>(diskIODataObj_.Durs()[CurrentRow()]));
71             break;
72         }
73         case Index::RD: {
74             sqlite3_result_int64(context_, static_cast<int64_t>(diskIODataObj_.RdDatas()[CurrentRow()]));
75             break;
76         }
77         case Index::WR: {
78             sqlite3_result_int64(context_, static_cast<int64_t>(diskIODataObj_.WrDatas()[CurrentRow()]));
79             break;
80         }
81         case Index::RD_SPEED: {
82             sqlite3_result_double(context_, static_cast<double>(diskIODataObj_.RdSpeedDatas()[CurrentRow()]));
83             break;
84         }
85         case Index::WR_SPEED: {
86             sqlite3_result_double(context_, static_cast<double>(diskIODataObj_.WrSpeedDatas()[CurrentRow()]));
87             break;
88         }
89         case Index::RD_COUNT: {
90             sqlite3_result_int64(context_, static_cast<int64_t>(diskIODataObj_.RdCountDatas()[CurrentRow()]));
91             break;
92         }
93         case Index::WR_COUNT: {
94             sqlite3_result_int64(context_, static_cast<int64_t>(diskIODataObj_.WrCountDatas()[CurrentRow()]));
95             break;
96         }
97         case Index::RD_COUNT_SPEED: {
98             sqlite3_result_double(context_, static_cast<double>(diskIODataObj_.RdCountPerSecDatas()[CurrentRow()]));
99             break;
100         }
101         case Index::WR_COUNT_SPEED: {
102             sqlite3_result_double(context_, static_cast<double>(diskIODataObj_.WrCountPerSecDatas()[CurrentRow()]));
103             break;
104         }
105         default:
106             TS_LOGF("Unregistered diskIoColumn : %d", diskIoColumn);
107             break;
108     }
109     return SQLITE_OK;
110 }
111 } // namespace TraceStreamer
112 } // namespace SysTuning
113