• 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 "cpu_usage_info_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t { TS = 0, DUR, TOTAL_LOAD, USER_LOAD, SYSTEM_LOAD, THREADS };
CpuUsageInfoTable(const TraceDataCache * dataCache)21 CpuUsageInfoTable::CpuUsageInfoTable(const TraceDataCache *dataCache) : TableBase(dataCache)
22 {
23     tableColumn_.push_back(TableBase::ColumnInfo("ts", "INTEGER"));
24     tableColumn_.push_back(TableBase::ColumnInfo("dur", "INTEGER"));
25     tableColumn_.push_back(TableBase::ColumnInfo("total_load", "REAL"));
26     tableColumn_.push_back(TableBase::ColumnInfo("user_load", "REAL"));
27     tableColumn_.push_back(TableBase::ColumnInfo("system_load", "REAL"));
28     tableColumn_.push_back(TableBase::ColumnInfo("process_num", "INTEGER"));
29     tablePriKey_.push_back("ts");
30 }
31 
~CpuUsageInfoTable()32 CpuUsageInfoTable::~CpuUsageInfoTable() {}
33 
CreateCursor()34 std::unique_ptr<TableBase::Cursor> CpuUsageInfoTable::CreateCursor()
35 {
36     return std::make_unique<Cursor>(dataCache_, this);
37 }
38 
Cursor(const TraceDataCache * dataCache,TableBase * table)39 CpuUsageInfoTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
40     : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstCpuUsageInfoData().Size())),
41       cpuUsageInfoObj_(dataCache->GetConstCpuUsageInfoData())
42 {
43 }
44 
~Cursor()45 CpuUsageInfoTable::Cursor::~Cursor() {}
46 
Column(int32_t cpuUsageInfoColumn) const47 int32_t CpuUsageInfoTable::Cursor::Column(int32_t cpuUsageInfoColumn) const
48 {
49     switch (static_cast<Index>(cpuUsageInfoColumn)) {
50         case Index::TS: {
51             sqlite3_result_int64(context_, static_cast<int64_t>(cpuUsageInfoObj_.TimeStampData()[CurrentRow()]));
52             break;
53         }
54         case Index::DUR: {
55             sqlite3_result_int64(context_, static_cast<int64_t>(cpuUsageInfoObj_.Durs()[CurrentRow()]));
56             break;
57         }
58         case Index::TOTAL_LOAD: {
59             sqlite3_result_int64(context_, static_cast<int64_t>(cpuUsageInfoObj_.TotalLoad()[CurrentRow()]));
60             break;
61         }
62         case Index::USER_LOAD: {
63             sqlite3_result_double(context_, cpuUsageInfoObj_.UserLoad()[CurrentRow()]);
64             break;
65         }
66         case Index::SYSTEM_LOAD: {
67             sqlite3_result_double(context_, cpuUsageInfoObj_.SystemLoad()[CurrentRow()]);
68             break;
69         }
70         case Index::THREADS: {
71             sqlite3_result_int(context_, static_cast<int32_t>(cpuUsageInfoObj_.Threads()[CurrentRow()]));
72             break;
73         }
74         default:
75             TS_LOGF("Unregistered cpuUsageInfoColumn : %d", cpuUsageInfoColumn);
76             break;
77     }
78     return SQLITE_OK;
79 }
80 } // namespace TraceStreamer
81 } // namespace SysTuning
82