• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2024. 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 "xpower_app_statistic_table.h"
17 
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t { ID = 0, COMPONENT_TYPE, START_TIME, DURATION, ENERGYS };
XpowerAppStatisticTable(const TraceDataCache * dataCache)21 XpowerAppStatisticTable::XpowerAppStatisticTable(const TraceDataCache *dataCache) : TableBase(dataCache)
22 {
23     tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
24     tableColumn_.push_back(TableBase::ColumnInfo("component_type_id", "INTEGER"));
25     tableColumn_.push_back(TableBase::ColumnInfo("start_time", "INTEGER"));
26     tableColumn_.push_back(TableBase::ColumnInfo("duration", "INTEGER"));
27     tableColumn_.push_back(TableBase::ColumnInfo("energy", "INTEGER"));
28     tablePriKey_.push_back("id");
29 }
30 
~XpowerAppStatisticTable()31 XpowerAppStatisticTable::~XpowerAppStatisticTable() {}
32 
CreateCursor()33 std::unique_ptr<TableBase::Cursor> XpowerAppStatisticTable::CreateCursor()
34 {
35     return std::make_unique<Cursor>(dataCache_, this);
36 }
37 
Cursor(const TraceDataCache * dataCache,TableBase * table)38 XpowerAppStatisticTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
39     : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstXPowerAppStatisticInfo().Size())),
40       xPowerAppStatisticObj_(dataCache->GetConstXPowerAppStatisticInfo())
41 {
42 }
43 
~Cursor()44 XpowerAppStatisticTable::Cursor::~Cursor() {}
Column(int32_t column) const45 int32_t XpowerAppStatisticTable::Cursor::Column(int32_t column) const
46 {
47     switch (static_cast<Index>(column)) {
48         case Index::ID:
49             sqlite3_result_int64(context_, xPowerAppStatisticObj_.IdsData()[CurrentRow()]);
50             break;
51         case Index::COMPONENT_TYPE:
52             sqlite3_result_int64(context_, xPowerAppStatisticObj_.ComponentTypesData()[CurrentRow()]);
53             break;
54         case Index::START_TIME:
55             SetTypeColumnInt64(xPowerAppStatisticObj_.TimeStampData()[CurrentRow()], INVALID_INT64);
56             break;
57         case Index::DURATION:
58             SetTypeColumnInt64(xPowerAppStatisticObj_.DurationsData()[CurrentRow()], INVALID_INT64);
59             break;
60         case Index::ENERGYS:
61             SetTypeColumnInt64(xPowerAppStatisticObj_.EnergysData()[CurrentRow()], INVALID_INT64);
62             break;
63         default:
64             TS_LOGF("Unregistered column : %d", column);
65             break;
66     }
67     return SQLITE_OK;
68 }
69 } // namespace TraceStreamer
70 } // namespace SysTuning
71