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_component_top_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t {
21 ID = 0,
22 COMPONENT_TYPE,
23 START_TIME,
24 APPNAME,
25 BACKGROUND_DURATION,
26 BACKGROUND_ENERGY,
27 FOREGROUND_DURATION,
28 FOREGROUND_ENERGY,
29 SCREEN_OFF_DURATION,
30 SCREEN_OFF_ENERGY,
31 SCREEN_ON_DURATION,
32 SCREEN_ON_ENERGY,
33 CAMERA_ID,
34 UID,
35 LOAD,
36 APP_USAGE_DURATION,
37 APP_USAGE_ENERGY
38 };
XpowerComponentTopTable(const TraceDataCache * dataCache)39 XpowerComponentTopTable::XpowerComponentTopTable(const TraceDataCache *dataCache) : TableBase(dataCache)
40 {
41 tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
42 tableColumn_.push_back(TableBase::ColumnInfo("component_type_id", "INTEGER"));
43 tableColumn_.push_back(TableBase::ColumnInfo("start_time", "INTEGER"));
44 tableColumn_.push_back(TableBase::ColumnInfo("appname", "INTEGER"));
45 tableColumn_.push_back(TableBase::ColumnInfo("background_duration", "INTEGER"));
46 tableColumn_.push_back(TableBase::ColumnInfo("background_energy", "INTEGER"));
47 tableColumn_.push_back(TableBase::ColumnInfo("foreground_duration", "INTEGER"));
48 tableColumn_.push_back(TableBase::ColumnInfo("foreground_energy", "INTEGER"));
49 tableColumn_.push_back(TableBase::ColumnInfo("screen_off_duration", "INTEGER"));
50 tableColumn_.push_back(TableBase::ColumnInfo("screen_off_energy", "INTEGER"));
51 tableColumn_.push_back(TableBase::ColumnInfo("screen_on_duration", "INTEGER"));
52 tableColumn_.push_back(TableBase::ColumnInfo("screen_on_energy", "INTEGER"));
53 tableColumn_.push_back(TableBase::ColumnInfo("camera_id", "INTEGER"));
54 tableColumn_.push_back(TableBase::ColumnInfo("uid", "INTEGER"));
55 tableColumn_.push_back(TableBase::ColumnInfo("load", "INTEGER"));
56 tableColumn_.push_back(TableBase::ColumnInfo("app_usage_duration", "INTEGER"));
57 tableColumn_.push_back(TableBase::ColumnInfo("app_usage_energy", "INTEGER"));
58 tablePriKey_.push_back("id");
59 }
60
~XpowerComponentTopTable()61 XpowerComponentTopTable::~XpowerComponentTopTable() {}
62
CreateCursor()63 std::unique_ptr<TableBase::Cursor> XpowerComponentTopTable::CreateCursor()
64 {
65 return std::make_unique<Cursor>(dataCache_, this);
66 }
67
Cursor(const TraceDataCache * dataCache,TableBase * table)68 XpowerComponentTopTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
69 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstXPowerComponentTopInfo().Size())),
70 xPowerComponentTopObj_(dataCache->GetConstXPowerComponentTopInfo())
71 {
72 }
73
~Cursor()74 XpowerComponentTopTable::Cursor::~Cursor() {}
Column(int32_t column) const75 int32_t XpowerComponentTopTable::Cursor::Column(int32_t column) const
76 {
77 switch (static_cast<Index>(column)) {
78 case Index::ID:
79 sqlite3_result_int64(context_, xPowerComponentTopObj_.IdsData()[CurrentRow()]);
80 break;
81 case Index::COMPONENT_TYPE:
82 sqlite3_result_int64(context_, xPowerComponentTopObj_.ComponentTypesData()[CurrentRow()]);
83 break;
84 case Index::START_TIME:
85 SetTypeColumnInt64(xPowerComponentTopObj_.TimeStampData()[CurrentRow()], INVALID_INT64);
86 break;
87 case Index::APPNAME:
88 SetTypeColumnInt64(xPowerComponentTopObj_.AppnamesData()[CurrentRow()], INVALID_INT64);
89 break;
90 case Index::BACKGROUND_DURATION:
91 SetTypeColumnInt64(xPowerComponentTopObj_.BackgroundDurationsData()[CurrentRow()], INVALID_INT64);
92 break;
93 case Index::BACKGROUND_ENERGY:
94 SetTypeColumnInt64(xPowerComponentTopObj_.BackgroundEnergysData()[CurrentRow()], INVALID_INT64);
95 break;
96 case Index::FOREGROUND_DURATION:
97 SetTypeColumnInt64(xPowerComponentTopObj_.ForegroundDurationsData()[CurrentRow()], INVALID_INT64);
98 break;
99 case Index::FOREGROUND_ENERGY:
100 SetTypeColumnInt64(xPowerComponentTopObj_.ForegroundEnergysData()[CurrentRow()], INVALID_INT64);
101 break;
102 case Index::SCREEN_OFF_DURATION:
103 SetTypeColumnInt64(xPowerComponentTopObj_.ScreenOffDurationsData()[CurrentRow()], INVALID_INT64);
104 break;
105 case Index::SCREEN_OFF_ENERGY:
106 SetTypeColumnInt64(xPowerComponentTopObj_.ScreenOffEnergysData()[CurrentRow()], INVALID_INT64);
107 break;
108 case Index::SCREEN_ON_DURATION:
109 SetTypeColumnInt64(xPowerComponentTopObj_.ScreenOnDurationsData()[CurrentRow()], INVALID_INT64);
110 break;
111 case Index::SCREEN_ON_ENERGY:
112 SetTypeColumnInt64(xPowerComponentTopObj_.ScreenOnEnergysData()[CurrentRow()], INVALID_INT64);
113 break;
114 case Index::CAMERA_ID:
115 SetTypeColumnInt64(xPowerComponentTopObj_.CameraIdsData()[CurrentRow()], INVALID_INT64);
116 break;
117 case Index::UID:
118 SetTypeColumnInt64(xPowerComponentTopObj_.UidsData()[CurrentRow()], INVALID_INT64);
119 break;
120 case Index::LOAD:
121 SetTypeColumnInt64(xPowerComponentTopObj_.LoadsData()[CurrentRow()], INVALID_INT64);
122 break;
123 case Index::APP_USAGE_DURATION:
124 SetTypeColumnInt64(xPowerComponentTopObj_.AppUsageDurationsData()[CurrentRow()], INVALID_INT64);
125 break;
126 case Index::APP_USAGE_ENERGY:
127 SetTypeColumnInt64(xPowerComponentTopObj_.AppUsageEnergysData()[CurrentRow()], INVALID_INT64);
128 break;
129 default:
130 TS_LOGF("Unregistered column : %d", column);
131 break;
132 }
133 return SQLITE_OK;
134 }
135 } // namespace TraceStreamer
136 } // namespace SysTuning
137