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 "app_startup_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t { ID = 0, CALL_ID, IPID, TID, START_TIME, END_TIME, START_NAME, PACKED_NAME };
AppStartupTable(const TraceDataCache * dataCache)21 AppStartupTable::AppStartupTable(const TraceDataCache *dataCache) : TableBase(dataCache)
22 {
23 tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
24 tableColumn_.push_back(TableBase::ColumnInfo("call_id", "INTEGER"));
25 tableColumn_.push_back(TableBase::ColumnInfo("ipid", "INTEGER"));
26 tableColumn_.push_back(TableBase::ColumnInfo("tid", "INTEGER"));
27 tableColumn_.push_back(TableBase::ColumnInfo("start_time", "INTEGER"));
28 tableColumn_.push_back(TableBase::ColumnInfo("end_time", "INTEGER"));
29 tableColumn_.push_back(TableBase::ColumnInfo("start_name", "INTEGER"));
30 tableColumn_.push_back(TableBase::ColumnInfo("packed_name", "TEXT"));
31 tablePriKey_.push_back("id");
32 }
33
~AppStartupTable()34 AppStartupTable::~AppStartupTable() {}
35
CreateCursor()36 std::unique_ptr<TableBase::Cursor> AppStartupTable::CreateCursor()
37 {
38 return std::make_unique<Cursor>(dataCache_, this);
39 }
40
Cursor(const TraceDataCache * dataCache,TableBase * table)41 AppStartupTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
42 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstAppStartupData().Size())),
43 appStartupObj_(dataCache->GetConstAppStartupData())
44 {
45 }
46
~Cursor()47 AppStartupTable::Cursor::~Cursor() {}
48
Column(int32_t appStartupCol) const49 int32_t AppStartupTable::Cursor::Column(int32_t appStartupCol) const
50 {
51 switch (static_cast<Index>(appStartupCol)) {
52 case Index::ID:
53 sqlite3_result_int64(context_, static_cast<int32_t>(CurrentRow()));
54 break;
55 case Index::CALL_ID:
56 sqlite3_result_int64(context_, static_cast<int64_t>(appStartupObj_.CallIds()[CurrentRow()]));
57 break;
58 case Index::IPID:
59 sqlite3_result_int64(context_, static_cast<int64_t>(appStartupObj_.Pids()[CurrentRow()]));
60 break;
61 case Index::TID:
62 sqlite3_result_int64(context_, static_cast<int64_t>(appStartupObj_.Tids()[CurrentRow()]));
63 break;
64 case Index::START_TIME:
65 sqlite3_result_int64(context_, static_cast<int64_t>(appStartupObj_.StartTimes()[CurrentRow()]));
66 break;
67 case Index::END_TIME:
68 sqlite3_result_int64(context_, static_cast<int64_t>(appStartupObj_.EndTimes()[CurrentRow()]));
69 break;
70 case Index::START_NAME:
71 sqlite3_result_int64(context_, static_cast<int64_t>(appStartupObj_.StartNames()[CurrentRow()]));
72 break;
73 case Index::PACKED_NAME:
74 sqlite3_result_text(context_,
75 dataCache_->GetDataFromDict(appStartupObj_.PackedNames()[CurrentRow()]).c_str(),
76 STR_DEFAULT_LEN, nullptr);
77 break;
78 default:
79 TS_LOGF("Unregistered appStartupCol : %d", appStartupCol);
80 break;
81 }
82 return SQLITE_OK;
83 }
84 } // namespace TraceStreamer
85 } // namespace SysTuning
86