1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
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 "perf_report_table.h"
17
18 namespace SysTuning {
19 namespace TraceStreamer {
20 namespace {
21 enum Index { ID = 0, REPORT_TYPE, REPORT_VALUE, };
22 }
PerfReportTable(const TraceDataCache * dataCache)23 PerfReportTable::PerfReportTable(const TraceDataCache* dataCache) : TableBase(dataCache)
24 {
25 tableColumn_.push_back(TableBase::ColumnInfo("id", "INTEGER"));
26 tableColumn_.push_back(TableBase::ColumnInfo("report_type", "TEXT"));
27 tableColumn_.push_back(TableBase::ColumnInfo("report_value", "TEXT"));
28 tablePriKey_.push_back("id");
29 }
30
~PerfReportTable()31 PerfReportTable::~PerfReportTable() {}
32
CreateCursor()33 std::unique_ptr<TableBase::Cursor> PerfReportTable::CreateCursor()
34 {
35 return std::make_unique<Cursor>(dataCache_, this);
36 }
37
Cursor(const TraceDataCache * dataCache,TableBase * table)38 PerfReportTable::Cursor::Cursor(const TraceDataCache* dataCache, TableBase* table)
39 : TableBase::Cursor(dataCache, table, static_cast<uint32_t>(dataCache->GetConstPerfReportData().Size())),
40 perfReportObj_(dataCache->GetConstPerfReportData())
41 {
42 }
43
~Cursor()44 PerfReportTable::Cursor::~Cursor() {}
45
Column(int column) const46 int PerfReportTable::Cursor::Column(int column) const
47 {
48 switch (column) {
49 case ID:
50 sqlite3_result_int64(context_, static_cast<int64_t>(perfReportObj_.IdsData()[CurrentRow()]));
51 break;
52 case REPORT_TYPE:
53 if (perfReportObj_.Types()[CurrentRow()] != INVALID_UINT64) {
54 auto typeIndex = static_cast<size_t>(perfReportObj_.Types()[CurrentRow()]);
55 sqlite3_result_text(context_, dataCache_->GetDataFromDict(typeIndex).c_str(), STR_DEFAULT_LEN, nullptr);
56 }
57 break;
58 case REPORT_VALUE:
59 if (perfReportObj_.Values()[CurrentRow()] != INVALID_UINT64) {
60 auto typeValueIndex = static_cast<size_t>(perfReportObj_.Values()[CurrentRow()]);
61 sqlite3_result_text(context_, dataCache_->GetDataFromDict(typeValueIndex).c_str(), STR_DEFAULT_LEN,
62 nullptr);
63 }
64 break;
65 default:
66 TS_LOGF("Unregistered column : %d", column);
67 break;
68 }
69 return SQLITE_OK;
70 }
71 } // namespace TraceStreamer
72 } // namespace SysTuning
73