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 "sysevent_all_event_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 enum class Index : int32_t {
21 ID = 0,
22 DOMAIN_ID,
23 EVENT_NAME_ID,
24 TS,
25 TYPE,
26 TIME_ZONE,
27 PID,
28 TID,
29 UID,
30 LEVEL,
31 TAG,
32 EVENT_ID,
33 SEQ,
34 INFO,
35 CONTEXT
36 };
SysEventAllEventTable(const TraceDataCache * dataCache)37 SysEventAllEventTable::SysEventAllEventTable(const TraceDataCache *dataCache) : TableBase(dataCache)
38 {
39 tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
40 tableColumn_.push_back(TableBase::ColumnInfo("domain_id", "INTEGER"));
41 tableColumn_.push_back(TableBase::ColumnInfo("event_name_id", "INTEGER"));
42 tableColumn_.push_back(TableBase::ColumnInfo("ts", "INTEGER"));
43 tableColumn_.push_back(TableBase::ColumnInfo("type", "INTEGER"));
44 tableColumn_.push_back(TableBase::ColumnInfo("time_zone", "TEXT"));
45 tableColumn_.push_back(TableBase::ColumnInfo("pid", "INTEGER"));
46 tableColumn_.push_back(TableBase::ColumnInfo("tid", "INTEGER"));
47 tableColumn_.push_back(TableBase::ColumnInfo("uid", "INTEGER"));
48 tableColumn_.push_back(TableBase::ColumnInfo("level", "TEXT"));
49 tableColumn_.push_back(TableBase::ColumnInfo("tag", "TEXT"));
50 tableColumn_.push_back(TableBase::ColumnInfo("event_id", "TEXT"));
51 tableColumn_.push_back(TableBase::ColumnInfo("seq", "INTEGER"));
52 tableColumn_.push_back(TableBase::ColumnInfo("info", "TEXT"));
53 tableColumn_.push_back(TableBase::ColumnInfo("contents", "TEXT"));
54 tablePriKey_.push_back("id");
55 }
56
~SysEventAllEventTable()57 SysEventAllEventTable::~SysEventAllEventTable() {}
58
CreateCursor()59 std::unique_ptr<TableBase::Cursor> SysEventAllEventTable::CreateCursor()
60 {
61 return std::make_unique<Cursor>(dataCache_, this);
62 }
63
Cursor(const TraceDataCache * dataCache,TableBase * table)64 SysEventAllEventTable::Cursor::Cursor(const TraceDataCache *dataCache, TableBase *table)
65 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstHiSysEventAllEventData().Size())),
66 hiSysEventAllEventObj_(dataCache->GetConstHiSysEventAllEventData())
67 {
68 }
69
~Cursor()70 SysEventAllEventTable::Cursor::~Cursor() {}
Column(int32_t column) const71 int32_t SysEventAllEventTable::Cursor::Column(int32_t column) const
72 {
73 switch (static_cast<Index>(column)) {
74 case Index::ID:
75 sqlite3_result_int64(context_, hiSysEventAllEventObj_.IdsData()[CurrentRow()]);
76 break;
77 case Index::DOMAIN_ID:
78 sqlite3_result_int64(context_, hiSysEventAllEventObj_.DomainIds()[CurrentRow()]);
79 break;
80 case Index::EVENT_NAME_ID:
81 sqlite3_result_int64(context_, hiSysEventAllEventObj_.EventNameIds()[CurrentRow()]);
82 break;
83 case Index::TS:
84 sqlite3_result_int64(context_, hiSysEventAllEventObj_.TimeStampData()[CurrentRow()]);
85 break;
86 case Index::TYPE:
87 sqlite3_result_int(context_, hiSysEventAllEventObj_.Types()[CurrentRow()]);
88 break;
89 case Index::TIME_ZONE:
90 sqlite3_result_text(context_, hiSysEventAllEventObj_.TimeZones()[CurrentRow()].c_str(), STR_DEFAULT_LEN,
91 nullptr);
92 break;
93 case Index::PID:
94 sqlite3_result_int(context_, hiSysEventAllEventObj_.Pids()[CurrentRow()]);
95 break;
96 case Index::TID:
97 sqlite3_result_int(context_, hiSysEventAllEventObj_.Tids()[CurrentRow()]);
98 break;
99 case Index::UID:
100 sqlite3_result_int(context_, hiSysEventAllEventObj_.Uids()[CurrentRow()]);
101 break;
102 default:
103 HandleTypeColumns(column);
104 }
105 return SQLITE_OK;
106 }
HandleTypeColumns(int32_t sysEventAllEventColumn) const107 void SysEventAllEventTable::Cursor::HandleTypeColumns(int32_t sysEventAllEventColumn) const
108 {
109 switch (static_cast<Index>(sysEventAllEventColumn)) {
110 case Index::LEVEL:
111 sqlite3_result_text(context_, hiSysEventAllEventObj_.Levels()[CurrentRow()].c_str(), STR_DEFAULT_LEN,
112 nullptr);
113 break;
114 case Index::TAG:
115 sqlite3_result_text(context_, hiSysEventAllEventObj_.Tags()[CurrentRow()].c_str(), STR_DEFAULT_LEN,
116 nullptr);
117 break;
118 case Index::EVENT_ID:
119 sqlite3_result_text(context_, hiSysEventAllEventObj_.EventIds()[CurrentRow()].c_str(), STR_DEFAULT_LEN,
120 nullptr);
121 break;
122 case Index::SEQ:
123 sqlite3_result_int(context_, hiSysEventAllEventObj_.Seqs()[CurrentRow()]);
124 break;
125 case Index::INFO:
126 sqlite3_result_text(context_, hiSysEventAllEventObj_.Infos()[CurrentRow()].c_str(), STR_DEFAULT_LEN,
127 nullptr);
128 break;
129 case Index::CONTEXT:
130 sqlite3_result_text(context_, hiSysEventAllEventObj_.Contents()[CurrentRow()].c_str(), STR_DEFAULT_LEN,
131 nullptr);
132 break;
133 default:
134 TS_LOGF("Unregistered sysEventAllEventColumn : %d", sysEventAllEventColumn);
135 break;
136 }
137 }
138 } // namespace TraceStreamer
139 } // namespace SysTuning
140